vm: more refactoring
parent
6789a40fc6
commit
1f76a64e91
|
@ -40,12 +40,15 @@ template<typename Strategy> void factor_vm::trace_handle(cell *handle, Strategy
|
||||||
if(strategy.should_copy_p(untagged))
|
if(strategy.should_copy_p(untagged))
|
||||||
{
|
{
|
||||||
object *forwarding = resolve_forwarding(untagged,strategy);
|
object *forwarding = resolve_forwarding(untagged,strategy);
|
||||||
|
|
||||||
if(forwarding == untagged)
|
if(forwarding == untagged)
|
||||||
*handle = strategy.copy_object(pointer);
|
untagged = strategy.copy_object(untagged);
|
||||||
else if(strategy.should_copy_p(forwarding))
|
else if(strategy.should_copy_p(forwarding))
|
||||||
*handle = strategy.copy_object(RETAG(forwarding,TAG(pointer)));
|
untagged = strategy.copy_object(forwarding);
|
||||||
else
|
else
|
||||||
*handle = RETAG(forwarding,TAG(pointer));
|
untagged = forwarding;
|
||||||
|
|
||||||
|
*handle = RETAG(untagged,TAG(pointer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,6 +65,22 @@ template<typename Strategy> void factor_vm::trace_slots(object *ptr, Strategy &s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename Strategy> 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<typename Strategy> void factor_vm::trace_card(card *ptr, cell gen, cell here, Strategy &strategy)
|
template<typename Strategy> void factor_vm::trace_card(card *ptr, cell gen, cell here, Strategy &strategy)
|
||||||
{
|
{
|
||||||
cell card_scan = card_to_addr(ptr) + card_offset(ptr);
|
cell card_scan = card_to_addr(ptr) + card_offset(ptr);
|
||||||
|
@ -407,28 +426,17 @@ template<typename Strategy> Strategy ©ing_collector<Strategy>::strategy()
|
||||||
return static_cast<Strategy &>(*this);
|
return static_cast<Strategy &>(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Given a pointer to oldspace, copy it to newspace */
|
template<typename Strategy> object *copying_collector<Strategy>::allot(cell size)
|
||||||
template<typename Strategy> object *copying_collector<Strategy>::copy_untagged_object(object *pointer, cell size)
|
|
||||||
{
|
{
|
||||||
if(newspace->here + size >= newspace->end)
|
if(newspace->here + size <= newspace->end)
|
||||||
longjmp(current_gc->gc_unwind,1);
|
return myvm->allot_zone(newspace,size);
|
||||||
|
else
|
||||||
object *newpointer = myvm->allot_zone(newspace,size);
|
return NULL;
|
||||||
|
|
||||||
gc_stats *s = &myvm->stats[current_gc->collecting_gen];
|
|
||||||
s->object_count++;
|
|
||||||
s->bytes_copied += size;
|
|
||||||
|
|
||||||
memcpy(newpointer,pointer,size);
|
|
||||||
return newpointer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Strategy> cell copying_collector<Strategy>::copy_object(cell pointer)
|
template<typename Strategy> object *copying_collector<Strategy>::copy_object(object *untagged)
|
||||||
{
|
{
|
||||||
object *untagged = myvm->untag<object>(pointer);
|
return myvm->promote_object(untagged,strategy());
|
||||||
object *newpointer = copy_untagged_object(untagged,myvm->untagged_object_size(untagged));
|
|
||||||
untagged->h.forward_to(newpointer);
|
|
||||||
return RETAG(newpointer,TAG(pointer));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Strategy> bool copying_collector<Strategy>::should_copy_p(object *pointer)
|
template<typename Strategy> bool copying_collector<Strategy>::should_copy_p(object *pointer)
|
||||||
|
|
|
@ -63,10 +63,10 @@ template<typename Strategy> struct copying_collector {
|
||||||
|
|
||||||
explicit copying_collector(factor_vm *myvm_, zone *newspace);
|
explicit copying_collector(factor_vm *myvm_, zone *newspace);
|
||||||
Strategy &strategy();
|
Strategy &strategy();
|
||||||
object *copy_untagged_object(object *pointer, cell size);
|
object *allot(cell size);
|
||||||
cell trace_next(cell scan);
|
cell trace_next(cell scan);
|
||||||
cell copy_object(cell pointer);
|
object *copy_object(object *untagged);
|
||||||
bool should_copy_p(object *pointer);
|
bool should_copy_p(object *untagged);
|
||||||
void go();
|
void go();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -239,6 +239,7 @@ struct factor_vm
|
||||||
void init_data_gc();
|
void init_data_gc();
|
||||||
template<typename Strategy> object *resolve_forwarding(object *untagged, Strategy &strategy);
|
template<typename Strategy> object *resolve_forwarding(object *untagged, Strategy &strategy);
|
||||||
template<typename Strategy> void trace_handle(cell *handle, Strategy &strategy);
|
template<typename Strategy> void trace_handle(cell *handle, Strategy &strategy);
|
||||||
|
template<typename Strategy> object *promote_object(object *pointer, Strategy &strategy);
|
||||||
template<typename Strategy> void trace_slots(object *ptr, Strategy &strategy);
|
template<typename Strategy> void trace_slots(object *ptr, Strategy &strategy);
|
||||||
template<typename Strategy> void trace_card(card *ptr, cell gen, cell here, Strategy &strategy);
|
template<typename Strategy> void trace_card(card *ptr, cell gen, cell here, Strategy &strategy);
|
||||||
template<typename Strategy> void trace_card_deck(card_deck *deck, cell gen, card mask, card unmask, Strategy &strategy);
|
template<typename Strategy> void trace_card_deck(card_deck *deck, cell gen, card mask, card unmask, Strategy &strategy);
|
||||||
|
|
Loading…
Reference in New Issue