Skip to content

Commit e8206b6

Browse files
[3.15] gh-154014: Initialize cold executor vm_data fields (GH-154142) (GH-154457)
gh-154014: Initialize cold executor vm_data fields (GH-154142) (cherry picked from commit d1174a4) Co-authored-by: Bhuvansh <bhuvanshkataria@gmail.com>
1 parent 314e753 commit e8206b6

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
@@ -5102,6 +5102,16 @@ def f():
51025102
f" {executor} at offset {idx} rather"
51035103
f" than expected _EXIT_TRACE")
51045104

5105+
def test_jit_shutdown_after_cold_executor_creation(self):
5106+
script_helper.assert_python_ok("-c", textwrap.dedent(f"""
5107+
def f():
5108+
for x in range({TIER2_THRESHOLD + 3}):
5109+
for y in range({TIER2_THRESHOLD + 3}):
5110+
z = x + y
5111+
5112+
f()
5113+
"""), PYTHON_JIT="1")
5114+
51055115
def test_enter_executor_valid_op_arg(self):
51065116
script_helper.assert_python_ok("-c", textwrap.dedent("""
51075117
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
@@ -1830,14 +1830,19 @@ make_cold_executor(uint16_t opcode)
18301830
Py_FatalError("Cannot allocate core JIT code");
18311831
}
18321832
((_PyUOpInstruction *)cold->trace)->opcode = opcode;
1833+
// Cold executors bypass _Py_ExecutorInit().
1834+
cold->vm_data.valid = true;
1835+
cold->vm_data.pending_deletion = 0;
1836+
cold->vm_data.code = NULL;
1837+
18331838
// This is initialized to false so we can prevent the executor
18341839
// from being immediately detected as cold and invalidated.
18351840
cold->vm_data.cold = false;
18361841
#ifdef _Py_JIT
18371842
cold->jit_code = NULL;
18381843
cold->jit_size = 0;
18391844
if (_PyJIT_Compile(cold, cold->trace, 1)) {
1840-
Py_DECREF(cold);
1845+
_PyExecutor_Free(cold);
18411846
Py_FatalError("Cannot allocate core JIT code");
18421847
}
18431848
#endif

0 commit comments

Comments
 (0)