summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2024-11-20 16:41:20 (GMT)
committerGitHub <noreply@github.com>2024-11-20 16:41:20 (GMT)
commitaea0c586d181abb897511b6b46d28bfbe4858f79 (patch)
treec80958b80c4cf5eeb75898c89b868440a2174b99 /Python
parent7191b7662efcd79f2f19821c9b9fa2155df6f698 (diff)
downloadcpython-aea0c586d181abb897511b6b46d28bfbe4858f79.zip
cpython-aea0c586d181abb897511b6b46d28bfbe4858f79.tar.gz
cpython-aea0c586d181abb897511b6b46d28bfbe4858f79.tar.bz2
GH-127010: Don't lazily track and untrack dicts (GH-127027)
Diffstat (limited to 'Python')
-rw-r--r--Python/bytecodes.c4
-rw-r--r--Python/executor_cases.c.h4
-rw-r--r--Python/gc.c35
-rw-r--r--Python/gc_free_threading.c9
-rw-r--r--Python/generated_cases.c.h4
5 files changed, 5 insertions, 51 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index 029bdb2..7ffe2f5 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -2340,10 +2340,6 @@ dummy_func(
DEOPT_IF(ep->me_key != name);
PyObject *old_value = ep->me_value;
DEOPT_IF(old_value == NULL);
- /* Ensure dict is GC tracked if it needs to be */
- if (!_PyObject_GC_IS_TRACKED(dict) && _PyObject_GC_MAY_BE_TRACKED(PyStackRef_AsPyObjectBorrow(value))) {
- _PyObject_GC_TRACK(dict);
- }
_PyDict_NotifyEvent(tstate->interp, PyDict_EVENT_MODIFIED, dict, name, PyStackRef_AsPyObjectBorrow(value));
ep->me_value = PyStackRef_AsPyObjectSteal(value);
// old_value should be DECREFed after GC track checking is done, if not, it could raise a segmentation fault,
diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h
index e9c9ed2..976a342 100644
--- a/Python/executor_cases.c.h
+++ b/Python/executor_cases.c.h
@@ -2914,10 +2914,6 @@
UOP_STAT_INC(uopcode, miss);
JUMP_TO_JUMP_TARGET();
}
- /* Ensure dict is GC tracked if it needs to be */
- if (!_PyObject_GC_IS_TRACKED(dict) && _PyObject_GC_MAY_BE_TRACKED(PyStackRef_AsPyObjectBorrow(value))) {
- _PyObject_GC_TRACK(dict);
- }
_PyFrame_SetStackPointer(frame, stack_pointer);
_PyDict_NotifyEvent(tstate->interp, PyDict_EVENT_MODIFIED, dict, name, PyStackRef_AsPyObjectBorrow(value));
stack_pointer = _PyFrame_GetStackPointer(frame);
diff --git a/Python/gc.c b/Python/gc.c
index a774183..63adecf 100644
--- a/Python/gc.c
+++ b/Python/gc.c
@@ -5,7 +5,7 @@
#include "Python.h"
#include "pycore_ceval.h" // _Py_set_eval_breaker_bit()
#include "pycore_context.h"
-#include "pycore_dict.h" // _PyDict_MaybeUntrack()
+#include "pycore_dict.h" // _PyInlineValuesSize()
#include "pycore_initconfig.h"
#include "pycore_interp.h" // PyInterpreterState.gc
#include "pycore_object.h"
@@ -747,21 +747,6 @@ untrack_tuples(PyGC_Head *head)
}
}
-/* Try to untrack all currently tracked dictionaries */
-static void
-untrack_dicts(PyGC_Head *head)
-{
- PyGC_Head *next, *gc = GC_NEXT(head);
- while (gc != head) {
- PyObject *op = FROM_GC(gc);
- next = GC_NEXT(gc);
- if (PyDict_CheckExact(op)) {
- _PyDict_MaybeUntrack(op);
- }
- gc = next;
- }
-}
-
/* Return true if object has a pre-PEP 442 finalization method. */
static int
has_legacy_finalizer(PyObject *op)
@@ -1258,15 +1243,10 @@ handle_resurrected_objects(PyGC_Head *unreachable, PyGC_Head* still_unreachable,
gc_list_merge(resurrected, old_generation);
}
-
-#define UNTRACK_TUPLES 1
-#define UNTRACK_DICTS 2
-
static void
gc_collect_region(PyThreadState *tstate,
PyGC_Head *from,
PyGC_Head *to,
- int untrack,
struct gc_collection_stats *stats);
static inline Py_ssize_t
@@ -1328,7 +1308,7 @@ gc_collect_young(PyThreadState *tstate,
PyGC_Head survivors;
gc_list_init(&survivors);
- gc_collect_region(tstate, young, &survivors, UNTRACK_TUPLES, stats);
+ gc_collect_region(tstate, young, &survivors, stats);
Py_ssize_t survivor_count = 0;
if (gcstate->visited_space) {
/* objects in visited space have bit set, so we set it here */
@@ -1471,7 +1451,7 @@ gc_collect_increment(PyThreadState *tstate, struct gc_collection_stats *stats)
gc_list_validate_space(&increment, gcstate->visited_space);
PyGC_Head survivors;
gc_list_init(&survivors);
- gc_collect_region(tstate, &increment, &survivors, UNTRACK_TUPLES, stats);
+ gc_collect_region(tstate, &increment, &survivors, stats);
gc_list_validate_space(&survivors, gcstate->visited_space);
gc_list_merge(&survivors, visited);
assert(gc_list_is_empty(&increment));
@@ -1504,7 +1484,6 @@ gc_collect_full(PyThreadState *tstate,
gc_list_merge(pending, visited);
gc_collect_region(tstate, visited, visited,
- UNTRACK_TUPLES | UNTRACK_DICTS,
stats);
gcstate->young.count = 0;
gcstate->old[0].count = 0;
@@ -1522,7 +1501,6 @@ static void
gc_collect_region(PyThreadState *tstate,
PyGC_Head *from,
PyGC_Head *to,
- int untrack,
struct gc_collection_stats *stats)
{
PyGC_Head unreachable; /* non-problematic unreachable trash */
@@ -1536,12 +1514,7 @@ gc_collect_region(PyThreadState *tstate,
gc_list_init(&unreachable);
deduce_unreachable(from, &unreachable);
validate_consistent_old_space(from);
- if (untrack & UNTRACK_TUPLES) {
- untrack_tuples(from);
- }
- if (untrack & UNTRACK_DICTS) {
- untrack_dicts(from);
- }
+ untrack_tuples(from);
validate_consistent_old_space(to);
if (from != to) {
gc_list_merge(from, to);
diff --git a/Python/gc_free_threading.c b/Python/gc_free_threading.c
index 499ee51..a6e0022 100644
--- a/Python/gc_free_threading.c
+++ b/Python/gc_free_threading.c
@@ -3,7 +3,7 @@
#include "pycore_brc.h" // struct _brc_thread_state
#include "pycore_ceval.h" // _Py_set_eval_breaker_bit()
#include "pycore_context.h"
-#include "pycore_dict.h" // _PyDict_MaybeUntrack()
+#include "pycore_dict.h" // _PyInlineValuesSize()
#include "pycore_freelist.h" // _PyObject_ClearFreeLists()
#include "pycore_initconfig.h"
#include "pycore_interp.h" // PyInterpreterState.gc
@@ -493,13 +493,6 @@ update_refs(const mi_heap_t *heap, const mi_heap_area_t *area,
return true;
}
}
- else if (PyDict_CheckExact(op)) {
- _PyDict_MaybeUntrack(op);
- if (!_PyObject_GC_IS_TRACKED(op)) {
- gc_restore_refs(op);
- return true;
- }
- }
}
// We repurpose ob_tid to compute "gc_refs", the number of external
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index 4d89753..f3db2f9 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
@@ -7435,10 +7435,6 @@
DEOPT_IF(ep->me_key != name, STORE_ATTR);
PyObject *old_value = ep->me_value;
DEOPT_IF(old_value == NULL, STORE_ATTR);
- /* Ensure dict is GC tracked if it needs to be */
- if (!_PyObject_GC_IS_TRACKED(dict) && _PyObject_GC_MAY_BE_TRACKED(PyStackRef_AsPyObjectBorrow(value))) {
- _PyObject_GC_TRACK(dict);
- }
_PyFrame_SetStackPointer(frame, stack_pointer);
_PyDict_NotifyEvent(tstate->interp, PyDict_EVENT_MODIFIED, dict, name, PyStackRef_AsPyObjectBorrow(value));
stack_pointer = _PyFrame_GetStackPointer(frame);