Skip to content

Commit

Permalink
[wasm] Implement LEAVE_CHECK in the jiterpreter (as a bailout) (dotne…
Browse files Browse the repository at this point in the history
…t#84387)

LEAVE_CHECK is a variant of LEAVE that only appears inside catch clauses, and catch clauses will not be running during normal optimized execution. So it's reasonable for the jiterpreter to compile them into bailouts, which will allow trace compilation to continue past the catch clause.
  • Loading branch information
kg authored Apr 6, 2023
1 parent 2c8cb12 commit 8f7d818
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/mono/mono/mini/interp/jiterpreter.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,12 @@ jiterp_should_abort_trace (InterpInst *ins, gboolean *inside_branch_block)
case MINT_SDB_SEQ_POINT:
return TRACE_IGNORE;

case MINT_LEAVE_CHECK:
case MINT_LEAVE_S_CHECK:
// These are only generated inside catch clauses, so it's safe to assume that
// during normal execution they won't run, and compile them as a bailout.
return TRACE_IGNORE;

case MINT_INITLOCAL:
case MINT_INITLOCALS:
case MINT_LOCALLOC:
Expand Down Expand Up @@ -748,10 +754,6 @@ jiterp_should_abort_trace (InterpInst *ins, gboolean *inside_branch_block)

return TRACE_ABORT;

case MINT_LEAVE_CHECK:
case MINT_LEAVE_S_CHECK:
return TRACE_ABORT;

case MINT_RETHROW:
case MINT_PROF_EXIT:
case MINT_PROF_EXIT_VOID:
Expand Down
2 changes: 2 additions & 0 deletions src/mono/wasm/runtime/jiterpreter-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const enum BailoutReason {
Debugging,
Icall,
UnexpectedRetIp,
LeaveCheck,
}

export const BailoutReasonNames = [
Expand Down Expand Up @@ -80,6 +81,7 @@ export const BailoutReasonNames = [
"Debugging",
"Icall",
"UnexpectedRetIp",
"LeaveCheck",
];

type FunctionType = [
Expand Down
8 changes: 8 additions & 0 deletions src/mono/wasm/runtime/jiterpreter-trace-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,14 @@ export function generateWasmBody (
isLowValueOpcode = true;
break;

// These are generated in place of regular LEAVEs inside of the body of a catch clause.
// We can safely assume that during normal execution, catch clauses won't be running.
case MintOpcode.MINT_LEAVE_CHECK:
case MintOpcode.MINT_LEAVE_S_CHECK:
append_bailout(builder, ip, BailoutReason.LeaveCheck);
isLowValueOpcode = true;
break;

case MintOpcode.MINT_ENDFINALLY: {
if (
(builder.callHandlerReturnAddresses.length > 0) &&
Expand Down

0 comments on commit 8f7d818

Please sign in to comment.