From 64c2d813061566e4226b8a13313ccf38def63d26 Mon Sep 17 00:00:00 2001 From: Phil Dawes Date: Mon, 17 Aug 2009 21:37:05 +0100 Subject: [PATCH] moved data_gc fns over to vm struct --- vm/data_gc.cpp | 205 +++++++++++++++++++++++++++++++++++++++++-------- vm/vm.hpp | 32 ++++++++ 2 files changed, 206 insertions(+), 31 deletions(-) mode change 100644 => 100755 vm/data_gc.cpp diff --git a/vm/data_gc.cpp b/vm/data_gc.cpp old mode 100644 new mode 100755 index 458a437e37..ea7100fc02 --- a/vm/data_gc.cpp +++ b/vm/data_gc.cpp @@ -33,15 +33,20 @@ cell last_code_heap_scan; bool growing_data_heap; data_heap *old_data_heap; -void init_data_gc() +void factorvm::init_data_gc() { performing_gc = false; last_code_heap_scan = data->nursery(); collecting_aging_again = false; } +void init_data_gc() +{ + return vm->init_data_gc(); +} + /* Given a pointer to oldspace, copy it to newspace */ -static object *copy_untagged_object_impl(object *pointer, cell size) +object *factorvm::copy_untagged_object_impl(object *pointer, cell size) { if(newspace->here + size >= newspace->end) longjmp(gc_jmp,1); @@ -55,14 +60,24 @@ static object *copy_untagged_object_impl(object *pointer, cell size) return newpointer; } -static object *copy_object_impl(object *untagged) +object *copy_untagged_object_impl(object *pointer, cell size) +{ + return vm->copy_untagged_object_impl(pointer,size); +} + +object *factorvm::copy_object_impl(object *untagged) { object *newpointer = copy_untagged_object_impl(untagged,untagged_object_size(untagged)); untagged->h.forward_to(newpointer); return newpointer; } -static bool should_copy_p(object *untagged) +object *copy_object_impl(object *untagged) +{ + return vm->copy_object_impl(untagged); +} + +bool factorvm::should_copy_p(object *untagged) { if(in_zone(newspace,untagged)) return false; @@ -79,8 +94,13 @@ static bool should_copy_p(object *untagged) } } +bool should_copy_p(object *untagged) +{ + return vm->should_copy_p(untagged); +} + /* Follow a chain of forwarding pointers */ -static object *resolve_forwarding(object *untagged) +object *factorvm::resolve_forwarding(object *untagged) { check_data_pointer(untagged); @@ -98,7 +118,12 @@ static object *resolve_forwarding(object *untagged) } } -template static T *copy_untagged_object(T *untagged) +object *resolve_forwarding(object *untagged) +{ + return vm->resolve_forwarding(untagged); +} + +template T *factorvm::copy_untagged_object(T *untagged) { check_data_pointer(untagged); @@ -113,12 +138,22 @@ template static T *copy_untagged_object(T *untagged) return untagged; } -static cell copy_object(cell pointer) +template T *copy_untagged_object(T *untagged) +{ + return vm->copy_untagged_object(untagged); +} + +cell factorvm::copy_object(cell pointer) { return RETAG(copy_untagged_object(untag(pointer)),TAG(pointer)); } -void copy_handle(cell *handle) +cell copy_object(cell pointer) +{ + return vm->copy_object(pointer); +} + +void factorvm::copy_handle(cell *handle) { cell pointer = *handle; @@ -131,8 +166,13 @@ void copy_handle(cell *handle) } } +void copy_handle(cell *handle) +{ + return vm->copy_handle(handle); +} + /* Scan all the objects in the card */ -static void copy_card(card *ptr, cell gen, cell here) +void factorvm::copy_card(card *ptr, cell gen, cell here) { cell card_scan = card_to_addr(ptr) + card_offset(ptr); cell card_end = card_to_addr(ptr + 1); @@ -145,7 +185,12 @@ static void copy_card(card *ptr, cell gen, cell here) cards_scanned++; } -static void copy_card_deck(card_deck *deck, cell gen, card mask, card unmask) +void copy_card(card *ptr, cell gen, cell here) +{ + return vm->copy_card(ptr,gen,here); +} + +void factorvm::copy_card_deck(card_deck *deck, cell gen, card mask, card unmask) { card *first_card = deck_to_card(deck); card *last_card = deck_to_card(deck + 1); @@ -176,8 +221,13 @@ static void copy_card_deck(card_deck *deck, cell gen, card mask, card unmask) decks_scanned++; } +void copy_card_deck(card_deck *deck, cell gen, card mask, card unmask) +{ + return vm->copy_card_deck(deck,gen,mask,unmask); +} + /* Copy all newspace objects referenced from marked cards to the destination */ -static void copy_gen_cards(cell gen) +void factorvm::copy_gen_cards(cell gen) { card_deck *first_deck = addr_to_deck(data->generations[gen].start); card_deck *last_deck = addr_to_deck(data->generations[gen].end); @@ -242,9 +292,14 @@ static void copy_gen_cards(cell gen) } } +void copy_gen_cards(cell gen) +{ + return vm->copy_gen_cards(gen); +} + /* Scan cards in all generations older than the one being collected, copying old->new references */ -static void copy_cards() +void factorvm::copy_cards() { u64 start = current_micros(); @@ -255,8 +310,13 @@ static void copy_cards() card_scan_time += (current_micros() - start); } +void copy_cards() +{ + return vm->copy_cards(); +} + /* Copy all tagged pointers in a range of memory */ -static void copy_stack_elements(segment *region, cell top) +void factorvm::copy_stack_elements(segment *region, cell top) { cell ptr = region->start; @@ -264,7 +324,12 @@ static void copy_stack_elements(segment *region, cell top) copy_handle((cell*)ptr); } -static void copy_registered_locals() +void copy_stack_elements(segment *region, cell top) +{ + return vm->copy_stack_elements(region,top); +} + +void factorvm::copy_registered_locals() { std::vector::const_iterator iter = gc_locals.begin(); std::vector::const_iterator end = gc_locals.end(); @@ -273,7 +338,12 @@ static void copy_registered_locals() copy_handle((cell *)(*iter)); } -static void copy_registered_bignums() +void copy_registered_locals() +{ + return vm->copy_registered_locals(); +} + +void factorvm::copy_registered_bignums() { std::vector::const_iterator iter = gc_bignums.begin(); std::vector::const_iterator end = gc_bignums.end(); @@ -295,9 +365,14 @@ static void copy_registered_bignums() } } +void copy_registered_bignums() +{ + return vm->copy_registered_bignums(); +} + /* Copy roots over at the start of GC, namely various constants, stacks, the user environment and extra roots registered by local_roots.hpp */ -static void copy_roots() +void factorvm::copy_roots() { copy_handle(&T); copy_handle(&bignum_zero); @@ -331,7 +406,12 @@ static void copy_roots() copy_handle(&userenv[i]); } -static cell copy_next_from_nursery(cell scan) +void copy_roots() +{ + return vm->copy_roots(); +} + +cell factorvm::copy_next_from_nursery(cell scan) { cell *obj = (cell *)scan; cell *end = (cell *)(scan + binary_payload_start((object *)scan)); @@ -359,7 +439,12 @@ static cell copy_next_from_nursery(cell scan) return scan + untagged_object_size((object *)scan); } -static cell copy_next_from_aging(cell scan) +cell copy_next_from_nursery(cell scan) +{ + return vm->copy_next_from_nursery(scan); +} + +cell factorvm::copy_next_from_aging(cell scan) { cell *obj = (cell *)scan; cell *end = (cell *)(scan + binary_payload_start((object *)scan)); @@ -391,7 +476,12 @@ static cell copy_next_from_aging(cell scan) return scan + untagged_object_size((object *)scan); } -static cell copy_next_from_tenured(cell scan) +cell copy_next_from_aging(cell scan) +{ + return vm->copy_next_from_aging(scan); +} + +cell factorvm::copy_next_from_tenured(cell scan) { cell *obj = (cell *)scan; cell *end = (cell *)(scan + binary_payload_start((object *)scan)); @@ -421,7 +511,12 @@ static cell copy_next_from_tenured(cell scan) return scan + untagged_object_size((object *)scan); } -void copy_reachable_objects(cell scan, cell *end) +cell copy_next_from_tenured(cell scan) +{ + return vm->copy_next_from_tenured(scan); +} + +void factorvm::copy_reachable_objects(cell scan, cell *end) { if(collecting_gen == data->nursery()) { @@ -440,8 +535,13 @@ void copy_reachable_objects(cell scan, cell *end) } } +void copy_reachable_objects(cell scan, cell *end) +{ + return vm->copy_reachable_objects(scan,end); +} + /* Prepare to start copying reachable objects into an unused zone */ -static void begin_gc(cell requested_bytes) +void factorvm::begin_gc(cell requested_bytes) { if(growing_data_heap) { @@ -474,7 +574,12 @@ static void begin_gc(cell requested_bytes) } } -static void end_gc(cell gc_elapsed) +void begin_gc(cell requested_bytes) +{ + return vm->begin_gc(requested_bytes); +} + +void factorvm::end_gc(cell gc_elapsed) { gc_stats *s = &stats[collecting_gen]; @@ -512,12 +617,15 @@ static void end_gc(cell gc_elapsed) collecting_aging_again = false; } +void end_gc(cell gc_elapsed) +{ + return vm->end_gc(gc_elapsed); +} + /* Collect gen and all younger generations. If growing_data_heap_ is true, we must grow the data heap to such a size that an allocation of requested_bytes won't fail */ -void garbage_collection(cell gen, - bool growing_data_heap_, - cell requested_bytes) +void factorvm::garbage_collection(cell gen,bool growing_data_heap_,cell requested_bytes) { if(gc_off) { @@ -595,17 +703,32 @@ void garbage_collection(cell gen, performing_gc = false; } -void gc() +void garbage_collection(cell gen,bool growing_data_heap_,cell requested_bytes) +{ + return vm->garbage_collection(gen,growing_data_heap_,requested_bytes); +} + +void factorvm::gc() { garbage_collection(data->tenured(),false,0); } -PRIMITIVE(gc) +void gc() +{ + return vm->gc(); +} + +inline void factorvm::vmprim_gc() { gc(); } -PRIMITIVE(gc_stats) +PRIMITIVE(gc) +{ + PRIMITIVE_GETVM()->vmprim_gc(); +} + +inline void factorvm::vmprim_gc_stats() { growable_array result; @@ -635,7 +758,12 @@ PRIMITIVE(gc_stats) dpush(result.elements.value()); } -void clear_gc_stats() +PRIMITIVE(gc_stats) +{ + PRIMITIVE_GETVM()->vmprim_gc_stats(); +} + +void factorvm::clear_gc_stats() { for(cell i = 0; i < max_gen_count; i++) memset(&stats[i],0,sizeof(gc_stats)); @@ -646,6 +774,11 @@ void clear_gc_stats() code_heap_scans = 0; } +void clear_gc_stats() +{ + return vm->clear_gc_stats(); +} + PRIMITIVE(clear_gc_stats) { clear_gc_stats(); @@ -653,7 +786,7 @@ PRIMITIVE(clear_gc_stats) /* classes.tuple uses this to reshape tuples; tools.deploy.shaker uses this to coalesce equal but distinct quotations and wrappers. */ -PRIMITIVE(become) +inline void factorvm::vmprim_become() { array *new_objects = untag_check(dpop()); array *old_objects = untag_check(dpop()); @@ -682,7 +815,12 @@ PRIMITIVE(become) compile_all_words(); } -VM_ASM_API void inline_gc(cell *gc_roots_base, cell gc_roots_size) +PRIMITIVE(become) +{ + PRIMITIVE_GETVM()->vmprim_become(); +} + +VM_ASM_API void factorvm::inline_gc(cell *gc_roots_base, cell gc_roots_size) { for(cell i = 0; i < gc_roots_size; i++) gc_locals.push_back((cell)&gc_roots_base[i]); @@ -693,4 +831,9 @@ VM_ASM_API void inline_gc(cell *gc_roots_base, cell gc_roots_size) gc_locals.pop_back(); } +VM_ASM_API void inline_gc(cell *gc_roots_base, cell gc_roots_size) +{ + return vm->inline_gc(gc_roots_base,gc_roots_size); +} + } diff --git a/vm/vm.hpp b/vm/vm.hpp index 8ec5c7d094..5750d434c6 100644 --- a/vm/vm.hpp +++ b/vm/vm.hpp @@ -142,8 +142,40 @@ struct factorvm { inline void vmprim_end_scan(); template void each_object(T &functor); cell find_all_words(); + + //data_gc + void init_data_gc(); + object *copy_untagged_object_impl(object *pointer, cell size); + object *copy_object_impl(object *untagged); + bool should_copy_p(object *untagged); + object *resolve_forwarding(object *untagged); + template T *copy_untagged_object(T *untagged); + cell copy_object(cell pointer); + void copy_handle(cell *handle); + void copy_card(card *ptr, cell gen, cell here); + void copy_card_deck(card_deck *deck, cell gen, card mask, card unmask); + void copy_gen_cards(cell gen); + void copy_cards(); + void copy_stack_elements(segment *region, cell top); + void copy_registered_locals(); + void copy_registered_bignums(); + void copy_roots(); + cell copy_next_from_nursery(cell scan); + cell copy_next_from_aging(cell scan); + cell copy_next_from_tenured(cell scan); + void copy_reachable_objects(cell scan, cell *end); + void begin_gc(cell requested_bytes); + void end_gc(cell gc_elapsed); + void garbage_collection(cell gen,bool growing_data_heap_,cell requested_bytes); + void gc(); + inline void vmprim_gc(); + inline void vmprim_gc_stats(); + void clear_gc_stats(); + inline void vmprim_become(); + void inline_gc(cell *gc_roots_base, cell gc_roots_size); // next method here: + }; extern factorvm *vm;