summaryrefslogtreecommitdiffstats
path: root/Include/internal
diff options
context:
space:
mode:
authorHugo van Kemenade <1324225+hugovk@users.noreply.github.com>2024-11-19 09:25:09 (GMT)
committerGitHub <noreply@github.com>2024-11-19 09:25:09 (GMT)
commit899fdb213db6c5881c5f9c6760ead6fd713d2070 (patch)
treec4e291504c73e8055d02176551beeb39ab47e6ad /Include/internal
parent84f07c3a4cbcfe488ccfb4030571be0bc4de7e45 (diff)
downloadcpython-899fdb213db6c5881c5f9c6760ead6fd713d2070.zip
cpython-899fdb213db6c5881c5f9c6760ead6fd713d2070.tar.gz
cpython-899fdb213db6c5881c5f9c6760ead6fd713d2070.tar.bz2
Revert "GH-126491: GC: Mark objects reachable from roots before doing cycle collection (GH-126502)" (#126983)
Diffstat (limited to 'Include/internal')
-rw-r--r--Include/internal/pycore_dict.h2
-rw-r--r--Include/internal/pycore_frame.h3
-rw-r--r--Include/internal/pycore_gc.h11
-rw-r--r--Include/internal/pycore_object.h4
-rw-r--r--Include/internal/pycore_runtime_init.h1
5 files changed, 6 insertions, 15 deletions
diff --git a/Include/internal/pycore_dict.h b/Include/internal/pycore_dict.h
index f7d747c..c5399ad 100644
--- a/Include/internal/pycore_dict.h
+++ b/Include/internal/pycore_dict.h
@@ -43,6 +43,8 @@ extern int _PyDict_Next(
extern int _PyDict_HasOnlyStringKeys(PyObject *mp);
+extern void _PyDict_MaybeUntrack(PyObject *mp);
+
// Export for '_ctypes' shared extension
PyAPI_FUNC(Py_ssize_t) _PyDict_SizeOf(PyDictObject *);
diff --git a/Include/internal/pycore_frame.h b/Include/internal/pycore_frame.h
index b786c5f..8c01003 100644
--- a/Include/internal/pycore_frame.h
+++ b/Include/internal/pycore_frame.h
@@ -75,7 +75,6 @@ typedef struct _PyInterpreterFrame {
_PyStackRef *stackpointer;
uint16_t return_offset; /* Only relevant during a function call */
char owner;
- char visited;
/* Locals and stack */
_PyStackRef localsplus[1];
} _PyInterpreterFrame;
@@ -208,7 +207,6 @@ _PyFrame_Initialize(
#endif
frame->return_offset = 0;
frame->owner = FRAME_OWNED_BY_THREAD;
- frame->visited = 0;
for (int i = null_locals_from; i < code->co_nlocalsplus; i++) {
frame->localsplus[i] = PyStackRef_NULL;
@@ -391,7 +389,6 @@ _PyFrame_PushTrampolineUnchecked(PyThreadState *tstate, PyCodeObject *code, int
frame->instr_ptr = _PyCode_CODE(code);
#endif
frame->owner = FRAME_OWNED_BY_THREAD;
- frame->visited = 0;
frame->return_offset = 0;
#ifdef Py_GIL_DISABLED
diff --git a/Include/internal/pycore_gc.h b/Include/internal/pycore_gc.h
index c81e7a1..38a1c56 100644
--- a/Include/internal/pycore_gc.h
+++ b/Include/internal/pycore_gc.h
@@ -10,11 +10,11 @@ extern "C" {
/* GC information is stored BEFORE the object structure. */
typedef struct {
- // Tagged pointer to next object in the list.
+ // Pointer to next object in the list.
// 0 means the object is not tracked
uintptr_t _gc_next;
- // Tagged pointer to previous object in the list.
+ // Pointer to previous object in the list.
// Lowest two bits are used for flags documented later.
uintptr_t _gc_prev;
} PyGC_Head;
@@ -302,11 +302,6 @@ struct gc_generation_stats {
Py_ssize_t uncollectable;
};
-enum _GCPhase {
- GC_PHASE_MARK = 0,
- GC_PHASE_COLLECT = 1
-};
-
struct _gc_runtime_state {
/* List of objects that still need to be cleaned up, singly linked
* via their gc headers' gc_prev pointers. */
@@ -330,12 +325,10 @@ struct _gc_runtime_state {
/* a list of callbacks to be invoked when collection is performed */
PyObject *callbacks;
- Py_ssize_t prior_heap_size;
Py_ssize_t heap_size;
Py_ssize_t work_to_do;
/* Which of the old spaces is the visited space */
int visited_space;
- int phase;
#ifdef Py_GIL_DISABLED
/* This is the number of objects that survived the last full
diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h
index 0cba7bc..c7af720 100644
--- a/Include/internal/pycore_object.h
+++ b/Include/internal/pycore_object.h
@@ -466,8 +466,8 @@ static inline void _PyObject_GC_TRACK(
PyGC_Head *last = (PyGC_Head*)(generation0->_gc_prev);
_PyGCHead_SET_NEXT(last, gc);
_PyGCHead_SET_PREV(gc, last);
- uintptr_t not_visited = 1 ^ interp->gc.visited_space;
- gc->_gc_next = ((uintptr_t)generation0) | not_visited;
+ /* Young objects will be moved into the visited space during GC, so set the bit here */
+ gc->_gc_next = ((uintptr_t)generation0) | (uintptr_t)interp->gc.visited_space;
generation0->_gc_prev = (uintptr_t)gc;
#endif
}
diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h
index ce116ad..8a8f476 100644
--- a/Include/internal/pycore_runtime_init.h
+++ b/Include/internal/pycore_runtime_init.h
@@ -134,7 +134,6 @@ extern PyTypeObject _PyExc_MemoryError;
{ .threshold = 0, }, \
}, \
.work_to_do = -5000, \
- .phase = GC_PHASE_MARK, \
}, \
.qsbr = { \
.wr_seq = QSBR_INITIAL, \