vm: working on new object-oriented garbage collector
parent
23e133e383
commit
6939759f46
5
Makefile
5
Makefile
|
@ -31,6 +31,7 @@ ifdef CONFIG
|
||||||
endif
|
endif
|
||||||
|
|
||||||
DLL_OBJS = $(PLAF_DLL_OBJS) \
|
DLL_OBJS = $(PLAF_DLL_OBJS) \
|
||||||
|
vm/aging_collector.o \
|
||||||
vm/alien.o \
|
vm/alien.o \
|
||||||
vm/arrays.o \
|
vm/arrays.o \
|
||||||
vm/bignum.o \
|
vm/bignum.o \
|
||||||
|
@ -46,17 +47,21 @@ DLL_OBJS = $(PLAF_DLL_OBJS) \
|
||||||
vm/dispatch.o \
|
vm/dispatch.o \
|
||||||
vm/errors.o \
|
vm/errors.o \
|
||||||
vm/factor.o \
|
vm/factor.o \
|
||||||
|
vm/full_collector.o \
|
||||||
vm/heap.o \
|
vm/heap.o \
|
||||||
vm/image.o \
|
vm/image.o \
|
||||||
vm/inline_cache.o \
|
vm/inline_cache.o \
|
||||||
vm/io.o \
|
vm/io.o \
|
||||||
vm/jit.o \
|
vm/jit.o \
|
||||||
vm/math.o \
|
vm/math.o \
|
||||||
|
vm/nursery_collector.o \
|
||||||
|
vm/old_space.o \
|
||||||
vm/primitives.o \
|
vm/primitives.o \
|
||||||
vm/profiler.o \
|
vm/profiler.o \
|
||||||
vm/quotations.o \
|
vm/quotations.o \
|
||||||
vm/run.o \
|
vm/run.o \
|
||||||
vm/strings.o \
|
vm/strings.o \
|
||||||
|
vm/to_tenured_collector.o \
|
||||||
vm/tuples.o \
|
vm/tuples.o \
|
||||||
vm/utilities.o \
|
vm/utilities.o \
|
||||||
vm/vm.o \
|
vm/vm.o \
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
#include "master.hpp"
|
||||||
|
|
||||||
|
namespace factor
|
||||||
|
{
|
||||||
|
|
||||||
|
aging_collector::aging_collector(factor_vm *myvm_) :
|
||||||
|
copying_collector<aging_space,aging_policy>
|
||||||
|
(myvm_,myvm_->data->aging,aging_policy(myvm_)) {}
|
||||||
|
|
||||||
|
void aging_collector::go()
|
||||||
|
{
|
||||||
|
trace_roots();
|
||||||
|
trace_contexts();
|
||||||
|
trace_cards(data->tenured);
|
||||||
|
trace_code_heap_roots();
|
||||||
|
cheneys_algorithm();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
namespace factor
|
||||||
|
{
|
||||||
|
|
||||||
|
struct aging_policy {
|
||||||
|
factor_vm *myvm;
|
||||||
|
zone *aging, *tenured;
|
||||||
|
|
||||||
|
aging_policy(factor_vm *myvm_) :
|
||||||
|
myvm(myvm_),
|
||||||
|
aging(myvm->data->aging),
|
||||||
|
tenured(myvm->data->tenured) {}
|
||||||
|
|
||||||
|
bool should_copy_p(object *untagged)
|
||||||
|
{
|
||||||
|
return !(aging->contains_p(untagged) || tenured->contains_p(untagged));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct aging_collector : copying_collector<aging_space,aging_policy> {
|
||||||
|
aging_collector(factor_vm *myvm_);
|
||||||
|
void go();
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
namespace factor
|
||||||
|
{
|
||||||
|
|
||||||
|
struct aging_space : old_space {
|
||||||
|
aging_space(cell size, cell start) : old_space(size,start) {}
|
||||||
|
|
||||||
|
bool is_nursery_p() { return false; }
|
||||||
|
bool is_aging_p() { return true; }
|
||||||
|
bool is_tenured_p() { return false; }
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,143 @@
|
||||||
|
namespace factor
|
||||||
|
{
|
||||||
|
|
||||||
|
template<typename TargetGeneration, typename Policy> struct collector {
|
||||||
|
factor_vm *myvm;
|
||||||
|
data_heap *data;
|
||||||
|
gc_state *current_gc;
|
||||||
|
TargetGeneration *target;
|
||||||
|
Policy policy;
|
||||||
|
|
||||||
|
explicit collector(factor_vm *myvm_, TargetGeneration *target_, Policy policy_) :
|
||||||
|
myvm(myvm_),
|
||||||
|
data(myvm_->data),
|
||||||
|
current_gc(myvm_->current_gc),
|
||||||
|
target(target_),
|
||||||
|
policy(policy_) {}
|
||||||
|
|
||||||
|
object *resolve_forwarding(object *untagged)
|
||||||
|
{
|
||||||
|
myvm->check_data_pointer(untagged);
|
||||||
|
|
||||||
|
/* is there another forwarding pointer? */
|
||||||
|
while(untagged->h.forwarding_pointer_p())
|
||||||
|
untagged = untagged->h.forwarding_pointer();
|
||||||
|
|
||||||
|
/* we've found the destination */
|
||||||
|
untagged->h.check_header();
|
||||||
|
return untagged;
|
||||||
|
}
|
||||||
|
|
||||||
|
void trace_handle(cell *handle)
|
||||||
|
{
|
||||||
|
cell pointer = *handle;
|
||||||
|
|
||||||
|
if(immediate_p(pointer)) return;
|
||||||
|
|
||||||
|
object *untagged = myvm->untag<object>(pointer);
|
||||||
|
if(!policy.should_copy_p(untagged))
|
||||||
|
return;
|
||||||
|
|
||||||
|
object *forwarding = resolve_forwarding(untagged);
|
||||||
|
|
||||||
|
if(forwarding == untagged)
|
||||||
|
untagged = promote_object(untagged);
|
||||||
|
else if(policy.should_copy_p(forwarding))
|
||||||
|
untagged = promote_object(forwarding);
|
||||||
|
else
|
||||||
|
untagged = forwarding;
|
||||||
|
|
||||||
|
*handle = RETAG(untagged,TAG(pointer));
|
||||||
|
}
|
||||||
|
|
||||||
|
void trace_slots(object *ptr)
|
||||||
|
{
|
||||||
|
cell *slot = (cell *)ptr;
|
||||||
|
cell *end = (cell *)((cell)ptr + myvm->binary_payload_start(ptr));
|
||||||
|
|
||||||
|
if(slot != end)
|
||||||
|
{
|
||||||
|
slot++;
|
||||||
|
for(; slot < end; slot++) trace_handle(slot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
object *promote_object(object *untagged)
|
||||||
|
{
|
||||||
|
cell size = myvm->untagged_object_size(untagged);
|
||||||
|
object *newpointer = target->allot(size);
|
||||||
|
/* XXX not exception-safe */
|
||||||
|
if(!newpointer) longjmp(current_gc->gc_unwind,1);
|
||||||
|
|
||||||
|
memcpy(newpointer,untagged,size);
|
||||||
|
untagged->h.forward_to(newpointer);
|
||||||
|
|
||||||
|
return newpointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
void trace_stack_elements(segment *region, cell *top)
|
||||||
|
{
|
||||||
|
for(cell *ptr = (cell *)region->start; ptr <= top; ptr++)
|
||||||
|
trace_handle(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void trace_registered_locals()
|
||||||
|
{
|
||||||
|
std::vector<cell>::const_iterator iter = myvm->gc_locals.begin();
|
||||||
|
std::vector<cell>::const_iterator end = myvm->gc_locals.end();
|
||||||
|
|
||||||
|
for(; iter < end; iter++)
|
||||||
|
trace_handle((cell *)(*iter));
|
||||||
|
}
|
||||||
|
|
||||||
|
void trace_registered_bignums()
|
||||||
|
{
|
||||||
|
std::vector<cell>::const_iterator iter = myvm->gc_bignums.begin();
|
||||||
|
std::vector<cell>::const_iterator end = myvm->gc_bignums.end();
|
||||||
|
|
||||||
|
for(; iter < end; iter++)
|
||||||
|
{
|
||||||
|
cell *handle = (cell *)(*iter);
|
||||||
|
|
||||||
|
if(*handle)
|
||||||
|
{
|
||||||
|
*handle |= BIGNUM_TYPE;
|
||||||
|
trace_handle(handle);
|
||||||
|
*handle &= ~BIGNUM_TYPE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Copy roots over at the start of GC, namely various constants, stacks,
|
||||||
|
the user environment and extra roots registered by local_roots.hpp */
|
||||||
|
void trace_roots()
|
||||||
|
{
|
||||||
|
trace_handle(&myvm->T);
|
||||||
|
trace_handle(&myvm->bignum_zero);
|
||||||
|
trace_handle(&myvm->bignum_pos_one);
|
||||||
|
trace_handle(&myvm->bignum_neg_one);
|
||||||
|
|
||||||
|
trace_registered_locals();
|
||||||
|
trace_registered_bignums();
|
||||||
|
|
||||||
|
for(int i = 0; i < USER_ENV; i++) trace_handle(&myvm->userenv[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void trace_contexts()
|
||||||
|
{
|
||||||
|
context *stacks = myvm->stack_chain;
|
||||||
|
|
||||||
|
while(stacks)
|
||||||
|
{
|
||||||
|
trace_stack_elements(stacks->datastack_region,(cell *)stacks->datastack);
|
||||||
|
trace_stack_elements(stacks->retainstack_region,(cell *)stacks->retainstack);
|
||||||
|
|
||||||
|
trace_handle(&stacks->catchstack_save);
|
||||||
|
trace_handle(&stacks->current_callback_save);
|
||||||
|
|
||||||
|
stacks = stacks->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,159 @@
|
||||||
|
namespace factor
|
||||||
|
{
|
||||||
|
|
||||||
|
template<typename TargetGeneration, typename Policy>
|
||||||
|
struct copying_collector : collector<TargetGeneration,Policy> {
|
||||||
|
cell scan;
|
||||||
|
|
||||||
|
explicit copying_collector(factor_vm *myvm_, TargetGeneration *target_, Policy policy_) :
|
||||||
|
collector<TargetGeneration,Policy>(myvm_,target_,policy_), scan(target_->here) {}
|
||||||
|
|
||||||
|
template<typename SourceGeneration> void trace_objects_between(SourceGeneration *gen, cell scan, cell *end)
|
||||||
|
{
|
||||||
|
while(scan && scan < *end)
|
||||||
|
{
|
||||||
|
this->trace_slots((object *)scan);
|
||||||
|
scan = gen->next_object_after(this->myvm,scan);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename SourceGeneration> void trace_card(SourceGeneration *gen, card *ptr)
|
||||||
|
{
|
||||||
|
cell card_start = this->myvm->card_to_addr(ptr);
|
||||||
|
cell card_scan = card_start + gen->card_offset(card_start);
|
||||||
|
cell card_end = this->myvm->card_to_addr(ptr + 1);
|
||||||
|
|
||||||
|
trace_objects_between(gen,card_scan,&card_end);
|
||||||
|
|
||||||
|
this->myvm->gc_stats.cards_scanned++;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename SourceGeneration> void trace_card_deck(SourceGeneration *gen, card_deck *deck, card mask, card unmask)
|
||||||
|
{
|
||||||
|
card *first_card = this->myvm->deck_to_card(deck);
|
||||||
|
card *last_card = this->myvm->deck_to_card(deck + 1);
|
||||||
|
|
||||||
|
u32 *quad_ptr;
|
||||||
|
u32 quad_mask = mask | (mask << 8) | (mask << 16) | (mask << 24);
|
||||||
|
|
||||||
|
for(quad_ptr = (u32 *)first_card; quad_ptr < (u32 *)last_card; quad_ptr++)
|
||||||
|
{
|
||||||
|
if(*quad_ptr & quad_mask)
|
||||||
|
{
|
||||||
|
card *ptr = (card *)quad_ptr;
|
||||||
|
|
||||||
|
for(int card = 0; card < 4; card++)
|
||||||
|
{
|
||||||
|
if(ptr[card] & mask)
|
||||||
|
{
|
||||||
|
trace_card(gen,&ptr[card]);
|
||||||
|
ptr[card] &= ~unmask;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this->myvm->gc_stats.decks_scanned++;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename SourceGeneration> void trace_cards(SourceGeneration *gen)
|
||||||
|
{
|
||||||
|
u64 start = current_micros();
|
||||||
|
|
||||||
|
card_deck *first_deck = this->myvm->addr_to_deck(gen->start);
|
||||||
|
card_deck *last_deck = this->myvm->addr_to_deck(gen->end);
|
||||||
|
|
||||||
|
card mask, unmask;
|
||||||
|
|
||||||
|
/* if we are collecting the nursery, we care about old->nursery pointers
|
||||||
|
but not old->aging pointers */
|
||||||
|
if(this->current_gc->collecting_nursery_p())
|
||||||
|
{
|
||||||
|
mask = card_points_to_nursery;
|
||||||
|
|
||||||
|
/* after the collection, no old->nursery pointers remain
|
||||||
|
anywhere, but old->aging pointers might remain in tenured
|
||||||
|
space */
|
||||||
|
if(gen->is_tenured_p())
|
||||||
|
unmask = card_points_to_nursery;
|
||||||
|
/* after the collection, all cards in aging space can be
|
||||||
|
cleared */
|
||||||
|
else if(gen->is_aging_p())
|
||||||
|
unmask = card_mark_mask;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
critical_error("bug in trace_gen_cards",0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* if we are collecting aging space into tenured space, we care about
|
||||||
|
all old->nursery and old->aging pointers. no old->aging pointers can
|
||||||
|
remain */
|
||||||
|
else if(this->current_gc->collecting_aging_p())
|
||||||
|
{
|
||||||
|
if(this->current_gc->collecting_aging_again)
|
||||||
|
{
|
||||||
|
mask = card_points_to_aging;
|
||||||
|
unmask = card_mark_mask;
|
||||||
|
}
|
||||||
|
/* after we collect aging space into the aging semispace, no
|
||||||
|
old->nursery pointers remain but tenured space might still have
|
||||||
|
pointers to aging space. */
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mask = card_points_to_aging;
|
||||||
|
unmask = card_points_to_nursery;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
critical_error("bug in trace_gen_cards",0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(card_deck *ptr = first_deck; ptr < last_deck; ptr++)
|
||||||
|
{
|
||||||
|
if(*ptr & mask)
|
||||||
|
{
|
||||||
|
trace_card_deck(gen,ptr,mask,unmask);
|
||||||
|
*ptr &= ~unmask;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this->myvm->gc_stats.card_scan_time += (current_micros() - start);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Trace all literals referenced from a code block. Only for aging and nursery collections */
|
||||||
|
void trace_literal_references(code_block *compiled)
|
||||||
|
{
|
||||||
|
this->trace_handle(&compiled->owner);
|
||||||
|
this->trace_handle(&compiled->literals);
|
||||||
|
this->trace_handle(&compiled->relocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Trace literals referenced from all code blocks. Only for aging and nursery collections */
|
||||||
|
void trace_code_heap_roots()
|
||||||
|
{
|
||||||
|
if(this->current_gc->collecting_gen >= this->myvm->code->youngest_referenced_generation)
|
||||||
|
{
|
||||||
|
unordered_map<code_block *,cell> &remembered_set = this->myvm->code->remembered_set;
|
||||||
|
unordered_map<code_block *,cell>::const_iterator iter = remembered_set.begin();
|
||||||
|
unordered_map<code_block *,cell>::const_iterator end = remembered_set.end();
|
||||||
|
|
||||||
|
for(; iter != end; iter++)
|
||||||
|
{
|
||||||
|
if(this->current_gc->collecting_gen >= iter->second)
|
||||||
|
trace_literal_references(iter->first);
|
||||||
|
}
|
||||||
|
|
||||||
|
this->myvm->gc_stats.code_heap_scans++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void cheneys_algorithm()
|
||||||
|
{
|
||||||
|
trace_objects_between(this->target,scan,&this->target->here);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -399,48 +399,48 @@ void factor_vm::update_dirty_code_blocks()
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Strategy>
|
template<typename Strategy>
|
||||||
copying_collector<Strategy>::copying_collector(factor_vm *myvm_, old_space *target_)
|
cheney_collector<Strategy>::cheney_collector(factor_vm *myvm_, old_space *target_)
|
||||||
: myvm(myvm_), current_gc(myvm_->current_gc), target(target_)
|
: myvm(myvm_), current_gc(myvm_->current_gc), target(target_)
|
||||||
{
|
{
|
||||||
scan = target->here;
|
scan = target->here;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Strategy> Strategy ©ing_collector<Strategy>::strategy()
|
template<typename Strategy> Strategy &cheney_collector<Strategy>::strategy()
|
||||||
{
|
{
|
||||||
return static_cast<Strategy &>(*this);
|
return static_cast<Strategy &>(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Strategy> object *copying_collector<Strategy>::allot(cell size)
|
template<typename Strategy> object *cheney_collector<Strategy>::allot(cell size)
|
||||||
{
|
{
|
||||||
return target->allot(size);
|
return target->allot(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Strategy> object *copying_collector<Strategy>::copy_object(object *untagged)
|
template<typename Strategy> object *cheney_collector<Strategy>::copy_object(object *untagged)
|
||||||
{
|
{
|
||||||
return myvm->promote_object(untagged,strategy());
|
return myvm->promote_object(untagged,strategy());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Strategy> bool copying_collector<Strategy>::should_copy_p(object *pointer)
|
template<typename Strategy> bool cheney_collector<Strategy>::should_copy_p(object *pointer)
|
||||||
{
|
{
|
||||||
return strategy().should_copy_p(pointer);
|
return strategy().should_copy_p(pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Strategy> cell copying_collector<Strategy>::trace_next(cell scan)
|
template<typename Strategy> cell cheney_collector<Strategy>::trace_next(cell scan)
|
||||||
{
|
{
|
||||||
object *obj = (object *)scan;
|
object *obj = (object *)scan;
|
||||||
myvm->trace_slots(obj,strategy());
|
myvm->trace_slots(obj,strategy());
|
||||||
return scan + myvm->untagged_object_size(obj);
|
return scan + myvm->untagged_object_size(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Strategy> void copying_collector<Strategy>::go()
|
template<typename Strategy> void cheney_collector<Strategy>::go()
|
||||||
{
|
{
|
||||||
strategy().copy_reachable_objects(scan,&target->here);
|
strategy().copy_reachable_objects(scan,&target->here);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct nursery_collector : copying_collector<nursery_collector>
|
struct nursery_strategy : cheney_collector<nursery_strategy>
|
||||||
{
|
{
|
||||||
explicit nursery_collector(factor_vm *myvm_, old_space *target_) :
|
explicit nursery_strategy(factor_vm *myvm_, old_space *target_) :
|
||||||
copying_collector<nursery_collector>(myvm_,target_) {}
|
cheney_collector<nursery_strategy>(myvm_,target_) {}
|
||||||
|
|
||||||
bool should_copy_p(object *untagged)
|
bool should_copy_p(object *untagged)
|
||||||
{
|
{
|
||||||
|
@ -453,12 +453,12 @@ struct nursery_collector : copying_collector<nursery_collector>
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct aging_collector : copying_collector<aging_collector>
|
struct aging_strategy : cheney_collector<aging_strategy>
|
||||||
{
|
{
|
||||||
zone *tenured;
|
zone *tenured;
|
||||||
|
|
||||||
explicit aging_collector(factor_vm *myvm_, old_space *target_) :
|
explicit aging_strategy(factor_vm *myvm_, old_space *target_) :
|
||||||
copying_collector<aging_collector>(myvm_,target_),
|
cheney_collector<aging_strategy>(myvm_,target_),
|
||||||
tenured(myvm->data->tenured) {}
|
tenured(myvm->data->tenured) {}
|
||||||
|
|
||||||
bool should_copy_p(object *untagged)
|
bool should_copy_p(object *untagged)
|
||||||
|
@ -475,10 +475,10 @@ struct aging_collector : copying_collector<aging_collector>
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct aging_again_collector : copying_collector<aging_again_collector>
|
struct aging_agian_strategy : cheney_collector<aging_agian_strategy>
|
||||||
{
|
{
|
||||||
explicit aging_again_collector(factor_vm *myvm_, old_space *target_) :
|
explicit aging_agian_strategy(factor_vm *myvm_, old_space *target_) :
|
||||||
copying_collector<aging_again_collector>(myvm_,target_) {}
|
cheney_collector<aging_agian_strategy>(myvm_,target_) {}
|
||||||
|
|
||||||
bool should_copy_p(object *untagged)
|
bool should_copy_p(object *untagged)
|
||||||
{
|
{
|
||||||
|
@ -491,10 +491,10 @@ struct aging_again_collector : copying_collector<aging_again_collector>
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct tenured_collector : copying_collector<tenured_collector>
|
struct tenured_strategy : cheney_collector<tenured_strategy>
|
||||||
{
|
{
|
||||||
explicit tenured_collector(factor_vm *myvm_, old_space *target_) :
|
explicit tenured_strategy(factor_vm *myvm_, old_space *target_) :
|
||||||
copying_collector<tenured_collector>(myvm_,target_) {}
|
cheney_collector<tenured_strategy>(myvm_,target_) {}
|
||||||
|
|
||||||
bool should_copy_p(object *untagged)
|
bool should_copy_p(object *untagged)
|
||||||
{
|
{
|
||||||
|
@ -513,7 +513,7 @@ struct tenured_collector : copying_collector<tenured_collector>
|
||||||
|
|
||||||
void factor_vm::collect_nursery()
|
void factor_vm::collect_nursery()
|
||||||
{
|
{
|
||||||
nursery_collector collector(this,data->aging);
|
nursery_strategy collector(this,data->aging);
|
||||||
|
|
||||||
trace_roots(collector);
|
trace_roots(collector);
|
||||||
trace_contexts(collector);
|
trace_contexts(collector);
|
||||||
|
@ -531,7 +531,7 @@ void factor_vm::collect_aging()
|
||||||
std::swap(data->aging,data->aging_semispace);
|
std::swap(data->aging,data->aging_semispace);
|
||||||
reset_generation(data->aging);
|
reset_generation(data->aging);
|
||||||
|
|
||||||
aging_collector collector(this,data->aging);
|
aging_strategy collector(this,data->aging);
|
||||||
|
|
||||||
trace_roots(collector);
|
trace_roots(collector);
|
||||||
trace_contexts(collector);
|
trace_contexts(collector);
|
||||||
|
@ -545,7 +545,7 @@ void factor_vm::collect_aging()
|
||||||
|
|
||||||
void factor_vm::collect_aging_again()
|
void factor_vm::collect_aging_again()
|
||||||
{
|
{
|
||||||
aging_again_collector collector(this,data->tenured);
|
aging_agian_strategy collector(this,data->tenured);
|
||||||
|
|
||||||
trace_roots(collector);
|
trace_roots(collector);
|
||||||
trace_contexts(collector);
|
trace_contexts(collector);
|
||||||
|
@ -571,7 +571,7 @@ void factor_vm::collect_tenured(cell requested_bytes, bool trace_contexts_)
|
||||||
reset_generation(data->tenured);
|
reset_generation(data->tenured);
|
||||||
}
|
}
|
||||||
|
|
||||||
tenured_collector collector(this,data->tenured);
|
tenured_strategy collector(this,data->tenured);
|
||||||
|
|
||||||
trace_roots(collector);
|
trace_roots(collector);
|
||||||
if(trace_contexts_) trace_contexts(collector);
|
if(trace_contexts_) trace_contexts(collector);
|
||||||
|
|
|
@ -63,13 +63,13 @@ struct gc_state {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Strategy> struct copying_collector {
|
template<typename Strategy> struct cheney_collector {
|
||||||
factor_vm *myvm;
|
factor_vm *myvm;
|
||||||
gc_state *current_gc;
|
gc_state *current_gc;
|
||||||
old_space *target;
|
old_space *target;
|
||||||
cell scan;
|
cell scan;
|
||||||
|
|
||||||
explicit copying_collector(factor_vm *myvm_, old_space *target);
|
explicit cheney_collector(factor_vm *myvm_, old_space *target);
|
||||||
Strategy &strategy();
|
Strategy &strategy();
|
||||||
object *allot(cell size);
|
object *allot(cell size);
|
||||||
cell trace_next(cell scan);
|
cell trace_next(cell scan);
|
||||||
|
|
|
@ -37,11 +37,11 @@ data_heap::data_heap(factor_vm *myvm, cell young_size_, cell aging_size_, cell t
|
||||||
|
|
||||||
cell start = align(seg->start,deck_size);
|
cell start = align(seg->start,deck_size);
|
||||||
|
|
||||||
tenured = new old_space(tenured_size,start);
|
tenured = new tenured_space(tenured_size,start);
|
||||||
tenured_semispace = new old_space(tenured_size,tenured->end);
|
tenured_semispace = new tenured_space(tenured_size,tenured->end);
|
||||||
|
|
||||||
aging = new old_space(aging_size,tenured_semispace->end);
|
aging = new aging_space(aging_size,tenured_semispace->end);
|
||||||
aging_semispace = new old_space(aging_size,aging->end);
|
aging_semispace = new aging_space(aging_size,aging->end);
|
||||||
|
|
||||||
nursery = new zone(young_size,aging_semispace->end);
|
nursery = new zone(young_size,aging_semispace->end);
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,10 @@ struct data_heap {
|
||||||
segment *seg;
|
segment *seg;
|
||||||
|
|
||||||
zone *nursery;
|
zone *nursery;
|
||||||
old_space *aging;
|
aging_space *aging;
|
||||||
old_space *aging_semispace;
|
aging_space *aging_semispace;
|
||||||
old_space *tenured;
|
tenured_space *tenured;
|
||||||
old_space *tenured_semispace;
|
tenured_space *tenured_semispace;
|
||||||
|
|
||||||
char *cards;
|
char *cards;
|
||||||
char *cards_end;
|
char *cards_end;
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
#include "master.hpp"
|
||||||
|
|
||||||
|
namespace factor
|
||||||
|
{
|
||||||
|
|
||||||
|
full_collector::full_collector(factor_vm *myvm_, bool trace_contexts_p_) :
|
||||||
|
copying_collector<tenured_space,full_policy>(myvm_,myvm_->data->tenured,full_policy(myvm_)),
|
||||||
|
trace_contexts_p(trace_contexts_p_) {}
|
||||||
|
|
||||||
|
void full_collector::go()
|
||||||
|
{
|
||||||
|
trace_roots();
|
||||||
|
if(trace_contexts_p) trace_contexts();
|
||||||
|
cheneys_algorithm();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
namespace factor
|
||||||
|
{
|
||||||
|
|
||||||
|
struct full_policy {
|
||||||
|
factor_vm *myvm;
|
||||||
|
zone *tenured;
|
||||||
|
|
||||||
|
full_policy(factor_vm *myvm_) : myvm(myvm_), tenured(myvm->data->tenured) {}
|
||||||
|
|
||||||
|
bool should_copy_p(object *untagged)
|
||||||
|
{
|
||||||
|
return !tenured->contains_p(untagged);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct full_collector : copying_collector<tenured_space,full_policy> {
|
||||||
|
bool trace_contexts_p;
|
||||||
|
|
||||||
|
full_collector(factor_vm *myvm_, bool trace_contexts_p_);
|
||||||
|
void go();
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -72,6 +72,8 @@ namespace factor
|
||||||
#include "zone.hpp"
|
#include "zone.hpp"
|
||||||
#include "write_barrier.hpp"
|
#include "write_barrier.hpp"
|
||||||
#include "old_space.hpp"
|
#include "old_space.hpp"
|
||||||
|
#include "aging_space.hpp"
|
||||||
|
#include "tenured_space.hpp"
|
||||||
#include "data_heap.hpp"
|
#include "data_heap.hpp"
|
||||||
#include "data_gc.hpp"
|
#include "data_gc.hpp"
|
||||||
#include "debug.hpp"
|
#include "debug.hpp"
|
||||||
|
@ -87,6 +89,12 @@ namespace factor
|
||||||
#include "vm.hpp"
|
#include "vm.hpp"
|
||||||
#include "tagged.hpp"
|
#include "tagged.hpp"
|
||||||
#include "local_roots.hpp"
|
#include "local_roots.hpp"
|
||||||
|
#include "collector.hpp"
|
||||||
|
#include "copying_collector.hpp"
|
||||||
|
#include "nursery_collector.hpp"
|
||||||
|
#include "aging_collector.hpp"
|
||||||
|
#include "to_tenured_collector.hpp"
|
||||||
|
#include "full_collector.hpp"
|
||||||
#include "callstack.hpp"
|
#include "callstack.hpp"
|
||||||
#include "generic_arrays.hpp"
|
#include "generic_arrays.hpp"
|
||||||
#include "arrays.hpp"
|
#include "arrays.hpp"
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
#include "master.hpp"
|
||||||
|
|
||||||
|
namespace factor
|
||||||
|
{
|
||||||
|
|
||||||
|
nursery_collector::nursery_collector(factor_vm *myvm_) :
|
||||||
|
copying_collector<aging_space,nursery_policy>
|
||||||
|
(myvm_,myvm_->data->aging,nursery_policy(myvm_)) {}
|
||||||
|
|
||||||
|
void nursery_collector::go()
|
||||||
|
{
|
||||||
|
trace_roots();
|
||||||
|
trace_contexts();
|
||||||
|
trace_cards(data->tenured);
|
||||||
|
trace_cards(data->aging);
|
||||||
|
trace_code_heap_roots();
|
||||||
|
cheneys_algorithm();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
namespace factor
|
||||||
|
{
|
||||||
|
|
||||||
|
struct nursery_policy {
|
||||||
|
factor_vm *myvm;
|
||||||
|
|
||||||
|
nursery_policy(factor_vm *myvm_) : myvm(myvm_) {}
|
||||||
|
|
||||||
|
bool should_copy_p(object *untagged)
|
||||||
|
{
|
||||||
|
return myvm->nursery.contains_p(untagged);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct nursery_collector : copying_collector<aging_space,nursery_policy> {
|
||||||
|
nursery_collector(factor_vm *myvm_);
|
||||||
|
void go();
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
#include "master.hpp"
|
||||||
|
|
||||||
|
namespace factor
|
||||||
|
{
|
||||||
|
|
||||||
|
old_space::old_space(cell size_, cell start_) : zone(size_,start_)
|
||||||
|
{
|
||||||
|
cell cards_size = size_ >> card_bits;
|
||||||
|
allot_markers = new card[cards_size];
|
||||||
|
allot_markers_end = allot_markers + cards_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
old_space::~old_space()
|
||||||
|
{
|
||||||
|
delete[] allot_markers;
|
||||||
|
}
|
||||||
|
|
||||||
|
card *old_space::addr_to_allot_marker(object *a)
|
||||||
|
{
|
||||||
|
return (card *)((((cell)a - start) >> card_bits) + (cell)allot_markers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* we need to remember the first object allocated in the card */
|
||||||
|
void old_space::record_allocation(object *obj)
|
||||||
|
{
|
||||||
|
card *ptr = addr_to_allot_marker(obj);
|
||||||
|
if(*ptr == invalid_allot_marker)
|
||||||
|
*ptr = ((cell)obj & addr_card_mask);
|
||||||
|
}
|
||||||
|
|
||||||
|
object *old_space::allot(cell size)
|
||||||
|
{
|
||||||
|
if(here + size > end) return NULL;
|
||||||
|
|
||||||
|
object *obj = zone::allot(size);
|
||||||
|
record_allocation(obj);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
void old_space::clear_allot_markers()
|
||||||
|
{
|
||||||
|
memset(allot_markers,invalid_allot_marker,size >> card_bits);
|
||||||
|
}
|
||||||
|
|
||||||
|
cell old_space::next_object_after(factor_vm *myvm, cell scan)
|
||||||
|
{
|
||||||
|
cell size = myvm->untagged_object_size((object *)scan);
|
||||||
|
if(scan + size < end)
|
||||||
|
return scan + size;
|
||||||
|
else
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -5,58 +5,19 @@ struct old_space : zone {
|
||||||
card *allot_markers;
|
card *allot_markers;
|
||||||
card *allot_markers_end;
|
card *allot_markers_end;
|
||||||
|
|
||||||
old_space(cell size_, cell start_) : zone(size_,start_)
|
old_space(cell size_, cell start_);
|
||||||
{
|
~old_space();
|
||||||
cell cards_size = size_ >> card_bits;
|
|
||||||
allot_markers = new card[cards_size];
|
|
||||||
allot_markers_end = allot_markers + cards_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
~old_space()
|
|
||||||
{
|
|
||||||
delete[] allot_markers;
|
|
||||||
}
|
|
||||||
|
|
||||||
card *addr_to_allot_marker(object *a)
|
|
||||||
{
|
|
||||||
return (card *)((((cell)a - start) >> card_bits) + (cell)allot_markers);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* we need to remember the first object allocated in the card */
|
|
||||||
void record_allocation(object *obj)
|
|
||||||
{
|
|
||||||
card *ptr = addr_to_allot_marker(obj);
|
|
||||||
if(*ptr == invalid_allot_marker)
|
|
||||||
*ptr = ((cell)obj & addr_card_mask);
|
|
||||||
}
|
|
||||||
|
|
||||||
cell card_offset(cell address)
|
cell card_offset(cell address)
|
||||||
{
|
{
|
||||||
return allot_markers[(address - start) >> card_bits];
|
return allot_markers[(address - start) >> card_bits];
|
||||||
}
|
}
|
||||||
|
|
||||||
object *allot(cell size)
|
card *addr_to_allot_marker(object *a);
|
||||||
{
|
void record_allocation(object *obj);
|
||||||
if(here + size > end) return NULL;
|
object *allot(cell size);
|
||||||
|
void clear_allot_markers();
|
||||||
object *obj = zone::allot(size);
|
cell next_object_after(factor_vm *myvm, cell scan);
|
||||||
record_allocation(obj);
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
void clear_allot_markers()
|
|
||||||
{
|
|
||||||
memset(allot_markers,invalid_allot_marker,size >> card_bits);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* object *next_object_after(object *ptr)
|
|
||||||
{
|
|
||||||
cell size = untagged_object_size(ptr);
|
|
||||||
if((cell)ptr + size < end)
|
|
||||||
return (object *)((cell)ptr + size);
|
|
||||||
else
|
|
||||||
return NULL;
|
|
||||||
} */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
namespace factor
|
||||||
|
{
|
||||||
|
|
||||||
|
struct tenured_space : old_space {
|
||||||
|
tenured_space(cell size, cell start) : old_space(size,start) {}
|
||||||
|
|
||||||
|
bool is_nursery_p() { return false; }
|
||||||
|
bool is_aging_p() { return false; }
|
||||||
|
bool is_tenured_p() { return true; }
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
#include "master.hpp"
|
||||||
|
|
||||||
|
namespace factor
|
||||||
|
{
|
||||||
|
|
||||||
|
to_tenured_collector::to_tenured_collector(factor_vm *myvm_) :
|
||||||
|
copying_collector<tenured_space,to_tenured_policy>
|
||||||
|
(myvm_,myvm_->data->tenured,to_tenured_policy(myvm_)) {}
|
||||||
|
|
||||||
|
void to_tenured_collector::go()
|
||||||
|
{
|
||||||
|
trace_roots();
|
||||||
|
trace_contexts();
|
||||||
|
trace_cards(data->tenured);
|
||||||
|
trace_code_heap_roots();
|
||||||
|
cheneys_algorithm();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
namespace factor
|
||||||
|
{
|
||||||
|
|
||||||
|
struct to_tenured_policy {
|
||||||
|
factor_vm *myvm;
|
||||||
|
zone *tenured;
|
||||||
|
|
||||||
|
to_tenured_policy(factor_vm *myvm_) : myvm(myvm_), tenured(myvm->data->tenured) {}
|
||||||
|
|
||||||
|
bool should_copy_p(object *untagged)
|
||||||
|
{
|
||||||
|
return !tenured->contains_p(untagged);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct to_tenured_collector : copying_collector<tenured_space,to_tenured_policy> {
|
||||||
|
to_tenured_collector(factor_vm *myvm_);
|
||||||
|
void go();
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -9,13 +9,7 @@ struct zone {
|
||||||
cell size;
|
cell size;
|
||||||
cell end;
|
cell end;
|
||||||
|
|
||||||
cell init_zone(cell size_, cell start_)
|
zone(cell size_, cell start_) : start(start_), here(0), size(size_), end(start_ + size_) {}
|
||||||
{
|
|
||||||
size = size_;
|
|
||||||
start = here = start_;
|
|
||||||
end = start_ + size_;
|
|
||||||
return end;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool contains_p(object *pointer)
|
inline bool contains_p(object *pointer)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue