[3.14] gh-129752: Don't update adaptive counters when TLBC=0 in free-threading. (gh-155497) (gh-155715)

corona10 <[email protected]>
Newsgroups gmane.comp.python.cvs
Message-ID <[email protected]>
https://github.com/python/cpython/commit/c749534b06fd4b4bf99fed1b0cc3e6e5596744e7
commit: c749534b06fd4b4bf99fed1b0cc3e6e5596744e7
branch: 3.14
author: Donghee Na <[email protected]>
committer: corona10 <[email protected]>
date: 2026-08-13T15:20:04Z
summary:

[3.14] gh-129752: Don't update adaptive counters when TLBC=0 in free-threading. (gh-155497) (gh-155715)

(cherry picked from commit ee4fe00a8f72ea84a421bb626d7c78335c5c9ea1)

files:
A Misc/NEWS.d/next/Core_and_Builtins/2026-08-11-01-45-24.gh-issue-129752.Zo3OUx.rst
M Lib/test/test_thread_local_bytecode.py
M Python/ceval_macros.h

diff --git a/Lib/test/test_thread_local_bytecode.py b/Lib/test/test_thread_local_bytecode.py
index d5c56db8d5da58..6ea0e777e02605 100644
--- a/Lib/test/test_thread_local_bytecode.py
+++ b/Lib/test/test_thread_local_bytecode.py
@@ -108,7 +108,6 @@ def f(a, b, q=None):
         """)
         assert_python_ok("-X", "tlbc=1", "-c", code)
 
-    @support.skip_if_sanitizer("gh-129752: data race on adaptive counter", thread=True)
     def test_no_copies_if_tlbc_disabled(self):
         code = textwrap.dedent("""
         import queue
diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-08-11-01-45-24.gh-issue-129752.Zo3OUx.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-08-11-01-45-24.gh-issue-129752.Zo3OUx.rst
new file mode 100644
index 00000000000000..aad13dc0adef34
--- /dev/null
+++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-08-11-01-45-24.gh-issue-129752.Zo3OUx.rst
@@ -0,0 +1,2 @@
+Don't update adaptive counters in the free-threaded build when thread-local
+bytecode is disabled (``-X tlbc=0``). Patch by Donghee Na.
diff --git a/Python/ceval_macros.h b/Python/ceval_macros.h
index 95a8e719d4d0d1..c75c0b2410c677 100644
--- a/Python/ceval_macros.h
+++ b/Python/ceval_macros.h
@@ -285,6 +285,25 @@ GETITEM(PyObject *v, Py_ssize_t i) {
 #define ADAPTIVE_COUNTER_TRIGGERS(COUNTER) \
     backoff_counter_triggers(forge_backoff_counter((COUNTER)))
 
+#ifdef Py_GIL_DISABLED
+/* Counters are unreachable when thread-local bytecode is disabled,
+ * so there is no need to update them. */
+#define ADVANCE_ADAPTIVE_COUNTER(COUNTER) \
+    do { \
+        _Py_BackoffCounter cnt = (COUNTER); \
+        if (!is_unreachable_backoff_counter(cnt)) { \
+            (COUNTER) = advance_backoff_counter(cnt); \
+        } \
+    } while (0);
+
+#define PAUSE_ADAPTIVE_COUNTER(COUNTER) \
+    do { \
+        _Py_BackoffCounter cnt = (COUNTER); \
+        if (!is_unreachable_backoff_counter(cnt)) { \
+            (COUNTER) = pause_backoff_counter(cnt); \
+        } \
+    } while (0);
+#else
 #define ADVANCE_ADAPTIVE_COUNTER(COUNTER) \
     do { \
         (COUNTER) = advance_backoff_counter((COUNTER)); \
@@ -294,6 +313,7 @@ GETITEM(PyObject *v, Py_ssize_t i) {
     do { \
         (COUNTER) = pause_backoff_counter((COUNTER)); \
     } while (0);
+#endif
 
 #ifdef ENABLE_SPECIALIZATION_FT
 /* Multiple threads may execute these concurrently if thread-local bytecode is

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.