Skip to content

Commit 85dab0d

Browse files
committed
Lock dict instead of owner when specializing for dict access
1 parent b0b8102 commit 85dab0d

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

Python/specialize.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -998,19 +998,14 @@ specialize_inline_values_access_lock_held(
998998

999999
static int
10001000
specialize_managed_dict_access_lock_held(
1001-
PyObject *owner, _Py_CODEUNIT *instr, PyTypeObject *type,
1001+
PyDictObject *dict, _Py_CODEUNIT *instr, PyTypeObject *type,
10021002
unsigned int tp_version,
10031003
PyObject *name, int base_op, int hint_op)
10041004
{
1005-
PyDictObject *dict = _PyObject_GetManagedDict(owner);
10061005
_PyAttrCache *cache = (_PyAttrCache *)(instr + 1);
10071006

1008-
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(owner);
1007+
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(dict);
10091008

1010-
if (dict == NULL || !PyDict_CheckExact(dict)) {
1011-
SPECIALIZATION_FAIL(base_op, SPEC_FAIL_NO_DICT);
1012-
return 0;
1013-
}
10141009
// We found an instance with a __dict__.
10151010
if (dict->ma_values) {
10161011
SPECIALIZATION_FAIL(base_op, SPEC_FAIL_ATTR_SPLIT_DICT);
@@ -1046,19 +1041,26 @@ specialize_dict_access(
10461041
return 0;
10471042
}
10481043
int result;
1049-
Py_BEGIN_CRITICAL_SECTION(owner);
10501044
if (type->tp_flags & Py_TPFLAGS_INLINE_VALUES &&
10511045
_PyObject_InlineValues(owner)->valid &&
10521046
!(base_op == STORE_ATTR && _PyObject_GetManagedDict(owner) != NULL))
10531047
{
1048+
Py_BEGIN_CRITICAL_SECTION(owner);
10541049
result = specialize_inline_values_access_lock_held(
10551050
owner, instr, type, tp_version, name, base_op, values_op);
1051+
Py_END_CRITICAL_SECTION();
10561052
}
10571053
else {
1054+
PyDictObject *dict = _PyObject_GetManagedDict(owner);
1055+
if (dict == NULL || !PyDict_CheckExact(dict)) {
1056+
SPECIALIZATION_FAIL(base_op, SPEC_FAIL_NO_DICT);
1057+
return 0;
1058+
}
1059+
Py_BEGIN_CRITICAL_SECTION(dict);
10581060
result = specialize_managed_dict_access_lock_held(
1059-
owner, instr, type, tp_version, name, base_op, hint_op);
1061+
dict, instr, type, tp_version, name, base_op, hint_op);
1062+
Py_END_CRITICAL_SECTION();
10601063
}
1061-
Py_END_CRITICAL_SECTION();
10621064
return result;
10631065
}
10641066

0 commit comments

Comments
 (0)