]> gitweb.factorcode.org Git - factor.git/blob - vm/code_heap.hpp
VM: Refactor code_heap to Factor style
[factor.git] / vm / code_heap.hpp
1 namespace factor {
2
3 #if defined(WINDOWS) && defined(FACTOR_64)
4 const cell seh_area_size = 1024;
5 #else
6 const cell seh_area_size = 0;
7 #endif
8
9 struct code_heap {
10   /* The actual memory area */
11   segment* seg;
12
13   /* Memory area reserved for safepoint guard page */
14   void* safepoint_page;
15
16   /* Memory area reserved for SEH. Only used on Windows */
17   char* seh_area;
18
19   /* Memory allocator */
20   free_list_allocator<code_block>* allocator;
21
22   std::set<cell> all_blocks;
23
24   /* Keys are blocks which need to be initialized by initialize_code_block().
25      Values are literal tables. Literal table arrays are GC roots until the
26      time the block is initialized, after which point they are discarded. */
27   std::map<code_block*, cell> uninitialized_blocks;
28
29   /* Code blocks which may reference objects in the nursery */
30   std::set<code_block*> points_to_nursery;
31
32   /* Code blocks which may reference objects in aging space or the nursery */
33   std::set<code_block*> points_to_aging;
34
35   explicit code_heap(cell size);
36   ~code_heap();
37   void write_barrier(code_block* compiled);
38   void clear_remembered_set();
39   bool uninitialized_p(code_block* compiled);
40   bool marked_p(code_block* compiled);
41   void set_marked_p(code_block* compiled);
42   void clear_mark_bits();
43   void free(code_block* compiled);
44   void flush_icache();
45   void guard_safepoint();
46   void unguard_safepoint();
47   void verify_all_blocks_set();
48   void initialize_all_blocks_set();
49
50   void sweep();
51
52   code_block* code_block_for_address(cell address);
53
54   bool safepoint_p(cell addr) {
55     cell page_mask = ~(getpagesize() - 1);
56     return (addr & page_mask) == (cell) safepoint_page;
57   }
58 };
59
60 struct code_heap_room {
61   cell size;
62   cell occupied_space;
63   cell total_free;
64   cell contiguous_free;
65   cell free_block_count;
66 };
67
68 }