Skip to content

Commit 31a5157

Browse files
committed
gh-137838: Fix JIT trace buffer overrun by increasing possible exit stubs
1 parent ffaec6e commit 31a5157

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

Lib/test/test_sys_settrace.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ class TraceTestCase(unittest.TestCase):
360360
# Disable gc collection when tracing, otherwise the
361361
# deallocators may be traced as well.
362362
def setUp(self):
363+
if os.environ.get('PYTHON_UOPS_OPTIMIZE') == '0':
364+
self.skipTest("Line tracing behavior differs when JIT optimizer is disabled")
363365
self.using_gc = gc.isenabled()
364366
gc.disable()
365367
self.addCleanup(sys.settrace, sys.gettrace())

Lib/test/test_trace.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ def test_traced_func_linear(self):
142142

143143
self.assertEqual(self.tracer.results().counts, expected)
144144

145+
@unittest.skipIf(os.environ.get('PYTHON_UOPS_OPTIMIZE') == '0',
146+
"Line counts differ when JIT optimizer is disabled")
145147
def test_traced_func_loop(self):
146148
self.tracer.runfunc(traced_func_loop, 2, 3)
147149

@@ -166,6 +168,8 @@ def test_traced_func_importing(self):
166168

167169
self.assertEqual(self.tracer.results().counts, expected)
168170

171+
@unittest.skipIf(os.environ.get('PYTHON_UOPS_OPTIMIZE') == '0',
172+
"Line counts differ when JIT optimizer is disabled")
169173
def test_trace_func_generator(self):
170174
self.tracer.runfunc(traced_func_calling_generator)
171175

@@ -236,6 +240,8 @@ def setUp(self):
236240
self.my_py_filename = fix_ext_py(__file__)
237241
self.addCleanup(sys.settrace, sys.gettrace())
238242

243+
@unittest.skipIf(os.environ.get('PYTHON_UOPS_OPTIMIZE') == '0',
244+
"Line counts differ when JIT optimizer is disabled")
239245
def test_exec_counts(self):
240246
self.tracer = Trace(count=1, trace=0, countfuncs=0, countcallers=0)
241247
code = r'''traced_func_loop(2, 5)'''
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix JIT trace buffer overrun by pre-reserving exit stub space. Patch By
2+
Donghee Na.

Python/optimizer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,8 @@ translate_bytecode_to_trace(
591591

592592
for (;;) {
593593
target = INSTR_IP(instr, code);
594-
// Need space for _DEOPT
595-
max_length--;
594+
// Every instruction might need _DEOPT, and _DEOPT might have _ERROR_POP_N before it
595+
max_length -= 2;
596596

597597
uint32_t opcode = instr->op.code;
598598
uint32_t oparg = instr->op.arg;

0 commit comments

Comments
 (0)