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