Skip to content

Commit aef7fa6

Browse files
committed
Merge upstream CPython main (2e64e36) into parallel-gc-dev
Merge 1,411 upstream commits from python/cpython main into parallel-gc-dev. Conflicts resolved: - Modules/Setup.stdlib.in: add both upstream (interpreter.c, tuple.c) and our (test_ws_deque.c) test module files - Modules/_testinternalcapi.c: add both Tuple and WSDeque init calls - Modules/_testinternalcapi/parts.h: add both Tuple and WSDeque declarations - Python/pylifecycle.c: auto-resolved (upstream JIT/hugepages includes + our parallel GC includes) - Python/gc_free_threading.c: auto-resolved by git Semantic fix applied: - gc_free_threading_parallel.c: update scan_heap_block_visitor to match upstream commit 48b6866 which changed long_lived_total counting to include untracked and frozen objects (was only counting reachable tracked objects). Also add par_gc_is_frozen() check matching upstream gc_is_frozen(). Configure fix: - Re-apply --with-parallel-gc patch on clean upstream configure (previous hand-patched configure had stale rm -f pyconfig.h that broke config.status) Tested: FTP+flag 121/121 pass, GIL+flag 92/92 pass.
1 parent df1cc93 commit aef7fa6

3 files changed

Lines changed: 14 additions & 18 deletions

File tree

Python/frozen_modules/README.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.

Python/gc_free_threading_parallel.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2613,7 +2613,7 @@ par_disable_deferred_refcounting(PyObject *op)
26132613
frame->f_executable = PyStackRef_AsStrongReference(frame->f_executable);
26142614
frame->f_funcobj = PyStackRef_AsStrongReference(frame->f_funcobj);
26152615
for (_PyStackRef *ref = frame->localsplus; ref < frame->stackpointer; ref++) {
2616-
if (!PyStackRef_IsNullOrInt(*ref) && PyStackRef_IsDeferred(*ref)) {
2616+
if (!PyStackRef_IsNullOrInt(*ref) && !PyStackRef_RefcountOnObject(*ref)) {
26172617
*ref = PyStackRef_AsStrongReference(*ref);
26182618
}
26192619
}
@@ -2625,7 +2625,7 @@ par_disable_deferred_refcounting(PyObject *op)
26252625
frame->f_executable = PyStackRef_AsStrongReference(frame->f_executable);
26262626
frame->f_funcobj = PyStackRef_AsStrongReference(frame->f_funcobj);
26272627
for (_PyStackRef *ref = frame->localsplus; ref < frame->stackpointer; ref++) {
2628-
if (!PyStackRef_IsNullOrInt(*ref) && PyStackRef_IsDeferred(*ref)) {
2628+
if (!PyStackRef_IsNullOrInt(*ref) && !PyStackRef_RefcountOnObject(*ref)) {
26292629
*ref = PyStackRef_AsStrongReference(*ref);
26302630
}
26312631
}
@@ -2683,7 +2683,7 @@ par_disable_deferred_collect_ids(PyObject *op, struct _PyGCScanWorkerState *work
26832683
frame->f_executable = PyStackRef_AsStrongReference(frame->f_executable);
26842684
frame->f_funcobj = PyStackRef_AsStrongReference(frame->f_funcobj);
26852685
for (_PyStackRef *ref = frame->localsplus; ref < frame->stackpointer; ref++) {
2686-
if (!PyStackRef_IsNullOrInt(*ref) && PyStackRef_IsDeferred(*ref)) {
2686+
if (!PyStackRef_IsNullOrInt(*ref) && !PyStackRef_RefcountOnObject(*ref)) {
26872687
*ref = PyStackRef_AsStrongReference(*ref);
26882688
}
26892689
}
@@ -2695,7 +2695,7 @@ par_disable_deferred_collect_ids(PyObject *op, struct _PyGCScanWorkerState *work
26952695
frame->f_executable = PyStackRef_AsStrongReference(frame->f_executable);
26962696
frame->f_funcobj = PyStackRef_AsStrongReference(frame->f_funcobj);
26972697
for (_PyStackRef *ref = frame->localsplus; ref < frame->stackpointer; ref++) {
2698-
if (!PyStackRef_IsNullOrInt(*ref) && PyStackRef_IsDeferred(*ref)) {
2698+
if (!PyStackRef_IsNullOrInt(*ref) && !PyStackRef_RefcountOnObject(*ref)) {
26992699
*ref = PyStackRef_AsStrongReference(*ref);
27002700
}
27012701
}
@@ -2738,7 +2738,13 @@ scan_heap_block_visitor(const mi_heap_t *heap, const mi_heap_area_t *area,
27382738
struct scan_page_visitor_args *args = (struct scan_page_visitor_args *)arg;
27392739
PyObject *op = (PyObject *)((char *)block + args->offset);
27402740

2741-
if (!_PyObject_GC_IS_TRACKED(op)) {
2741+
// The free-threaded GC cost is proportional to the number of objects in
2742+
// the mimalloc GC heap and so we should include the counts for untracked
2743+
// and frozen objects as well. This is especially important if many
2744+
// tuples have been untracked.
2745+
args->worker->long_lived_total++;
2746+
2747+
if (!_PyObject_GC_IS_TRACKED(op) || par_gc_is_frozen(op)) {
27422748
return true;
27432749
}
27442750

@@ -2757,12 +2763,14 @@ scan_heap_block_visitor(const mi_heap_t *heap, const mi_heap_area_t *area,
27572763
else {
27582764
scan_worklist_push(&args->worker->unreachable, op);
27592765
}
2766+
// It is possible this object will be resurrected but
2767+
// for now we assume it will be deallocated.
2768+
args->worker->long_lived_total--;
27602769
}
27612770
else {
27622771
// Reachable object
27632772
par_gc_restore_tid(op);
27642773
par_gc_clear_alive(op);
2765-
args->worker->long_lived_total++;
27662774
}
27672775

27682776
return true;

configure

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

0 commit comments

Comments
 (0)