]> gitweb.factorcode.org Git - factor.git/blob - vm/aging_collector.cpp
VM: Refactor aging_collector to Factor style
[factor.git] / vm / aging_collector.cpp
1 #include "master.hpp"
2
3 namespace factor {
4
5 aging_collector::aging_collector(factor_vm* parent_)
6     : copying_collector<aging_space, aging_policy>(parent_,
7                                                    parent_->data->aging,
8                                                    aging_policy(parent_)) {}
9
10 void factor_vm::collect_aging() {
11   /* Promote objects referenced from tenured space to tenured space, copy
12      everything else to the aging semi-space, and reset the nursery pointer. */
13   {
14     /* Change the op so that if we fail here, an assertion will be
15        raised. */
16     current_gc->op = collect_to_tenured_op;
17
18     to_tenured_collector collector(this);
19
20     gc_event* event = current_gc->event;
21
22     if (event)
23       event->started_card_scan();
24     collector.trace_cards(data->tenured, card_points_to_aging, full_unmarker());
25     if (event)
26       event->ended_card_scan(collector.cards_scanned, collector.decks_scanned);
27
28     if (event)
29       event->started_code_scan();
30     collector.trace_code_heap_roots(&code->points_to_aging);
31     if (event)
32       event->ended_code_scan(collector.code_blocks_scanned);
33
34     collector.tenure_reachable_objects();
35   }
36   {
37     /* If collection fails here, do a to_tenured collection. */
38     current_gc->op = collect_aging_op;
39
40     std::swap(data->aging, data->aging_semispace);
41     data->reset_generation(data->aging);
42
43     aging_collector collector(this);
44
45     collector.trace_roots();
46     collector.trace_contexts();
47
48     collector.cheneys_algorithm();
49
50     data->reset_generation(&nursery);
51     code->clear_remembered_set();
52   }
53 }
54
55 }