@@ -9,107 +9,6 @@ extern "C" {
99#endif
1010
1111#include "pymem.h" // PyMemAllocatorName
12- #include "pycore_gc.h" // PyGC_Head
13-
14-
15- /* GC runtime state */
16-
17- /* If we change this, we need to change the default value in the
18- signature of gc.collect. */
19- #define NUM_GENERATIONS 3
20- /*
21- NOTE: about untracking of mutable objects.
22-
23- Certain types of container cannot participate in a reference cycle, and
24- so do not need to be tracked by the garbage collector. Untracking these
25- objects reduces the cost of garbage collections. However, determining
26- which objects may be untracked is not free, and the costs must be
27- weighed against the benefits for garbage collection.
28-
29- There are two possible strategies for when to untrack a container:
30-
31- i) When the container is created.
32- ii) When the container is examined by the garbage collector.
33-
34- Tuples containing only immutable objects (integers, strings etc, and
35- recursively, tuples of immutable objects) do not need to be tracked.
36- The interpreter creates a large number of tuples, many of which will
37- not survive until garbage collection. It is therefore not worthwhile
38- to untrack eligible tuples at creation time.
39-
40- Instead, all tuples except the empty tuple are tracked when created.
41- During garbage collection it is determined whether any surviving tuples
42- can be untracked. A tuple can be untracked if all of its contents are
43- already not tracked. Tuples are examined for untracking in all garbage
44- collection cycles. It may take more than one cycle to untrack a tuple.
45-
46- Dictionaries containing only immutable objects also do not need to be
47- tracked. Dictionaries are untracked when created. If a tracked item is
48- inserted into a dictionary (either as a key or value), the dictionary
49- becomes tracked. During a full garbage collection (all generations),
50- the collector will untrack any dictionaries whose contents are not
51- tracked.
52-
53- The module provides the python function is_tracked(obj), which returns
54- the CURRENT tracking status of the object. Subsequent garbage
55- collections may change the tracking status of the object.
56-
57- Untracking of certain containers was introduced in issue #4688, and
58- the algorithm was refined in response to issue #14775.
59- */
60-
61- struct gc_generation {
62- PyGC_Head head ;
63- int threshold ; /* collection threshold */
64- int count ; /* count of allocations or collections of younger
65- generations */
66- };
67-
68- /* Running stats per generation */
69- struct gc_generation_stats {
70- /* total number of collections */
71- Py_ssize_t collections ;
72- /* total number of collected objects */
73- Py_ssize_t collected ;
74- /* total number of uncollectable objects (put into gc.garbage) */
75- Py_ssize_t uncollectable ;
76- };
77-
78- struct _gc_runtime_state {
79- /* List of objects that still need to be cleaned up, singly linked
80- * via their gc headers' gc_prev pointers. */
81- PyObject * trash_delete_later ;
82- /* Current call-stack depth of tp_dealloc calls. */
83- int trash_delete_nesting ;
84-
85- int enabled ;
86- int debug ;
87- /* linked lists of container objects */
88- struct gc_generation generations [NUM_GENERATIONS ];
89- PyGC_Head * generation0 ;
90- /* a permanent generation which won't be collected */
91- struct gc_generation permanent_generation ;
92- struct gc_generation_stats generation_stats [NUM_GENERATIONS ];
93- /* true if we are currently running the collector */
94- int collecting ;
95- /* list of uncollectable objects */
96- PyObject * garbage ;
97- /* a list of callbacks to be invoked when collection is performed */
98- PyObject * callbacks ;
99- /* This is the number of objects that survived the last full
100- collection. It approximates the number of long lived objects
101- tracked by the GC.
102-
103- (by "full collection", we mean a collection of the oldest
104- generation). */
105- Py_ssize_t long_lived_total ;
106- /* This is the number of objects that survived all "non-full"
107- collections, and are awaiting to undergo a full collection for
108- the first time. */
109- Py_ssize_t long_lived_pending ;
110- };
111-
112- PyAPI_FUNC (void ) _PyGC_InitState (struct _gc_runtime_state * );
11312
11413
11514/* Set the memory allocator of the specified domain to the default.
0 commit comments