2009-10-07 16:48:09 -04:00
|
|
|
#include "master.hpp"
|
|
|
|
|
|
|
|
namespace factor
|
|
|
|
{
|
|
|
|
|
2009-10-18 21:31:59 -04:00
|
|
|
full_collector::full_collector(factor_vm *parent_) :
|
2009-10-20 23:20:49 -04:00
|
|
|
collector<tenured_space,full_policy>(
|
2009-10-18 21:31:59 -04:00
|
|
|
parent_,
|
|
|
|
parent_->data->tenured,
|
|
|
|
full_policy(parent_)) {}
|
2009-10-07 16:48:09 -04:00
|
|
|
|
2009-11-02 19:10:34 -05: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 gets GCd as a result,
|
|
|
|
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();
|
|
|
|
|
|
|
|
mark_bits<code_block> *state = &code->allocator->state;
|
|
|
|
|
|
|
|
for(; iter < end; iter++)
|
|
|
|
{
|
|
|
|
code_root *root = *iter;
|
|
|
|
code_block *block = (code_block *)(root->value & -block_granularity);
|
|
|
|
if(root->valid && !state->marked_p(block))
|
|
|
|
root->valid = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* After a compaction, invalidate any code heap roots which are not
|
|
|
|
marked as above, and also slide the valid roots up so that call sites
|
|
|
|
can be updated correctly. */
|
|
|
|
void factor_vm::update_code_roots_for_compaction()
|
|
|
|
{
|
|
|
|
std::vector<code_root *>::const_iterator iter = code_roots.begin();
|
|
|
|
std::vector<code_root *>::const_iterator end = code_roots.end();
|
|
|
|
|
|
|
|
mark_bits<code_block> *state = &code->allocator->state;
|
|
|
|
|
|
|
|
for(; iter < end; iter++)
|
|
|
|
{
|
|
|
|
code_root *root = *iter;
|
|
|
|
code_block *block = (code_block *)(root->value & -block_granularity);
|
|
|
|
|
|
|
|
/* Offset of return address within 16-byte allocation line */
|
|
|
|
cell offset = root->value - (cell)block;
|
|
|
|
|
|
|
|
if(root->valid && state->marked_p((code_block *)root->value))
|
|
|
|
{
|
|
|
|
block = state->forward_block(block);
|
|
|
|
root->value = (cell)block + offset;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
root->valid = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-24 04:54:53 -04:00
|
|
|
struct code_block_marker {
|
|
|
|
code_heap *code;
|
2009-10-08 01:23:29 -04:00
|
|
|
full_collector *collector;
|
|
|
|
|
2009-10-24 04:54:53 -04:00
|
|
|
explicit code_block_marker(code_heap *code_, full_collector *collector_) :
|
|
|
|
code(code_), collector(collector_) {}
|
2009-10-08 01:23:29 -04:00
|
|
|
|
2009-10-24 04:54:53 -04:00
|
|
|
code_block *operator()(code_block *compiled)
|
2009-10-08 01:23:29 -04:00
|
|
|
{
|
2009-10-24 04:54:53 -04:00
|
|
|
if(!code->marked_p(compiled))
|
2009-10-08 01:23:29 -04:00
|
|
|
{
|
2009-10-24 04:54:53 -04:00
|
|
|
code->set_marked_p(compiled);
|
|
|
|
collector->trace_literal_references(compiled);
|
2009-10-08 01:23:29 -04:00
|
|
|
}
|
|
|
|
|
2009-10-24 04:54:53 -04:00
|
|
|
return compiled;
|
2009-10-16 12:39:22 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-10-25 15:02:14 -04:00
|
|
|
void factor_vm::collect_mark_impl(bool trace_contexts_p)
|
2009-10-14 03:06:01 -04:00
|
|
|
{
|
2009-10-08 03:10:28 -04:00
|
|
|
full_collector collector(this);
|
|
|
|
|
2009-10-20 16:15:05 -04:00
|
|
|
code->clear_mark_bits();
|
2009-10-20 23:20:49 -04:00
|
|
|
data->tenured->clear_mark_bits();
|
2009-10-21 20:41:54 -04:00
|
|
|
data->tenured->clear_mark_stack();
|
2009-10-16 15:41:40 -04:00
|
|
|
|
2009-10-24 05:36:29 -04:00
|
|
|
code_block_visitor<code_block_marker> code_marker(this,code_block_marker(code,&collector));
|
|
|
|
|
2009-10-08 03:10:28 -04:00
|
|
|
collector.trace_roots();
|
|
|
|
if(trace_contexts_p)
|
|
|
|
{
|
|
|
|
collector.trace_contexts();
|
2009-10-24 05:36:29 -04:00
|
|
|
code_marker.visit_context_code_blocks();
|
|
|
|
code_marker.visit_callback_code_blocks();
|
2009-10-08 03:10:28 -04:00
|
|
|
}
|
|
|
|
|
2009-10-24 05:36:29 -04:00
|
|
|
std::vector<object *> *mark_stack = &data->tenured->mark_stack;
|
|
|
|
|
|
|
|
while(!mark_stack->empty())
|
|
|
|
{
|
|
|
|
object *obj = mark_stack->back();
|
|
|
|
mark_stack->pop_back();
|
2009-11-02 04:25:39 -05:00
|
|
|
collector.trace_object(obj);
|
2009-10-24 05:36:29 -04:00
|
|
|
code_marker.visit_object_code_block(obj);
|
|
|
|
}
|
2009-10-08 03:10:28 -04:00
|
|
|
|
2009-10-21 20:41:54 -04:00
|
|
|
data->reset_generation(data->tenured);
|
2009-10-20 14:13:39 -04:00
|
|
|
data->reset_generation(data->aging);
|
2009-10-21 20:41:54 -04:00
|
|
|
data->reset_generation(&nursery);
|
|
|
|
code->clear_remembered_set();
|
2009-10-14 03:06:01 -04:00
|
|
|
}
|
2009-10-08 03:10:28 -04:00
|
|
|
|
2009-10-25 15:02:14 -04:00
|
|
|
void factor_vm::collect_sweep_impl()
|
2009-10-25 09:07:21 -04:00
|
|
|
{
|
2009-10-27 00:57:26 -04:00
|
|
|
current_gc->event->started_data_sweep();
|
2009-11-01 05:40:15 -05:00
|
|
|
data->tenured->sweep();
|
2009-11-02 19:10:34 -05:00
|
|
|
update_code_roots_for_sweep();
|
2009-10-27 00:57:26 -04:00
|
|
|
current_gc->event->ended_data_sweep();
|
2009-11-05 20:03:51 -05:00
|
|
|
|
|
|
|
current_gc->event->started_code_sweep();
|
|
|
|
code->allocator->sweep();
|
|
|
|
current_gc->event->ended_code_sweep();
|
2009-10-25 09:07:21 -04:00
|
|
|
}
|
|
|
|
|
2009-11-03 23:25:22 -05:00
|
|
|
void factor_vm::collect_full(bool trace_contexts_p)
|
|
|
|
{
|
|
|
|
collect_mark_impl(trace_contexts_p);
|
|
|
|
collect_sweep_impl();
|
2009-11-08 07:08:17 -05:00
|
|
|
if(data->low_memory_p())
|
2009-11-13 10:29:21 -05:00
|
|
|
{
|
|
|
|
current_gc->op = collect_compact_op;
|
|
|
|
current_gc->event->op = collect_compact_op;
|
2009-11-03 23:25:22 -05:00
|
|
|
collect_compact_impl(trace_contexts_p);
|
2009-11-13 10:29:21 -05:00
|
|
|
}
|
2009-11-03 23:25:22 -05:00
|
|
|
else
|
|
|
|
update_code_heap_words_and_literals();
|
|
|
|
}
|
|
|
|
|
|
|
|
void factor_vm::collect_compact(bool trace_contexts_p)
|
|
|
|
{
|
|
|
|
collect_mark_impl(trace_contexts_p);
|
|
|
|
collect_compact_impl(trace_contexts_p);
|
|
|
|
}
|
|
|
|
|
2009-10-25 15:02:14 -04:00
|
|
|
void factor_vm::collect_growing_heap(cell requested_bytes, bool trace_contexts_p)
|
2009-10-14 03:06:01 -04:00
|
|
|
{
|
2009-10-16 03:55:02 -04:00
|
|
|
/* Grow the data heap and copy all live objects to the new heap. */
|
2009-10-14 03:06:01 -04:00
|
|
|
data_heap *old = data;
|
|
|
|
set_data_heap(data->grow(requested_bytes));
|
2009-10-25 15:02:14 -04:00
|
|
|
collect_mark_impl(trace_contexts_p);
|
2009-11-01 05:40:15 -05:00
|
|
|
collect_compact_code_impl(trace_contexts_p);
|
2009-10-14 03:06:01 -04:00
|
|
|
delete old;
|
2009-10-07 16:48:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|