From 791d654f92a0e9e7e5c61e3ea8b2cca18e192083 Mon Sep 17 00:00:00 2001 From: Phil Dawes Date: Mon, 28 Sep 2009 19:02:51 +0100 Subject: [PATCH] moved local_roots and write_barrier stuff out of inlineimpls.hpp --- vm/inlineimpls.hpp | 96 ---------------------------------------------- vm/local_roots.hpp | 44 +++++++++++++++++++++ vm/master.hpp | 2 +- vm/vm.hpp | 63 ++++++++++++++++++++++++------ 4 files changed, 97 insertions(+), 108 deletions(-) diff --git a/vm/inlineimpls.hpp b/vm/inlineimpls.hpp index 7074f0d33a..74620dc4c1 100644 --- a/vm/inlineimpls.hpp +++ b/vm/inlineimpls.hpp @@ -4,59 +4,6 @@ namespace factor // I've had to copy inline implementations here to make dependencies work. Am hoping to move this code back into include files // once the rest of the reentrant changes are done. -PD -// write_barrier.hpp - -inline card *factor_vm::addr_to_card(cell a) -{ - return (card*)(((cell)(a) >> card_bits) + cards_offset); -} - -inline cell factor_vm::card_to_addr(card *c) -{ - return ((cell)c - cards_offset) << card_bits; -} - -inline cell factor_vm::card_offset(card *c) -{ - return *(c - (cell)data->cards + (cell)data->allot_markers); -} - -inline card_deck *factor_vm::addr_to_deck(cell a) -{ - return (card_deck *)(((cell)a >> deck_bits) + decks_offset); -} - -inline cell factor_vm::deck_to_addr(card_deck *c) -{ - return ((cell)c - decks_offset) << deck_bits; -} - -inline card *factor_vm::deck_to_card(card_deck *d) -{ - return (card *)((((cell)d - decks_offset) << (deck_bits - card_bits)) + cards_offset); -} - -inline card *factor_vm::addr_to_allot_marker(object *a) -{ - return (card *)(((cell)a >> card_bits) + allot_markers_offset); -} - -/* the write barrier must be called any time we are potentially storing a -pointer from an older generation to a younger one */ -inline void factor_vm::write_barrier(object *obj) -{ - *addr_to_card((cell)obj) = card_mark_mask; - *addr_to_deck((cell)obj) = card_mark_mask; -} - -/* we need to remember the first object allocated in the card */ -inline void factor_vm::allot_barrier(object *address) -{ - card *ptr = addr_to_allot_marker(address); - if(*ptr == invalid_allot_marker) - *ptr = ((cell)address & addr_card_mask); -} - //data_gc.hpp inline bool factor_vm::collecting_accumulation_gen_p() { @@ -158,49 +105,6 @@ inline void factor_vm::check_tagged_pointer(cell tagged) #endif } -//local_roots.hpp -template -struct gc_root : public tagged -{ - factor_vm *parent_vm; - - void push() { parent_vm->check_tagged_pointer(tagged::value()); parent_vm->gc_locals.push_back((cell)this); } - - explicit gc_root(cell value_,factor_vm *vm) : tagged(value_),parent_vm(vm) { push(); } - explicit gc_root(TYPE *value_, factor_vm *vm) : tagged(value_),parent_vm(vm) { push(); } - - const gc_root& operator=(const TYPE *x) { tagged::operator=(x); return *this; } - const gc_root& operator=(const cell &x) { tagged::operator=(x); return *this; } - - ~gc_root() { -#ifdef FACTOR_DEBUG - assert(myvm->gc_locals.back() == (cell)this); -#endif - parent_vm->gc_locals.pop_back(); - } -}; - -/* A similar hack for the bignum implementation */ -struct gc_bignum -{ - bignum **addr; - factor_vm *parent_vm; - gc_bignum(bignum **addr_, factor_vm *vm) : addr(addr_), parent_vm(vm) { - if(*addr_) - parent_vm->check_data_pointer(*addr_); - parent_vm->gc_bignums.push_back((cell)addr); - } - - ~gc_bignum() { -#ifdef FACTOR_DEBUG - assert(myvm->gc_bignums.back() == (cell)addr); -#endif - parent_vm->gc_bignums.pop_back(); - } -}; - -#define GC_BIGNUM(x) gc_bignum x##__gc_root(&x,this) - //generic_arrays.hpp template TYPE *factor_vm::allot_array_internal(cell capacity) { diff --git a/vm/local_roots.hpp b/vm/local_roots.hpp index 0d6a033f82..a827c08f9c 100644 --- a/vm/local_roots.hpp +++ b/vm/local_roots.hpp @@ -1,3 +1,47 @@ namespace factor { + +//local_roots.hpp +template +struct gc_root : public tagged +{ + factor_vm *parent_vm; + + void push() { parent_vm->check_tagged_pointer(tagged::value()); parent_vm->gc_locals.push_back((cell)this); } + + explicit gc_root(cell value_,factor_vm *vm) : tagged(value_),parent_vm(vm) { push(); } + explicit gc_root(TYPE *value_, factor_vm *vm) : tagged(value_),parent_vm(vm) { push(); } + + const gc_root& operator=(const TYPE *x) { tagged::operator=(x); return *this; } + const gc_root& operator=(const cell &x) { tagged::operator=(x); return *this; } + + ~gc_root() { +#ifdef FACTOR_DEBUG + assert(myvm->gc_locals.back() == (cell)this); +#endif + parent_vm->gc_locals.pop_back(); + } +}; + +/* A similar hack for the bignum implementation */ +struct gc_bignum +{ + bignum **addr; + factor_vm *parent_vm; + gc_bignum(bignum **addr_, factor_vm *vm) : addr(addr_), parent_vm(vm) { + if(*addr_) + parent_vm->check_data_pointer(*addr_); + parent_vm->gc_bignums.push_back((cell)addr); + } + + ~gc_bignum() { +#ifdef FACTOR_DEBUG + assert(myvm->gc_bignums.back() == (cell)addr); +#endif + parent_vm->gc_bignums.pop_back(); + } +}; + +#define GC_BIGNUM(x) gc_bignum x##__gc_root(&x,this) + } diff --git a/vm/master.hpp b/vm/master.hpp index e51273f546..d970f1aaea 100755 --- a/vm/master.hpp +++ b/vm/master.hpp @@ -52,7 +52,6 @@ #include "data_heap.hpp" #include "write_barrier.hpp" #include "data_gc.hpp" -#include "local_roots.hpp" #include "generic_arrays.hpp" #include "debug.hpp" #include "arrays.hpp" @@ -71,6 +70,7 @@ #include "alien.hpp" #include "vm.hpp" #include "tagged.hpp" +#include "local_roots.hpp" #include "inlineimpls.hpp" #include "jit.hpp" #include "quotations.hpp" diff --git a/vm/vm.hpp b/vm/vm.hpp index a628de5405..46c9865cca 100644 --- a/vm/vm.hpp +++ b/vm/vm.hpp @@ -176,17 +176,58 @@ struct factor_vm //write barrier cell allot_markers_offset; - inline card *addr_to_card(cell a); - inline cell card_to_addr(card *c); - inline cell card_offset(card *c); - inline card_deck *addr_to_deck(cell a); - inline cell deck_to_addr(card_deck *c); - inline card *deck_to_card(card_deck *d); - inline card *addr_to_allot_marker(object *a); - inline void write_barrier(object *obj); - inline void allot_barrier(object *address); - - //data_gc + inline card *addr_to_card(cell a) + { + return (card*)(((cell)(a) >> card_bits) + cards_offset); + } + + inline cell card_to_addr(card *c) + { + return ((cell)c - cards_offset) << card_bits; + } + + inline cell card_offset(card *c) + { + return *(c - (cell)data->cards + (cell)data->allot_markers); + } + + inline card_deck *addr_to_deck(cell a) + { + return (card_deck *)(((cell)a >> deck_bits) + decks_offset); + } + + inline cell deck_to_addr(card_deck *c) + { + return ((cell)c - decks_offset) << deck_bits; + } + + inline card *deck_to_card(card_deck *d) + { + return (card *)((((cell)d - decks_offset) << (deck_bits - card_bits)) + cards_offset); + } + + inline card *addr_to_allot_marker(object *a) + { + return (card *)(((cell)a >> card_bits) + allot_markers_offset); + } + + /* the write barrier must be called any time we are potentially storing a + pointer from an older generation to a younger one */ + inline void write_barrier(object *obj) + { + *addr_to_card((cell)obj) = card_mark_mask; + *addr_to_deck((cell)obj) = card_mark_mask; + } + + /* we need to remember the first object allocated in the card */ + inline void allot_barrier(object *address) + { + card *ptr = addr_to_allot_marker(address); + if(*ptr == invalid_allot_marker) + *ptr = ((cell)address & addr_card_mask); + } + + // data_gc /* used during garbage collection only */ zone *newspace; bool performing_gc; -- 2.34.1