Skip to content

Commit d1174a4

Browse files
authored
gh-154014: Initialize cold executor vm_data fields (GH-154142)
1 parent 1bf86c1 commit d1174a4

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

Lib/test/test_capi/test_opt.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5127,6 +5127,16 @@ def f():
51275127
f" {executor} at offset {idx} rather"
51285128
f" than expected _EXIT_TRACE")
51295129

5130+
def test_jit_shutdown_after_cold_executor_creation(self):
5131+
script_helper.assert_python_ok("-c", textwrap.dedent(f"""
5132+
def f():
5133+
for x in range({TIER2_THRESHOLD + 3}):
5134+
for y in range({TIER2_THRESHOLD + 3}):
5135+
z = x + y
5136+
5137+
f()
5138+
"""), PYTHON_JIT="1")
5139+
51305140
def test_enter_executor_valid_op_arg(self):
51315141
script_helper.assert_python_ok("-c", textwrap.dedent("""
51325142
import sys
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a JIT assertion during interpreter shutdown by initializing ``vm_data``
2+
fields for cold executors that bypass ``_Py_ExecutorInit()``.

Python/optimizer.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1797,14 +1797,19 @@ make_cold_executor(uint16_t opcode)
17971797
Py_FatalError("Cannot allocate core JIT code");
17981798
}
17991799
((_PyUOpInstruction *)cold->trace)->opcode = opcode;
1800+
// Cold executors bypass _Py_ExecutorInit().
1801+
cold->vm_data.valid = true;
1802+
cold->vm_data.pending_deletion = 0;
1803+
cold->vm_data.code = NULL;
1804+
18001805
// This is initialized to false so we can prevent the executor
18011806
// from being immediately detected as cold and invalidated.
18021807
cold->vm_data.cold = false;
18031808
#ifdef _Py_JIT
18041809
cold->jit_code = NULL;
18051810
cold->jit_size = 0;
18061811
if (_PyJIT_Compile(cold, cold->trace, 1)) {
1807-
Py_DECREF(cold);
1812+
_PyExecutor_Free(cold);
18081813
Py_FatalError("Cannot allocate core JIT code");
18091814
}
18101815
#endif

0 commit comments

Comments
 (0)