]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.15] gh-154014: Initialize cold executor vm_data fields (GH-154142) (GH-154457)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 22 Jul 2026 09:49:29 +0000 (11:49 +0200)
committerGitHub <noreply@github.com>
Wed, 22 Jul 2026 09:49:29 +0000 (09:49 +0000)
gh-154014: Initialize cold executor vm_data fields (GH-154142)
(cherry picked from commit d1174a48ea8fda8bd0057f10e9776ec148276100)

Co-authored-by: Bhuvansh <bhuvanshkataria@gmail.com>
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 9f0427172b5048e3bd99b6149ff1c8cc16fd16c3..b2439dfdeb7a221a5f54725856e0e3be87baae0a 100644 (file)
@@ -5102,6 +5102,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 db258fff22cdd13aff52e4767a29cf2e9a0d70ba..a39d0494ddc5d5b2239a47aab8a481004e1f57f2 100644 (file)
@@ -1830,6 +1830,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;
@@ -1837,7 +1842,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