]> gitweb.factorcode.org Git - factor.git/blob - vm/code_gc.h
Merge branch 'master' into experimental
[factor.git] / vm / code_gc.h
1 typedef enum
2 {
3         B_FREE,
4         B_ALLOCATED,
5         B_MARKED
6 } F_BLOCK_STATUS;
7
8 typedef struct _F_BLOCK
9 {
10         F_BLOCK_STATUS status;
11
12         /* In bytes, includes this header */
13         CELL size;
14
15         /* Filled in on image load */
16         struct _F_BLOCK *next_free;
17
18         /* Used during compaction */
19         struct _F_BLOCK *forwarding;
20 } F_BLOCK;
21
22 typedef struct {
23         F_SEGMENT *segment;
24         F_BLOCK *free_list;
25 } F_HEAP;
26
27 void new_heap(F_HEAP *heap, CELL size);
28 void build_free_list(F_HEAP *heap, CELL size);
29 void *heap_allot(F_HEAP *heap, CELL size);
30 void mark_block(F_BLOCK *block);
31 void unmark_marked(F_HEAP *heap);
32 void free_unmarked(F_HEAP *heap);
33 void heap_usage(F_HEAP *heap, CELL *used, CELL *total_free, CELL *max_free);
34 CELL heap_size(F_HEAP *heap);
35 CELL compute_heap_forwarding(F_HEAP *heap);
36 void compact_heap(F_HEAP *heap);
37
38 INLINE F_BLOCK *next_block(F_HEAP *heap, F_BLOCK *block)
39 {
40         CELL next = ((CELL)block + block->size);
41         if(next == heap->segment->end)
42                 return NULL;
43         else
44                 return (F_BLOCK *)next;
45 }
46
47 INLINE F_BLOCK *first_block(F_HEAP *heap)
48 {
49         return (F_BLOCK *)heap->segment->start;
50 }
51
52 INLINE F_BLOCK *last_block(F_HEAP *heap)
53 {
54         return (F_BLOCK *)heap->segment->end;
55 }