@@ -142,14 +142,11 @@ static inline void _PyObject_GC_SET_SHARED_INLINE(PyObject *op) {
142142
143143/* Bit flags for _gc_prev */
144144/* Bit 0 is set when tp_finalize is called */
145- #define _PyGC_PREV_MASK_FINALIZED 1
145+ #define _PyGC_PREV_MASK_FINALIZED (1)
146146/* Bit 1 is set when the object is in generation which is GCed currently. */
147- #define _PyGC_PREV_MASK_COLLECTING 2
148-
149- /* Bit 0 is set if the object belongs to old space 1 */
150- #define _PyGC_NEXT_MASK_OLD_SPACE_1 1
151-
152- #define _PyGC_PREV_SHIFT 2
147+ #define _PyGC_PREV_MASK_COLLECTING (2)
148+ /* The (N-2) most significant bits contain the real address. */
149+ #define _PyGC_PREV_SHIFT (2)
153150#define _PyGC_PREV_MASK (((uintptr_t) -1) << _PyGC_PREV_SHIFT)
154151
155152/* set for debugging information */
@@ -175,21 +172,18 @@ typedef enum {
175172// Lowest bit of _gc_next is used for flags only in GC.
176173// But it is always 0 for normal code.
177174static inline PyGC_Head * _PyGCHead_NEXT (PyGC_Head * gc ) {
178- uintptr_t next = gc -> _gc_next & _PyGC_PREV_MASK ;
175+ uintptr_t next = gc -> _gc_next ;
179176 return (PyGC_Head * )next ;
180177}
181178static inline void _PyGCHead_SET_NEXT (PyGC_Head * gc , PyGC_Head * next ) {
182- uintptr_t unext = (uintptr_t )next ;
183- assert ((unext & ~_PyGC_PREV_MASK ) == 0 );
184- gc -> _gc_next = (gc -> _gc_next & ~_PyGC_PREV_MASK ) | unext ;
179+ gc -> _gc_next = (uintptr_t )next ;
185180}
186181
187182// Lowest two bits of _gc_prev is used for _PyGC_PREV_MASK_* flags.
188183static inline PyGC_Head * _PyGCHead_PREV (PyGC_Head * gc ) {
189184 uintptr_t prev = (gc -> _gc_prev & _PyGC_PREV_MASK );
190185 return (PyGC_Head * )prev ;
191186}
192-
193187static inline void _PyGCHead_SET_PREV (PyGC_Head * gc , PyGC_Head * prev ) {
194188 uintptr_t uprev = (uintptr_t )prev ;
195189 assert ((uprev & ~_PyGC_PREV_MASK ) == 0 );
@@ -275,13 +269,6 @@ struct gc_generation {
275269 generations */
276270};
277271
278- struct gc_collection_stats {
279- /* number of collected objects */
280- Py_ssize_t collected ;
281- /* total number of uncollectable objects (put into gc.garbage) */
282- Py_ssize_t uncollectable ;
283- };
284-
285272/* Running stats per generation */
286273struct gc_generation_stats {
287274 /* total number of collections */
@@ -303,8 +290,8 @@ struct _gc_runtime_state {
303290 int enabled ;
304291 int debug ;
305292 /* linked lists of container objects */
306- struct gc_generation young ;
307- struct gc_generation old [ 2 ] ;
293+ struct gc_generation generations [ NUM_GENERATIONS ] ;
294+ PyGC_Head * generation0 ;
308295 /* a permanent generation which won't be collected */
309296 struct gc_generation permanent_generation ;
310297 struct gc_generation_stats generation_stats [NUM_GENERATIONS ];
@@ -315,11 +302,7 @@ struct _gc_runtime_state {
315302 /* a list of callbacks to be invoked when collection is performed */
316303 PyObject * callbacks ;
317304
318- Py_ssize_t work_to_do ;
319- /* Which of the old spaces is the visited space */
320- int visited_space ;
321-
322- #ifdef Py_GIL_DISABLED
305+ #ifndef Py_GIL_DISABLED
323306 /* This is the number of objects that survived the last full
324307 collection. It approximates the number of long lived objects
325308 tracked by the GC.
@@ -352,8 +335,9 @@ struct _gc_thread_state {
352335
353336extern void _PyGC_InitState (struct _gc_runtime_state * );
354337
355- extern Py_ssize_t _PyGC_Collect (PyThreadState * tstate , int generation , _PyGC_Reason reason );
356- extern void _PyGC_CollectNoFail (PyThreadState * tstate );
338+ extern Py_ssize_t _PyGC_Collect (PyThreadState * tstate , int generation ,
339+ _PyGC_Reason reason );
340+ extern Py_ssize_t _PyGC_CollectNoFail (PyThreadState * tstate );
357341
358342/* Freeze objects tracked by the GC and ignore them in future collections. */
359343extern void _PyGC_Freeze (PyInterpreterState * interp );
0 commit comments