]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-154014: Initialize cold executor vm_data fields (GH-154142)
authorBhuvansh <bhuvanshkataria@gmail.com>
Wed, 22 Jul 2026 09:17:47 +0000 (14:47 +0530)
committerGitHub <noreply@github.com>
Wed, 22 Jul 2026 09:17:47 +0000 (10:17 +0100)
Lib/test/test_capi/test_opt.py
Misc/NEWS.d/next/Core_and_Builtins/2026-07-19-16-18-25.gh-issue-154014.CJsjVL.rst [new file with mode: 0644]
Python/optimizer.c

index 25b2c393e6773de499b69947787ca61daae9bf3f..5806216d46e7eb6eb5c5c2c53de60487ee2b3d5c 100644 (file)
@@ -5127,6 +5127,16 @@ class TestUopsOptimization(unittest.TestCase):
                               f" {executor} at offset {idx} rather"
                               f" than expected _EXIT_TRACE")
 
+    def test_jit_shutdown_after_cold_executor_creation(self):
+        script_helper.assert_python_ok("-c", textwrap.dedent(f"""
+            def f():
+                for x in range({TIER2_THRESHOLD + 3}):
+                    for y in range({TIER2_THRESHOLD + 3}):
+                        z = x + y
+
+            f()
+        """), PYTHON_JIT="1")
+
     def test_enter_executor_valid_op_arg(self):
         script_helper.assert_python_ok("-c", textwrap.dedent("""
             import sys
diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-07-19-16-18-25.gh-issue-154014.CJsjVL.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-07-19-16-18-25.gh-issue-154014.CJsjVL.rst
new file mode 100644 (file)
index 0000000..6bdcf83
--- /dev/null
@@ -0,0 +1,2 @@
+Fix a JIT assertion during interpreter shutdown by initializing ``vm_data``
+fields for cold executors that bypass ``_Py_ExecutorInit()``.
index c9f6ebdb62f07b203218dbf9bd062a37128fa22b..e05adb344c8d06df81f2788ac5657923d6b9fda0 100644 (file)
@@ -1797,6 +1797,11 @@ make_cold_executor(uint16_t opcode)
         Py_FatalError("Cannot allocate core JIT code");
     }
     ((_PyUOpInstruction *)cold->trace)->opcode = opcode;
+    // Cold executors bypass _Py_ExecutorInit().
+    cold->vm_data.valid = true;
+    cold->vm_data.pending_deletion = 0;
+    cold->vm_data.code = NULL;
+
     // This is initialized to false so we can prevent the executor
     // from being immediately detected as cold and invalidated.
     cold->vm_data.cold = false;
@@ -1804,7 +1809,7 @@ make_cold_executor(uint16_t opcode)
     cold->jit_code = NULL;
     cold->jit_size = 0;
     if (_PyJIT_Compile(cold, cold->trace, 1)) {
-        Py_DECREF(cold);
+        _PyExecutor_Free(cold);
         Py_FatalError("Cannot allocate core JIT code");
     }
 #endif