]> gitweb.factorcode.org Git - factor.git/blob - vm/aging_collector.cpp
vm: replace block comments /**/ with line comments //
[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 raised.
26     current_gc->op = collect_to_tenured_op;
27
28     gc_workhorse<tenured_space, to_tenured_policy>
29         workhorse(this, data->tenured, to_tenured_policy(this));
30     slot_visitor<gc_workhorse<tenured_space, to_tenured_policy>>
31         visitor(this, workhorse);
32
33     gc_event* event = current_gc->event;
34
35     if (event)
36       event->reset_timer();
37     visitor.visit_cards(data->tenured, card_points_to_aging, 0xff);
38     if (event)
39       event->ended_card_scan(visitor.cards_scanned, visitor.decks_scanned);
40
41     if (event)
42       event->reset_timer();
43     visitor.visit_code_heap_roots(&code->points_to_aging);
44     if (event)
45       event->ended_code_scan(code->points_to_aging.size());
46
47     visitor.visit_mark_stack(&mark_stack);
48   }
49   {
50     // If collection fails here, do a to_tenured collection.
51     current_gc->op = collect_aging_op;
52
53     std::swap(data->aging, data->aging_semispace);
54     data->reset_aging();
55
56     aging_space *target = data->aging;
57     gc_workhorse<aging_space, aging_policy>
58         workhorse(this, target, aging_policy(this));
59     slot_visitor<gc_workhorse<aging_space, aging_policy>>
60         visitor(this, workhorse);
61     cell scan = target->start + target->occupied_space();
62
63     visitor.visit_all_roots();
64     visitor.cheneys_algorithm(target, scan);
65
66     data->reset_nursery();
67     code->clear_remembered_set();
68   }
69 }
70
71 }