]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix handling of ENTER_EXECUTOR
authorKen Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Sat, 20 Sep 2025 22:55:09 +0000 (23:55 +0100)
committerKen Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Sat, 20 Sep 2025 22:55:09 +0000 (23:55 +0100)
Python/bytecodes.c
Python/ceval_macros.h
Python/generated_cases.c.h
Python/optimizer.c

index 166383e4af6b82ffba8323d259a4ea381f1353b3..a377bb5a385f2b2c60a206bfd21a8cbc69a65907 100644 (file)
@@ -3044,7 +3044,11 @@ dummy_func(
             }
             assert(executor != tstate->interp->cold_executor);
             tstate->jit_exit = NULL;
-            TIER1_TO_TIER2(executor);
+            if (IS_JIT_TRACING()) {
+                RECORD_TRACE();
+                BAIL_TRACING_NO_DISPATCH();
+            }
+            TIER1_TO_TIER2(executor, 1);
             #else
             Py_FatalError("ENTER_EXECUTOR is not supported in this build");
             #endif /* _Py_TIER2 */
index 32815ad8c1a58f11abd87b3431b841a512229fff..47da165924536fe355b016aaf91a9fee00bd130d 100644 (file)
 #  define IS_JIT_TRACING() (DISPATCH_TABLE_VAR == TRACING_DISPATCH_TABLE)
 #  define ENTER_TRACING() DISPATCH_TABLE_VAR = TRACING_DISPATCH_TABLE;
 #  define LEAVE_TRACING() DISPATCH_TABLE_VAR = DISPATCH_TABLE;
-#  define BAIL_TRACING() \
+#  define BAIL_TRACING_NO_DISPATCH() \
     LEAVE_TRACING(); \
     int err = _PyOptimizer_Optimize(frame, tstate); \
     tstate->interp->jit_tracer_code_curr_size = 0; \
     if (err < 0) { \
         JUMP_TO_LABEL(error); \
-    } \
+    }
+#  define BAIL_TRACING() \
+    BAIL_TRACING_NO_DISPATCH() \
     DISPATCH();
 #  define RECORD_TRACE() do { \
         frame->instr_ptr = next_instr; \
@@ -395,7 +397,7 @@ _PyFrame_SetStackPointer(frame, stack_pointer)
 
 /* Tier-switching macros. */
 
-#define TIER1_TO_TIER2(EXECUTOR)                        \
+#define TIER1_TO_TIER2(EXECUTOR, IN_ENTER_EXECUTOR)                        \
 do {                                                   \
     OPT_STAT_INC(traces_executed);                     \
     next_instr = _Py_jit_entry((EXECUTOR), frame, stack_pointer, tstate); \
@@ -407,7 +409,7 @@ do {                                                   \
         next_instr = frame->instr_ptr;                 \
         JUMP_TO_LABEL(error);                          \
     }                                                  \
-    if (keep_tracing_bit) { \
+    if (!IN_ENTER_EXECUTOR && keep_tracing_bit) { \
         ENTER_TRACING(); \
         _PyJIT_InitializeTracing(tstate, frame, next_instr, STACK_LEVEL(), 0); \
     } \
index b612a51bc056df5646711dc3b2ccba001a10219f..4183e23cdf1802b743684b5c0293c9f8f85ea0c0 100644 (file)
             }
             assert(executor != tstate->interp->cold_executor);
             tstate->jit_exit = NULL;
-            TIER1_TO_TIER2(executor);
+            if (IS_JIT_TRACING()) {
+                RECORD_TRACE();
+                BAIL_TRACING_NO_DISPATCH();
+            }
+            TIER1_TO_TIER2(executor, 1);
             #else
             Py_FatalError("ENTER_EXECUTOR is not supported in this build");
             #endif /* _Py_TIER2 */
             }
             assert(executor != tstate->interp->cold_executor);
             tstate->jit_exit = NULL;
-            TIER1_TO_TIER2(executor);
+            if (IS_JIT_TRACING()) {
+                RECORD_TRACE();
+                BAIL_TRACING_NO_DISPATCH();
+            }
+            TIER1_TO_TIER2(executor, 1);
             #else
             Py_FatalError("ENTER_EXECUTOR is not supported in this build");
             #endif /* _Py_TIER2 */
index f0b207f721cde64c2be76f14a223f52e9cc033dc..b973fdd7ac4159deb7c215779873b31f7d3321f6 100644 (file)
@@ -585,7 +585,6 @@ _PyJIT_translate_single_bytecode_to_trace(
     if (opcode == EXTENDED_ARG) {
         return 1;
     }
-    assert(opcode != ENTER_EXECUTOR && opcode != EXTENDED_ARG);
     if (opcode == NOP) {
         return 1;
     }
@@ -594,6 +593,8 @@ _PyJIT_translate_single_bytecode_to_trace(
         goto full;
     }
 
+    assert(opcode != ENTER_EXECUTOR && opcode != EXTENDED_ARG);
+
     bool needs_guard_ip = _PyOpcode_NeedsGuardIp[opcode] &&
         !(opcode == FOR_ITER_RANGE || opcode == FOR_ITER_LIST || opcode == FOR_ITER_TUPLE) &&
         !(opcode == JUMP_BACKWARD_NO_INTERRUPT || opcode == JUMP_BACKWARD || opcode == JUMP_BACKWARD_JIT) &&