/home/travis/build/MoarVM/MoarVM/src/6model/reprs/MVMCompUnit.h
Line | Count | Source |
1 | | struct MVMExtOpRecord { |
2 | | /* Used to query the extop registry. */ |
3 | | MVMString *name; |
4 | | |
5 | | /* Resolved by the validator. */ |
6 | | MVMOpInfo *info; |
7 | | |
8 | | /* The actual function executed by the interpreter. |
9 | | * Resolved by the validator. */ |
10 | | MVMExtOpFunc *func; |
11 | | |
12 | | /* Tells the interpreter by how much to increment |
13 | | * the instruction pointer. */ |
14 | | MVMuint16 operand_bytes; |
15 | | |
16 | | /* Indicates the JIT should not emit a call to this op, because it needs |
17 | | * to be used in an interpreter context. */ |
18 | | MVMuint16 no_jit; |
19 | | |
20 | | /* Indicates the extop allocates and that its output is some allocated |
21 | | * object. Used by allocation profiling. */ |
22 | | MVMuint16 allocating; |
23 | | |
24 | | /* Read from the bytecode stream. */ |
25 | | MVMuint8 operand_descriptor[MVM_MAX_OPERANDS]; |
26 | | |
27 | | /* Specialization function. */ |
28 | | MVMExtOpSpesh *spesh; |
29 | | |
30 | | /* Discover facts for spesh. */ |
31 | | MVMExtOpFactDiscover *discover; |
32 | | }; |
33 | | |
34 | | /* How to release memory. */ |
35 | | typedef enum { |
36 | | MVM_DEALLOCATE_NOOP, |
37 | | MVM_DEALLOCATE_FREE, |
38 | | MVM_DEALLOCATE_UNMAP |
39 | | } MVMDeallocate; |
40 | | |
41 | | /* Representation for a compilation unit in the VM. */ |
42 | | struct MVMCompUnitBody { |
43 | | /* The start and size of the raw data for this compilation unit. */ |
44 | | MVMuint8 *data_start; |
45 | | MVMuint32 data_size; |
46 | | |
47 | | /* Refers to the extops pointer below. Lives here for struct layout */ |
48 | | MVMuint16 num_extops; |
49 | | |
50 | | /* See callsites, num_callsites, and orig_callsites below. */ |
51 | | MVMuint16 max_callsite_size; |
52 | | |
53 | | /* The code objects for each frame, along with counts of frames. */ |
54 | | MVMObject **coderefs; |
55 | | MVMuint32 num_frames; /* Total, inc. added by inliner. */ |
56 | | MVMuint32 orig_frames; /* Original from loading comp unit. */ |
57 | | |
58 | | /* Special frames. */ |
59 | | MVMStaticFrame *main_frame; |
60 | | MVMStaticFrame *load_frame; |
61 | | MVMStaticFrame *deserialize_frame; |
62 | | |
63 | | /* The callsites in the compilation unit. */ |
64 | | MVMCallsite **callsites; |
65 | | MVMuint32 num_callsites; |
66 | | MVMuint32 orig_callsites; |
67 | | |
68 | | /* The extension ops used by the compilation unit. */ |
69 | | MVMExtOpRecord *extops; |
70 | | |
71 | | /* The string heap and number of strings. */ |
72 | | MVMString **strings; |
73 | | MVMuint32 num_strings; |
74 | | MVMuint32 orig_strings; |
75 | | |
76 | | /* We decode strings on first use. Scanning through the string heap every |
77 | | * time to find where a string lives, however, would be extremely time |
78 | | * consuming. So, we keep a table that has the offsets into the string heap |
79 | | * every MVM_STRING_FAST_TABLE_SPAN strings. For example, were it 16, then |
80 | | * string_heap_fast_table[1] is where we'd look to find out how to locate |
81 | | * strings 16..31, then scanning through the string blob itself to get to |
82 | | * the string within that region. string_heap_fast_table_top contains the |
83 | | * top location in string_heap_fast_table that has been initialized so far. |
84 | | * It starts out at 0, which is safe even if we don't do anything since the |
85 | | * first string will be at the start of the blob anyway. Finally, we don't |
86 | | * do any concurrency control over this table, since all threads will be |
87 | | * working towards the same result anyway. Duplicate work occasionally will |
88 | | * almost always be cheaper than unrequired synchronization every time. A |
89 | | * memory barrier before updating string_heap_fast_table_top makes sure we |
90 | | * never have its update getting moved ahead of writes into the table. */ |
91 | | MVMuint32 *string_heap_fast_table; |
92 | | MVMuint32 string_heap_fast_table_top; |
93 | | |
94 | | /* Refers to serialized below. sneaked in here to optimize struct layout */ |
95 | | MVMint32 serialized_size; |
96 | | |
97 | | MVMuint8 *string_heap_start; |
98 | | MVMuint8 *string_heap_read_limit; |
99 | | |
100 | | /* Serialized data, if any. */ |
101 | | /* For its size, see serialized_size above. */ |
102 | | MVMuint8 *serialized; |
103 | | |
104 | | /* Array of the resolved serialization contexts, and how many we |
105 | | * have. A null in the list indicates not yet resolved */ |
106 | | MVMSerializationContext **scs; |
107 | | MVMuint32 num_scs; |
108 | | |
109 | | /* How we should deallocate data_start. */ |
110 | | MVMDeallocate deallocate; |
111 | | |
112 | | /* List of serialization contexts in need of resolution. This is an |
113 | | * array of string handles; its length is determined by num_scs above. |
114 | | * once an SC has been resolved, the entry on this list is NULLed. If |
115 | | * all are resolved, this pointer itself becomes NULL. */ |
116 | | MVMSerializationContextBody **scs_to_resolve; |
117 | | |
118 | | /* List of SC handle string indexes. */ |
119 | | MVMint32 *sc_handle_idxs; |
120 | | |
121 | | /* HLL configuration for this compilation unit. */ |
122 | | MVMHLLConfig *hll_config; |
123 | | MVMString *hll_name; |
124 | | |
125 | | /* Filename, if any, that we loaded it from. */ |
126 | | MVMString *filename; |
127 | | |
128 | | /* Handle, if any, associated with a mapped file. */ |
129 | | void *handle; |
130 | | |
131 | | /* Unmanaged (so not GC-aware) mutex taken if we want to add extra string, |
132 | | * callsite, extop, or coderef constants to the pools. This is done in |
133 | | * some cases of cross-compilation-unit inlining. We are never at risk of |
134 | | * recursion on this mutex, and since spesh can never GC it's important we |
135 | | * do not use a GC-aware mutex, which could trigger GC. */ |
136 | | uv_mutex_t *inline_tweak_mutex; |
137 | | |
138 | | /* MVMReentrantLock to be taken when we want to finish deserializing a |
139 | | * frame inside of the compilation unit. */ |
140 | | MVMObject *deserialize_frame_mutex; |
141 | | |
142 | | /* Version of the bytecode format we deserialized this comp unit from. */ |
143 | | MVMuint16 bytecode_version; |
144 | | |
145 | | /* Was a frame in this compilation unit invoked yet? */ |
146 | | MVMuint8 invoked; |
147 | | }; |
148 | | struct MVMCompUnit { |
149 | | MVMObject common; |
150 | | MVMCompUnitBody body; |
151 | | }; |
152 | | |
153 | | /* Strings per entry in the fast table; see above for details. */ |
154 | 3.94M | #define MVM_STRING_FAST_TABLE_SPAN 16 |
155 | | |
156 | | struct MVMLoadedCompUnitName { |
157 | | /* Loaded filename. */ |
158 | | MVMString *filename; |
159 | | |
160 | | /* Inline handle to the loaded filenames hash (in MVMInstance). */ |
161 | | UT_hash_handle hash_handle; |
162 | | }; |
163 | | |
164 | | /* Function for REPR setup. */ |
165 | | const MVMREPROps * MVMCompUnit_initialize(MVMThreadContext *tc); |