VM: visit_roots and visit_contexts where always called in tandem, make a new method visit_all_roots that calls them both

db4
Björn Lindqvist 2015-02-19 04:43:53 +00:00 committed by John Benediktsson
parent fe2c2d23de
commit 5490c50217
9 changed files with 21 additions and 24 deletions

View File

@ -38,9 +38,8 @@ void factor_vm::collect_aging() {
copying_collector<aging_space, aging_policy> collector(this, copying_collector<aging_space, aging_policy> collector(this,
this->data->aging, this->data->aging,
aging_policy(this)); aging_policy(this));
collector.data_visitor.visit_roots();
collector.data_visitor.visit_contexts();
collector.visitor.visit_all_roots();
collector.cheneys_algorithm(); collector.cheneys_algorithm();
data->reset_nursery(); data->reset_nursery();

View File

@ -44,10 +44,13 @@ template <typename Iterator, typename Fixup>
void factor_vm::iterate_callstack(context* ctx, Iterator& iterator, void factor_vm::iterate_callstack(context* ctx, Iterator& iterator,
Fixup& fixup) { Fixup& fixup) {
FACTOR_ASSERT(!Fixup::translated_code_block_map);
cell top = ctx->callstack_top; cell top = ctx->callstack_top;
cell bottom = ctx->callstack_bottom;
/* When we are translating the code block maps, all callstacks must
be empty. */
FACTOR_ASSERT(!Fixup::translated_code_block_map || top == bottom);
while (top < ctx->callstack_bottom) { while (top < bottom) {
cell addr = *(cell*)top; cell addr = *(cell*)top;
FACTOR_ASSERT(addr != 0); FACTOR_ASSERT(addr != 0);
@ -65,7 +68,7 @@ void factor_vm::iterate_callstack(context* ctx, Iterator& iterator,
iterator(top, size, owner, addr); iterator(top, size, owner, addr);
top += size; top += size;
} }
FACTOR_ASSERT(top == ctx->callstack_bottom); FACTOR_ASSERT(top == bottom);
} }
/* Allocates memory */ /* Allocates memory */

View File

@ -211,8 +211,7 @@ void factor_vm::collect_compact_impl() {
code->allocator->compact(code_block_updater, fixup, &code_finger); code->allocator->compact(code_block_updater, fixup, &code_finger);
} }
forwarder.visit_roots(); forwarder.visit_all_roots();
forwarder.visit_contexts();
forwarder.visit_context_code_blocks(); forwarder.visit_context_code_blocks();
} }

View File

@ -32,8 +32,7 @@ void factor_vm::collect_mark_impl() {
code->allocator->state.clear_mark_bits(); code->allocator->state.clear_mark_bits();
data->tenured->state.clear_mark_bits(); data->tenured->state.clear_mark_bits();
visitor.visit_roots(); visitor.visit_all_roots();
visitor.visit_contexts();
visitor.visit_context_code_blocks(); visitor.visit_context_code_blocks();
visitor.visit_uninitialized_code_blocks(); visitor.visit_uninitialized_code_blocks();

View File

@ -117,8 +117,8 @@ struct start_object_updater {
void factor_vm::fixup_data(cell data_offset, cell code_offset) { void factor_vm::fixup_data(cell data_offset, cell code_offset) {
startup_fixup fixup(data_offset, code_offset); startup_fixup fixup(data_offset, code_offset);
slot_visitor<startup_fixup> data_workhorse(this, fixup); slot_visitor<startup_fixup> visitor(this, fixup);
data_workhorse.visit_roots(); visitor.visit_all_roots();
start_object_updater updater(this, fixup); start_object_updater updater(this, fixup);
data->tenured->iterate(updater, fixup); data->tenured->iterate(updater, fixup);

View File

@ -9,9 +9,7 @@ void factor_vm::collect_nursery() {
this->data->aging, this->data->aging,
nursery_policy(this)); nursery_policy(this));
collector.data_visitor.visit_roots(); collector.visitor.visit_all_roots();
collector.data_visitor.visit_contexts();
gc_event* event = current_gc->event; gc_event* event = current_gc->event;
if (event) if (event)

View File

@ -146,8 +146,7 @@ void factor_vm::primitive_become() {
{ {
slot_visitor<slot_become_fixup> workhorse(this, slot_visitor<slot_become_fixup> workhorse(this,
slot_become_fixup(&become_map)); slot_become_fixup(&become_map));
workhorse.visit_roots(); workhorse.visit_all_roots();
workhorse.visit_contexts();
object_become_visitor object_visitor(&workhorse); object_become_visitor object_visitor(&workhorse);
each_object(object_visitor); each_object(object_visitor);

View File

@ -101,9 +101,8 @@ them.
This is used by GC's copying, sweep and compact phases, and the implementation This is used by GC's copying, sweep and compact phases, and the implementation
of the become primitive. of the become primitive.
Iteration is driven by visit_*() methods. Some of them define GC roots: Iteration is driven by visit_*() methods. Only one of them define GC roots:
- visit_roots() - visit_all_roots()
- visit_contexts()
Code block visitors iterate over sets of code blocks, applying a functor to Code block visitors iterate over sets of code blocks, applying a functor to
each one. The functor returns a new code_block pointer, which may or may not each one. The functor returns a new code_block pointer, which may or may not
@ -132,7 +131,7 @@ template <typename Fixup> struct slot_visitor {
void visit_data_roots(); void visit_data_roots();
void visit_callback_roots(); void visit_callback_roots();
void visit_literal_table_roots(); void visit_literal_table_roots();
void visit_roots(); void visit_all_roots();
void visit_callstack_object(callstack* stack); void visit_callstack_object(callstack* stack);
void visit_callstack(context* ctx); void visit_callstack(context* ctx);
void visit_context(context *ctx); void visit_context(context *ctx);
@ -242,7 +241,7 @@ template <typename Fixup> void slot_visitor<Fixup>::visit_sample_threads() {
} }
} }
template <typename Fixup> void slot_visitor<Fixup>::visit_roots() { template <typename Fixup> void slot_visitor<Fixup>::visit_all_roots() {
visit_handle(&parent->true_object); visit_handle(&parent->true_object);
visit_handle(&parent->bignum_zero); visit_handle(&parent->bignum_zero);
visit_handle(&parent->bignum_pos_one); visit_handle(&parent->bignum_pos_one);
@ -256,6 +255,9 @@ template <typename Fixup> void slot_visitor<Fixup>::visit_roots() {
visit_object_array(parent->special_objects, visit_object_array(parent->special_objects,
parent->special_objects + special_object_count); parent->special_objects + special_object_count);
visit_contexts();
} }
/* primitive_minor_gc() is invoked by inline GC checks, and it needs to fill in /* primitive_minor_gc() is invoked by inline GC checks, and it needs to fill in

View File

@ -22,9 +22,7 @@ void factor_vm::collect_to_tenured() {
mark_stack.clear(); mark_stack.clear();
collector.data_visitor.visit_roots(); collector.visitor.visit_all_roots();
collector.data_visitor.visit_contexts();
gc_event* event = current_gc->event; gc_event* event = current_gc->event;
if (event) if (event)