Skip to content

Commit 6a1fe7e

Browse files
committed
Avoid locking in _LOAD_ATTR_WITH_HINT
1 parent ccf1732 commit 6a1fe7e

File tree

5 files changed

+73
-45
lines changed

5 files changed

+73
-45
lines changed

Include/internal/pycore_opcode_metadata.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_metadata.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/bytecodes.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2286,38 +2286,40 @@ dummy_func(
22862286
}
22872287

22882288
op(_LOAD_ATTR_WITH_HINT, (hint/1, owner, dict: PyDictObject * -- attr)) {
2289+
PyDictKeysObject *dk = FT_ATOMIC_LOAD_PTR(dict->ma_keys);
22892290
PyObject *attr_o;
2290-
if (!LOCK_OBJECT(dict)) {
2291-
POP_INPUT(dict);
2292-
DEOPT_IF(true);
2293-
}
2294-
2295-
if (hint >= (size_t)dict->ma_keys->dk_nentries) {
2296-
UNLOCK_OBJECT(dict);
2291+
if (hint >= (size_t)dk->dk_nentries) {
22972292
POP_INPUT(dict);
22982293
DEOPT_IF(true);
22992294
}
23002295
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg>>1);
2301-
if (dict->ma_keys->dk_kind != DICT_KEYS_UNICODE) {
2302-
UNLOCK_OBJECT(dict);
2296+
if (dk->dk_kind != DICT_KEYS_UNICODE) {
23032297
POP_INPUT(dict);
23042298
DEOPT_IF(true);
23052299
}
2306-
PyDictUnicodeEntry *ep = DK_UNICODE_ENTRIES(dict->ma_keys) + hint;
2300+
PyDictUnicodeEntry *ep = DK_UNICODE_ENTRIES(dk) + hint;
23072301
if (ep->me_key != name) {
2308-
UNLOCK_OBJECT(dict);
23092302
POP_INPUT(dict);
23102303
DEOPT_IF(true);
23112304
}
2312-
attr_o = ep->me_value;
2305+
attr_o = FT_ATOMIC_LOAD_PTR(ep->me_value);
23132306
if (attr_o == NULL) {
2314-
UNLOCK_OBJECT(dict);
23152307
POP_INPUT(dict);
23162308
DEOPT_IF(true);
23172309
}
2318-
STAT_INC(LOAD_ATTR, hit);
2310+
#ifdef Py_GIL_DISABLED
2311+
if (!_Py_TryIncrefCompareStackRef(&ep->me_value, attr_o, &attr)) {
2312+
POP_INPUT(dict);
2313+
DEOPT_IF(true);
2314+
} else if (dk != FT_ATOMIC_LOAD_PTR(dict->ma_keys)) {
2315+
PyStackRef_CLOSE(attr);
2316+
POP_INPUT(dict);
2317+
DEOPT_IF(true);
2318+
}
2319+
#else
23192320
attr = PyStackRef_FromPyObjectNew(attr_o);
2320-
UNLOCK_OBJECT(dict);
2321+
#endif
2322+
STAT_INC(LOAD_ATTR, hit);
23212323
DEAD(dict);
23222324
DECREF_INPUTS();
23232325
}

Python/executor_cases.c.h

Lines changed: 25 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

Lines changed: 29 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)