Coverage Report

Created: 2018-06-21 18:56

/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
485
MVMObject * MVM_spesh_try_get_how(MVMThreadContext *tc, MVMObject *obj) {
14
485
    return STABLE(obj)->HOW;
15
485
}
16
17
/* Tries to look up the method using the method cache, provided that the
18
 * method cache has already been deserialized. */
19
15.0k
MVMObject * MVM_spesh_try_find_method(MVMThreadContext *tc, MVMObject *obj, MVMString *name) {
20
15.0k
    return STABLE(obj)->method_cache
21
14.8k
        ? MVM_6model_find_method_cache_only(tc, obj, name)
22
15.0k
        : NULL;
23
15.0k
}
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.73k
MVMint64 MVM_spesh_try_can_method(MVMThreadContext *tc, MVMObject *obj, MVMString *name) {
28
2.73k
    return STABLE(obj)->method_cache
29
540
        ? MVM_6model_can_method_cache_only(tc, obj, name)
30
2.19k
        : -1;
31
2.73k
}
32
33
283k
MVMint8 MVM_spesh_get_reg_type(MVMThreadContext *tc, MVMSpeshGraph *sg, MVMuint16 reg) {
34
242k
    return sg->local_types ? sg->local_types[reg] : sg->sf->body.local_types[reg];
35
283k
}
36
37
782
MVMint8 MVM_spesh_get_lex_type(MVMThreadContext *tc, MVMSpeshGraph *sg, MVMuint16 outers, MVMuint16 idx) {
38
782
    if (outers == 0) {
39
515
        return sg->lexical_types ? sg->lexical_types[idx] : sg->sf->body.lexical_types[idx];
40
18
    } else {
41
18
        MVMStaticFrame *sf;
42
39
        for (sf = sg->sf; sf != NULL && outers--; sf = sf->body.outer);
43
18
        return sf->body.lexical_types[idx];
44
18
    }
45
782
}