From e66b8673f46b2cfab06406e181e5066c2f4d2c0d Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sun, 22 Nov 2009 13:37:39 -0600 Subject: [PATCH] vm: minor GC traces embedded pointers --- vm/aging_collector.cpp | 4 - vm/code_blocks.cpp | 45 -------- vm/full_collector.cpp | 3 +- vm/gc.cpp | 9 -- vm/master.hpp | 2 +- vm/nursery_collector.cpp | 4 - vm/slot_visitor.hpp | 222 +++++++++++++++++++++--------------- vm/to_tenured_collector.cpp | 4 - vm/vm.hpp | 21 +++- 9 files changed, 155 insertions(+), 159 deletions(-) diff --git a/vm/aging_collector.cpp b/vm/aging_collector.cpp index 3572677aa6..1695846ee7 100644 --- a/vm/aging_collector.cpp +++ b/vm/aging_collector.cpp @@ -33,10 +33,6 @@ void factor_vm::collect_aging() current_gc->event->ended_code_scan(collector.code_blocks_scanned); collector.tenure_reachable_objects(); - - current_gc->event->started_code_sweep(); - update_code_heap_for_minor_gc(&code->points_to_aging); - current_gc->event->ended_code_sweep(); } { /* If collection fails here, do a to_tenured collection. */ diff --git a/vm/code_blocks.cpp b/vm/code_blocks.cpp index d33d468d20..a7df30d4bf 100755 --- a/vm/code_blocks.cpp +++ b/vm/code_blocks.cpp @@ -151,51 +151,6 @@ cell factor_vm::compute_relocation(relocation_entry rel, cell index, code_block #undef ARG } -template void factor_vm::iterate_relocations(code_block *compiled, Iterator &iter) -{ - if(to_boolean(compiled->relocation)) - { - byte_array *relocation = untag(compiled->relocation); - - cell index = 0; - cell length = array_capacity(relocation) / sizeof(relocation_entry); - - for(cell i = 0; i < length; i++) - { - relocation_entry rel = relocation->data()[i]; - iter(rel,index,compiled); - index += rel.number_of_parameters(); - } - } -} - -struct literal_references_updater { - factor_vm *parent; - - explicit literal_references_updater(factor_vm *parent_) : parent(parent_) {} - - void operator()(relocation_entry rel, cell index, code_block *compiled) - { - if(rel.rel_type() == RT_IMMEDIATE) - { - embedded_pointer ptr(rel.rel_class(),rel.rel_offset() + (cell)(compiled + 1)); - array *literals = untag(compiled->literals); - ptr.store_address(array_nth(literals,index)); - } - } -}; - -/* Update pointers to literals from compiled code. */ -void factor_vm::update_literal_references(code_block *compiled) -{ - if(!code->needs_fixup_p(compiled)) - { - literal_references_updater updater(this); - iterate_relocations(compiled,updater); - flush_icache_for(compiled); - } -} - /* Compute an address to store at a relocation */ void factor_vm::relocate_code_block_step(relocation_entry rel, cell index, code_block *compiled) { diff --git a/vm/full_collector.cpp b/vm/full_collector.cpp index 188ab55efc..e6f155e58a 100644 --- a/vm/full_collector.cpp +++ b/vm/full_collector.cpp @@ -114,9 +114,10 @@ void factor_vm::collect_sweep_impl() { current_gc->event->started_data_sweep(); data->tenured->sweep(); - update_code_roots_for_sweep(); current_gc->event->ended_data_sweep(); + update_code_roots_for_sweep(); + current_gc->event->started_code_sweep(); code->allocator->sweep(); current_gc->event->ended_code_sweep(); diff --git a/vm/gc.cpp b/vm/gc.cpp index ff458e95dc..f90ad58f23 100755 --- a/vm/gc.cpp +++ b/vm/gc.cpp @@ -126,15 +126,6 @@ void factor_vm::start_gc_again() current_gc->event = new gc_event(current_gc->op,this); } -void factor_vm::update_code_heap_for_minor_gc(std::set *remembered_set) -{ - /* The youngest generation that any code block can now reference */ - std::set::const_iterator iter = remembered_set->begin(); - std::set::const_iterator end = remembered_set->end(); - - for(; iter != end; iter++) update_literal_references(*iter); -} - void factor_vm::gc(gc_op op, cell requested_bytes, bool trace_contexts_p) { assert(!gc_off); diff --git a/vm/master.hpp b/vm/master.hpp index cfb71a4715..ba782c3bd7 100755 --- a/vm/master.hpp +++ b/vm/master.hpp @@ -79,6 +79,7 @@ namespace factor #include "tagged.hpp" #include "data_roots.hpp" #include "code_roots.hpp" +#include "generic_arrays.hpp" #include "slot_visitor.hpp" #include "collector.hpp" #include "copying_collector.hpp" @@ -89,7 +90,6 @@ namespace factor #include "compaction.hpp" #include "full_collector.hpp" #include "callstack.hpp" -#include "generic_arrays.hpp" #include "arrays.hpp" #include "math.hpp" #include "booleans.hpp" diff --git a/vm/nursery_collector.cpp b/vm/nursery_collector.cpp index 5eb77fd763..062aa6aed3 100644 --- a/vm/nursery_collector.cpp +++ b/vm/nursery_collector.cpp @@ -36,10 +36,6 @@ void factor_vm::collect_nursery() collector.cheneys_algorithm(); - current_gc->event->started_code_sweep(); - update_code_heap_for_minor_gc(&code->points_to_nursery); - current_gc->event->ended_code_sweep(); - data->reset_generation(&nursery); code->points_to_nursery.clear(); } diff --git a/vm/slot_visitor.hpp b/vm/slot_visitor.hpp index 908e0f3152..aa2751d690 100644 --- a/vm/slot_visitor.hpp +++ b/vm/slot_visitor.hpp @@ -8,106 +8,150 @@ template struct slot_visitor { explicit slot_visitor(factor_vm *parent_, Visitor visitor_) : parent(parent_), visitor(visitor_) {} - cell visit_pointer(cell pointer) - { - if(immediate_p(pointer)) return pointer; + cell visit_pointer(cell pointer); + void visit_handle(cell *handle); + void visit_slots(object *ptr, cell payload_start); + void visit_slots(object *ptr); + void visit_stack_elements(segment *region, cell *top); + void visit_data_roots(); + void visit_bignum_roots(); + void visit_roots(); + void visit_contexts(); + void visit_literal_references(code_block *compiled); +}; - object *untagged = untag(pointer); - untagged = visitor(untagged); - return RETAG(untagged,TAG(pointer)); +template +cell slot_visitor::visit_pointer(cell pointer) +{ + if(immediate_p(pointer)) return pointer; + + object *untagged = untag(pointer); + untagged = visitor(untagged); + return RETAG(untagged,TAG(pointer)); +} + +template +void slot_visitor::visit_handle(cell *handle) +{ + *handle = visit_pointer(*handle); +} + +template +void slot_visitor::visit_slots(object *ptr, cell payload_start) +{ + cell *slot = (cell *)ptr; + cell *end = (cell *)((cell)ptr + payload_start); + + if(slot != end) + { + slot++; + for(; slot < end; slot++) visit_handle(slot); } +} - void visit_handle(cell *handle) +template +void slot_visitor::visit_slots(object *ptr) +{ + visit_slots(ptr,ptr->binary_payload_start()); +} + +template +void slot_visitor::visit_stack_elements(segment *region, cell *top) +{ + for(cell *ptr = (cell *)region->start; ptr <= top; ptr++) + visit_handle(ptr); +} + +template +void slot_visitor::visit_data_roots() +{ + std::vector::const_iterator iter = parent->data_roots.begin(); + std::vector::const_iterator end = parent->data_roots.end(); + + for(; iter < end; iter++) { - *handle = visit_pointer(*handle); + data_root_range r = *iter; + for(cell index = 0; index < r.len; index++) + visit_handle(r.start + index); } +} - void visit_slots(object *ptr, cell payload_start) +template +void slot_visitor::visit_bignum_roots() +{ + std::vector::const_iterator iter = parent->bignum_roots.begin(); + std::vector::const_iterator end = parent->bignum_roots.end(); + + for(; iter < end; iter++) { - cell *slot = (cell *)ptr; - cell *end = (cell *)((cell)ptr + payload_start); + cell *handle = (cell *)(*iter); - if(slot != end) + if(*handle) + *handle = (cell)visitor(*(object **)handle); + } +} + +template +void slot_visitor::visit_roots() +{ + visit_handle(&parent->true_object); + visit_handle(&parent->bignum_zero); + visit_handle(&parent->bignum_pos_one); + visit_handle(&parent->bignum_neg_one); + + visit_data_roots(); + visit_bignum_roots(); + + for(cell i = 0; i < special_object_count; i++) + visit_handle(&parent->special_objects[i]); +} + +template +void slot_visitor::visit_contexts() +{ + context *ctx = parent->ctx; + + while(ctx) + { + visit_stack_elements(ctx->datastack_region,(cell *)ctx->datastack); + visit_stack_elements(ctx->retainstack_region,(cell *)ctx->retainstack); + + visit_handle(&ctx->catchstack_save); + visit_handle(&ctx->current_callback_save); + + ctx = ctx->next; + } +} + +template +struct literal_references_visitor { + factor_vm *parent; + slot_visitor *visitor; + + explicit literal_references_visitor(factor_vm *parent_, slot_visitor *visitor_) + : parent(parent_), visitor(visitor_) {} + + void operator()(relocation_entry rel, cell index, code_block *compiled) + { + if(rel.rel_type() == RT_IMMEDIATE) { - slot++; - for(; slot < end; slot++) visit_handle(slot); + embedded_pointer ptr(rel.rel_class(),rel.rel_offset() + (cell)(compiled + 1)); + cell literal = ptr.load_address(); + literal = visitor->visit_pointer(literal); + ptr.store_address(literal); } } - - void visit_slots(object *ptr) - { - visit_slots(ptr,ptr->binary_payload_start()); - } - - void visit_stack_elements(segment *region, cell *top) - { - for(cell *ptr = (cell *)region->start; ptr <= top; ptr++) - visit_handle(ptr); - } - - void visit_data_roots() - { - std::vector::const_iterator iter = parent->data_roots.begin(); - std::vector::const_iterator end = parent->data_roots.end(); - - for(; iter < end; iter++) - { - data_root_range r = *iter; - for(cell index = 0; index < r.len; index++) - visit_handle(r.start + index); - } - } - - void visit_bignum_roots() - { - std::vector::const_iterator iter = parent->bignum_roots.begin(); - std::vector::const_iterator end = parent->bignum_roots.end(); - - for(; iter < end; iter++) - { - cell *handle = (cell *)(*iter); - - if(*handle) - *handle = (cell)visitor(*(object **)handle); - } - } - - void visit_roots() - { - visit_handle(&parent->true_object); - visit_handle(&parent->bignum_zero); - visit_handle(&parent->bignum_pos_one); - visit_handle(&parent->bignum_neg_one); - - visit_data_roots(); - visit_bignum_roots(); - - for(cell i = 0; i < special_object_count; i++) - visit_handle(&parent->special_objects[i]); - } - - void visit_contexts() - { - context *ctx = parent->ctx; - - while(ctx) - { - visit_stack_elements(ctx->datastack_region,(cell *)ctx->datastack); - visit_stack_elements(ctx->retainstack_region,(cell *)ctx->retainstack); - - visit_handle(&ctx->catchstack_save); - visit_handle(&ctx->current_callback_save); - - ctx = ctx->next; - } - } - - void visit_literal_references(code_block *compiled) - { - visit_handle(&compiled->owner); - visit_handle(&compiled->literals); - visit_handle(&compiled->relocation); - } }; +template +void slot_visitor::visit_literal_references(code_block *compiled) +{ + visit_handle(&compiled->owner); + visit_handle(&compiled->literals); + visit_handle(&compiled->relocation); + + literal_references_visitor visitor(parent,this); + parent->iterate_relocations(compiled,visitor); +} + } diff --git a/vm/to_tenured_collector.cpp b/vm/to_tenured_collector.cpp index 0cee748205..b2fe3461b9 100644 --- a/vm/to_tenured_collector.cpp +++ b/vm/to_tenured_collector.cpp @@ -42,10 +42,6 @@ void factor_vm::collect_to_tenured() collector.tenure_reachable_objects(); - current_gc->event->started_code_sweep(); - update_code_heap_for_minor_gc(&code->points_to_aging); - current_gc->event->ended_code_sweep(); - data->reset_generation(&nursery); data->reset_generation(data->aging); code->clear_remembered_set(); diff --git a/vm/vm.hpp b/vm/vm.hpp index 67997e8590..5548f71905 100755 --- a/vm/vm.hpp +++ b/vm/vm.hpp @@ -504,8 +504,25 @@ struct factor_vm void undefined_symbol(); void *get_rel_symbol(array *literals, cell index); cell compute_relocation(relocation_entry rel, cell index, code_block *compiled); - template void iterate_relocations(code_block *compiled, Iterator &iter); - void update_literal_references(code_block *compiled); + + template void iterate_relocations(code_block *compiled, Iterator &iter) + { + if(to_boolean(compiled->relocation)) + { + byte_array *relocation = (byte_array *)UNTAG(compiled->relocation); + + cell index = 0; + cell length = (relocation->capacity >> TAG_BITS) / sizeof(relocation_entry); + + for(cell i = 0; i < length; i++) + { + relocation_entry rel = relocation->data()[i]; + iter(rel,index,compiled); + index += rel.number_of_parameters(); + } + } + } + void relocate_code_block_step(relocation_entry rel, cell index, code_block *compiled); void update_word_references(code_block *compiled); void update_code_block_words_and_literals(code_block *compiled);