vm: restructure data_roots so that its a sequence of handle/len pairs rather than just handles, use it in inline_gc() and all_instances() so that we don't run out of heap while building the object array
parent
b011295300
commit
e2107166ff
|
@ -245,10 +245,14 @@ cell factor_vm::instances(cell type)
|
|||
each_object(accum);
|
||||
cell object_count = accum.objects.size();
|
||||
|
||||
gc_off = true;
|
||||
data_roots.push_back(accum.objects[0]);
|
||||
data_roots.push_back(object_count);
|
||||
|
||||
array *objects = allot_array(object_count,false_object);
|
||||
memcpy(objects->data(),&accum.objects[0],object_count * sizeof(cell));
|
||||
gc_off = false;
|
||||
|
||||
data_roots.pop_back();
|
||||
data_roots.pop_back();
|
||||
|
||||
return tag<array>(objects);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ struct data_root : public tagged<Type> {
|
|||
void push()
|
||||
{
|
||||
parent->data_roots.push_back((cell)this);
|
||||
parent->data_roots.push_back(1);
|
||||
}
|
||||
|
||||
explicit data_root(cell value_, factor_vm *parent_)
|
||||
|
@ -27,6 +28,10 @@ struct data_root : public tagged<Type> {
|
|||
|
||||
~data_root()
|
||||
{
|
||||
#ifdef FACTOR_DEBUG
|
||||
assert(parent->data_roots.back() == 1);
|
||||
#endif
|
||||
parent->data_roots.pop_back();
|
||||
#ifdef FACTOR_DEBUG
|
||||
assert(parent->data_roots.back() == (cell)this);
|
||||
#endif
|
||||
|
|
12
vm/gc.cpp
12
vm/gc.cpp
|
@ -218,18 +218,18 @@ void factor_vm::primitive_compact_gc()
|
|||
true /* trace contexts? */);
|
||||
}
|
||||
|
||||
void factor_vm::inline_gc(cell *data_roots_base, cell data_roots_size)
|
||||
void factor_vm::inline_gc(cell data_roots_base, cell data_roots_size)
|
||||
{
|
||||
for(cell i = 0; i < data_roots_size; i++)
|
||||
data_roots.push_back((cell)&data_roots_base[i]);
|
||||
data_roots.push_back(data_roots_base);
|
||||
data_roots.push_back(data_roots_size);
|
||||
|
||||
primitive_minor_gc();
|
||||
|
||||
for(cell i = 0; i < data_roots_size; i++)
|
||||
data_roots.pop_back();
|
||||
data_roots.pop_back();
|
||||
data_roots.pop_back();
|
||||
}
|
||||
|
||||
VM_C_API void inline_gc(cell *data_roots_base, cell data_roots_size, factor_vm *parent)
|
||||
VM_C_API void inline_gc(cell data_roots_base, cell data_roots_size, factor_vm *parent)
|
||||
{
|
||||
parent->inline_gc(data_roots_base,data_roots_size);
|
||||
}
|
||||
|
|
|
@ -53,6 +53,6 @@ struct gc_state {
|
|||
void start_again(gc_op op_, factor_vm *parent);
|
||||
};
|
||||
|
||||
VM_C_API void inline_gc(cell *data_roots_base, cell data_roots_size, factor_vm *parent);
|
||||
VM_C_API void inline_gc(cell data_roots_base, cell data_roots_size, factor_vm *parent);
|
||||
|
||||
}
|
||||
|
|
|
@ -8,15 +8,18 @@ template<typename Visitor> struct slot_visitor {
|
|||
explicit slot_visitor<Visitor>(factor_vm *parent_, Visitor visitor_) :
|
||||
parent(parent_), visitor(visitor_) {}
|
||||
|
||||
cell visit_pointer(cell pointer)
|
||||
{
|
||||
object *untagged = untag<object>(pointer);
|
||||
untagged = visitor(untagged);
|
||||
return RETAG(untagged,TAG(pointer));
|
||||
}
|
||||
|
||||
void visit_handle(cell *handle)
|
||||
{
|
||||
cell pointer = *handle;
|
||||
|
||||
if(immediate_p(pointer)) return;
|
||||
|
||||
object *untagged = untag<object>(pointer);
|
||||
untagged = visitor(untagged);
|
||||
*handle = RETAG(untagged,TAG(pointer));
|
||||
if(!immediate_p(pointer))
|
||||
*handle = visit_pointer(pointer);
|
||||
}
|
||||
|
||||
void visit_slots(object *ptr, cell payload_start)
|
||||
|
@ -47,8 +50,13 @@ template<typename Visitor> struct slot_visitor {
|
|||
std::vector<cell>::const_iterator iter = parent->data_roots.begin();
|
||||
std::vector<cell>::const_iterator end = parent->data_roots.end();
|
||||
|
||||
for(; iter < end; iter++)
|
||||
visit_handle((cell *)(*iter));
|
||||
while(iter < end)
|
||||
{
|
||||
cell start = *iter++;
|
||||
cell len = *iter++;
|
||||
for(cell index = 0; index < len; index++)
|
||||
visit_handle((cell *)start + index);
|
||||
}
|
||||
}
|
||||
|
||||
void visit_bignum_roots()
|
||||
|
|
|
@ -281,7 +281,7 @@ struct factor_vm
|
|||
void primitive_minor_gc();
|
||||
void primitive_full_gc();
|
||||
void primitive_compact_gc();
|
||||
void inline_gc(cell *data_roots_base, cell data_roots_size);
|
||||
void inline_gc(cell data_roots_base, cell data_roots_size);
|
||||
void primitive_enable_gc_events();
|
||||
void primitive_disable_gc_events();
|
||||
object *allot_object(header header, cell size);
|
||||
|
|
Loading…
Reference in New Issue