8000 Export tier 2 threshold from _testinternalcapi · python/cpython@72f6b0d · GitHub
[go: up one dir, main page]

Skip to content

Commit 72f6b0d

Browse files
committed
Export tier 2 threshold from _testinternalcapi
1 parent df6f34c commit 72f6b0d

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from test.support import script_helper, requires_specialization
1212

13+
from _testinternalcapi import TIER2_THRESHOLD
1314

1415
@contextlib.contextmanager
1516
def temporary_optimizer(opt):
@@ -69,8 +70,8 @@ def loop():
6970
self.assertEqual(opt.get_count(), 0)
7071
with clear_executors(loop):
7172
loop()
72-
# Subtract 16 because optimizer doesn't kick in until 16
73-
self.assertEqual(opt.get_count(), 1000 - 16)
73+
# Subtract because optimizer doesn't kick in sooner
74+
self.assertEqual(opt.get_count(), 1000 - TIER2_THRESHOLD)
7475

7576
def test_long_loop(self):
7677
"Check that we aren't confused by EXTENDED_ARG"
@@ -97,7 +98,7 @@ def long_loop():
9798
with temporary_optimizer(opt):
9899
self.assertEqual(opt.get_count(), 0)
99100
long_loop()
100-
self.assertEqual(opt.get_count(), 20 - 16) # Need 16 iterations to warm up
101+
self.assertEqual(opt.get_count(), 20 - TIER2_THRESHOLD) # Need iterations to warm up
101102

102103
def test_code_restore_for_ENTER_EXECUTOR(self):
103104
def testfunc(x):
@@ -933,10 +934,10 @@ def testfunc(n):
933934
exec(src, ns, ns)
934935
testfunc = ns['testfunc']
935936
ns['_test_global'] = 0
936-
_, ex = self._run_with_optimizer(testfunc, 16)
937+
_, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
937938
self.assertIsNone(ex)
938939
ns['_test_global'] = 1
939-
_, ex = self._run_with_optimizer(testfunc, 16)
940+
_, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
940941
self.assertIsNotNone(ex)
941942
uops = get_opnames(ex)
942943
self.assertNotIn("_GUARD_BOTH_INT", uops)
@@ -947,10 +948,10 @@ def testfunc(n):
947948
exec(src, ns, ns)
948949
testfunc = ns['testfunc']
949950
ns['_test_global'] = 0
950-
_, ex = self._run_with_optimizer(testfunc, 16)
951+
_, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
951952
self.assertIsNone(ex)
952953
ns['_test_global'] = 3.14
953-
_, ex = self._run_with_optimizer(testfunc, 16)
954+
_, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
954955
self.assertIsNone(ex)
955956

956957
def test_many_nested(self):

Modules/_testinternalcapi.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#undef NDEBUG
1111

1212
#include "Python.h"
13+
#include "pycore_backoff.h" // JUMP_BACKWARD_INITIAL_VALUE
1314
#include "pycore_bitutils.h" // _Py_bswap32()
1415
#include "pycore_bytesobject.h" // _PyBytes_Find()
1516
#include "pycore_ceval.h" // _PyEval_AddPendingCall()
@@ -1918,6 +1919,11 @@ module_exec(PyObject *module)
19181919
return 1;
19191920
}
19201921

1922+
if (PyModule_Add(module, "TIER2_THRESHOLD",
1923+
PyLong_FromLong(JUMP_BACKWARD_INITIAL_VALUE)) < 0) {
1924+
return 1;
1925+
}
1926+
19211927
return 0;
19221928
}
19231929

0 commit comments

Comments
 (0)
0