]> gitweb.factorcode.org Git - factor.git/blob - vm/data_heap.hpp
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / vm / data_heap.hpp
1 namespace factor
2 {
3
4 /* Set by the -securegc command line argument */
5 extern bool secure_gc;
6
7 /* generational copying GC divides memory into zones */
8 struct zone {
9         /* allocation pointer is 'here'; its offset is hardcoded in the
10         compiler backends */
11         cell start;
12         cell here;
13         cell size;
14         cell end;
15 };
16
17 struct data_heap {
18         segment *seg;
19
20         cell young_size;
21         cell aging_size;
22         cell tenured_size;
23
24         cell gen_count;
25
26         zone *generations;
27         zone *semispaces;
28
29         cell *allot_markers;
30         cell *allot_markers_end;
31
32         cell *cards;
33         cell *cards_end;
34
35         cell *decks;
36         cell *decks_end;
37         
38         /* the 0th generation is where new objects are allocated. */
39         cell nursery() { return 0; }
40         
41         /* where objects hang around */
42         cell aging() { return gen_count - 2; }
43         
44         /* the oldest generation */
45         cell tenured() { return gen_count - 1; }
46         
47         bool have_aging_p() { return gen_count > 2; }
48 };
49
50 extern data_heap *data;
51
52 static const cell max_gen_count = 3;
53
54 inline static bool in_zone(zone *z, object *pointer)
55 {
56         return (cell)pointer >= z->start && (cell)pointer < z->end;
57 }
58
59 cell init_zone(zone *z, cell size, cell base);
60
61 void init_card_decks();
62
63 data_heap *grow_data_heap(data_heap *data, cell requested_bytes);
64
65 void dealloc_data_heap(data_heap *data);
66
67 void clear_cards(cell from, cell to);
68 void clear_decks(cell from, cell to);
69 void clear_allot_markers(cell from, cell to);
70 void reset_generation(cell i);
71 void reset_generations(cell from, cell to);
72
73 void set_data_heap(data_heap *data_heap_);
74
75 void init_data_heap(cell gens,
76         cell young_size,
77         cell aging_size,
78         cell tenured_size,
79         bool secure_gc_);
80
81 /* set up guard pages to check for under/overflow.
82 size must be a multiple of the page size */
83 segment *alloc_segment(cell size);
84 void dealloc_segment(segment *block);
85
86 cell untagged_object_size(object *pointer);
87 cell unaligned_object_size(object *pointer);
88 cell binary_payload_start(object *pointer);
89 cell object_size(cell tagged);
90
91 void begin_scan();
92 void end_scan();
93 cell next_object();
94
95 PRIMITIVE(data_room);
96 PRIMITIVE(size);
97
98 PRIMITIVE(begin_scan);
99 PRIMITIVE(next_object);
100 PRIMITIVE(end_scan);
101
102 /* GC is off during heap walking */
103 extern bool gc_off;
104
105 cell find_all_words();
106
107 /* Every object has a regular representation in the runtime, which makes GC
108 much simpler. Every slot of the object until binary_payload_start is a pointer
109 to some other object. */
110 inline static void do_slots(cell obj, void (* iter)(cell *))
111 {
112         cell scan = obj;
113         cell payload_start = binary_payload_start((object *)obj);
114         cell end = obj + payload_start;
115
116         scan += sizeof(cell);
117
118         while(scan < end)
119         {
120                 iter((cell *)scan);
121                 scan += sizeof(cell);
122         }
123 }
124
125 }
126
127 /* new objects are allocated here */
128 VM_C_API factor::zone nursery;