summaryrefslogtreecommitdiffstats
path: root/Python/bytecodes.c
diff options
context:
space:
mode:
authorT. Wouters <thomas@python.org>2025-01-29 00:07:56 (GMT)
committerGitHub <noreply@github.com>2025-01-29 00:07:56 (GMT)
commit5c930a26fb78c40929f1b894efee1b07c6d828fd (patch)
tree393ee4f7fb4c2dc4f0736144647c985e771ca87e /Python/bytecodes.c
parent789390872b16e1c8cc681605bf100d2d7b3e9111 (diff)
downloadcpython-5c930a26fb78c40929f1b894efee1b07c6d828fd.zip
cpython-5c930a26fb78c40929f1b894efee1b07c6d828fd.tar.gz
cpython-5c930a26fb78c40929f1b894efee1b07c6d828fd.tar.bz2
gh-115999: Enable free-threaded specialization of LOAD_CONST (#129365)
Enable free-threaded specialization of LOAD_CONST.
Diffstat (limited to 'Python/bytecodes.c')
-rw-r--r--Python/bytecodes.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index 5f0be8d..7d46351 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -294,11 +294,21 @@ dummy_func(
* marshalling can intern strings and make them immortal. */
PyObject *obj = GETITEM(FRAME_CO_CONSTS, oparg);
value = PyStackRef_FromPyObjectNew(obj);
-#if ENABLE_SPECIALIZATION
+#if ENABLE_SPECIALIZATION_FT
+#ifdef Py_GIL_DISABLED
+ uint8_t expected = LOAD_CONST;
+ if (!_Py_atomic_compare_exchange_uint8(
+ &this_instr->op.code, &expected,
+ _Py_IsImmortal(obj) ? LOAD_CONST_IMMORTAL : LOAD_CONST_MORTAL)) {
+ // We might lose a race with instrumentation, which we don't care about.
+ assert(expected >= MIN_INSTRUMENTED_OPCODE);
+ }
+#else
if (this_instr->op.code == LOAD_CONST) {
this_instr->op.code = _Py_IsImmortal(obj) ? LOAD_CONST_IMMORTAL : LOAD_CONST_MORTAL;
}
#endif
+#endif
}
inst(LOAD_CONST_MORTAL, (-- value)) {
@@ -2558,7 +2568,7 @@ dummy_func(
}
OPCODE_DEFERRED_INC(COMPARE_OP);
ADVANCE_ADAPTIVE_COUNTER(this_instr[1].counter);
- #endif /* ENABLE_SPECIALIZATION */
+ #endif /* ENABLE_SPECIALIZATION_FT */
}
op(_COMPARE_OP, (left, right -- res)) {