Skip to content

Commit 3066963

Browse files
Fix handling of ENTER_EXECUTOR
1 parent f886c43 commit 3066963

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

Python/bytecodes.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3044,7 +3044,11 @@ dummy_func(
30443044
}
30453045
assert(executor != tstate->interp->cold_executor);
30463046
tstate->jit_exit = NULL;
3047-
TIER1_TO_TIER2(executor);
3047+
if (IS_JIT_TRACING()) {
3048+
RECORD_TRACE();
3049+
BAIL_TRACING_NO_DISPATCH();
3050+
}
3051+
TIER1_TO_TIER2(executor, 1);
30483052
#else
30493053
Py_FatalError("ENTER_EXECUTOR is not supported in this build");
30503054
#endif /* _Py_TIER2 */

Python/ceval_macros.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,15 @@
134134
# define IS_JIT_TRACING() (DISPATCH_TABLE_VAR == TRACING_DISPATCH_TABLE)
135135
# define ENTER_TRACING() DISPATCH_TABLE_VAR = TRACING_DISPATCH_TABLE;
136136
# define LEAVE_TRACING() DISPATCH_TABLE_VAR = DISPATCH_TABLE;
137-
# define BAIL_TRACING() \
137+
# define BAIL_TRACING_NO_DISPATCH() \
138138
LEAVE_TRACING(); \
139139
int err = _PyOptimizer_Optimize(frame, tstate); \
140140
tstate->interp->jit_tracer_code_curr_size = 0; \
141141
if (err < 0) { \
142142
JUMP_TO_LABEL(error); \
143-
} \
143+
}
144+
# define BAIL_TRACING() \
145+
BAIL_TRACING_NO_DISPATCH() \
144146
DISPATCH();
145147
# define RECORD_TRACE() do { \
146148
frame->instr_ptr = next_instr; \
@@ -395,7 +397,7 @@ _PyFrame_SetStackPointer(frame, stack_pointer)
395397

396398
/* Tier-switching macros. */
397399

398-
#define TIER1_TO_TIER2(EXECUTOR) \
400+
#define TIER1_TO_TIER2(EXECUTOR, IN_ENTER_EXECUTOR) \
399401
do { \
400402
OPT_STAT_INC(traces_executed); \
401403
next_instr = _Py_jit_entry((EXECUTOR), frame, stack_pointer, tstate); \
@@ -407,7 +409,7 @@ do { \
407409
next_instr = frame->instr_ptr; \
408410
JUMP_TO_LABEL(error); \
409411
} \
410-
if (keep_tracing_bit) { \
412+
if (!IN_ENTER_EXECUTOR && keep_tracing_bit) { \
411413
ENTER_TRACING(); \
412414
_PyJIT_InitializeTracing(tstate, frame, next_instr, STACK_LEVEL(), 0); \
413415
} \

Python/generated_cases.c.h

Lines changed: 10 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/optimizer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,6 @@ _PyJIT_translate_single_bytecode_to_trace(
585585
if (opcode == EXTENDED_ARG) {
586586
return 1;
587587
}
588-
assert(opcode != ENTER_EXECUTOR && opcode != EXTENDED_ARG);
589588
if (opcode == NOP) {
590589
return 1;
591590
}
@@ -594,6 +593,8 @@ _PyJIT_translate_single_bytecode_to_trace(
594593
goto full;
595594
}
596595

596+
assert(opcode != ENTER_EXECUTOR && opcode != EXTENDED_ARG);
597+
597598
bool needs_guard_ip = _PyOpcode_NeedsGuardIp[opcode] &&
598599
!(opcode == FOR_ITER_RANGE || opcode == FOR_ITER_LIST || opcode == FOR_ITER_TUPLE) &&
599600
!(opcode == JUMP_BACKWARD_NO_INTERRUPT || opcode == JUMP_BACKWARD || opcode == JUMP_BACKWARD_JIT) &&

0 commit comments

Comments
 (0)