@@ -64,6 +64,26 @@ static inline int _PyObject_GC_MAY_BE_TRACKED(PyObject *obj) {
64
64
#define _PyGC_PREV_SHIFT (2)
65
65
#define _PyGC_PREV_MASK (((uintptr_t) -1) << _PyGC_PREV_SHIFT)
66
66
67
+ /* set for debugging information */
68
+ #define _PyGC_DEBUG_STATS (1<<0) /* print collection statistics */
69
+ #define _PyGC_DEBUG_COLLECTABLE (1<<1) /* print collectable objects */
70
+ #define _PyGC_DEBUG_UNCOLLECTABLE (1<<2) /* print uncollectable objects */
71
+ #define _PyGC_DEBUG_SAVEALL (1<<5) /* save all garbage in gc.garbage */
72
+ #define _PyGC_DEBUG_LEAK _PyGC_DEBUG_COLLECTABLE | \
73
+ _PyGC_DEBUG_UNCOLLECTABLE | \
74
+ _PyGC_DEBUG_SAVEALL
75
+
76
+ typedef enum {
77
+ // GC was triggered by heap allocation
78
+ _Py_GC_REASON_HEAP ,
79
+
80
+ // GC was called during shutdown
81
+ _Py_GC_REASON_SHUTDOWN ,
82
+
83
+ // GC was called by gc.collect() or PyGC_Collect()
84
+ _Py_GC_REASON_MANUAL
85
+ } _PyGC_Reason ;
86
+
67
87
// Lowest bit of _gc_next is used for flags only in GC.
68
88
// But it is always 0 for normal code.
69
89
static inline PyGC_Head * _PyGCHead_NEXT (PyGC_Head * gc ) {
@@ -203,8 +223,19 @@ struct _gc_runtime_state {
203
223
204
224
extern void _PyGC_InitState (struct _gc_runtime_state * );
205
225
226
+ extern Py_ssize_t _PyGC_Collect (PyThreadState * tstate , int generation ,
227
+ _PyGC_Reason reason );
206
228
extern Py_ssize_t _PyGC_CollectNoFail (PyThreadState * tstate );
207
229
230
+ /* Freeze objects tracked by the GC and ignore them in future collections. */
231
+ extern void _PyGC_Freeze (PyInterpreterState * interp );
232
+ /* Unfreezes objects placing them in the oldest generation */
233
+ extern void _PyGC_Unfreeze (PyInterpreterState * interp );
234
+ /* Number of frozen objects */
235
+ extern Py_ssize_t _PyGC_GetFreezeCount (PyInterpreterState * interp );
236
+
237
+ extern PyObject * _PyGC_GetObjects (PyInterpreterState * interp , Py_ssize_t generation );
238
+ extern PyObject * _PyGC_GetReferrers (PyInterpreterState * interp , PyObject * objs );
208
239
209
240
// Functions to clear types free lists
210
241
extern void _PyTuple_ClearFreeList (PyInterpreterState * interp );
0 commit comments