summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_capi
diff options
context:
space:
mode:
authormpage <mpage@cs.stanford.edu>2024-11-04 19:13:32 (GMT)
committerGitHub <noreply@github.com>2024-11-04 19:13:32 (GMT)
commit2e95c5ba3bf7e5004c7e2304afda4a8f8e2443a7 (patch)
treede32ac52ed5ffcb9460dfc062effc6b4b662ee5d /Lib/test/test_capi
parente5a4b402ae55f5eeeb44d3e7bc3f3ec39b249846 (diff)
downloadcpython-2e95c5ba3bf7e5004c7e2304afda4a8f8e2443a7.zip
cpython-2e95c5ba3bf7e5004c7e2304afda4a8f8e2443a7.tar.gz
cpython-2e95c5ba3bf7e5004c7e2304afda4a8f8e2443a7.tar.bz2
gh-115999: Implement thread-local bytecode and enable specialization for `BINARY_OP` (#123926)
Each thread specializes a thread-local copy of the bytecode, created on the first RESUME, in free-threaded builds. All copies of the bytecode for a code object are stored in the co_tlbc array on the code object. Threads reserve a globally unique index identifying its copy of the bytecode in all co_tlbc arrays at thread creation and release the index at thread destruction. The first entry in every co_tlbc array always points to the "main" copy of the bytecode that is stored at the end of the code object. This ensures that no bytecode is copied for programs that do not use threads. Thread-local bytecode can be disabled at runtime by providing either -X tlbc=0 or PYTHON_TLBC=0. Disabling thread-local bytecode also disables specialization. Concurrent modifications to the bytecode made by the specializing interpreter and instrumentation use atomics, with specialization taking care not to overwrite an instruction that was instrumented concurrently.
Diffstat (limited to 'Lib/test/test_capi')
-rw-r--r--Lib/test/test_capi/test_config.py1
-rw-r--r--Lib/test/test_capi/test_opt.py7
2 files changed, 7 insertions, 1 deletions
diff --git a/Lib/test/test_capi/test_config.py b/Lib/test/test_capi/test_config.py
index 71fb9ae..77730ad 100644
--- a/Lib/test/test_capi/test_config.py
+++ b/Lib/test/test_capi/test_config.py
@@ -100,6 +100,7 @@ class CAPITests(unittest.TestCase):
options.append(("run_presite", str | None, None))
if sysconfig.get_config_var('Py_GIL_DISABLED'):
options.append(("enable_gil", int, None))
+ options.append(("tlbc_enabled", int, None))
if support.MS_WINDOWS:
options.extend((
("legacy_windows_stdio", bool, None),
diff --git a/Lib/test/test_capi/test_opt.py b/Lib/test/test_capi/test_opt.py
index f1ab721..c352325 100644
--- a/Lib/test/test_capi/test_opt.py
+++ b/Lib/test/test_capi/test_opt.py
@@ -7,7 +7,8 @@ import os
import _opcode
-from test.support import script_helper, requires_specialization, import_helper
+from test.support import (script_helper, requires_specialization,
+ import_helper, Py_GIL_DISABLED)
_testinternalcapi = import_helper.import_module("_testinternalcapi")
@@ -34,6 +35,7 @@ def clear_executors(func):
@requires_specialization
+@unittest.skipIf(Py_GIL_DISABLED, "optimizer not yet supported in free-threaded builds")
@unittest.skipUnless(hasattr(_testinternalcapi, "get_optimizer"),
"Requires optimizer infrastructure")
class TestOptimizerAPI(unittest.TestCase):
@@ -138,6 +140,7 @@ def get_opnames(ex):
@requires_specialization
+@unittest.skipIf(Py_GIL_DISABLED, "optimizer not yet supported in free-threaded builds")
@unittest.skipUnless(hasattr(_testinternalcapi, "get_optimizer"),
"Requires optimizer infrastructure")
class TestExecutorInvalidation(unittest.TestCase):
@@ -219,6 +222,7 @@ class TestExecutorInvalidation(unittest.TestCase):
@requires_specialization
+@unittest.skipIf(Py_GIL_DISABLED, "optimizer not yet supported in free-threaded builds")
@unittest.skipUnless(hasattr(_testinternalcapi, "get_optimizer"),
"Requires optimizer infrastructure")
@unittest.skipIf(os.getenv("PYTHON_UOPS_OPTIMIZE") == "0", "Needs uop optimizer to run.")
@@ -586,6 +590,7 @@ class TestUops(unittest.TestCase):
@requires_specialization
+@unittest.skipIf(Py_GIL_DISABLED, "optimizer not yet supported in free-threaded builds")
@unittest.skipUnless(hasattr(_testinternalcapi, "get_optimizer"),
"Requires optimizer infrastructure")
@unittest.skipIf(os.getenv("PYTHON_UOPS_OPTIMIZE") == "0", "Needs uop optimizer to run.")