Skip to content

Commit 027e19b

Browse files
authored
Improve jiterpreter heuristic branch handling (#80275)
* Improve jiterpreter heuristic and bailout conditions * Handle backwards branches in the jiterpreter heuristic
1 parent 9f515ff commit 027e19b

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/mono/mono/mini/interp/jiterpreter.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -687,14 +687,21 @@ jiterp_should_abort_trace (InterpInst *ins, gboolean *inside_branch_block)
687687

688688
case MINT_BR:
689689
case MINT_BR_S:
690-
if (*inside_branch_block)
691-
return TRACE_CONTINUE;
690+
case MINT_LEAVE:
691+
case MINT_LEAVE_S:
692+
// Detect backwards branches
693+
if (ins->info.target_bb->il_offset <= ins->il_offset) {
694+
if (*inside_branch_block)
695+
return TRACE_CONTINUE;
696+
else
697+
return TRACE_ABORT;
698+
}
692699

693-
return TRACE_ABORT;
700+
*inside_branch_block = TRUE;
701+
return TRACE_CONTINUE;
694702

703+
case MINT_MONO_RETHROW:
695704
case MINT_THROW:
696-
case MINT_LEAVE:
697-
case MINT_LEAVE_S:
698705
if (*inside_branch_block)
699706
return TRACE_CONTINUE;
700707

@@ -708,7 +715,6 @@ jiterp_should_abort_trace (InterpInst *ins, gboolean *inside_branch_block)
708715
case MINT_CALL_HANDLER_S:
709716
case MINT_ENDFINALLY:
710717
case MINT_RETHROW:
711-
case MINT_MONO_RETHROW:
712718
case MINT_PROF_EXIT:
713719
case MINT_PROF_EXIT_VOID:
714720
case MINT_SAFEPOINT:

src/mono/wasm/runtime/jiterpreter.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,9 @@ function generate_wasm_body (
11751175
}
11761176
break;
11771177

1178+
// Unlike regular rethrow which will only appear in catch blocks,
1179+
// MONO_RETHROW appears to show up in other places, so it's worth conditional bailout
1180+
case MintOpcode.MINT_MONO_RETHROW:
11781181
case MintOpcode.MINT_THROW:
11791182
// As above, only abort if this throw happens unconditionally.
11801183
// Otherwise, it may be in a branch that is unlikely to execute

0 commit comments

Comments
 (0)