Revert "lists: Add list literal doc example."
[factor.git] / vm / nursery_collector.cpp
blob3634110d1e4a7222e7595cd21eeb2bd78236fe02
1 #include "master.hpp"
3 namespace factor {
5 struct nursery_copier : no_fixup {
6 bump_allocator* nursery;
7 aging_space* aging;
9 nursery_copier(bump_allocator* nursery, aging_space* aging)
10 : nursery(nursery), aging(aging) { }
12 object* fixup_data(object* obj) {
13 if (!nursery->contains_p(obj)) {
14 return obj;
17 // The while-loop is a needed micro-optimization.
18 while (obj->forwarding_pointer_p()) {
19 obj = obj->forwarding_pointer();
22 if (!nursery->contains_p(obj)) {
23 return obj;
26 cell size = obj->size();
27 object* newpointer = aging->allot(size);
28 if (!newpointer)
29 throw must_start_gc_again();
31 memcpy(newpointer, obj, size);
32 obj->forward_to(newpointer);
33 return newpointer;
37 void factor_vm::collect_nursery() {
38 // Copy live objects from the nursery (as determined by the root set and
39 // marked cards in aging and tenured) to aging space.
40 slot_visitor<nursery_copier>
41 visitor(this, nursery_copier(data->nursery, data->aging));
43 cell scan = data->aging->start + data->aging->occupied_space();
45 visitor.visit_all_roots();
46 gc_event* event = current_gc->event;
48 if (event)
49 event->reset_timer();
50 visitor.visit_cards(data->tenured, card_points_to_nursery,
51 card_points_to_nursery);
52 visitor.visit_cards(data->aging, card_points_to_nursery, 0xff);
53 if (event) {
54 event->ended_phase(PHASE_CARD_SCAN);
55 event->cards_scanned += visitor.cards_scanned;
56 event->decks_scanned += visitor.decks_scanned;
59 if (event)
60 event->reset_timer();
61 visitor.visit_code_heap_roots(&code->points_to_nursery);
62 if (event) {
63 event->ended_phase(PHASE_CODE_SCAN);
64 event->code_blocks_scanned += code->points_to_nursery.size();
67 visitor.cheneys_algorithm(data->aging, scan);
69 data->reset_nursery();
70 code->points_to_nursery.clear();