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