vm: make compaction its own gc_op

db4
Slava Pestov 2009-10-25 14:02:14 -05:00
parent 7d8c85443e
commit c30df42e48
6 changed files with 30 additions and 52 deletions

View File

@ -110,7 +110,7 @@ struct code_block_compaction_updater {
}
};
void factor_vm::collect_full_compact(bool trace_contexts_p)
void factor_vm::collect_compact_impl(bool trace_contexts_p)
{
tenured_space *tenured = data->tenured;
mark_bits<object> *data_forwarding_map = &tenured->state;

View File

@ -40,7 +40,7 @@ struct object_start_map_updater {
}
};
void factor_vm::collect_full_mark(bool trace_contexts_p)
void factor_vm::collect_mark_impl(bool trace_contexts_p)
{
full_collector collector(this);
@ -74,43 +74,21 @@ void factor_vm::collect_full_mark(bool trace_contexts_p)
code->clear_remembered_set();
}
void factor_vm::collect_full_sweep()
void factor_vm::collect_sweep_impl()
{
data->tenured->starts.clear_object_start_offsets();
object_start_map_updater updater(&data->tenured->starts);
data->tenured->sweep(updater);
}
void factor_vm::collect_growing_heap(cell requested_bytes,
bool trace_contexts_p,
bool compact_p)
void factor_vm::collect_growing_heap(cell requested_bytes, bool trace_contexts_p)
{
/* Grow the data heap and copy all live objects to the new heap. */
data_heap *old = data;
set_data_heap(data->grow(requested_bytes));
collect_full_mark(trace_contexts_p);
collect_mark_impl(trace_contexts_p);
collect_compact_impl(trace_contexts_p);
delete old;
if(compact_p)
collect_full_compact(trace_contexts_p);
else
{
collect_full_sweep();
relocate_code_heap();
}
}
void factor_vm::collect_full(bool trace_contexts_p, bool compact_p)
{
collect_full_mark(trace_contexts_p);
if(compact_p)
collect_full_compact(trace_contexts_p);
else
{
collect_full_sweep();
update_code_heap_words_and_literals();
}
}
}

View File

@ -25,10 +25,7 @@ void factor_vm::record_gc_stats(generation_statistics *stats)
stats->max_gc_time = gc_elapsed;
}
void factor_vm::gc(gc_op op,
cell requested_bytes,
bool trace_contexts_p,
bool compact_p)
void factor_vm::gc(gc_op op, cell requested_bytes, bool trace_contexts_p)
{
assert(!gc_off);
assert(!current_gc);
@ -57,6 +54,7 @@ void factor_vm::gc(gc_op op,
current_gc->op = collect_full_op;
break;
case collect_full_op:
case collect_compact_op:
current_gc->op = collect_growing_heap_op;
break;
default:
@ -83,11 +81,18 @@ void factor_vm::gc(gc_op op,
record_gc_stats(&gc_stats.aging_stats);
break;
case collect_full_op:
collect_full(trace_contexts_p,compact_p);
collect_mark_impl(trace_contexts_p);
collect_sweep_impl();
update_code_heap_words_and_literals();
record_gc_stats(&gc_stats.full_stats);
break;
case collect_compact_op:
collect_mark_impl(trace_contexts_p);
collect_compact_impl(trace_contexts_p);
record_gc_stats(&gc_stats.full_stats);
break;
case collect_growing_heap_op:
collect_growing_heap(requested_bytes,trace_contexts_p,compact_p);
collect_growing_heap(requested_bytes,trace_contexts_p);
record_gc_stats(&gc_stats.full_stats);
break;
default:
@ -106,24 +111,21 @@ void factor_vm::primitive_minor_gc()
{
gc(collect_nursery_op,
0, /* requested size */
true, /* trace contexts? */
false /* compact code heap? */);
true /* trace contexts? */);
}
void factor_vm::primitive_full_gc()
{
gc(collect_full_op,
0, /* requested size */
true, /* trace contexts? */
true /* compact code heap? */);
true /* trace contexts? */);
}
void factor_vm::primitive_compact_gc()
{
gc(collect_full_op,
gc(collect_compact_op,
0, /* requested size */
true, /* trace contexts? */
true /* compact code heap? */);
true /* trace contexts? */);
}
void factor_vm::add_gc_stats(generation_statistics *stats, growable_array *result)
@ -251,8 +253,7 @@ object *factor_vm::allot_object(header header, cell size)
{
gc(collect_growing_heap_op,
size, /* requested size */
true, /* trace contexts? */
false /* compact code heap? */);
true /* trace contexts? */);
}
}

View File

@ -6,6 +6,7 @@ enum gc_op {
collect_aging_op,
collect_to_tenured_op,
collect_full_op,
collect_compact_op,
collect_growing_heap_op
};

View File

@ -327,10 +327,9 @@ void factor_vm::primitive_save_image_and_exit()
for(cell i = 0; i < special_object_count; i++)
if(!save_env_p(i)) special_objects[i] = false_object;
gc(collect_full_op,
gc(collect_compact_op,
0, /* requested size */
false, /* discard objects only reachable from stacks */
true /* compact the code heap */);
false /* discard objects only reachable from stacks */);
/* Save the image */
if(save_image((vm_char *)(path.untagged() + 1)))

View File

@ -247,13 +247,12 @@ struct factor_vm
void collect_nursery();
void collect_aging();
void collect_to_tenured();
void collect_full_mark(bool trace_contexts_p);
void collect_full_sweep();
void collect_full_compact(bool trace_contexts_p);
void collect_growing_heap(cell requested_bytes, bool trace_contexts_p, bool compact_p);
void collect_full(bool trace_contexts_p, bool compact_p);
void collect_mark_impl(bool trace_contexts_p);
void collect_sweep_impl();
void collect_compact_impl(bool trace_contexts_p);
void collect_growing_heap(cell requested_bytes, bool trace_contexts_p);
void record_gc_stats(generation_statistics *stats);
void gc(gc_op op, cell requested_bytes, bool trace_contexts_p, bool compact_p);
void gc(gc_op op, cell requested_bytes, bool trace_contexts_p);
void primitive_minor_gc();
void primitive_full_gc();
void primitive_compact_gc();