2009-10-07 16:48:09 -04:00
|
|
|
#include "master.hpp"
|
|
|
|
|
2013-05-11 22:02:39 -04:00
|
|
|
namespace factor {
|
|
|
|
|
2015-08-03 18:06:57 -04:00
|
|
|
struct full_policy {
|
|
|
|
factor_vm* parent;
|
|
|
|
tenured_space* tenured;
|
|
|
|
|
|
|
|
explicit full_policy(factor_vm* parent)
|
|
|
|
: parent(parent), tenured(parent->data->tenured) {}
|
|
|
|
|
|
|
|
bool should_copy_p(object* untagged) {
|
|
|
|
return !tenured->contains_p(untagged);
|
|
|
|
}
|
|
|
|
|
|
|
|
void promoted_object(object* obj) {
|
|
|
|
tenured->state.set_marked_p((cell)obj, obj->size());
|
|
|
|
parent->mark_stack.push_back((cell)obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
void visited_object(object* obj) {
|
|
|
|
if (!tenured->state.marked_p((cell)obj))
|
|
|
|
promoted_object(obj);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-08-21 10:26:04 -04:00
|
|
|
// After a sweep, invalidate any code heap roots which are not marked,
|
|
|
|
// so that if a block makes a tail call to a generic word, and the PIC
|
|
|
|
// compiler triggers a GC, and the caller block gets GCd as a result,
|
|
|
|
// the PIC code won't try to overwrite the call site
|
2013-05-11 22:02:39 -04:00
|
|
|
void factor_vm::update_code_roots_for_sweep() {
|
2015-01-06 11:58:24 -05:00
|
|
|
mark_bits* state = &code->allocator->state;
|
2013-05-11 22:02:39 -04:00
|
|
|
|
2015-05-29 06:25:12 -04:00
|
|
|
FACTOR_FOR_EACH(code_roots) {
|
2013-05-11 22:02:39 -04:00
|
|
|
code_root* root = *iter;
|
2015-01-06 11:58:24 -05:00
|
|
|
cell block = root->value & (~data_alignment - 1);
|
2013-05-11 22:02:39 -04:00
|
|
|
if (root->valid && !state->marked_p(block))
|
|
|
|
root->valid = false;
|
|
|
|
}
|
2009-11-02 19:10:34 -05:00
|
|
|
}
|
|
|
|
|
2015-01-12 01:19:06 -05:00
|
|
|
void factor_vm::collect_mark_impl() {
|
2015-01-10 10:00:12 -05:00
|
|
|
gc_workhorse<tenured_space, full_policy>
|
|
|
|
workhorse(this, this->data->tenured, full_policy(this));
|
2016-05-04 11:52:04 -04:00
|
|
|
slot_visitor<gc_workhorse<tenured_space, full_policy>>
|
|
|
|
visitor(this, workhorse);
|
2013-05-11 22:02:39 -04:00
|
|
|
|
|
|
|
mark_stack.clear();
|
|
|
|
|
2015-01-09 16:28:16 -05:00
|
|
|
code->allocator->state.clear_mark_bits();
|
|
|
|
data->tenured->state.clear_mark_bits();
|
2013-05-11 22:02:39 -04:00
|
|
|
|
2015-02-18 23:43:53 -05:00
|
|
|
visitor.visit_all_roots();
|
2015-01-12 01:19:06 -05:00
|
|
|
visitor.visit_context_code_blocks();
|
|
|
|
visitor.visit_uninitialized_code_blocks();
|
2013-05-11 22:02:39 -04:00
|
|
|
|
2015-02-19 08:43:54 -05:00
|
|
|
visitor.visit_mark_stack(&mark_stack);
|
|
|
|
|
2015-01-10 10:14:54 -05:00
|
|
|
data->reset_tenured();
|
|
|
|
data->reset_aging();
|
|
|
|
data->reset_nursery();
|
2013-05-11 22:02:39 -04:00
|
|
|
code->clear_remembered_set();
|
2009-10-14 03:06:01 -04:00
|
|
|
}
|
2009-10-08 03:10:28 -04:00
|
|
|
|
2013-05-11 22:02:39 -04:00
|
|
|
void factor_vm::collect_sweep_impl() {
|
|
|
|
gc_event* event = current_gc->event;
|
2010-09-04 16:21:45 -04:00
|
|
|
|
2013-05-11 22:02:39 -04:00
|
|
|
if (event)
|
2016-04-24 09:21:17 -04:00
|
|
|
event->reset_timer();
|
2013-05-11 22:02:39 -04:00
|
|
|
data->tenured->sweep();
|
|
|
|
if (event)
|
|
|
|
event->ended_data_sweep();
|
2009-11-05 20:03:51 -05:00
|
|
|
|
2013-05-11 22:02:39 -04:00
|
|
|
update_code_roots_for_sweep();
|
2009-11-22 14:37:39 -05:00
|
|
|
|
2013-05-11 22:02:39 -04:00
|
|
|
if (event)
|
2016-04-24 09:21:17 -04:00
|
|
|
event->reset_timer();
|
2013-05-11 22:02:39 -04:00
|
|
|
code->sweep();
|
|
|
|
if (event)
|
|
|
|
event->ended_code_sweep();
|
2009-10-25 09:07:21 -04:00
|
|
|
}
|
|
|
|
|
2015-01-12 01:19:06 -05:00
|
|
|
void factor_vm::collect_full() {
|
|
|
|
collect_mark_impl();
|
2013-05-11 22:02:39 -04:00
|
|
|
collect_sweep_impl();
|
|
|
|
|
|
|
|
if (data->low_memory_p()) {
|
2016-08-21 10:26:04 -04:00
|
|
|
// Full GC did not free up enough memory. Grow the heap.
|
2013-05-11 22:02:39 -04:00
|
|
|
set_current_gc_op(collect_growing_heap_op);
|
2015-01-12 01:19:06 -05:00
|
|
|
collect_growing_heap(0);
|
2013-05-11 22:02:39 -04:00
|
|
|
} else if (data->high_fragmentation_p()) {
|
2016-08-21 10:26:04 -04:00
|
|
|
// Enough free memory, but it is not contiguous. Perform a
|
|
|
|
// compaction.
|
2013-05-11 22:02:39 -04:00
|
|
|
set_current_gc_op(collect_compact_op);
|
2015-01-12 01:19:06 -05:00
|
|
|
collect_compact_impl();
|
2013-05-11 22:02:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
code->flush_icache();
|
2009-10-07 16:48:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|