Skip to content

Commit

Permalink
Fix candidate discarding on instrumentation
Browse files Browse the repository at this point in the history
Previously it was enough to simply throw away the arg guard, since we
added to it. Now that we rebuild it from the candidate list each time,
we need to keep track of which spesh candidates we discarded, so that we
do not include them in it again.
  • Loading branch information
jnthn committed Feb 18, 2020
1 parent 72c9673 commit 91efac0
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 10 deletions.
5 changes: 2 additions & 3 deletions src/instrument/crossthreadwrite.c
Expand Up @@ -132,9 +132,8 @@ void MVM_cross_thread_write_instrument(MVMThreadContext *tc, MVMStaticFrame *sf)
sf->body.handlers = sf->body.instrumentation->instrumented_handlers;
sf->body.bytecode_size = sf->body.instrumentation->instrumented_bytecode_size;

/* Throw away any argument guard so we'll never resolve prior
* specializations again. */
MVM_spesh_arg_guard_discard(tc, sf);
/* Throw away any existing specializations. */
MVM_spesh_candidate_discard_existing(tc, sf);
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/instrument/line_coverage.c
Expand Up @@ -289,9 +289,8 @@ static void line_numbers_instrument(MVMThreadContext *tc, MVMStaticFrame *sf, MV
sf->body.handlers = sf->body.instrumentation->instrumented_handlers;
sf->body.bytecode_size = sf->body.instrumentation->instrumented_bytecode_size;

/* Throw away any argument guard so we'll never resolve prior
* specializations again. */
MVM_spesh_arg_guard_discard(tc, sf);
/* Throw away any existing specializations. */
MVM_spesh_candidate_discard_existing(tc, sf);
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/profiler/instrument.c
Expand Up @@ -249,9 +249,8 @@ void MVM_profile_instrument(MVMThreadContext *tc, MVMStaticFrame *sf) {
sf->body.handlers = sf->body.instrumentation->instrumented_handlers;
sf->body.bytecode_size = sf->body.instrumentation->instrumented_bytecode_size;

/* Throw away any argument guard so we'll never resolve prior
* specializations again. */
MVM_spesh_arg_guard_discard(tc, sf);
/* Throw away any existing specializations. */
MVM_spesh_candidate_discard_existing(tc, sf);
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/spesh/arg_guard.c
Expand Up @@ -325,9 +325,13 @@ void MVM_spesh_arg_guard_regenerate(MVMThreadContext *tc, MVMSpeshArgGuard **gua
MVM_VECTOR_INIT(by_callsite, num_spesh_candidates);
MVMuint32 tree_size = 0;
for (i = 0; i < num_spesh_candidates; i++) {
/* See if we already have a candidate for this. */
/* Skip discarded candidates. */
MVMSpeshCandidate *cand = candidates[i];
MVMint32 found = -1;
if (cand->discarded)
continue;

/* See if we already have a candidate for this. */
for (j = 0; j < MVM_VECTOR_ELEMS(by_callsite); j++) {
if (by_callsite[j].cs == cand->cs) {
found = j;
Expand Down
13 changes: 13 additions & 0 deletions src/spesh/candidate.c
Expand Up @@ -226,3 +226,16 @@ void MVM_spesh_candidate_destroy(MVMThreadContext *tc, MVMSpeshCandidate *candid
MVM_free(candidate->deopt_usage_info);
MVM_free(candidate);
}

/* Discards existing candidates. Used when we instrument bytecode, and so
* need to ignore these ones from here on. */
void MVM_spesh_candidate_discard_existing(MVMThreadContext *tc, MVMStaticFrame *sf) {
MVMStaticFrameSpesh *spesh = sf->body.spesh;
if (spesh) {
MVMuint32 num_candidates = spesh->body.num_spesh_candidates;
MVMuint32 i;
for (i = 0; i < num_candidates; i++)
spesh->body.spesh_candidates[i]->discarded = 1;
MVM_spesh_arg_guard_discard(tc, sf);
}
}
4 changes: 4 additions & 0 deletions src/spesh/candidate.h
Expand Up @@ -7,6 +7,9 @@ struct MVMSpeshCandidate {
* certian specialization. */
MVMSpeshStatsType *type_tuple;

/* Has the candidated been discarded? */
MVMuint8 discarded;

/* Length of the specialized bytecode in bytes. */
MVMuint32 bytecode_size;

Expand Down Expand Up @@ -77,3 +80,4 @@ struct MVMSpeshCandidate {
/* Functions for creating and clearing up specializations. */
void MVM_spesh_candidate_add(MVMThreadContext *tc, MVMSpeshPlanned *p);
void MVM_spesh_candidate_destroy(MVMThreadContext *tc, MVMSpeshCandidate *candidate);
void MVM_spesh_candidate_discard_existing(MVMThreadContext *tc, MVMStaticFrame *sf);

0 comments on commit 91efac0

Please sign in to comment.