/home/travis/build/MoarVM/MoarVM/src/spesh/lookup.c
Line | Count | Source |
1 | | /* This file contains a number of functions that do lookups of data held in |
2 | | * data structures outside of the realm of spesh. We need to be very careful |
3 | | * how we do these, in various cases. For example, in the past we had cases |
4 | | * where we tried to look up a method, which in turn triggered method cache |
5 | | * deserialization, which acquired a mutex, which would block for GC and so |
6 | | * could end up with a collection taking place while spesh was working. This |
7 | | * broke the "no GC during spesh" invariant. */ |
8 | | |
9 | | #include "moar.h" |
10 | | |
11 | | /* Tries to get the HOW (meta-object) of an object - but only if it's already |
12 | | * available (e.g. deserialized). In the case it's not, returns NULL. */ |
13 | 489 | MVMObject * MVM_spesh_try_get_how(MVMThreadContext *tc, MVMObject *obj) { |
14 | 489 | return STABLE(obj)->HOW; |
15 | 489 | } |
16 | | |
17 | | /* Tries to look up the method using the method cache, provided that the |
18 | | * method cache has already been deserialized. */ |
19 | 15.8k | MVMObject * MVM_spesh_try_find_method(MVMThreadContext *tc, MVMObject *obj, MVMString *name) { |
20 | 15.8k | return STABLE(obj)->method_cache |
21 | 15.6k | ? MVM_6model_find_method_cache_only(tc, obj, name) |
22 | 15.8k | : NULL; |
23 | 15.8k | } |
24 | | |
25 | | /* Tries to check if the method exists on the object using the method cache, |
26 | | * provided the method cache has already been deserialized. */ |
27 | 2.82k | MVMint64 MVM_spesh_try_can_method(MVMThreadContext *tc, MVMObject *obj, MVMString *name) { |
28 | 2.82k | return STABLE(obj)->method_cache |
29 | 528 | ? MVM_6model_can_method_cache_only(tc, obj, name) |
30 | 2.29k | : -1; |
31 | 2.82k | } |
32 | | |
33 | 300k | MVMint8 MVM_spesh_get_reg_type(MVMThreadContext *tc, MVMSpeshGraph *sg, MVMuint16 reg) { |
34 | 256k | return sg->local_types ? sg->local_types[reg] : sg->sf->body.local_types[reg]; |
35 | 300k | } |
36 | | |
37 | 846 | MVMint8 MVM_spesh_get_lex_type(MVMThreadContext *tc, MVMSpeshGraph *sg, MVMuint16 outers, MVMuint16 idx) { |
38 | 846 | if (outers == 0) { |
39 | 554 | return sg->lexical_types ? sg->lexical_types[idx] : sg->sf->body.lexical_types[idx]; |
40 | 19 | } else { |
41 | 19 | MVMStaticFrame *sf; |
42 | 43 | for (sf = sg->sf; sf != NULL && outers--; sf = sf->body.outer); |
43 | 19 | return sf->body.lexical_types[idx]; |
44 | 19 | } |
45 | 846 | } |