]> gitweb.factorcode.org Git - factor.git/blob - vm/collector.hpp
VM: renaming verify_memory_protection_error to set_memory_protection_error
[factor.git] / vm / collector.hpp
1 namespace factor {
2
3 struct must_start_gc_again {
4 };
5
6 template <typename TargetGeneration, typename Policy>
7 struct gc_workhorse : no_fixup {
8   static const bool translated_code_block_map = false;
9
10   factor_vm* parent;
11   TargetGeneration* target;
12   Policy policy;
13   code_heap* code;
14
15   gc_workhorse(factor_vm* parent, TargetGeneration* target, Policy policy)
16       : parent(parent), target(target), policy(policy), code(parent->code) {}
17
18   object* fixup_data(object* obj) {
19     FACTOR_ASSERT((parent->current_gc &&
20                    parent->current_gc->op == collect_growing_heap_op) ||
21                   parent->data->seg->in_segment_p((cell)obj));
22
23     if (!policy.should_copy_p(obj)) {
24       policy.visited_object(obj);
25       return obj;
26     }
27
28     // is there another forwarding pointer?
29     while (obj->forwarding_pointer_p()) {
30       object* dest = obj->forwarding_pointer();
31       obj = dest;
32     }
33
34     if (!policy.should_copy_p(obj)) {
35       policy.visited_object(obj);
36       return obj;
37     }
38
39     cell size = obj->size();
40     object* newpointer = target->allot(size);
41     if (!newpointer)
42       throw must_start_gc_again();
43
44     memcpy(newpointer, obj, size);
45     obj->forward_to(newpointer);
46
47     policy.promoted_object(newpointer);
48
49     return newpointer;
50   }
51
52   code_block* fixup_code(code_block* compiled) {
53     if (!code->allocator->state.marked_p((cell)compiled)) {
54       code->allocator->state.set_marked_p((cell)compiled, compiled->size());
55       parent->mark_stack.push_back((cell)compiled + 1);
56     }
57
58     return compiled;
59   }
60 };
61
62 }