]> gitweb.factorcode.org Git - factor.git/blob - vm/code_blocks.hpp
vm: strip out call-counting profiler
[factor.git] / vm / code_blocks.hpp
1 namespace factor
2 {
3
4 /* The compiled code heap is structured into blocks. */
5 struct code_block
6 {
7         cell header;
8         cell owner; /* tagged pointer to word, quotation or f */
9         cell parameters; /* tagged pointer to array or f */
10         cell relocation; /* tagged pointer to byte-array or f */
11
12         bool free_p() const
13         {
14                 return (header & 1) == 1;
15         }
16
17         code_block_type type() const
18         {
19                 return (code_block_type)((header >> 1) & 0x3);
20         }
21
22         void set_type(code_block_type type)
23         {
24                 header = ((header & ~0x7) | (type << 1));
25         }
26
27         bool pic_p() const
28         {
29                 return type() == code_block_pic;
30         }
31
32         bool optimized_p() const
33         {
34                 return type() == code_block_optimized;
35         }
36
37         cell size() const
38         {
39                 cell size = header & ~7;
40 #ifdef FACTOR_DEBUG
41                 assert(size > 0);
42 #endif
43                 return size;
44         }
45
46         template<typename Fixup> cell size(Fixup fixup) const
47         {
48                 return size();
49         }
50
51         void *entry_point() const
52         {
53                 return (void *)(this + 1);
54         }
55
56         /* GC info is stored at the end of the block */
57         gc_info *block_gc_info() const
58         {
59                 return (gc_info *)((u8 *)this + size() - sizeof(gc_info));
60         }
61
62         void flush_icache()
63         {
64                 factor::flush_icache((cell)this,size());
65         }
66
67         template<typename Iterator> void each_instruction_operand(Iterator &iter)
68         {
69                 if(to_boolean(relocation))
70                 {
71                         byte_array *rels = (byte_array *)UNTAG(relocation);
72
73                         cell index = 0;
74                         cell length = (rels->capacity >> TAG_BITS) / sizeof(relocation_entry);
75
76                         for(cell i = 0; i < length; i++)
77                         {
78                                 relocation_entry rel = rels->data<relocation_entry>()[i];
79                                 iter(instruction_operand(rel,this,index));
80                                 index += rel.number_of_parameters();
81                         }
82                 }
83         }
84 };
85
86 VM_C_API void undefined_symbol(void);
87
88 inline code_block *word::code() const {
89         assert(entry_point != NULL);
90         return (code_block*)entry_point - 1;
91 }
92
93 inline code_block *quotation::code() const {
94         assert(entry_point != NULL);
95         return (code_block*)entry_point - 1;
96 }
97
98 }
99
100