]> gitweb.factorcode.org Git - factor.git/blob - vm/data_heap.hpp
7e6ff81e705974c9f6dbf847eed65981db5f1a01
[factor.git] / vm / data_heap.hpp
1 namespace factor
2 {
3
4
5 /* generational copying GC divides memory into zones */
6 struct zone {
7         /* allocation pointer is 'here'; its offset is hardcoded in the
8         compiler backends */
9         cell start;
10         cell here;
11         cell size;
12         cell end;
13 };
14
15 struct data_heap {
16         segment *seg;
17
18         cell young_size;
19         cell aging_size;
20         cell tenured_size;
21
22         cell gen_count;
23
24         zone *generations;
25         zone *semispaces;
26
27         cell *allot_markers;
28         cell *allot_markers_end;
29
30         cell *cards;
31         cell *cards_end;
32
33         cell *decks;
34         cell *decks_end;
35         
36         /* the 0th generation is where new objects are allocated. */
37         cell nursery() { return 0; }
38         
39         /* where objects hang around */
40         cell aging() { return gen_count - 2; }
41         
42         /* the oldest generation */
43         cell tenured() { return gen_count - 1; }
44         
45         bool have_aging_p() { return gen_count > 2; }
46 };
47
48
49 static const cell max_gen_count = 3;
50
51 inline static bool in_zone(zone *z, object *pointer)
52 {
53         return (cell)pointer >= z->start && (cell)pointer < z->end;
54 }
55
56 /* set up guard pages to check for under/overflow.
57 size must be a multiple of the page size */
58 segment *alloc_segment(cell size);    //  defined in OS-*.cpp files PD
59 void dealloc_segment(segment *block);
60
61 PRIMITIVE(data_room);
62 PRIMITIVE(size);
63
64 PRIMITIVE(begin_scan);
65 PRIMITIVE(next_object);
66 PRIMITIVE(end_scan);
67
68 }