8000 GH-126491: GC: Mark objects reachable from roots before doing cycle collection by markshannon · Pull Request #126502 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-126491: GC: Mark objects reachable from roots before doing cycle collection #126502

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 35 commits into from
Nov 18, 2024
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2ec8d8a
GC experiment: mark almost all reachable objects before doing collect…
markshannon Nov 4, 2024
1fdf00e
Add stats for objects marked
markshannon Nov 4, 2024
5e813c5
Start with mark phase
markshannon Nov 4, 2024
8bd7606
Add stats for visits during marking
markshannon Nov 5, 2024
3513da2
Visit new frames before each increment
markshannon Nov 5, 2024
ab1faec
Redo stats
markshannon Nov 6, 2024
9e2d93c
Fix freezing and GC untracking
markshannon Nov 6, 2024
3c18fc8
Don't untrack dicts
markshannon Nov 6, 2024
94da963
Remove lazy dict tracking from no-gil build
markshannon Nov 6, 2024
659fd1e
Remove unused variable
markshannon Nov 6, 2024
4cfbc4f
Add news
markshannon Nov 6, 2024
8c92ca6
Fix use after free
markshannon Nov 6, 2024
12d7f7c
Attempt more careful fix of use-after-free
markshannon Nov 7, 2024
1f619d7
Typo
markshannon Nov 7, 2024
b55fe37
Fix use of uninitialized variable
markshannon Nov 7, 2024
73b7f52
Fix compiler warnings
markshannon Nov 7, 2024
33f6386
Tweak test
markshannon Nov 7, 2024
8574d00
Add section to internal docs
markshannon Nov 11, 2024
70007b0
Rephrase new docs
markshannon Nov 11, 2024
f043080
Use symbolic constant
markshannon Nov 13, 2024
db2e173
Update section on untracking
markshannon Nov 13, 2024
6a50c2f
Merge branch 'main' into mark-first-gc
8000 markshannon Nov 14, 2024
b9467ec
Update docs
markshannon Nov 14, 2024
14ae8d7
A few more edits
markshannon Nov 14, 2024
3337512
Update comment
markshannon Nov 14, 2024
3ae87fa
Address doc review comments
markshannon Nov 14, 2024
a2d9e3e
Merge branch 'main' into mark-first-gc
markshannon Nov 15, 2024
1452378
Avoid repeated collection of the young gen
markshannon Nov 15, 2024
595b14c
Clearer calculation of work to do.
markshannon Nov 15, 2024
278059b
Make sure tuples are untracked and avoid quadratic time validation
markshannon Nov 15, 2024
f186b4a
Update InternalDocs/garbage_collector.md
markshannon Nov 18, 2024
5f6d04e
Remove unused variable
markshannon Nov 18, 2024
9cfb5f0
Tweak work to do calculation
markshannon Nov 18, 2024
c7683a4
Explain work to do calculation
markshannon Nov 18, 2024
170ea6d
Initialize field to prevent code analyzer warning.
markshannon Nov 18, 2024
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
Prev Previous commit
Next Next commit
Attempt more careful fix of use-after-free
  • Loading branch information
markshannon committed Nov 7, 2024
commit 12d7f7cac333a5d6c8b319dd72b9ee86421a6589
23 changes: 16 additions & 7 deletions Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -7117,6 +7117,7 @@
// since we locked it.
dict = _PyObject_ManagedDictPointer(obj)->dict;
err = _PyDict_DetachFromObject(dict, obj);
assert(err == 0 || new_dict == NULL);
if (err == 0) {
FT_ATOMIC_STORE_PTR(_PyObject_ManagedDictPointer(obj)->dict,
(PyDictObject *)Py_XNewRef(new_dict));
Expand Down Expand Up @@ -7149,7 +7150,21 @@
PyObject_ClearManagedDict(PyObject *obj)
{
if (_PyObject_SetManagedDict(obj, NULL) < 0) {
/* Must be out of memory */
assert(PyErr_Occurred() == PyExc_MemoryError);
PyErr_WriteUnraisable(NULL);
/* Clear the dict */
PyDictObject *dict = _PyObject_GetManagedDict(obj);
Py_BEGIN_CRITICAL_SECTION2(dict, obj);
dict = _PyObject_ManagedDictPointer(obj)->dict;
PyInterpreterState *interp = _PyInterpreterState_GET();
PyDictKeysObject *oldkeys = dict->ma_keys;
set_keys(dict, Py_EMPTY_KEYS);
dict->ma_values = NULL;
dictkeys_decref(interp, oldkeys, IS_DICT_SHARED(mp));

Check failure on line 7164 in Objects/dictobject.c

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-24.04)

‘mp’ undeclared (first use in this function)

Check failure on line 7164 in Objects/dictobject.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build (arm64)

'mp': undeclared identifier [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 7164 in Objects/dictobject.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build (arm64)

'type cast': conversion from 'int' to 'PyObject *' of greater size [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]
STORE_USED(dict, 0);
set_dict_inline_values(obj, NULL);
Py_END_CRITICAL_SECTION2();
}
}

Expand All @@ -7173,17 +7188,11 @@

PyDictValues *values = copy_values(mp->ma_values);

mp->ma_values = values;
if (values == NULL) {
/* Out of memory. Clear the dict */
PyInterpreterState *interp = _PyInterpreterState_GET();
PyDictKeysObject *oldkeys = mp->ma_keys;
set_keys(mp, Py_EMPTY_KEYS);
dic 5EC7 tkeys_decref(interp, oldkeys, IS_DICT_SHARED(mp));
STORE_USED(mp, 0);
PyErr_NoMemory();
return -1;
}
mp->ma_values = values;

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

Expand Down
Loading
0