Skip to content

gh-115999: Specialize LOAD_ATTR for instance and class receivers in free-threaded builds #128164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 75 commits into from
Jan 14, 2025
Merged
Changes from 1 commit
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
8eeb4fe
Add _PyDictKeys_StringLookupAndVersion
mpage Dec 10, 2024
fcd05a0
Pass shared keys version to specialization
mpage Dec 10, 2024
5c03db0
Add support for enabling each of the instance attribute kinds
mpage Dec 10, 2024
a576748
Only cache deferred descriptors
mpage Dec 10, 2024
8475fd6
Make analyze_descriptor thread-safe
mpage Dec 11, 2024
29c3356
Use an atomic load for GUARD_TYPE_VERSION
mpage Dec 11, 2024
4f9eeb3
Use atomics to load valid bit for inline values in _GUARD_DORV_VALUES…
mpage Dec 11, 2024
e9050fc
Use atomic to load keys version in _GUARD_KEYS_VERSION
mpage Dec 11, 2024
ade57f2
Use an atomic load for managed dict in `_CHECK_ATTR_METHOD_LAZY_DICT`
mpage Dec 11, 2024
0a87264
Enable specialization of method loads
mpage Dec 11, 2024
816e22f
Use atomics for fetching type flags
mpage Dec 11, 2024
ca1e232
Get a strong reference to dict in instance_has_key
mpage Dec 11, 2024
945b61c
Split specialize_dict_access
mpage Dec 11, 2024
feb7d34
Pass type version to specialize_dict_access
mpage Dec 12, 2024
ecfd199
Take a critical section around dict specialization
mpage Dec 12, 2024
9fda5db
Use thread-safe version of _PyDictKeys_StringLookup
mpage Dec 12, 2024
3b2c220
Use atomic load in _CHECK_MANAGED_OBJECT_HAS_VALUES
mpage Dec 12, 2024
408e44b
Make _LOAD_ATTR_INSTANCE_VALUE thread-safe
mpage Dec 12, 2024
16aab70
Make _LOAD_ATTR_WITH_HINT thread-safe
mpage Dec 12, 2024
d0920ea
Specialize instance accesses
mpage Dec 12, 2024
e7cea82
Specialize LOAD_ATTR_SLOT
mpage Dec 12, 2024
8dac8c4
Enable LOAD_ATTR_PROPERTY
mpage Dec 13, 2024
d29b3aa
Checkpoint LOAD_ATTR_GETATTRIBUTE_OVERRIDEN
mpage Dec 13, 2024
b0b8102
Lock dict in instance_has_key
mpage Dec 13, 2024
85dab0d
Lock dict instead of owner when specializing for dict access
mpage Dec 13, 2024
581869e
Use atomic load for valid bit
mpage Dec 13, 2024
96be738
Use _PyDictKeys_StringLookup and lock around it, rather than wasting …
mpage Dec 13, 2024
9afe052
Fix cases_generator bug
mpage Dec 13, 2024
e190a0d
Fix load
mpage Dec 13, 2024
8c78369
Remove FT_UNIMPLEMENTED
mpage Dec 13, 2024
cdf8eb5
Specialize class attribute loads
mpage Dec 13, 2024
1398699
Fix test_type_lookup_mro_reference
mpage Dec 14, 2024
3fbe18b
Remove TYPE_CHANGED
mpage Dec 14, 2024
5aa68cc
Misc clean ups
mpage Dec 14, 2024
e1bf1f4
Check that inline values still valid after taking CS
mpage Dec 14, 2024
396edb1
Enable test_opcache tests
mpage Dec 18, 2024
e5e2508
Skip test that triggers gh-127773 in refleak tests
mpage Dec 20, 2024
fa02260
Merge branch 'main' into gh-115999-load-attr
mpage Dec 20, 2024
47c794f
Add test for LOAD_ATTR_CLASS_WITH_METACLASS_CHECK
mpage Dec 20, 2024
3876bc7
Undo workaround for cases generator bug
mpage Dec 20, 2024
08d14d0
Fix whitespace after merge
mpage Dec 20, 2024
56e9a8a
Double check that dict hasn't changed after locking it
mpage Dec 20, 2024
8ca405b
Use correct type for loading type version
mpage Dec 20, 2024
4c7a4b9
Remove unnecessary comma
mpage Dec 20, 2024
1b787b3
Use atomics when loading oparg
mpage Dec 20, 2024
b868363
Fix formatting
mpage Dec 20, 2024
d6d4c73
Always return type version from analyze_descriptor_load
mpage Dec 20, 2024
9755562
Merge branch 'main' into gh-115999-load-attr-instance-merged
mpage Dec 23, 2024
9673f78
Combine incref/steal into new stackref
mpage Dec 23, 2024
6c3041f
Fix formatting
mpage Dec 23, 2024
a20a4a4
Remove unnecessary error check for PyUnicode_Type.tp_hash
mpage Dec 23, 2024
35b31c6
Check keys kind explicitly
mpage Dec 23, 2024
e5a7ae9
Pass dict from `_CHECK_ATTR_WITH_HINT` to `_LOAD_ATTR_WITH_HINT`
mpage Dec 23, 2024
bb00f5a
Fix unused variable warning
mpage Dec 23, 2024
b6ae487
Update number of specialization failure kinds
mpage Dec 24, 2024
11a351d
Clarify construction of deferred object
mpage Dec 24, 2024
6f8aebf
Add suppression for _PyUnicode_CheckConsistency
mpage Dec 24, 2024
07b7c20
Merge branch 'main' into gh-115999-load-attr-instance-merged
mpage Jan 2, 2025
1870885
Fix compiler warning
mpage Jan 2, 2025
f1fdcc6
Make it easier to reason about thread-safety of instance_has_key
mpage Jan 2, 2025
8b71951
Restore refactor lost in merge
mpage Jan 2, 2025
7190a2e
Merge branch 'main' into gh-115999-load-attr-instance-merged
mpage Jan 2, 2025
8b96368
Revert "Add suppression for _PyUnicode_CheckConsistency"
mpage Jan 2, 2025
db02869
Merge branch 'main' into gh-115999-load-attr-instance-merged
mpage Jan 8, 2025
dc3ba7f
Merge branch 'main' into gh-115999-load-attr-instance-merged
mpage Jan 9, 2025
e07fb62
Split check_keys_and_hash
mpage Jan 9, 2025
a3f89b7
Clear inline values upon invalidation
mpage Jan 9, 2025
3baa840
Replace kill/pop_dead_inputs with pop_input
mpage Jan 10, 2025
9250e4e
Fix formatting
mpage Jan 10, 2025
675eb82
Fix visibility
mpage Jan 10, 2025
d24dc3a
Merge branch 'main' into gh-115999-load-attr-instance-merged
mpage Jan 10, 2025
10d693d
Use release instead of seq_cst
mpage Jan 10, 2025
7ab3ec6
Make POP_INPUT take the name of the TOS
mpage Jan 10, 2025
8c70ea4
Merge branch 'main' into gh-115999-load-attr-instance-merged
mpage Jan 14, 2025
3616eab
Use DECREF_INPUTS() instead of manually closing inputs
mpage Jan 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1951,6 +1951,17 @@ build_indices_unicode(PyDictKeysObject *keys, PyDictUnicodeEntry *ep, Py_ssize_t
}
}


