From 1f76a64e91d71379489e0bddf70ffc95a22ccfef Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Tue, 6 Oct 2009 20:45:47 -0500 Subject: [PATCH] vm: more refactoring --- vm/data_gc.cpp | 50 +++++++++++++++++++++++++++++--------------------- vm/data_gc.hpp | 6 +++--- vm/vm.hpp | 1 + 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/vm/data_gc.cpp b/vm/data_gc.cpp index 8680ffa99a..1b12bddaf3 100755 --- a/vm/data_gc.cpp +++ b/vm/data_gc.cpp @@ -40,12 +40,15 @@ template void factor_vm::trace_handle(cell *handle, Strategy if(strategy.should_copy_p(untagged)) { object *forwarding = resolve_forwarding(untagged,strategy); + if(forwarding == untagged) - *handle = strategy.copy_object(pointer); + untagged = strategy.copy_object(untagged); else if(strategy.should_copy_p(forwarding)) - *handle = strategy.copy_object(RETAG(forwarding,TAG(pointer))); + untagged = strategy.copy_object(forwarding); else - *handle = RETAG(forwarding,TAG(pointer)); + untagged = forwarding; + + *handle = RETAG(untagged,TAG(pointer)); } } } @@ -62,6 +65,22 @@ template void factor_vm::trace_slots(object *ptr, Strategy &s } } +template object *factor_vm::promote_object(object *untagged, Strategy &strategy) +{ + cell size = untagged_object_size(untagged); + object *newpointer = strategy.allot(size); + if(!newpointer) longjmp(current_gc->gc_unwind,1); + + gc_stats *s = &stats[current_gc->collecting_gen]; + s->object_count++; + s->bytes_copied += size; + + memcpy(newpointer,untagged,size); + untagged->h.forward_to(newpointer); + + return newpointer; +} + template void factor_vm::trace_card(card *ptr, cell gen, cell here, Strategy &strategy) { cell card_scan = card_to_addr(ptr) + card_offset(ptr); @@ -407,28 +426,17 @@ template Strategy ©ing_collector::strategy() return static_cast(*this); } -/* Given a pointer to oldspace, copy it to newspace */ -template object *copying_collector::copy_untagged_object(object *pointer, cell size) +template object *copying_collector::allot(cell size) { - if(newspace->here + size >= newspace->end) - longjmp(current_gc->gc_unwind,1); - - object *newpointer = myvm->allot_zone(newspace,size); - - gc_stats *s = &myvm->stats[current_gc->collecting_gen]; - s->object_count++; - s->bytes_copied += size; - - memcpy(newpointer,pointer,size); - return newpointer; + if(newspace->here + size <= newspace->end) + return myvm->allot_zone(newspace,size); + else + return NULL; } -template cell copying_collector::copy_object(cell pointer) +template object *copying_collector::copy_object(object *untagged) { - object *untagged = myvm->untag(pointer); - object *newpointer = copy_untagged_object(untagged,myvm->untagged_object_size(untagged)); - untagged->h.forward_to(newpointer); - return RETAG(newpointer,TAG(pointer)); + return myvm->promote_object(untagged,strategy()); } template bool copying_collector::should_copy_p(object *pointer) diff --git a/vm/data_gc.hpp b/vm/data_gc.hpp index 15332ad225..c8b7b479c2 100755 --- a/vm/data_gc.hpp +++ b/vm/data_gc.hpp @@ -63,10 +63,10 @@ template struct copying_collector { explicit copying_collector(factor_vm *myvm_, zone *newspace); Strategy &strategy(); - object *copy_untagged_object(object *pointer, cell size); + object *allot(cell size); cell trace_next(cell scan); - cell copy_object(cell pointer); - bool should_copy_p(object *pointer); + object *copy_object(object *untagged); + bool should_copy_p(object *untagged); void go(); }; diff --git a/vm/vm.hpp b/vm/vm.hpp index 06421f871d..2ddb991b29 100755 --- a/vm/vm.hpp +++ b/vm/vm.hpp @@ -239,6 +239,7 @@ struct factor_vm void init_data_gc(); template object *resolve_forwarding(object *untagged, Strategy &strategy); template void trace_handle(cell *handle, Strategy &strategy); + template object *promote_object(object *pointer, Strategy &strategy); template void trace_slots(object *ptr, Strategy &strategy); template void trace_card(card *ptr, cell gen, cell here, Strategy &strategy); template void trace_card_deck(card_deck *deck, cell gen, card mask, card unmask, Strategy &strategy);