/home/travis/build/MoarVM/MoarVM/src/6model/sc.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* SC manipulation functions. */ |
2 | | MVMObject * MVM_sc_create(MVMThreadContext *tc, MVMString *handle); |
3 | | void MVM_sc_add_all_scs_entry(MVMThreadContext *tc, MVMSerializationContextBody *scb); |
4 | | MVMString * MVM_sc_get_handle(MVMThreadContext *tc, MVMSerializationContext *sc); |
5 | | MVMString * MVM_sc_get_description(MVMThreadContext *tc, MVMSerializationContext *sc); |
6 | | void MVM_sc_set_description(MVMThreadContext *tc, MVMSerializationContext *sc, MVMString *desc); |
7 | | MVMint64 MVM_sc_find_object_idx(MVMThreadContext *tc, MVMSerializationContext *sc, MVMObject *obj); |
8 | | MVMint64 MVM_sc_find_object_idx_jit(MVMThreadContext *tc, MVMObject *sc, MVMObject *obj); |
9 | | MVMint64 MVM_sc_find_stable_idx(MVMThreadContext *tc, MVMSerializationContext *sc, MVMSTable *st); |
10 | | MVMint64 MVM_sc_find_code_idx(MVMThreadContext *tc, MVMSerializationContext *sc, MVMObject *obj); |
11 | | MVMuint8 MVM_sc_is_object_immediately_available(MVMThreadContext *tc, MVMSerializationContext *sc, MVMint64 idx); |
12 | | MVMObject * MVM_sc_get_object(MVMThreadContext *tc, MVMSerializationContext *sc, MVMint64 idx); |
13 | | MVMObject * MVM_sc_try_get_object(MVMThreadContext *tc, MVMSerializationContext *sc, MVMint64 idx); |
14 | | void MVM_sc_set_object(MVMThreadContext *tc, MVMSerializationContext *sc, MVMint64 idx, MVMObject *obj); |
15 | | MVMSTable * MVM_sc_get_stable(MVMThreadContext *tc, MVMSerializationContext *sc, MVMint64 idx); |
16 | | MVMSTable * MVM_sc_try_get_stable(MVMThreadContext *tc, MVMSerializationContext *sc, MVMint64 idx); |
17 | | void MVM_sc_set_stable(MVMThreadContext *tc, MVMSerializationContext *sc, MVMint64 idx, MVMSTable *st); |
18 | | void MVM_sc_push_stable(MVMThreadContext *tc, MVMSerializationContext *sc, MVMSTable *st); |
19 | | MVMObject * MVM_sc_get_code(MVMThreadContext *tc, MVMSerializationContext *sc, MVMint64 idx); |
20 | | MVMSerializationContext * MVM_sc_find_by_handle(MVMThreadContext *tc, MVMString *handle); |
21 | | MVMSerializationContext * MVM_sc_get_sc_slow(MVMThreadContext *tc, MVMCompUnit *cu, MVMint16 dep); |
22 | | MVM_STATIC_INLINE MVMSerializationContext * MVM_sc_get_sc(MVMThreadContext *tc, |
23 | 0 | MVMCompUnit *cu, MVMint16 dep) { |
24 | 0 | MVMSerializationContext *sc = cu->body.scs[dep]; |
25 | 0 | return sc ? sc : MVM_sc_get_sc_slow(tc, cu, dep); |
26 | 0 | } |
27 | | MVM_STATIC_INLINE MVMObject * MVM_sc_get_sc_object(MVMThreadContext *tc, MVMCompUnit *cu, |
28 | 0 | MVMuint16 dep, MVMuint64 idx) { |
29 | 0 | MVMSerializationContext *sc = MVM_sc_get_sc(tc, cu, dep); |
30 | 0 | if (MVM_UNLIKELY(sc == NULL)) |
31 | 0 | MVM_exception_throw_adhoc(tc, "SC not yet resolved; lookup failed"); |
32 | 0 | return MVM_sc_get_object(tc, sc, idx); |
33 | 0 | } |
34 | | void MVM_sc_disclaim(MVMThreadContext *tc, MVMSerializationContext *sc); |
35 | | |
36 | 0 | MVM_STATIC_INLINE MVMuint32 MVM_sc_get_idx_of_sc(MVMCollectable *col) { |
37 | 0 | assert(!(col->flags & MVM_CF_FORWARDER_VALID)); |
38 | 0 | #ifdef MVM_USE_OVERFLOW_SERIALIZATION_INDEX |
39 | 0 | if (col->flags & MVM_CF_SERIALZATION_INDEX_ALLOCATED) |
40 | 0 | return col->sc_forward_u.sci->sc_idx; |
41 | 0 | #endif |
42 | 0 | return col->sc_forward_u.sc.sc_idx; |
43 | 0 | } |
44 | | |
45 | 0 | MVM_STATIC_INLINE MVMuint32 MVM_sc_get_idx_in_sc(MVMCollectable *col) { |
46 | 0 | assert(!(col->flags & MVM_CF_FORWARDER_VALID)); |
47 | 0 | #ifdef MVM_USE_OVERFLOW_SERIALIZATION_INDEX |
48 | 0 | if (col->flags & MVM_CF_SERIALZATION_INDEX_ALLOCATED) |
49 | 0 | return col->sc_forward_u.sci->idx; |
50 | 0 | if (col->sc_forward_u.sc.idx == MVM_DIRECT_SC_IDX_SENTINEL) |
51 | 0 | return ~0; |
52 | 0 | #endif |
53 | 0 | return col->sc_forward_u.sc.idx; |
54 | 0 | } |
55 | | |
56 | 0 | MVM_STATIC_INLINE void MVM_sc_set_idx_in_sc(MVMCollectable *col, MVMuint32 i) { |
57 | 0 | assert(!(col->flags & MVM_CF_FORWARDER_VALID)); |
58 | 0 | assert(i >= 0); |
59 | 0 | #ifdef MVM_USE_OVERFLOW_SERIALIZATION_INDEX |
60 | 0 | if (col->flags & MVM_CF_SERIALZATION_INDEX_ALLOCATED) { |
61 | 0 | col->sc_forward_u.sci->idx = i; |
62 | 0 | } else if (i >= MVM_DIRECT_SC_IDX_SENTINEL) { |
63 | 0 | struct MVMSerializationIndex *const sci |
64 | 0 | = MVM_malloc(sizeof(struct MVMSerializationIndex)); |
65 | 0 | sci->sc_idx = col->sc_forward_u.sc.sc_idx; |
66 | 0 | sci->idx = i; |
67 | 0 | col->sc_forward_u.sci = sci; |
68 | 0 | col->flags |= MVM_CF_SERIALZATION_INDEX_ALLOCATED; |
69 | 0 | } else |
70 | 0 | #endif |
71 | 0 | { |
72 | 0 | col->sc_forward_u.sc.idx = i; |
73 | 0 | } |
74 | 0 | } |
75 | | |
76 | | /* Gets a collectable's SC. */ |
77 | 0 | MVM_STATIC_INLINE MVMSerializationContext * MVM_sc_get_collectable_sc(MVMThreadContext *tc, MVMCollectable *col) { |
78 | 0 | MVMuint32 sc_idx; |
79 | 0 | assert(!(col->flags & MVM_CF_FORWARDER_VALID)); |
80 | 0 | sc_idx = MVM_sc_get_idx_of_sc(col); |
81 | 0 | assert(sc_idx != ~0); |
82 | 0 | return sc_idx > 0 ? tc->instance->all_scs[sc_idx]->sc : NULL; |
83 | 0 | } |
84 | | |
85 | | /* Gets an object's SC. */ |
86 | 0 | MVM_STATIC_INLINE MVMSerializationContext * MVM_sc_get_obj_sc(MVMThreadContext *tc, MVMObject *obj) { |
87 | 0 | return MVM_sc_get_collectable_sc(tc, &obj->header); |
88 | 0 | } |
89 | | |
90 | | /* Gets a frame's SC. */ |
91 | 0 | MVM_STATIC_INLINE MVMSerializationContext * MVM_sc_get_frame_sc(MVMThreadContext *tc, MVMFrame *f) { |
92 | 0 | return MVM_sc_get_collectable_sc(tc, &f->header); |
93 | 0 | } |
94 | | |
95 | | /* Gets an STables's SC. */ |
96 | 0 | MVM_STATIC_INLINE MVMSerializationContext * MVM_sc_get_stable_sc(MVMThreadContext *tc, MVMSTable *st) { |
97 | 0 | return MVM_sc_get_collectable_sc(tc, &st->header); |
98 | 0 | } |
99 | | |
100 | | /* Sets a collectable's SC. */ |
101 | 0 | MVM_STATIC_INLINE void MVM_sc_set_collectable_sc(MVMThreadContext *tc, MVMCollectable *col, MVMSerializationContext *sc) { |
102 | 0 | assert(!(col->flags & MVM_CF_FORWARDER_VALID)); |
103 | 0 | #ifdef MVM_USE_OVERFLOW_SERIALIZATION_INDEX |
104 | 0 | if (col->flags & MVM_CF_SERIALZATION_INDEX_ALLOCATED) { |
105 | 0 | col->sc_forward_u.sci->sc_idx = sc->body->sc_idx; |
106 | 0 | col->sc_forward_u.sci->idx = ~0; |
107 | 0 | } else |
108 | 0 | #endif |
109 | 0 | { |
110 | 0 | col->sc_forward_u.sc.sc_idx = sc->body->sc_idx; |
111 | 0 | #ifdef MVM_USE_OVERFLOW_SERIALIZATION_INDEX |
112 | 0 | if (col->sc_forward_u.sc.sc_idx != sc->body->sc_idx) { |
113 | 0 | struct MVMSerializationIndex *const sci |
114 | 0 | = MVM_malloc(sizeof(struct MVMSerializationIndex)); |
115 | 0 | sci->sc_idx = sc->body->sc_idx; |
116 | 0 | sci->idx = ~0; |
117 | 0 | col->sc_forward_u.sci = sci; |
118 | 0 | col->flags |= MVM_CF_SERIALZATION_INDEX_ALLOCATED; |
119 | 0 | } else |
120 | 0 | #endif |
121 | 0 | { |
122 | 0 | col->sc_forward_u.sc.idx = MVM_DIRECT_SC_IDX_SENTINEL; |
123 | 0 | } |
124 | 0 | } |
125 | 0 | } |
126 | | |
127 | | /* Sets an object's SC. */ |
128 | 0 | MVM_STATIC_INLINE void MVM_sc_set_obj_sc(MVMThreadContext *tc, MVMObject *obj, MVMSerializationContext *sc) { |
129 | 0 | MVM_sc_set_collectable_sc(tc, &obj->header, sc); |
130 | 0 | } |
131 | | |
132 | | /* Sets an frame's SC. */ |
133 | 0 | MVM_STATIC_INLINE void MVM_sc_set_frame_sc(MVMThreadContext *tc, MVMFrame *f, MVMSerializationContext *sc) { |
134 | 0 | MVM_sc_set_collectable_sc(tc, &f->header, sc); |
135 | 0 | } |
136 | | |
137 | | /* Sets an STable's SC. */ |
138 | 0 | MVM_STATIC_INLINE void MVM_sc_set_stable_sc(MVMThreadContext *tc, MVMSTable *st, MVMSerializationContext *sc) { |
139 | 0 | MVM_sc_set_collectable_sc(tc, &st->header, sc); |
140 | 0 | } |
141 | | |
142 | | /* Given an SC, an index and a code ref, store it and the index. */ |
143 | 0 | MVM_STATIC_INLINE void MVM_sc_set_code(MVMThreadContext *tc, MVMSerializationContext *sc, MVMint64 idx, MVMObject *code) { |
144 | 0 | MVMObject *roots = sc->body->root_codes; |
145 | 0 | MVM_repr_bind_pos_o(tc, roots, idx, code); |
146 | 0 | if (MVM_sc_get_idx_of_sc(&code->header) == sc->body->sc_idx) |
147 | 0 | MVM_sc_set_idx_in_sc(&code->header, idx); |
148 | 0 | } |
149 | | |
150 | | /* Sets the full list of code refs. */ |
151 | 0 | MVM_STATIC_INLINE void MVM_sc_set_code_list(MVMThreadContext *tc, MVMSerializationContext *sc, MVMObject *code_list) { |
152 | 0 | MVM_ASSIGN_REF(tc, &(sc->common.header), sc->body->root_codes, code_list); |
153 | 0 | } |
154 | | |
155 | | /* Gets the number of objects in the SC. */ |
156 | 0 | MVM_STATIC_INLINE MVMuint64 MVM_sc_get_object_count(MVMThreadContext *tc, MVMSerializationContext *sc) { |
157 | 0 | return sc->body->num_objects; |
158 | 0 | } |
159 | | |
160 | | /* Given an SC and an object, push it onto the SC. */ |
161 | 0 | MVM_STATIC_INLINE void MVM_sc_push_object(MVMThreadContext *tc, MVMSerializationContext *sc, MVMObject *obj) { |
162 | 0 | MVMuint32 idx = sc->body->num_objects; |
163 | 0 | MVM_sc_set_object(tc, sc, idx, obj); |
164 | 0 | if (MVM_sc_get_idx_of_sc(&obj->header) == sc->body->sc_idx) |
165 | 0 | MVM_sc_set_idx_in_sc(&obj->header, idx); |
166 | 0 | } |
167 | | |
168 | | /* SC repossession write barriers. */ |
169 | | void MVM_sc_wb_hit_obj(MVMThreadContext *tc, MVMObject *obj); |
170 | | void MVM_sc_wb_hit_st(MVMThreadContext *tc, MVMSTable *st); |
171 | | |
172 | | void MVM_SC_WB_OBJ(MVMThreadContext *tc, MVMObject *obj); |
173 | | |
174 | 0 | MVM_STATIC_INLINE void MVM_SC_WB_ST(MVMThreadContext *tc, MVMSTable *st) { |
175 | 0 | assert(!(st->header.flags & MVM_CF_FORWARDER_VALID)); |
176 | 0 | assert(MVM_sc_get_idx_of_sc(&st->header) != ~0); |
177 | 0 | if (MVM_sc_get_idx_of_sc(&st->header) > 0) |
178 | 0 | MVM_sc_wb_hit_st(tc, st); |
179 | 0 | } |