]> gitweb.factorcode.org Git - factor.git/blob - vm/code_gc.hpp
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / vm / code_gc.hpp
1 namespace factor
2 {
3
4 static const cell free_list_count = 16;
5 static const cell block_size_increment = 32;
6
7 struct heap_free_list {
8         free_heap_block *small_blocks[free_list_count];
9         free_heap_block *large_blocks;
10 };
11
12 struct heap {
13         segment *seg;
14         heap_free_list free;
15 };
16
17 typedef void (*heap_iterator)(heap_block *compiled);
18
19 void new_heap(heap *h, cell size);
20 void build_free_list(heap *h, cell size);
21 heap_block *heap_allot(heap *h, cell size);
22 void heap_free(heap *h, heap_block *block);
23 void mark_block(heap_block *block);
24 void unmark_marked(heap *heap);
25 void free_unmarked(heap *heap, heap_iterator iter);
26 void heap_usage(heap *h, cell *used, cell *total_free, cell *max_free);
27 cell heap_size(heap *h);
28 cell compute_heap_forwarding(heap *h, unordered_map<heap_block *,char *> &forwarding);
29 void compact_heap(heap *h, unordered_map<heap_block *,char *> &forwarding);
30
31 inline static heap_block *next_block(heap *h, heap_block *block)
32 {
33         cell next = ((cell)block + block->size);
34         if(next == h->seg->end)
35                 return NULL;
36         else
37                 return (heap_block *)next;
38 }
39
40 inline static heap_block *first_block(heap *h)
41 {
42         return (heap_block *)h->seg->start;
43 }
44
45 inline static heap_block *last_block(heap *h)
46 {
47         return (heap_block *)h->seg->end;
48 }
49
50 }