[wasm] Simplify exceptional continuation in interpreter.
This unifies how continuations after a control transfer are handled within the interpreter loop. To avoid bumping the {pc} we can either reset the opcode length to zero or just "continue" the loop. This just unifies the approach for the entire {Execute} method. R=clemensh@chromium.org Change-Id: Ifc33c3a87cff69d417f61fa0bc234260c7fa502a Reviewed-on: https://chromium-review.googlesource.com/c/1458216 Commit-Queue: Michael Starzinger <mstarzinger@chromium.org> Reviewed-by: Clemens Hammacher <clemensh@chromium.org> Cr-Commit-Position: refs/heads/master@{#59434}
This commit is contained in:
parent
4c65986a44
commit
eb69c7da2c
@ -1412,13 +1412,12 @@ class ThreadImpl {
|
||||
}
|
||||
|
||||
void ReloadFromFrameOnException(Decoder* decoder, InterpreterCode** code,
|
||||
pc_t* pc, pc_t* limit, int* len) {
|
||||
pc_t* pc, pc_t* limit) {
|
||||
Frame* top = &frames_.back();
|
||||
*code = top->code;
|
||||
*pc = top->pc;
|
||||
*limit = top->code->end - top->code->start;
|
||||
decoder->Reset(top->code->start, top->code->end);
|
||||
*len = 0; // The {pc} has already been set correctly.
|
||||
}
|
||||
|
||||
int LookupTargetDelta(InterpreterCode* code, pc_t pc) {
|
||||
@ -2377,13 +2376,12 @@ class ThreadImpl {
|
||||
|
||||
#ifdef DEBUG
|
||||
// Compute the stack effect of this opcode, and verify later that the
|
||||
// stack was modified accordingly (unless an exception was thrown).
|
||||
// stack was modified accordingly.
|
||||
std::pair<uint32_t, uint32_t> stack_effect =
|
||||
StackEffect(codemap_->module(), frames_.back().code->function->sig,
|
||||
code->orig_start + pc, code->orig_end);
|
||||
sp_t expected_new_stack_height =
|
||||
StackHeight() - stack_effect.first + stack_effect.second;
|
||||
bool exception_was_thrown = false;
|
||||
#endif
|
||||
|
||||
switch (orig) {
|
||||
@ -2424,15 +2422,15 @@ class ThreadImpl {
|
||||
CommitPc(pc); // Needed for local unwinding.
|
||||
const WasmException* exception = &module()->exceptions[imm.index];
|
||||
if (!DoThrowException(exception, imm.index)) return;
|
||||
ReloadFromFrameOnException(&decoder, &code, &pc, &limit, &len);
|
||||
break;
|
||||
ReloadFromFrameOnException(&decoder, &code, &pc, &limit);
|
||||
continue; // Do not bump pc.
|
||||
}
|
||||
case kExprRethrow: {
|
||||
WasmValue ex = Pop();
|
||||
CommitPc(pc); // Needed for local unwinding.
|
||||
if (!DoRethrowException(&ex)) return;
|
||||
ReloadFromFrameOnException(&decoder, &code, &pc, &limit, &len);
|
||||
break;
|
||||
ReloadFromFrameOnException(&decoder, &code, &pc, &limit);
|
||||
continue; // Do not bump pc.
|
||||
}
|
||||
case kExprSelect: {
|
||||
WasmValue cond = Pop();
|
||||
@ -2481,7 +2479,7 @@ class ThreadImpl {
|
||||
size_t arity = code->function->sig->return_count();
|
||||
if (!DoReturn(&decoder, &code, &pc, &limit, arity)) return;
|
||||
PAUSE_IF_BREAK_FLAG(AfterReturn);
|
||||
continue;
|
||||
continue; // Do not bump pc.
|
||||
}
|
||||
case kExprUnreachable: {
|
||||
return DoTrap(kTrapUnreachable, pc);
|
||||
@ -2563,9 +2561,8 @@ class ThreadImpl {
|
||||
case ExternalCallResult::EXTERNAL_UNWOUND:
|
||||
return;
|
||||
case ExternalCallResult::EXTERNAL_CAUGHT:
|
||||
ReloadFromFrameOnException(&decoder, &code, &pc, &limit, &len);
|
||||
DCHECK(exception_was_thrown = true);
|
||||
break;
|
||||
ReloadFromFrameOnException(&decoder, &code, &pc, &limit);
|
||||
continue; // Do not bump pc.
|
||||
}
|
||||
if (result.type != ExternalCallResult::INTERNAL) break;
|
||||
}
|
||||
@ -2573,7 +2570,7 @@ class ThreadImpl {
|
||||
if (!DoCall(&decoder, target, &pc, &limit)) return;
|
||||
code = target;
|
||||
PAUSE_IF_BREAK_FLAG(AfterCall);
|
||||
continue; // don't bump pc
|
||||
continue; // Do not bump pc.
|
||||
} break;
|
||||
case kExprCallIndirect: {
|
||||
CallIndirectImmediate<Decoder::kNoValidate> imm(&decoder,
|
||||
@ -2591,7 +2588,7 @@ class ThreadImpl {
|
||||
return;
|
||||
code = result.interpreter_code;
|
||||
PAUSE_IF_BREAK_FLAG(AfterCall);
|
||||
continue; // don't bump pc
|
||||
continue; // Do not bump pc.
|
||||
case ExternalCallResult::INVALID_FUNC:
|
||||
return DoTrap(kTrapFuncInvalid, pc);
|
||||
case ExternalCallResult::SIGNATURE_MISMATCH:
|
||||
@ -2603,9 +2600,8 @@ class ThreadImpl {
|
||||
case ExternalCallResult::EXTERNAL_UNWOUND:
|
||||
return;
|
||||
case ExternalCallResult::EXTERNAL_CAUGHT:
|
||||
ReloadFromFrameOnException(&decoder, &code, &pc, &limit, &len);
|
||||
DCHECK(exception_was_thrown = true);
|
||||
break;
|
||||
ReloadFromFrameOnException(&decoder, &code, &pc, &limit);
|
||||
continue; // Do not bump pc.
|
||||
}
|
||||
} break;
|
||||
case kExprGetGlobal: {
|
||||
@ -2853,7 +2849,7 @@ class ThreadImpl {
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
if (!WasmOpcodes::IsControlOpcode(opcode) && !exception_was_thrown) {
|
||||
if (!WasmOpcodes::IsControlOpcode(opcode)) {
|
||||
DCHECK_EQ(expected_new_stack_height, StackHeight());
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user