8 typedef struct _F_BLOCK
10 F_BLOCK_STATUS status;
12 /* In bytes, includes this header */
15 /* Filled in on image load */
16 struct _F_BLOCK *next_free;
18 /* Used during compaction */
19 struct _F_BLOCK *forwarding;
21 /* Alignment padding */
30 void new_heap(F_HEAP *heap, CELL size);
31 void build_free_list(F_HEAP *heap, CELL size);
32 CELL heap_allot(F_HEAP *heap, CELL size);
33 void unmark_marked(F_HEAP *heap);
34 void free_unmarked(F_HEAP *heap);
35 CELL heap_usage(F_HEAP *heap, F_BLOCK_STATUS status);
36 CELL heap_size(F_HEAP *heap);
38 INLINE F_BLOCK *next_block(F_HEAP *heap, F_BLOCK *block)
40 CELL next = ((CELL)block + block->size);
41 if(next == heap->segment->end)
44 return (F_BLOCK *)next;
50 /* The compiled code heap is structured into blocks. */
53 CELL type; /* this is WORD_TYPE or QUOTATION_TYPE */
54 CELL code_length; /* # bytes */
55 CELL reloc_length; /* # bytes */
56 CELL literals_length; /* # bytes */
57 CELL words_length; /* # bytes */
58 CELL finalized; /* has finalize_code_block() been called on this yet? */
62 typedef void (*CODE_HEAP_ITERATOR)(F_COMPILED *compiled, CELL code_start,
63 CELL reloc_start, CELL literals_start, CELL words_start, CELL words_end);
65 INLINE void iterate_code_heap_step(F_COMPILED *compiled, CODE_HEAP_ITERATOR iter)
67 CELL code_start = (CELL)(compiled + 1);
68 CELL reloc_start = code_start + compiled->code_length;
69 CELL literals_start = reloc_start + compiled->reloc_length;
70 CELL words_start = literals_start + compiled->literals_length;
71 CELL words_end = words_start + compiled->words_length;
73 iter(compiled,code_start,reloc_start,literals_start,words_start,words_end);
76 INLINE F_BLOCK *xt_to_block(XT xt)
78 return (F_BLOCK *)((CELL)xt - sizeof(F_BLOCK) - sizeof(F_COMPILED));
81 INLINE F_COMPILED *xt_to_compiled(XT xt)
83 return (F_COMPILED *)((CELL)xt - sizeof(F_COMPILED));
86 INLINE F_COMPILED *block_to_compiled(F_BLOCK *block)
88 return (F_COMPILED *)(block + 1);
91 INLINE XT block_to_xt(F_BLOCK *block)
93 return (XT)((CELL)block + sizeof(F_BLOCK) + sizeof(F_COMPILED));
96 INLINE F_BLOCK *first_block(F_HEAP *heap)
98 return (F_BLOCK *)heap->segment->start;
101 INLINE F_BLOCK *last_block(F_HEAP *heap)
103 return (F_BLOCK *)heap->segment->end;
106 void init_code_heap(CELL size);
107 bool in_code_heap_p(CELL ptr);
108 void iterate_code_heap(CODE_HEAP_ITERATOR iter);
109 void collect_literals(void);
110 void recursive_mark(XT xt);
111 void dump_heap(F_HEAP *heap);
113 void compact_code_heap(void);
115 DECLARE_PRIMITIVE(code_room);
116 DECLARE_PRIMITIVE(code_gc);