Skip to content

Commit

Permalink
Fix bind_key to use correct frame in write barrier
Browse files Browse the repository at this point in the history
Since we traverse lazily, the frame available in the context is no
longer always the one that owns the lexical being bound to.
  • Loading branch information
jnthn committed Jul 19, 2018
1 parent 1c8c270 commit f356e5a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
9 changes: 5 additions & 4 deletions src/6model/reprs/MVMContext.c
Expand Up @@ -73,7 +73,7 @@ static void at_key(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, void *d
MVMRegister *found;
MVMuint16 found_kind;
if (!setup_frame_walker(tc, &fw, body) || !MVM_spesh_frame_walker_get_lex(tc, &fw,
name, &found, &found_kind, 1)) {
name, &found, &found_kind, 1, NULL)) {
char *c_name = MVM_string_utf8_encode_C_string(tc, name);
char *waste[] = { c_name, NULL };
MVM_exception_throw_adhoc_free(tc, waste,
Expand Down Expand Up @@ -128,8 +128,9 @@ static void bind_key(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, void
MVMSpeshFrameWalker fw;
MVMRegister *found;
MVMuint16 got_kind;
MVMFrame *found_frame;
if (!setup_frame_walker(tc, &fw, body) || !MVM_spesh_frame_walker_get_lex(tc, &fw,
name, &found, &got_kind, 1)) {
name, &found, &got_kind, 1, &found_frame)) {
char *c_name = MVM_string_utf8_encode_C_string(tc, name);
char *waste[] = { c_name, NULL };
MVM_exception_throw_adhoc_free(tc, waste,
Expand All @@ -147,7 +148,7 @@ static void bind_key(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, void
}

if (got_kind == MVM_reg_obj || got_kind == MVM_reg_str) {
MVM_ASSIGN_REF(tc, &(frame->header), found->o, value.o);
MVM_ASSIGN_REF(tc, &(found_frame->header), found->o, value.o);
}
else {
*found = value;
Expand All @@ -173,7 +174,7 @@ static MVMint64 exists_key(MVMThreadContext *tc, MVMSTable *st, MVMObject *root,
MVMRegister *found;
MVMuint16 found_kind;
MVMuint64 result = setup_frame_walker(tc, &fw, body) && MVM_spesh_frame_walker_get_lex(tc, &fw,
(MVMString *)key, &found, &found_kind, 0);
(MVMString *)key, &found, &found_kind, 0, NULL);
MVM_spesh_frame_walker_cleanup(tc, &fw);

return result;
Expand Down
4 changes: 2 additions & 2 deletions src/core/frame.c
Expand Up @@ -1394,7 +1394,7 @@ MVMRegister * MVM_frame_lexical_lookup_using_frame_walker(MVMThreadContext *tc,
while (MVM_spesh_frame_walker_next(tc, fw)) {
MVMRegister *found;
MVMuint16 found_kind;
if (MVM_spesh_frame_walker_get_lex(tc, fw, name, &found, &found_kind, 1)) {
if (MVM_spesh_frame_walker_get_lex(tc, fw, name, &found, &found_kind, 1, NULL)) {
MVM_spesh_frame_walker_cleanup(tc, fw);
if (found_kind == MVM_reg_obj) {
return found;
Expand Down Expand Up @@ -1516,7 +1516,7 @@ MVMRegister * MVM_frame_find_dynamic_using_frame_walker(MVMThreadContext *tc,
icost++;

/* See if we have the lexical at this location. */
if (MVM_spesh_frame_walker_get_lex(tc, fw, name, &result, type, vivify)) {
if (MVM_spesh_frame_walker_get_lex(tc, fw, name, &result, type, vivify, found_frame)) {
/* Yes, found it. If we walked some way, try to cache it. */
if (fcost+icost > 1)
try_cache_dynlex(tc, initial_frame, last_real_frame, name,
Expand Down
12 changes: 9 additions & 3 deletions src/spesh/frame_walker.c
Expand Up @@ -221,7 +221,8 @@ static void find_lex_info(MVMThreadContext *tc, MVMSpeshFrameWalker *fw, MVMFram
* trigger vivification of the lexical if needed. */
MVMuint32 MVM_spesh_frame_walker_get_lex(MVMThreadContext *tc, MVMSpeshFrameWalker *fw,
MVMString *name, MVMRegister **found_out,
MVMuint16 *found_kind_out, MVMuint32 vivify) {
MVMuint16 *found_kind_out, MVMuint32 vivify,
MVMFrame **found_frame) {
MVMFrame *cur_frame;
MVMStaticFrame *sf;
MVMuint32 base_index;
Expand All @@ -238,8 +239,13 @@ MVMuint32 MVM_spesh_frame_walker_get_lex(MVMThreadContext *tc, MVMSpeshFrameWalk
MVMuint16 kind = sf->body.lexical_types[entry->value];
*found_out = result;
*found_kind_out = kind;
if (vivify && kind == MVM_reg_obj && !result->o)
MVM_frame_vivify_lexical(tc, cur_frame, index);
if (vivify && kind == MVM_reg_obj && !result->o) {
MVMROOT(tc, cur_frame, {
MVM_frame_vivify_lexical(tc, cur_frame, index);
});
}
if (found_frame)
*found_frame = cur_frame;
return 1;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/spesh/frame_walker.h
Expand Up @@ -38,7 +38,8 @@ void MVM_spesh_frame_walker_init_for_outers(MVMThreadContext *tc, MVMSpeshFrameW
MVMFrame *start);
MVMuint32 MVM_spesh_frame_walker_next(MVMThreadContext *tc, MVMSpeshFrameWalker *fw);
MVMuint32 MVM_spesh_frame_walker_get_lex(MVMThreadContext *tc, MVMSpeshFrameWalker *fw,
MVMString *name, MVMRegister **found_out, MVMuint16 *found_kind_out, MVMuint32 vivify);
MVMString *name, MVMRegister **found_out, MVMuint16 *found_kind_out,
MVMuint32 vivify, MVMFrame **found_frame);
MVMuint32 MVM_spesh_frame_walker_is_inline(MVMThreadContext *tc, MVMSpeshFrameWalker *fw);
MVMFrame * MVM_spesh_frame_walker_current_frame(MVMThreadContext *tc, MVMSpeshFrameWalker *fw);
MVMuint32 MVM_spesh_frame_walker_move_outer(MVMThreadContext *tc, MVMSpeshFrameWalker *fw);
Expand Down

0 comments on commit f356e5a

Please sign in to comment.