2009-10-07 16:48:09 -04:00
|
|
|
#include "master.hpp"
|
|
|
|
|
2013-05-11 22:02:39 -04:00
|
|
|
namespace factor {
|
|
|
|
|
2009-11-02 19:10:34 -05:00
|
|
|
/* After a sweep, invalidate any code heap roots which are not marked,
|
2013-05-11 22:02:39 -04:00
|
|
|
so that if a block makes a tail call to a generic word, and the PIC
|
2015-01-10 10:00:12 -05:00
|
|
|
compiler triggers a GC, and the caller block gets GCd as a result,
|
2013-05-11 22:02:39 -04:00
|
|
|
the PIC code won't try to overwrite the call site */
|
|
|
|
void factor_vm::update_code_roots_for_sweep() {
|
|
|
|
std::vector<code_root*>::const_iterator iter = code_roots.begin();
|
|
|
|
std::vector<code_root*>::const_iterator end = code_roots.end();
|
|
|
|
|
2015-01-06 11:58:24 -05:00
|
|
|
mark_bits* state = &code->allocator->state;
|
2013-05-11 22:02:39 -04:00
|
|
|
|
|
|
|
for (; iter < end; iter++) {
|
|
|
|
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));
|
|
|
|
|
|
|
|
slot_visitor<gc_workhorse<tenured_space, full_policy> >
|
2015-01-11 23:58:55 -05:00
|
|
|
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-01-11 23:58:55 -05:00
|
|
|
visitor.visit_roots();
|
2015-01-12 01:19:06 -05:00
|
|
|
visitor.visit_contexts();
|
|
|
|
visitor.visit_context_code_blocks();
|
|
|
|
visitor.visit_uninitialized_code_blocks();
|
2013-05-11 22:02:39 -04:00
|
|
|
|
|
|
|
while (!mark_stack.empty()) {
|
|
|
|
cell ptr = mark_stack.back();
|
|
|
|
mark_stack.pop_back();
|
|
|
|
|
|
|
|
if (ptr & 1) {
|
|
|
|
code_block* compiled = (code_block*)(ptr - 1);
|
2015-01-11 23:58:55 -05:00
|
|
|
visitor.visit_code_block_objects(compiled);
|
|
|
|
visitor.visit_embedded_literals(compiled);
|
|
|
|
visitor.visit_embedded_code_pointers(compiled);
|
2013-05-11 22:02:39 -04:00
|
|
|
} else {
|
|
|
|
object* obj = (object*)ptr;
|
2015-01-11 23:58:55 -05:00
|
|
|
visitor.visit_slots(obj);
|
2015-01-10 10:00:12 -05:00
|
|
|
if (obj->type() == ALIEN_TYPE)
|
|
|
|
((alien*)obj)->update_address();
|
2015-01-11 23:58:55 -05:00
|
|
|
visitor.visit_object_code_block(obj);
|
2013-05-11 22:02:39 -04:00
|
|
|
}
|
|
|
|
}
|
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)
|
|
|
|
event->started_data_sweep();
|
|
|
|
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)
|
|
|
|
event->started_code_sweep();
|
|
|
|
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()) {
|
|
|
|
/* Full GC did not free up enough memory. Grow the heap. */
|
|
|
|
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()) {
|
|
|
|
/* Enough free memory, but it is not contiguous. Perform a
|
|
|
|
compaction. */
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|