Skip to content

Commit

Permalink
Make deopt no longer require effective_bytecode.
Browse files Browse the repository at this point in the history
Which makes it rather clearer anyway.
  • Loading branch information
jnthn committed Jul 26, 2017
1 parent 49ed81f commit 7455420
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions src/spesh/deopt.c
Expand Up @@ -58,12 +58,12 @@ static void uninline(MVMThreadContext *tc, MVMFrame *f, MVMSpeshCandidate *cand,
if (last_uninlined) {
/* Yes; multi-level un-inline. Switch it back to deopt'd
* code. */
uf->effective_bytecode = uf->static_info->body.bytecode;
uf->effective_bytecode = usf->body.bytecode;
uf->effective_spesh_slots = NULL;
uf->spesh_cand = NULL;

/* Set up the return location. */
uf->return_address = uf->static_info->body.bytecode +
uf->return_address = usf->body.bytecode +
cand->deopts[2 * last_return_deopt_idx];

/* Set result type and register. */
Expand All @@ -85,7 +85,7 @@ static void uninline(MVMThreadContext *tc, MVMFrame *f, MVMSpeshCandidate *cand,
MVM_ASSIGN_REF(tc, &(callee->header), callee->caller, uf);

/* Copy over the return location. */
uf->return_address = uf->effective_bytecode + deopt_offset;
uf->return_address = usf->body.bytecode + deopt_offset;

/* Set result type and register. */
uf->return_type = f->return_type;
Expand All @@ -103,8 +103,8 @@ static void uninline(MVMThreadContext *tc, MVMFrame *f, MVMSpeshCandidate *cand,
* the interpreter. */
tc->cur_frame = uf;
tc->current_frame_nr = uf->sequence_nr;
*(tc->interp_cur_op) = uf->effective_bytecode + deopt_offset;
*(tc->interp_bytecode_start) = uf->effective_bytecode;
*(tc->interp_cur_op) = usf->body.bytecode + deopt_offset;
*(tc->interp_bytecode_start) = usf->body.bytecode;
*(tc->interp_reg_base) = uf->work;
*(tc->interp_cu) = usf->body.cu;
}
Expand Down Expand Up @@ -138,7 +138,7 @@ static void uninline(MVMThreadContext *tc, MVMFrame *f, MVMSpeshCandidate *cand,
/* Weren't in an inline after all. What kind of deopt? */
if (callee) {
/* Deopt all. Move return address. */
f->return_address = f->effective_bytecode + deopt_offset;
f->return_address = f->static_info->body.bytecode + deopt_offset;
}
else {
/* Deopt one. Move interpreter. */
Expand Down Expand Up @@ -186,8 +186,8 @@ static void deopt_frame(MVMThreadContext *tc, MVMFrame *f, MVMint32 deopt_offset
else {
/* No inlining; simple case. Switch back to the original code. */
f->effective_bytecode = f->static_info->body.bytecode;
*(tc->interp_cur_op) = f->effective_bytecode + deopt_target;
*(tc->interp_bytecode_start) = f->effective_bytecode;
*(tc->interp_cur_op) = f->static_info->body.bytecode + deopt_target;
*(tc->interp_bytecode_start) = f->static_info->body.bytecode;
f->effective_spesh_slots = NULL;
f->spesh_cand = NULL;
#if MVM_LOG_DEOPTS
Expand All @@ -211,8 +211,8 @@ void MVM_spesh_deopt_one(MVMThreadContext *tc) {
MVM_string_utf8_encode_C_string(tc, tc->cur_frame->static_info->body.cuuid));
#endif
clear_dynlex_cache(tc, f);
if (f->effective_bytecode != f->static_info->body.bytecode) {
MVMint32 deopt_offset = *(tc->interp_cur_op) - f->effective_bytecode;
if (f->spesh_cand) {
MVMint32 deopt_offset = *(tc->interp_cur_op) - f->spesh_cand->bytecode;
MVMint32 deopt_target = find_deopt_target(tc, f, deopt_offset);
deopt_frame(tc, tc->cur_frame, deopt_offset, deopt_target);
}
Expand All @@ -230,14 +230,7 @@ void MVM_spesh_deopt_one_direct(MVMThreadContext *tc, MVMint32 deopt_offset,
if (tc->instance->profiling)
MVM_profiler_log_deopt_one(tc);
clear_dynlex_cache(tc, f);
if (f->effective_bytecode != f->static_info->body.bytecode) {
deopt_frame(tc, tc->cur_frame, deopt_offset, deopt_target);
} else {
MVM_oops(tc, "deopt_one_direct failed for %s (%s)",
MVM_string_utf8_encode_C_string(tc, tc->cur_frame->static_info->body.name),
MVM_string_utf8_encode_C_string(tc, tc->cur_frame->static_info->body.cuuid));
}

deopt_frame(tc, tc->cur_frame, deopt_offset, deopt_target);
}

/* De-optimizes all specialized frames on the call stack. Used when a change
Expand All @@ -251,7 +244,7 @@ void MVM_spesh_deopt_all(MVMThreadContext *tc) {
MVM_profiler_log_deopt_all(tc);
while (f) {
clear_dynlex_cache(tc, f);
if (f->effective_bytecode != f->static_info->body.bytecode) {
if (f->spesh_cand) {
/* Found one. Is it JITted code? */
if (f->spesh_cand->jitcode && f->jit_entry_label) {
MVMint32 num_deopts = f->spesh_cand->jitcode->num_deopts;
Expand Down Expand Up @@ -283,7 +276,7 @@ void MVM_spesh_deopt_all(MVMThreadContext *tc) {
});
}
else {
f->return_address = f->effective_bytecode + deopt_target;
f->return_address = f->static_info->body.bytecode + deopt_target;
}

/* No spesh cand/slots needed now. */
Expand All @@ -302,7 +295,7 @@ void MVM_spesh_deopt_all(MVMThreadContext *tc) {

else {
/* Not JITted; see if we can find the return address in the deopt table. */
MVMint32 ret_offset = f->return_address - f->effective_bytecode;
MVMint32 ret_offset = f->return_address - f->spesh_cand->bytecode;
MVMint32 i;
for (i = 0; i < f->spesh_cand->num_deopts * 2; i += 2) {
if (f->spesh_cand->deopts[i + 1] == ret_offset) {
Expand All @@ -319,7 +312,7 @@ void MVM_spesh_deopt_all(MVMThreadContext *tc) {
});
}
else {
f->return_address = f->effective_bytecode + f->spesh_cand->deopts[i];
f->return_address = f->static_info->body.bytecode + f->spesh_cand->deopts[i];
}

/* No spesh cand/slots needed now. */
Expand Down

0 comments on commit 7455420

Please sign in to comment.