Skip to content

Commit 4a0a530

Browse files
Partially address review
1 parent af09d44 commit 4a0a530

File tree

7 files changed

+23
-33
lines changed

7 files changed

+23
-33
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,9 @@ def get_all_executors(func):
4444
code = func.__code__
4545
co_code = code.co_code
4646
executors = []
47-
seen = set()
4847
for i in range(0, len(co_code), 2):
4948
try:
50-
exec = _opcode.get_executor(code, i)
51-
if id(exec) in seen:
52-
continue
53-
executors.append(exec)
54-
seen.add(id(exec))
55-
# Add the side exit executors as well.
56-
ops = get_ops(exec)
57-
for idx, op in enumerate(ops):
58-
opname = op[0]
59-
if opname == "_EXIT_TRACE":
60-
exit = op[3]
61-
link_to = _testinternalcapi.get_exit_executor(exit)
62-
if id(link_to) in seen:
63-
continue
64-
executors.append(link_to)
65-
seen.add(id(link_to))
49+
executors.append(_opcode.get_executor(code, i))
6650
except ValueError:
6751
pass
6852
return executors
@@ -345,10 +329,16 @@ def testfunc(x):
345329
return testfunc(x-1)
346330

347331
sys.setrecursionlimit(TIER2_RESUME_THRESHOLD * 2)
348-
testfunc(TIER2_RESUME_THRESHOLD)
332+
for _ in range((TIER2_RESUME_THRESHOLD + 99)//100):
333+
testfunc(101)
349334

350335
ex = get_first_executor(testfunc)
351336
self.assertIsNotNone(ex)
337+
uops = get_opnames(ex)
338+
# 0. _START_EXECUTOR
339+
# 1. _MAKE_WARM
340+
# 2. _TIER2_RESUME_CHECK
341+
self.assertEqual(uops[2], "_TIER2_RESUME_CHECK")
352342

353343
def test_jump_forward(self):
354344
def testfunc(n):
@@ -1447,7 +1437,7 @@ def test_guard_type_version_removed_invalidation(self):
14471437

14481438
def thing(a):
14491439
x = 0
1450-
for i in range(TIER2_THRESHOLD * 2 + 1):
1440+
for i in range(TIER2_THRESHOLD + 1):
14511441
x += a.attr
14521442
# The first TIER2_THRESHOLD iterations we set the attribute on
14531443
# this dummy class, which shouldn't trigger the type watcher.
@@ -1464,14 +1454,13 @@ class Bar:
14641454
pass
14651455

14661456
res, ex = self._run_with_optimizer(thing, Foo())
1467-
if ex is not None:
1468-
opnames = list(iter_opnames(ex))
1469-
self.assertEqual(res, TIER2_THRESHOLD * 6 + 1)
1470-
call = opnames.index("_CALL_BUILTIN_FAST")
1471-
load_attr_top = opnames.index("_POP_TOP_LOAD_CONST_INLINE_BORROW", 0, call)
1472-
load_attr_bottom = opnames.index("_POP_TOP_LOAD_CONST_INLINE_BORROW", call)
1473-
self.assertEqual(opnames[:load_attr_top].count("_GUARD_TYPE_VERSION"), 1)
1474-
self.assertEqual(opnames[call:load_attr_bottom].count("_CHECK_VALIDITY"), 2)
1457+
opnames = list(iter_opnames(ex))
1458+
self.assertEqual(res, TIER2_THRESHOLD * 2 + 2)
1459+
call = opnames.index("_CALL_BUILTIN_FAST")
1460+
load_attr_top = opnames.index("_POP_TOP_LOAD_CONST_INLINE_BORROW", 0, call)
1461+
load_attr_bottom = opnames.index("_POP_TOP_LOAD_CONST_INLINE_BORROW", call)
1462+
self.assertEqual(opnames[:load_attr_top].count("_GUARD_TYPE_VERSION"), 1)
1463+
self.assertEqual(opnames[call:load_attr_bottom].count("_CHECK_VALIDITY"), 2)
14751464

14761465
def test_guard_type_version_removed_escaping(self):
14771466

Lib/test/test_compile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2458,7 +2458,7 @@ def test_lambda_return_position(self):
24582458
for i, pos in enumerate(positions):
24592459
with self.subTest(i=i, pos=pos):
24602460
start_line, end_line, start_col, end_col = pos
2461-
if i == 0 or i == 1:
2461+
if i <= 1:
24622462
# ignore the RESUME and CACHE in the beginning
24632463
continue
24642464
self.assertEqual(start_line, 1)

Modules/_testinternalcapi.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3023,9 +3023,10 @@ module_exec(PyObject *module)
30233023
return 1;
30243024
}
30253025

3026+
// + 1 to specialize from RESUME to RESUME_CHECK_JIT
3027+
// + 1 more due to one loop spent on tracing.
30263028
long resume_threshold = interp->opt_config.resume_initial_value + 2;
30273029
if (PyModule_Add(module, "TIER2_RESUME_THRESHOLD",
3028-
// + 1 more due to one loop spent on tracing.
30293030
PyLong_FromLong(resume_threshold)) < 0) {
30303031
return 1;
30313032
}

Modules/_testinternalcapi/test_cases.c.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/bytecodes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3212,7 +3212,7 @@ dummy_func(
32123212
if (_PyOpcode_Caches[_PyOpcode_Deopt[opcode]]) {
32133213
PAUSE_ADAPTIVE_COUNTER(this_instr[1].counter);
32143214
}
3215-
DISPATCH_GOTO_NON_TRACING();
3215+
DISPATCH_GOTO();
32163216
}
32173217
assert(executor != tstate->interp->cold_executor);
32183218
tstate->jit_exit = NULL;

Python/ceval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ _PyObjectArray_Free(PyObject **array, PyObject **scratch)
11381138

11391139
#if _Py_TIER2
11401140
// 0 for success, -1 for error.
1141-
static Py_NO_INLINE int
1141+
static int
11421142
stop_tracing_and_jit(PyThreadState *tstate, _PyInterpreterFrame *frame)
11431143
{
11441144
int _is_sys_tracing = (tstate->c_tracefunc != NULL) || (tstate->c_profilefunc != NULL);

Python/generated_cases.c.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)