Revert "lists: Add list literal doc example."
[factor.git] / vm / aging_collector.cpp
blobc934984e01e304ba99941c0b801dd426c7b0f193
1 #include "master.hpp"
3 namespace factor {
5 struct to_aging_copier : no_fixup {
6 aging_space* aging;
7 tenured_space* tenured;
9 to_aging_copier(aging_space* aging, tenured_space* tenured)
10 : aging(aging), tenured(tenured) { }
12 object* fixup_data(object* obj) {
13 if (aging->contains_p(obj) || tenured->contains_p(obj)) {
14 return obj;
17 // Is there another forwarding pointer?
18 while (obj->forwarding_pointer_p()) {
19 object* dest = obj->forwarding_pointer();
20 obj = dest;
23 if (aging->contains_p(obj) || tenured->contains_p(obj)) {
24 return obj;
27 cell size = obj->size();
28 object* newpointer = aging->allot(size);
29 if (!newpointer)
30 throw must_start_gc_again();
32 memcpy(newpointer, obj, size);
33 obj->forward_to(newpointer);
35 return newpointer;
39 void factor_vm::collect_aging() {
40 // Promote objects referenced from tenured space to tenured space, copy
41 // everything else to the aging semi-space, and reset the nursery pointer.
43 // Change the op so that if we fail here, an assertion will be raised.
44 current_gc->op = COLLECT_TO_TENURED_OP;
46 slot_visitor<from_tenured_refs_copier>
47 visitor(this, from_tenured_refs_copier(data->tenured, &mark_stack));
49 gc_event* event = current_gc->event;
51 if (event)
52 event->reset_timer();
53 visitor.visit_cards(data->tenured, card_points_to_aging, 0xff);
54 if (event) {
55 event->ended_phase(PHASE_CARD_SCAN);
56 event->cards_scanned += visitor.cards_scanned;
57 event->decks_scanned += visitor.decks_scanned;
60 if (event)
61 event->reset_timer();
62 visitor.visit_code_heap_roots(&code->points_to_aging);
63 if (event) {
64 event->ended_phase(PHASE_CODE_SCAN);
65 event->code_blocks_scanned += code->points_to_aging.size();
67 visitor.visit_mark_stack(&mark_stack);
70 // If collection fails here, do a to_tenured collection.
71 current_gc->op = COLLECT_AGING_OP;
73 std::swap(data->aging, data->aging_semispace);
74 data->reset_aging();
76 aging_space *aging = data->aging;
77 slot_visitor<to_aging_copier>
78 visitor(this, to_aging_copier(aging, data->tenured));
80 cell scan = aging->start + aging->occupied_space();
82 visitor.visit_all_roots();
83 visitor.cheneys_algorithm(aging, scan);
85 data->reset_nursery();
86 code->clear_remembered_set();