]> gitweb.factorcode.org Git - factor.git/blob - vm/aging_collector.cpp
VM: the aging_policy and nursery_policy classes are so small that they
[factor.git] / vm / aging_collector.cpp
1 #include "master.hpp"
2
3 namespace factor {
4
5 struct aging_policy {
6   factor_vm* parent;
7   aging_space* aging;
8   tenured_space* tenured;
9
10   explicit aging_policy(factor_vm* parent)
11       : parent(parent),
12         aging(parent->data->aging),
13         tenured(parent->data->tenured) {}
14
15   bool should_copy_p(object* untagged) {
16     return !(aging->contains_p(untagged) || tenured->contains_p(untagged));
17   }
18
19   void promoted_object(object* obj) {}
20
21   void visited_object(object* obj) {}
22 };
23
24 void factor_vm::collect_aging() {
25   /* Promote objects referenced from tenured space to tenured space, copy
26      everything else to the aging semi-space, and reset the nursery pointer. */
27   {
28     /* Change the op so that if we fail here, an assertion will be
29        raised. */
30     current_gc->op = collect_to_tenured_op;
31
32     collector<tenured_space, to_tenured_policy> collector(this,
33                                                           this->data->tenured,
34                                                           to_tenured_policy(this));
35     gc_event* event = current_gc->event;
36
37     if (event)
38       event->started_card_scan();
39     collector.trace_cards(data->tenured, card_points_to_aging, 0xff);
40     if (event)
41       event->ended_card_scan(collector.cards_scanned, collector.decks_scanned);
42
43     if (event)
44       event->started_code_scan();
45     collector.trace_code_heap_roots(&code->points_to_aging);
46     if (event)
47       event->ended_code_scan(collector.code_blocks_scanned);
48
49     collector.visitor.visit_mark_stack(&mark_stack);
50   }
51   {
52     /* If collection fails here, do a to_tenured collection. */
53     current_gc->op = collect_aging_op;
54
55     std::swap(data->aging, data->aging_semispace);
56     data->reset_aging();
57
58     collector<aging_space, aging_policy> collector(this,
59                                                    this->data->aging,
60                                                    aging_policy(this));
61
62     collector.visitor.visit_all_roots();
63     collector.cheneys_algorithm();
64
65     data->reset_nursery();
66     code->clear_remembered_set();
67   }
68 }
69
70 }