Skip to content

Commit

Permalink
Account for deopt all vs. deopt on difference
Browse files Browse the repository at this point in the history
When we are doing a deopt all, the bytecode position is the op we will
return to. Thus we need to account for being one past the end of the
inline in that case (inclusive), but to *not* do it for a failed guard
that is immediately following a depot, otherwise we'll end up wrongly
uninlining an inline we were not in. (This may need a further look, as
in the worst case <= may also be correct for any post-deopt point, while
< is for pre-deopt points, but we don't currently have that info to
hand. In any case, the fact that pre-deopt points are now hugely common
but before they were really rare is reason enough for this issue to have
gone missed before now.)
  • Loading branch information
jnthn committed Jul 29, 2021
1 parent e3c36fc commit 18f6e3b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/spesh/deopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ MVM_STATIC_INLINE void clear_dynlex_cache(MVMThreadContext *tc, MVMFrame *f) {
* record on the callstack.
*/
static void uninline(MVMThreadContext *tc, MVMFrame *f, MVMSpeshCandidate *cand,
MVMuint32 offset) {
MVMuint32 offset, MVMint32 all) {
/* Make absolutely sure this is the top thing on the callstack. */
assert(MVM_callstack_current_frame(tc) == f);

Expand All @@ -37,7 +37,9 @@ static void uninline(MVMThreadContext *tc, MVMFrame *f, MVMSpeshCandidate *cand,
* first, thus we traverse it in the opposite order. */
MVMint32 i;
for (i = cand->body.num_inlines - 1; i >= 0; i--) {
if (offset > cand->body.inlines[i].start && offset <= cand->body.inlines[i].end) {
MVMuint32 start = cand->body.inlines[i].start;
MVMuint32 end = cand->body.inlines[i].end;
if (offset > start && (all ? offset <= end : offset < end)) {
/* Grab the current frame, which is the caller of this inline. */
MVMFrame *caller = MVM_callstack_current_frame(tc);

Expand Down Expand Up @@ -221,7 +223,7 @@ void MVM_spesh_deopt_one(MVMThreadContext *tc, MVMuint32 deopt_idx) {
if (f->spesh_cand->body.inlines) {
/* Perform uninlining. The top frame may have changes, so sync things
* up. */
uninline(tc, f, f->spesh_cand, deopt_offset);
uninline(tc, f, f->spesh_cand, deopt_offset, 0);
top_frame = MVM_callstack_current_frame(tc);
tc->cur_frame = top_frame;
tc->current_frame_nr = top_frame->sequence_nr;
Expand Down Expand Up @@ -355,7 +357,7 @@ void MVM_spesh_deopt_during_unwind(MVMThreadContext *tc) {
* one. */
MVMFrame *top_frame;
if (frame->spesh_cand->body.inlines) {
uninline(tc, frame, frame->spesh_cand, deopt_offset);
uninline(tc, frame, frame->spesh_cand, deopt_offset, 1);
top_frame = MVM_callstack_current_frame(tc);
}
else {
Expand Down

0 comments on commit 18f6e3b

Please sign in to comment.