vm: cleanup
							parent
							
								
									e2fcec6a99
								
							
						
					
					
						commit
						d10e27149c
					
				| 
						 | 
					@ -466,7 +466,7 @@ code_block *factor_vm::add_code_block(cell type, cell code_, cell labels_, cell
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* next time we do a minor GC, we have to scan the code heap for
 | 
						/* next time we do a minor GC, we have to scan the code heap for
 | 
				
			||||||
	literals */
 | 
						literals */
 | 
				
			||||||
	last_code_heap_scan = data->nursery();
 | 
						this->code->last_code_heap_scan = data->nursery();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return compiled;
 | 
						return compiled;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,10 +3,12 @@
 | 
				
			||||||
namespace factor
 | 
					namespace factor
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					code_heap::code_heap(factor_vm *myvm, cell size) : heap(myvm,size) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Allocate a code heap during startup */
 | 
					/* Allocate a code heap during startup */
 | 
				
			||||||
void factor_vm::init_code_heap(cell size)
 | 
					void factor_vm::init_code_heap(cell size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	code = new heap(this,size);
 | 
						code = new code_heap(this,size);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool factor_vm::in_code_heap_p(cell ptr)
 | 
					bool factor_vm::in_code_heap_p(cell ptr)
 | 
				
			||||||
| 
						 | 
					@ -28,6 +30,16 @@ void factor_vm::jit_compile_word(cell word_, cell def_, bool relocate)
 | 
				
			||||||
	if(word->pic_tail_def != F) jit_compile(word->pic_tail_def,relocate);
 | 
						if(word->pic_tail_def != F) jit_compile(word->pic_tail_def,relocate);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct word_updater {
 | 
				
			||||||
 | 
						factor_vm *myvm;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						explicit word_updater(factor_vm *myvm_) : myvm(myvm_) {}
 | 
				
			||||||
 | 
						void operator()(code_block *compiled)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							myvm->update_word_references(compiled);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Update pointers to words referenced from all code blocks. Only after
 | 
					/* Update pointers to words referenced from all code blocks. Only after
 | 
				
			||||||
defining a new word. */
 | 
					defining a new word. */
 | 
				
			||||||
void factor_vm::update_code_heap_words()
 | 
					void factor_vm::update_code_heap_words()
 | 
				
			||||||
| 
						 | 
					@ -100,7 +112,7 @@ void factor_vm::primitive_code_room()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
code_block *factor_vm::forward_xt(code_block *compiled)
 | 
					code_block *factor_vm::forward_xt(code_block *compiled)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	return (code_block *)forwarding[compiled];
 | 
						return (code_block *)code->forwarding[compiled];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct xt_forwarder {
 | 
					struct xt_forwarder {
 | 
				
			||||||
| 
						 | 
					@ -199,13 +211,13 @@ void factor_vm::compact_code_heap()
 | 
				
			||||||
	garbage_collection(data->tenured(),false,false,0);
 | 
						garbage_collection(data->tenured(),false,false,0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Figure out where the code heap blocks are going to end up */
 | 
						/* Figure out where the code heap blocks are going to end up */
 | 
				
			||||||
	cell size = code->compute_heap_forwarding(forwarding);
 | 
						cell size = code->compute_heap_forwarding();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Update word and quotation code pointers */
 | 
						/* Update word and quotation code pointers */
 | 
				
			||||||
	forward_object_xts();
 | 
						forward_object_xts();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Actually perform the compaction */
 | 
						/* Actually perform the compaction */
 | 
				
			||||||
	code->compact_heap(forwarding);
 | 
						code->compact_heap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Update word and quotation XTs */
 | 
						/* Update word and quotation XTs */
 | 
				
			||||||
	fixup_object_xts();
 | 
						fixup_object_xts();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,21 +1,14 @@
 | 
				
			||||||
namespace factor
 | 
					namespace factor
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
inline void factor_vm::check_code_pointer(cell ptr)
 | 
					struct code_heap : heap {
 | 
				
			||||||
{
 | 
						/* What generation was being collected when trace_code_heap_roots() was last
 | 
				
			||||||
#ifdef FACTOR_DEBUG
 | 
						   called? Until the next call to add_code_block(), future
 | 
				
			||||||
	assert(in_code_heap_p(ptr));
 | 
						   collections of younger generations don't have to touch the code
 | 
				
			||||||
#endif
 | 
						   heap. */
 | 
				
			||||||
}
 | 
						cell last_code_heap_scan;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
struct word_updater {
 | 
						explicit code_heap(factor_vm *myvm, cell size);
 | 
				
			||||||
	factor_vm *myvm;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	explicit word_updater(factor_vm *myvm_) : myvm(myvm_) {}
 | 
					 | 
				
			||||||
	void operator()(code_block *compiled)
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
		myvm->update_word_references(compiled);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,7 +5,7 @@ namespace factor
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void factor_vm::init_data_gc()
 | 
					void factor_vm::init_data_gc()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	last_code_heap_scan = data->nursery();
 | 
						code->last_code_heap_scan = data->nursery();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
gc_state::gc_state(data_heap *data_, bool growing_data_heap_, cell collecting_gen_) :
 | 
					gc_state::gc_state(data_heap *data_, bool growing_data_heap_, cell collecting_gen_) :
 | 
				
			||||||
| 
						 | 
					@ -321,15 +321,15 @@ template<typename Strategy> struct literal_reference_tracer {
 | 
				
			||||||
aging and nursery collections */
 | 
					aging and nursery collections */
 | 
				
			||||||
template<typename Strategy> void factor_vm::trace_code_heap_roots(Strategy &strategy)
 | 
					template<typename Strategy> void factor_vm::trace_code_heap_roots(Strategy &strategy)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if(current_gc->collecting_gen >= last_code_heap_scan)
 | 
						if(current_gc->collecting_gen >= code->last_code_heap_scan)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		literal_reference_tracer<Strategy> tracer(this,strategy);
 | 
							literal_reference_tracer<Strategy> tracer(this,strategy);
 | 
				
			||||||
		iterate_code_heap(tracer);
 | 
							iterate_code_heap(tracer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(current_gc->collecting_accumulation_gen_p())
 | 
							if(current_gc->collecting_accumulation_gen_p())
 | 
				
			||||||
			last_code_heap_scan = current_gc->collecting_gen;
 | 
								code->last_code_heap_scan = current_gc->collecting_gen;
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
			last_code_heap_scan = current_gc->collecting_gen + 1;
 | 
								code->last_code_heap_scan = current_gc->collecting_gen + 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		code_heap_scans++;
 | 
							code_heap_scans++;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -364,7 +364,7 @@ void factor_vm::free_unmarked_code_blocks()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	literal_and_word_reference_updater updater(this);
 | 
						literal_and_word_reference_updater updater(this);
 | 
				
			||||||
	code->free_unmarked(updater);
 | 
						code->free_unmarked(updater);
 | 
				
			||||||
	last_code_heap_scan = current_gc->collecting_gen;
 | 
						code->last_code_heap_scan = current_gc->collecting_gen;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void factor_vm::update_dirty_code_blocks()
 | 
					void factor_vm::update_dirty_code_blocks()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -96,7 +96,6 @@ void heap::assert_free_block(free_heap_block *block)
 | 
				
			||||||
		myvm->critical_error("Invalid block in free list",(cell)block);
 | 
							myvm->critical_error("Invalid block in free list",(cell)block);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		
 | 
					 | 
				
			||||||
free_heap_block *heap::find_free_block(cell size)
 | 
					free_heap_block *heap::find_free_block(cell size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	cell attempt = size;
 | 
						cell attempt = size;
 | 
				
			||||||
| 
						 | 
					@ -254,7 +253,7 @@ cell heap::heap_size()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Compute where each block is going to go, after compaction */
 | 
					/* Compute where each block is going to go, after compaction */
 | 
				
			||||||
cell heap::compute_heap_forwarding(unordered_map<heap_block *,char *> &forwarding)
 | 
					cell heap::compute_heap_forwarding()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	heap_block *scan = first_block();
 | 
						heap_block *scan = first_block();
 | 
				
			||||||
	char *address = (char *)first_block();
 | 
						char *address = (char *)first_block();
 | 
				
			||||||
| 
						 | 
					@ -275,7 +274,7 @@ cell heap::compute_heap_forwarding(unordered_map<heap_block *,char *> &forwardin
 | 
				
			||||||
	return (cell)address - seg->start;
 | 
						return (cell)address - seg->start;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void heap::compact_heap(unordered_map<heap_block *,char *> &forwarding)
 | 
					void heap::compact_heap()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	heap_block *scan = first_block();
 | 
						heap_block *scan = first_block();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,6 +13,7 @@ struct heap {
 | 
				
			||||||
	factor_vm *myvm;
 | 
						factor_vm *myvm;
 | 
				
			||||||
	segment *seg;
 | 
						segment *seg;
 | 
				
			||||||
	heap_free_list free;
 | 
						heap_free_list free;
 | 
				
			||||||
 | 
						unordered_map<heap_block *, char *> forwarding;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	explicit heap(factor_vm *myvm, cell size);
 | 
						explicit heap(factor_vm *myvm, cell size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -48,8 +49,8 @@ struct heap {
 | 
				
			||||||
	void unmark_marked();
 | 
						void unmark_marked();
 | 
				
			||||||
	void heap_usage(cell *used, cell *total_free, cell *max_free);
 | 
						void heap_usage(cell *used, cell *total_free, cell *max_free);
 | 
				
			||||||
	cell heap_size();
 | 
						cell heap_size();
 | 
				
			||||||
	cell compute_heap_forwarding(unordered_map<heap_block *,char *> &forwarding);
 | 
						cell compute_heap_forwarding();
 | 
				
			||||||
	void compact_heap(unordered_map<heap_block *,char *> &forwarding);
 | 
						void compact_heap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	heap_block *free_allocated(heap_block *prev, heap_block *scan);
 | 
						heap_block *free_allocated(heap_block *prev, heap_block *scan);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -76,6 +76,7 @@ namespace factor
 | 
				
			||||||
#include "heap.hpp"
 | 
					#include "heap.hpp"
 | 
				
			||||||
#include "image.hpp"
 | 
					#include "image.hpp"
 | 
				
			||||||
#include "alien.hpp"
 | 
					#include "alien.hpp"
 | 
				
			||||||
 | 
					#include "code_heap.hpp"
 | 
				
			||||||
#include "vm.hpp"
 | 
					#include "vm.hpp"
 | 
				
			||||||
#include "tagged.hpp"
 | 
					#include "tagged.hpp"
 | 
				
			||||||
#include "local_roots.hpp"
 | 
					#include "local_roots.hpp"
 | 
				
			||||||
| 
						 | 
					@ -84,7 +85,6 @@ namespace factor
 | 
				
			||||||
#include "arrays.hpp"
 | 
					#include "arrays.hpp"
 | 
				
			||||||
#include "math.hpp"
 | 
					#include "math.hpp"
 | 
				
			||||||
#include "booleans.hpp"
 | 
					#include "booleans.hpp"
 | 
				
			||||||
#include "code_heap.hpp"
 | 
					 | 
				
			||||||
#include "byte_arrays.hpp"
 | 
					#include "byte_arrays.hpp"
 | 
				
			||||||
#include "jit.hpp"
 | 
					#include "jit.hpp"
 | 
				
			||||||
#include "quotations.hpp"
 | 
					#include "quotations.hpp"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -43,9 +43,7 @@ void factor_vm::set_profiling(bool profiling)
 | 
				
			||||||
		update_word_xt(word.value());
 | 
							update_word_xt(word.value());
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Update XTs in code heap */
 | 
						update_code_heap_words();
 | 
				
			||||||
	word_updater updater(this);
 | 
					 | 
				
			||||||
	iterate_code_heap(updater);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void factor_vm::primitive_profiling()
 | 
					void factor_vm::primitive_profiling()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -343,9 +343,7 @@ void factor_vm::compile_all_words()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Update XTs in code heap */
 | 
						update_code_heap_words();
 | 
				
			||||||
	word_updater updater(this);
 | 
					 | 
				
			||||||
	iterate_code_heap(updater);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Allocates memory */
 | 
					/* Allocates memory */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										16
									
								
								vm/vm.hpp
								
								
								
								
							
							
						
						
									
										16
									
								
								vm/vm.hpp
								
								
								
								
							| 
						 | 
					@ -236,11 +236,6 @@ struct factor_vm
 | 
				
			||||||
	u64 decks_scanned;
 | 
						u64 decks_scanned;
 | 
				
			||||||
	u64 card_scan_time;
 | 
						u64 card_scan_time;
 | 
				
			||||||
	cell code_heap_scans;
 | 
						cell code_heap_scans;
 | 
				
			||||||
	/* What generation was being collected when trace_code_heap_roots() was last
 | 
					 | 
				
			||||||
	   called? Until the next call to add_code_block(), future
 | 
					 | 
				
			||||||
	   collections of younger generations don't have to touch the code
 | 
					 | 
				
			||||||
	   heap. */
 | 
					 | 
				
			||||||
	cell last_code_heap_scan;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void init_data_gc();
 | 
						void init_data_gc();
 | 
				
			||||||
	template<typename Strategy> void trace_handle(cell *handle, Strategy &strategy);
 | 
						template<typename Strategy> void trace_handle(cell *handle, Strategy &strategy);
 | 
				
			||||||
| 
						 | 
					@ -526,8 +521,14 @@ struct factor_vm
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//code_heap
 | 
						//code_heap
 | 
				
			||||||
	heap *code;
 | 
						code_heap *code;
 | 
				
			||||||
	unordered_map<heap_block *, char *> forwarding;
 | 
					
 | 
				
			||||||
 | 
						inline void check_code_pointer(cell ptr)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
						#ifdef FACTOR_DEBUG
 | 
				
			||||||
 | 
							assert(in_code_heap_p(ptr));
 | 
				
			||||||
 | 
						#endif
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void init_code_heap(cell size);
 | 
						void init_code_heap(cell size);
 | 
				
			||||||
	bool in_code_heap_p(cell ptr);
 | 
						bool in_code_heap_p(cell ptr);
 | 
				
			||||||
| 
						 | 
					@ -539,7 +540,6 @@ struct factor_vm
 | 
				
			||||||
	void forward_object_xts();
 | 
						void forward_object_xts();
 | 
				
			||||||
	void fixup_object_xts();
 | 
						void fixup_object_xts();
 | 
				
			||||||
	void compact_code_heap();
 | 
						void compact_code_heap();
 | 
				
			||||||
	inline void check_code_pointer(cell ptr);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Apply a function to every code block */
 | 
						/* Apply a function to every code block */
 | 
				
			||||||
	template<typename Iterator> void iterate_code_heap(Iterator &iter)
 | 
						template<typename Iterator> void iterate_code_heap(Iterator &iter)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue