]> 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 /* 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         cell init_zone(cell size_, cell start_)
14         {
15                 size = size_;
16                 start = here = start_;
17                 end = start_ + size_;
18                 return end;
19         }
20 };
21
22 struct data_heap {
23         segment *seg;
24
25         cell young_size;
26         cell aging_size;
27         cell tenured_size;
28
29         cell gen_count;
30
31         zone *generations;
32         zone *semispaces;
33
34         char *allot_markers;
35         char *allot_markers_end;
36
37         char *cards;
38         char *cards_end;
39
40         char *decks;
41         char *decks_end;
42         
43         /* the 0th generation is where new objects are allocated. */
44         cell nursery() { return 0; }
45         
46         /* where objects hang around */
47         cell aging() { return gen_count - 2; }
48         
49         /* the oldest generation */
50         cell tenured() { return gen_count - 1; }
51         
52         bool have_aging_p() { return gen_count > 2; }
53
54         data_heap(factor_vm *myvm, cell gen_count, cell young_size, cell aging_size, cell tenured_size);
55         ~data_heap();
56 };
57
58 static const cell max_gen_count = 3;
59
60 inline static bool in_zone(zone *z, object *pointer)
61 {
62         return (cell)pointer >= z->start && (cell)pointer < z->end;
63 }
64
65 PRIMITIVE(data_room);
66 PRIMITIVE(size);
67
68 PRIMITIVE(begin_scan);
69 PRIMITIVE(next_object);
70 PRIMITIVE(end_scan);
71
72 }