diff options
author | Dino Viehland <dinoviehland@meta.com> | 2025-03-28 22:16:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-28 22:16:41 (GMT) |
commit | 2984ff9e5196aa575c7322c2040d55dd4d4eaa02 (patch) | |
tree | 4f8baee1e3095f5d662abc6ee92814c5bb33ecb8 /Python/bytecodes.c | |
parent | 00f0771e4dbd8c8b66b302ebc16bb21f5d46b304 (diff) | |
download | cpython-2984ff9e5196aa575c7322c2040d55dd4d4eaa02.zip cpython-2984ff9e5196aa575c7322c2040d55dd4d4eaa02.tar.gz cpython-2984ff9e5196aa575c7322c2040d55dd4d4eaa02.tar.bz2 |
gh-130373: Avoid locking in _LOAD_ATTR_WITH_HINT (#130372)
Avoid locking in _LOAD_ATTR_WITH_HINT
Diffstat (limited to 'Python/bytecodes.c')
-rw-r--r-- | Python/bytecodes.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c index b3b7441..6336714 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -2283,34 +2283,36 @@ dummy_func( assert(Py_TYPE(owner_o)->tp_flags & Py_TPFLAGS_MANAGED_DICT); PyDictObject *dict = _PyObject_GetManagedDict(owner_o); DEOPT_IF(dict == NULL); + PyDictKeysObject *dk = FT_ATOMIC_LOAD_PTR(dict->ma_keys); assert(PyDict_CheckExact((PyObject *)dict)); +#ifdef Py_GIL_DISABLED + DEOPT_IF(!_Py_IsOwnedByCurrentThread((PyObject *)dict) && !_PyObject_GC_IS_SHARED(dict)); +#endif PyObject *attr_o; - if (!LOCK_OBJECT(dict)) { + if (hint >= (size_t)FT_ATOMIC_LOAD_SSIZE_RELAXED(dk->dk_nentries)) { DEOPT_IF(true); } - if (hint >= (size_t)dict->ma_keys->dk_nentries) { - UNLOCK_OBJECT(dict); - DEOPT_IF(true); - } PyObject *name = GETITEM(FRAME_CO_NAMES, oparg>>1); - if (dict->ma_keys->dk_kind != DICT_KEYS_UNICODE) { - UNLOCK_OBJECT(dict); + if (dk->dk_kind != DICT_KEYS_UNICODE) { DEOPT_IF(true); } - PyDictUnicodeEntry *ep = DK_UNICODE_ENTRIES(dict->ma_keys) + hint; - if (ep->me_key != name) { - UNLOCK_OBJECT(dict); + PyDictUnicodeEntry *ep = DK_UNICODE_ENTRIES(dk) + hint; + if (FT_ATOMIC_LOAD_PTR_RELAXED(ep->me_key) != name) { DEOPT_IF(true); } - attr_o = ep->me_value; + attr_o = FT_ATOMIC_LOAD_PTR(ep->me_value); if (attr_o == NULL) { - UNLOCK_OBJECT(dict); DEOPT_IF(true); } STAT_INC(LOAD_ATTR, hit); +#ifdef Py_GIL_DISABLED + if (!_Py_TryIncrefCompareStackRef(&ep->me_value, attr_o, &attr)) { + DEOPT_IF(true); + } +#else attr = PyStackRef_FromPyObjectNew(attr_o); - UNLOCK_OBJECT(dict); +#endif PyStackRef_CLOSE(owner); } |