diff --git a/vm/code_block.cpp b/vm/code_block.cpp index ab69ee8ca1..ec7da8af9f 100755 --- a/vm/code_block.cpp +++ b/vm/code_block.cpp @@ -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 literals */ - last_code_heap_scan = data->nursery(); + this->code->last_code_heap_scan = data->nursery(); return compiled; } diff --git a/vm/code_heap.cpp b/vm/code_heap.cpp index e44cbeba17..a0ad1a7dd0 100755 --- a/vm/code_heap.cpp +++ b/vm/code_heap.cpp @@ -3,10 +3,12 @@ namespace factor { +code_heap::code_heap(factor_vm *myvm, cell size) : heap(myvm,size) {} + /* Allocate a code heap during startup */ 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) @@ -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); } +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 defining a new word. */ 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) { - return (code_block *)forwarding[compiled]; + return (code_block *)code->forwarding[compiled]; } struct xt_forwarder { @@ -199,13 +211,13 @@ void factor_vm::compact_code_heap() garbage_collection(data->tenured(),false,false,0); /* 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 */ forward_object_xts(); /* Actually perform the compaction */ - code->compact_heap(forwarding); + code->compact_heap(); /* Update word and quotation XTs */ fixup_object_xts(); diff --git a/vm/code_heap.hpp b/vm/code_heap.hpp index a746d7a445..c0b6d9d1cf 100755 --- a/vm/code_heap.hpp +++ b/vm/code_heap.hpp @@ -1,21 +1,14 @@ namespace factor { -inline void factor_vm::check_code_pointer(cell ptr) -{ -#ifdef FACTOR_DEBUG - assert(in_code_heap_p(ptr)); -#endif -} - -struct word_updater { - factor_vm *myvm; - - explicit word_updater(factor_vm *myvm_) : myvm(myvm_) {} - void operator()(code_block *compiled) - { - myvm->update_word_references(compiled); - } +struct code_heap : heap { + /* 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; + + explicit code_heap(factor_vm *myvm, cell size); }; } diff --git a/vm/data_gc.cpp b/vm/data_gc.cpp index 35a5ba07de..291c5094d7 100755 --- a/vm/data_gc.cpp +++ b/vm/data_gc.cpp @@ -5,7 +5,7 @@ namespace factor 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_) : @@ -321,15 +321,15 @@ template struct literal_reference_tracer { aging and nursery collections */ template 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 tracer(this,strategy); iterate_code_heap(tracer); 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 - last_code_heap_scan = current_gc->collecting_gen + 1; + code->last_code_heap_scan = current_gc->collecting_gen + 1; code_heap_scans++; } @@ -364,7 +364,7 @@ void factor_vm::free_unmarked_code_blocks() { literal_and_word_reference_updater updater(this); 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() diff --git a/vm/heap.cpp b/vm/heap.cpp index 5bd8608f3d..91ebc291cd 100644 --- a/vm/heap.cpp +++ b/vm/heap.cpp @@ -96,7 +96,6 @@ void heap::assert_free_block(free_heap_block *block) myvm->critical_error("Invalid block in free list",(cell)block); } - free_heap_block *heap::find_free_block(cell size) { cell attempt = size; @@ -254,7 +253,7 @@ cell heap::heap_size() } /* Compute where each block is going to go, after compaction */ -cell heap::compute_heap_forwarding(unordered_map &forwarding) +cell heap::compute_heap_forwarding() { heap_block *scan = first_block(); char *address = (char *)first_block(); @@ -275,7 +274,7 @@ cell heap::compute_heap_forwarding(unordered_map &forwardin return (cell)address - seg->start; } -void heap::compact_heap(unordered_map &forwarding) +void heap::compact_heap() { heap_block *scan = first_block(); diff --git a/vm/heap.hpp b/vm/heap.hpp index 2558338f59..d878072057 100644 --- a/vm/heap.hpp +++ b/vm/heap.hpp @@ -13,6 +13,7 @@ struct heap { factor_vm *myvm; segment *seg; heap_free_list free; + unordered_map forwarding; explicit heap(factor_vm *myvm, cell size); @@ -48,8 +49,8 @@ struct heap { void unmark_marked(); void heap_usage(cell *used, cell *total_free, cell *max_free); cell heap_size(); - cell compute_heap_forwarding(unordered_map &forwarding); - void compact_heap(unordered_map &forwarding); + cell compute_heap_forwarding(); + void compact_heap(); heap_block *free_allocated(heap_block *prev, heap_block *scan); diff --git a/vm/master.hpp b/vm/master.hpp index 103387ad4b..0e34144099 100755 --- a/vm/master.hpp +++ b/vm/master.hpp @@ -76,6 +76,7 @@ namespace factor #include "heap.hpp" #include "image.hpp" #include "alien.hpp" +#include "code_heap.hpp" #include "vm.hpp" #include "tagged.hpp" #include "local_roots.hpp" @@ -84,7 +85,6 @@ namespace factor #include "arrays.hpp" #include "math.hpp" #include "booleans.hpp" -#include "code_heap.hpp" #include "byte_arrays.hpp" #include "jit.hpp" #include "quotations.hpp" diff --git a/vm/profiler.cpp b/vm/profiler.cpp index e61c10f293..228b163f83 100755 --- a/vm/profiler.cpp +++ b/vm/profiler.cpp @@ -43,9 +43,7 @@ void factor_vm::set_profiling(bool profiling) update_word_xt(word.value()); } - /* Update XTs in code heap */ - word_updater updater(this); - iterate_code_heap(updater); + update_code_heap_words(); } void factor_vm::primitive_profiling() diff --git a/vm/quotations.cpp b/vm/quotations.cpp index f8a9a7183b..a77b22844b 100755 --- a/vm/quotations.cpp +++ b/vm/quotations.cpp @@ -343,9 +343,7 @@ void factor_vm::compile_all_words() } - /* Update XTs in code heap */ - word_updater updater(this); - iterate_code_heap(updater); + update_code_heap_words(); } /* Allocates memory */ diff --git a/vm/vm.hpp b/vm/vm.hpp index ad0931112e..ce45a6122d 100755 --- a/vm/vm.hpp +++ b/vm/vm.hpp @@ -236,11 +236,6 @@ struct factor_vm u64 decks_scanned; u64 card_scan_time; 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(); template void trace_handle(cell *handle, Strategy &strategy); @@ -526,8 +521,14 @@ struct factor_vm } //code_heap - heap *code; - unordered_map forwarding; + code_heap *code; + + inline void check_code_pointer(cell ptr) + { + #ifdef FACTOR_DEBUG + assert(in_code_heap_p(ptr)); + #endif + } void init_code_heap(cell size); bool in_code_heap_p(cell ptr); @@ -539,7 +540,6 @@ struct factor_vm void forward_object_xts(); void fixup_object_xts(); void compact_code_heap(); - inline void check_code_pointer(cell ptr); /* Apply a function to every code block */ template void iterate_code_heap(Iterator &iter)