/home/travis/build/MoarVM/MoarVM/src/core/instance.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* The various "bootstrap" types, based straight off of some core |
2 | | * representations. They are used during the 6model bootstrap. */ |
3 | | struct MVMBootTypes { |
4 | | MVMObject *BOOTInt; |
5 | | MVMObject *BOOTNum; |
6 | | MVMObject *BOOTStr; |
7 | | MVMObject *BOOTArray; |
8 | | MVMObject *BOOTHash; |
9 | | MVMObject *BOOTCCode; |
10 | | MVMObject *BOOTCode; |
11 | | MVMObject *BOOTThread; |
12 | | MVMObject *BOOTIter; |
13 | | MVMObject *BOOTContext; |
14 | | MVMObject *BOOTIntArray; |
15 | | MVMObject *BOOTNumArray; |
16 | | MVMObject *BOOTStrArray; |
17 | | MVMObject *BOOTIO; |
18 | | MVMObject *BOOTException; |
19 | | MVMObject *BOOTStaticFrame; |
20 | | MVMObject *BOOTCompUnit; |
21 | | MVMObject *BOOTMultiCache; |
22 | | MVMObject *BOOTContinuation; |
23 | | MVMObject *BOOTQueue; |
24 | | MVMObject *BOOTAsync; |
25 | | MVMObject *BOOTReentrantMutex; |
26 | | }; |
27 | | |
28 | | /* Various raw types that don't need a HOW */ |
29 | | typedef struct { |
30 | | MVMObject *RawDLLSym; |
31 | | } MVMRawTypes; |
32 | | |
33 | | /* Various common string constants. */ |
34 | | struct MVMStringConsts { |
35 | | MVMString *empty; |
36 | | MVMString *Str; |
37 | | MVMString *Num; |
38 | | MVMString *integer; |
39 | | MVMString *float_str; |
40 | | MVMString *bits; |
41 | | MVMString *unsigned_str; |
42 | | MVMString *find_method; |
43 | | MVMString *type_check; |
44 | | MVMString *accepts_type; |
45 | | MVMString *name; |
46 | | MVMString *attribute; |
47 | | MVMString *of; |
48 | | MVMString *rw; |
49 | | MVMString *type; |
50 | | MVMString *typeobj; |
51 | | MVMString *free_str; |
52 | | MVMString *callback_args; |
53 | | MVMString *encoding; |
54 | | MVMString *inlined; |
55 | | MVMString *repr; |
56 | | MVMString *anon; |
57 | | MVMString *P6opaque; |
58 | | MVMString *array; |
59 | | MVMString *box_target; |
60 | | MVMString *positional_delegate; |
61 | | MVMString *associative_delegate; |
62 | | MVMString *auto_viv_container; |
63 | | MVMString *done; |
64 | | MVMString *error; |
65 | | MVMString *stdout_bytes; |
66 | | MVMString *stderr_bytes; |
67 | | MVMString *merge_bytes; |
68 | | MVMString *buf_type; |
69 | | MVMString *write; |
70 | | MVMString *stdin_fd; |
71 | | MVMString *stdout_fd; |
72 | | MVMString *stderr_fd; |
73 | | MVMString *nativeref; |
74 | | MVMString *refkind; |
75 | | MVMString *positional; |
76 | | MVMString *lexical; |
77 | | MVMString *dimensions; |
78 | | MVMString *ready; |
79 | | MVMString *multidim; |
80 | | MVMString *entry_point; |
81 | | MVMString *kind; |
82 | | MVMString *instrumented; |
83 | | MVMString *heap; |
84 | | MVMString *translate_newlines; |
85 | | MVMString *platform_newline; |
86 | | }; |
87 | | |
88 | | /* An entry in the representations registry. */ |
89 | | struct MVMReprRegistry { |
90 | | /* name of the REPR */ |
91 | | MVMString *name; |
92 | | |
93 | | /* the REPR vtable */ |
94 | | const MVMREPROps *repr; |
95 | | |
96 | | /* the uthash hash handle inline struct. */ |
97 | | UT_hash_handle hash_handle; |
98 | | }; |
99 | | |
100 | | /* An entry in the persistent object IDs hash, used to give still-movable |
101 | | * objects a lifetime-unique ID. */ |
102 | | struct MVMObjectId { |
103 | | /* The current object address. */ |
104 | | MVMObject *current; |
105 | | |
106 | | /* Then gen2 address that forms the persistent ID, and where we'll move |
107 | | * the object to if it lives long enough. */ |
108 | | MVMCollectable *gen2_addr; |
109 | | |
110 | | /* Hash handle. */ |
111 | | UT_hash_handle hash_handle; |
112 | | }; |
113 | | |
114 | | /* Represents a MoarVM instance. */ |
115 | | struct MVMInstance { |
116 | | /* The main thread. */ |
117 | | MVMThreadContext *main_thread; |
118 | | |
119 | | /* The ID to allocate the next-created thread. */ |
120 | | AO_t next_user_thread_id; |
121 | | |
122 | | /* The event loop thread, a mutex to avoid start-races, a concurrent |
123 | | * queue of tasks that need to be processed by the event loop thread |
124 | | * and an array of active tasks, for the purpose of keeping them GC |
125 | | * marked. */ |
126 | | MVMThreadContext *event_loop_thread; |
127 | | uv_mutex_t mutex_event_loop_start; |
128 | | uv_sem_t sem_event_loop_started; |
129 | | MVMObject *event_loop_todo_queue; |
130 | | MVMObject *event_loop_permit_queue; |
131 | | MVMObject *event_loop_cancel_queue; |
132 | | MVMObject *event_loop_active; |
133 | | uv_async_t *event_loop_wakeup; |
134 | | |
135 | | /* The VM null object. */ |
136 | | MVMObject *VMNull; |
137 | | |
138 | | /* The KnowHOW meta-object; all other meta-objects (which are |
139 | | * built in user-space) are built out of this. */ |
140 | | MVMObject *KnowHOW; |
141 | | |
142 | | /* The KnowHOWAttribute meta-object; used for declaring attributes |
143 | | * on a KnowHOW. */ |
144 | | MVMObject *KnowHOWAttribute; |
145 | | |
146 | | /* The VM's native string type, using MVMString. Note that this is a |
147 | | * native string, not an object boxing one. */ |
148 | | MVMObject *VMString; |
149 | | |
150 | | /* Serialization context type (known as SCRef, but it's actually the |
151 | | * serialization context itself). */ |
152 | | MVMObject *SCRef; |
153 | | |
154 | | /* Lexotic type, used in implementing return handling. */ |
155 | | MVMObject *Lexotic; |
156 | | |
157 | | /* CallCapture type, used by custom dispatchers. */ |
158 | | MVMObject *CallCapture; |
159 | | |
160 | | /* Thread type, representing a VM-level thread. */ |
161 | | MVMObject *Thread; |
162 | | |
163 | | /* Set of bootstrapping types. */ |
164 | | MVMBootTypes boot_types; |
165 | | |
166 | | /* Set of raw types. */ |
167 | | MVMRawTypes raw_types; |
168 | | |
169 | | /* Set of string constants. */ |
170 | | MVMStringConsts str_consts; |
171 | | |
172 | | /* int -> str cache */ |
173 | | MVMString **int_to_str_cache; |
174 | | |
175 | | /* Multi-dispatch cache and specialization installation mutexes |
176 | | * (global, as the additions are quite low contention, so no |
177 | | * real motivation to have it more fine-grained at present). */ |
178 | | uv_mutex_t mutex_multi_cache_add; |
179 | | uv_mutex_t mutex_spesh_install; |
180 | | |
181 | | /* Log file for specializations, if we're to log them. */ |
182 | | FILE *spesh_log_fh; |
183 | | |
184 | | /* Log file for dynamic var performance, if we're to log it. */ |
185 | | FILE *dynvar_log_fh; |
186 | | MVMint64 dynvar_log_lasttime; |
187 | | |
188 | | /* Flag for if spesh (and certain spesh features) are enabled. */ |
189 | | MVMint8 spesh_enabled; |
190 | | MVMint8 spesh_inline_enabled; |
191 | | MVMint8 spesh_osr_enabled; |
192 | | MVMint8 spesh_nodelay; |
193 | | |
194 | | /* Number of specializations produced, and limit on number of |
195 | | * specializations (zero if no limit). */ |
196 | | MVMint32 spesh_produced; |
197 | | MVMint32 spesh_limit; |
198 | | |
199 | | /* Flag for if NFA debugging is enabled. */ |
200 | | MVMint8 nfa_debug_enabled; |
201 | | |
202 | | /* Flag for if jit is enabled */ |
203 | | MVMint32 jit_enabled; |
204 | | |
205 | | /* File for JIT logging */ |
206 | | FILE *jit_log_fh; |
207 | | |
208 | | /* Directory name for JIT bytecode dumps */ |
209 | | char *jit_bytecode_dir; |
210 | | /* File for map of frame information for bytecode dumps */ |
211 | | FILE *jit_bytecode_map; |
212 | | /* sequence number for JIT compiled frames */ |
213 | | AO_t jit_seq_nr; |
214 | | |
215 | | /* Number of representations registered so far. */ |
216 | | MVMuint32 num_reprs; |
217 | | |
218 | | /* An array mapping representation IDs to registry entries. */ |
219 | | MVMReprRegistry **repr_list; |
220 | | |
221 | | /* A hash mapping representation names to registry entries. */ |
222 | | MVMReprRegistry *repr_hash; |
223 | | |
224 | | /* Mutex for REPR registration. */ |
225 | | uv_mutex_t mutex_repr_registry; |
226 | | |
227 | | /* Number of permanent GC roots we've got, allocated space for, and |
228 | | * a list of the addresses to them. The mutex controls writing to the |
229 | | * list, just in case multiple threads somehow end up doing so. Note |
230 | | * that during a GC the world is stopped so reading is safe. We also |
231 | | * keep a list of names for these, for the purpose of heap debugging |
232 | | * and heap profiling. */ |
233 | | MVMuint32 num_permroots; |
234 | | MVMuint32 alloc_permroots; |
235 | | MVMCollectable ***permroots; |
236 | | char **permroot_descriptions; |
237 | | uv_mutex_t mutex_permroots; |
238 | | |
239 | | /* The current GC run sequence number. May wrap around over time; that |
240 | | * is fine since only equality ever matters. */ |
241 | | AO_t gc_seq_number; |
242 | | /* The number of threads that vote for starting GC. */ |
243 | | AO_t gc_start; |
244 | | /* The number of threads that still need to vote for considering GC done. */ |
245 | | AO_t gc_finish; |
246 | | /* Whether the coordinator considers all in-trays clear. */ |
247 | | AO_t gc_intrays_clearing; |
248 | | /* The number of threads that have yet to acknowledge the finish. */ |
249 | | AO_t gc_ack; |
250 | | /* Linked list (via forwarder) of STables to free. */ |
251 | | MVMSTable *stables_to_free; |
252 | | /* Whether the current GC run is a full collection. */ |
253 | | MVMuint32 gc_full_collect; |
254 | | |
255 | | /* How many bytes of data have we promoted from the nursery to gen2 |
256 | | * since we last did a full collection? */ |
257 | | AO_t gc_promoted_bytes_since_last_full; |
258 | | |
259 | | /* Persistent object ID hash, used to give nursery objects a lifetime |
260 | | * unique ID. Plus a lock to protect it. */ |
261 | | MVMObjectId *object_ids; |
262 | | uv_mutex_t mutex_object_ids; |
263 | | |
264 | | /* MVMThreads completed starting, running, and/or exited. */ |
265 | | /* note: used atomically */ |
266 | | MVMThread *threads; |
267 | | |
268 | | /* raw command line args from APR */ |
269 | | char **raw_clargs; |
270 | | /* Number of passed command-line args */ |
271 | | MVMint64 num_clargs; |
272 | | /* executable name */ |
273 | | const char *exec_name; |
274 | | /* program name; becomes first clargs entry */ |
275 | | const char *prog_name; |
276 | | /* cached parsed command line args */ |
277 | | MVMObject *clargs; |
278 | | /* Any --libpath=... options, to prefix in loadbytecode lookups. */ |
279 | | const char *lib_path[8]; |
280 | | |
281 | | /* Hashes of HLLConfig objects. compiler_hll_configs is those for the |
282 | | * running compiler, and the default. compilee_hll_configs is used if |
283 | | * hll_compilee_depth is > 0. */ |
284 | | MVMHLLConfig *compiler_hll_configs; |
285 | | MVMHLLConfig *compilee_hll_configs; |
286 | | MVMint64 hll_compilee_depth; |
287 | | uv_mutex_t mutex_hllconfigs; |
288 | | |
289 | | /* By far the most common integers are between 0 and 8, but we cache up to 15 |
290 | | * so that it lines up properly. */ |
291 | | MVMIntConstCache *int_const_cache; |
292 | | uv_mutex_t mutex_int_const_cache; |
293 | | |
294 | | /* Atomically-incremented counter of newly invoked frames, used for |
295 | | * lexotic caching. */ |
296 | | AO_t num_frames_run; |
297 | | |
298 | | /* Hash of compiler objects keyed by name */ |
299 | | MVMObject *compiler_registry; |
300 | | uv_mutex_t mutex_compiler_registry; |
301 | | |
302 | | /* Hash of hashes of symbol tables per hll. */ |
303 | | MVMObject *hll_syms; |
304 | | uv_mutex_t mutex_hll_syms; |
305 | | |
306 | | MVMContainerRegistry *container_registry; /* Container registry */ |
307 | | uv_mutex_t mutex_container_registry; /* mutex for container registry */ |
308 | | |
309 | | /* Hash of all loaded DLLs. */ |
310 | | MVMDLLRegistry *dll_registry; |
311 | | uv_mutex_t mutex_dll_registry; |
312 | | |
313 | | /* Hash of all loaded extensions. */ |
314 | | MVMExtRegistry *ext_registry; |
315 | | uv_mutex_t mutex_ext_registry; |
316 | | |
317 | | /* Hash of all registered extension ops. */ |
318 | | MVMExtOpRegistry *extop_registry; |
319 | | uv_mutex_t mutex_extop_registry; |
320 | | |
321 | | /* Hash of all known serialization contexts. Marked for GC iff |
322 | | * the item is unresolved. Also, array of all SCs, used for the |
323 | | * index stored in object headers. When an SC goes away this is |
324 | | * simply nulled. That makes it a small memory leak if a lot of |
325 | | * SCs are created and go away over time. */ |
326 | | MVMSerializationContextBody *sc_weakhash; |
327 | | uv_mutex_t mutex_sc_weakhash; |
328 | | MVMSerializationContextBody **all_scs; |
329 | | MVMuint32 all_scs_next_idx; |
330 | | MVMuint32 all_scs_alloc; |
331 | | |
332 | | /* Hash of filenames of compunits loaded from disk. */ |
333 | | MVMLoadedCompUnitName *loaded_compunits; |
334 | | uv_mutex_t mutex_loaded_compunits; |
335 | | |
336 | | /* Interned callsites. */ |
337 | | MVMCallsiteInterns *callsite_interns; |
338 | | uv_mutex_t mutex_callsite_interns; |
339 | | |
340 | | /* Standard file handles. */ |
341 | | MVMObject *stdin_handle; |
342 | | MVMObject *stdout_handle; |
343 | | MVMObject *stderr_handle; |
344 | | |
345 | | /* Fixed size allocator. */ |
346 | | MVMFixedSizeAlloc *fsa; |
347 | | |
348 | | /* Normal Form Grapheme state (synthetics table, lookup, etc.). */ |
349 | | MVMNFGState *nfg; |
350 | | |
351 | | /* Next type cache ID, to go in STable. */ |
352 | | AO_t cur_type_cache_id; |
353 | | |
354 | | /* The current instrumentation level. Each time we turn on/off some kind |
355 | | * of instrumentation, such as profiling, this is incremented. The next |
356 | | * entry to a frame then knows it should instrument or switch back to an |
357 | | * uninstrumented version. As a special case, when we start up this is set |
358 | | * to 1 which also triggers frame verification. */ |
359 | | MVMuint32 instrumentation_level; |
360 | | |
361 | | /* Whether instrumented profiling is turned on or not. */ |
362 | | MVMuint32 profiling; |
363 | | |
364 | | /* Heap snapshots, if we're doing heap snapshotting. */ |
365 | | MVMHeapSnapshotCollection *heap_snapshots; |
366 | | |
367 | | /* Whether cross-thread write logging is turned on or not, and an output |
368 | | * mutex for it. */ |
369 | | MVMuint32 cross_thread_write_logging; |
370 | | MVMuint32 cross_thread_write_logging_include_locked; |
371 | | uv_mutex_t mutex_cross_thread_write_logging; |
372 | | |
373 | | MVMuint32 coverage_logging; |
374 | | /* Log file for coverage logging. */ |
375 | | FILE *coverage_log_fh; |
376 | | |
377 | | /* Cached backend config hash. */ |
378 | | MVMObject *cached_backend_config; |
379 | | }; |
380 | | |
381 | | /* Returns a true value if we have created user threads (and so are running a |
382 | | * multi-threaded application). */ |
383 | 0 | MVM_STATIC_INLINE MVMint32 MVM_instance_have_user_threads(MVMThreadContext *tc) { |
384 | 0 | return tc->instance->next_user_thread_id != 2; |
385 | 0 | } |