static void
invalidate_and_clear_inline_values(PyDictValues *values)
{
assert(values->embedded);
FT_ATOMIC_STORE_UINT8(values->valid, 0);
for (int i = 0; i < values->capacity; i++) {
FT_ATOMIC_STORE_PTR(values->values[i], NULL);
}
}

/*
Restructure the table by allocating a new table and reinserting all
items again. When entries have been deleted, the new table may
Expand Down Expand Up @@ -2042,7 +2053,7 @@ dictresize(PyInterpreterState *interp, PyDictObject *mp,
if (oldvalues->embedded) {
assert(oldvalues->embedded == 1);
assert(oldvalues->valid == 1);
FT_ATOMIC_STORE_UINT8(oldvalues->valid, 0);
invalidate_and_clear_inline_values(oldvalues);
}
else {
free_values(oldvalues, IS_DICT_SHARED(mp));
Expand Down Expand Up @@ -7032,7 +7043,13 @@ _PyObject_TryGetInstanceAttribute(PyObject *obj, PyObject *name, PyObject **attr

#ifdef Py_GIL_DISABLED
PyObject *value = _Py_atomic_load_ptr_acquire(&values->values[ix]);
if (value == NULL || _Py_TryIncrefCompare(&values->values[ix], value)) {
if (value == NULL) {
if (FT_ATOMIC_LOAD_UINT8(values->valid)) {
*attr = NULL;
return true;
}
}
else if (_Py_TryIncrefCompare(&values->values[ix], value)) {
*attr = value;
return true;
}
Expand Down Expand Up @@ -7370,7 +7387,7 @@ _PyDict_DetachFromObject(PyDictObject *mp, PyObject *obj)
}
mp->ma_values = values;

FT_ATOMIC_STORE_UINT8(_PyObject_InlineValues(obj)->valid, 0);
invalidate_and_clear_inline_values(_PyObject_InlineValues(obj));

assert(_PyObject_InlineValuesConsistencyCheck(obj));
ASSERT_CONSISTENT(mp);
Expand Down