]> gitweb.factorcode.org Git - factor.git/blob - vm/aging_collector.cpp
VM: all the started_<blah>() replaced with reset_timer()
[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.trace_cards(data->tenured, card_points_to_aging, 0xff);
37     if (event)
38       event->ended_card_scan(collector.cards_scanned, collector.decks_scanned);
39
40     if (event)
41       event->reset_timer();
42     collector.trace_code_heap_roots(&code->points_to_aging);
43     if (event)
44       event->ended_code_scan(code->points_to_aging.size());
45
46     collector.visitor.visit_mark_stack(&mark_stack);
47   }
48   {
49     /* If collection fails here, do a to_tenured collection. */
50     current_gc->op = collect_aging_op;
51
52     std::swap(data->aging, data->aging_semispace);
53     data->reset_aging();
54
55     collector<aging_space, aging_policy> collector(this,
56                                                    data->aging,
57                                                    aging_policy(this));
58
59     collector.visitor.visit_all_roots();
60     collector.cheneys_algorithm();
61
62     data->reset_nursery();
63     code->clear_remembered_set();
64   }
65 }
66
67 }