Home | History | Annotate | Download | only in Modules

Lines Matching refs:gc

11   http://www.arctrix.com/nas/python/gc/
31 /* Get an object's GC head */
34 /* Get the object given the GC head */
37 /*** Global GC state ***/
74 approximates the number of long lived objects tracked by the GC.
108 long-lived objects (e.g. building a large list of GC-tracked objects would
166 #define DEBUG_SAVEALL (1<<5) /* save all garbage in gc.garbage */
178 /* total number of uncollectable objects (put into gc.garbage) */
187 Between collections, every gc'ed object has one of two gc_refs values:
237 list->gc.gc_prev = list;
238 list->gc.gc_next = list;
244 return (list->gc.gc_next == list);
253 node->gc.gc_next = list;
254 node->gc.gc_prev = list->gc.gc_prev;
255 node->gc.gc_prev->gc.gc_next = node;
256 list->gc.gc_prev = node;
260 /* Remove `node` from the gc list it's currently in. */
264 node->gc.gc_prev->gc.gc_next = node->gc.gc_next;
265 node->gc.gc_next->gc.gc_prev = node->gc.gc_prev;
266 node->gc.gc_next = NULL; /* object is not currently tracked */
269 /* Move `node` from the gc list it's currently in (which is not explicitly
277 PyGC_Head *current_prev = node->gc.gc_prev;
278 PyGC_Head *current_next = node->gc.gc_next;
280 current_prev->gc.gc_next = current_next;
281 current_next->gc.gc_prev = current_prev;
283 new_prev = node->gc.gc_prev = list->gc.gc_prev;
284 new_prev->gc.gc_next = list->gc.gc_prev = node;
285 node->gc.gc_next = list;
295 tail = to->gc.gc_prev;
296 tail->gc.gc_next = from->gc.gc_next;
297 tail->gc.gc_next->gc.gc_prev = tail;
298 to->gc.gc_prev = from->gc.gc_prev;
299 to->gc.gc_prev->gc.gc_next = to;
307 PyGC_Head *gc;
309 for (gc = list->gc.gc_next; gc != list; gc = gc->gc.gc_next) {
315 /* Append objects in a GC list to a Python list.
321 PyGC_Head *gc;
322 for (gc = gc_list->gc.gc_next; gc != gc_list; gc = gc->gc.gc_next) {
323 PyObject *op = FROM_GC(gc);
337 * in containers, and is GC_REACHABLE for all tracked gc objects not in
343 PyGC_Head *gc = containers->gc.gc_next;
344 for (; gc != containers; gc = gc->gc.gc_next) {
345 assert(_PyGCHead_REFS(gc) == GC_REACHABLE);
346 _PyGCHead_SET_REFS(gc, Py_REFCNT(FROM_GC(gc)));
347 /* Python's cyclic gc should never see an incoming refcount
351 * routine left a gc-aware object tracked during its teardown
353 * that called back into Python. gc can trigger then, and may
355 * was added, such mistakes went on to allow gc to try to
365 assert(_PyGCHead_REFS(gc) != 0);
375 PyGC_Head *gc = AS_GC(op);
380 assert(_PyGCHead_REFS(gc) != 0); /* else refcount was too small */
381 if (_PyGCHead_REFS(gc) > 0)
382 _PyGCHead_DECREF(gc);
388 * for all objects in containers, and is GC_REACHABLE for all tracked gc
396 PyGC_Head *gc = containers->gc.gc_next;
397 for (; gc != containers; gc=gc->gc.gc_next) {
398 traverse = Py_TYPE(FROM_GC(gc))->tp_traverse;
399 (void) traverse(FROM_GC(gc),
410 PyGC_Head *gc = AS_GC(op);
411 const Py_ssize_t gc_refs = _PyGCHead_REFS(gc);
419 _PyGCHead_SET_REFS(gc, 1);
428 gc_list_move(gc, reachable);
429 _PyGCHead_SET_REFS(gc, 1);
451 * gc objects not in young or unreachable still have gc_refs = GC_REACHABLE.
459 PyGC_Head *gc = young->gc.gc_next;
470 while (gc != young) {
473 if (_PyGCHead_REFS(gc)) {
474 /* gc is definitely reachable from outside the
482 PyObject *op = FROM_GC(gc);
484 assert(_PyGCHead_REFS(gc) > 0);
485 _PyGCHead_SET_REFS(gc, GC_REACHABLE);
489 next = gc->gc.gc_next;
496 * assume it is. gc isn't directly reachable from
499 * visit_reachable will eventually move gc back into
502 next = gc->gc.gc_next;
503 gc_list_move(gc, unreachable);
504 _PyGCHead_SET_REFS(gc, GC_TENTATIVELY_UNREACHABLE);
506 gc = next;
514 PyGC_Head *next, *gc = head->gc.gc_next;
515 while (gc != head) {
516 PyObject *op = FROM_GC(gc);
517 next = gc->gc.gc_next;
520 gc = next;
538 PyGC_Head *gc;
544 for (gc = unreachable->gc.gc_next; gc != unreachable; gc = next) {
545 PyObject *op = FROM_GC(gc);
548 next = gc->gc.gc_next;
551 gc_list_move(gc, finalizers);
552 _PyGCHead_SET_REFS(gc, GC_REACHABLE);
563 PyGC_Head *gc = AS_GC(op);
564 gc_list_move(gc, tolist);
565 _PyGCHead_SET_REFS(gc, GC_REACHABLE);
578 PyGC_Head *gc = finalizers->gc.gc_next;
579 for (; gc != finalizers; gc = gc->gc.gc_next) {
581 traverse = Py_TYPE(FROM_GC(gc))->tp_traverse;
582 (void) traverse(FROM_GC(gc),
602 PyGC_Head *gc;
603 PyObject *op; /* generally FROM_GC(gc) */
619 for (gc = unreachable->gc.gc_next; gc != unreachable; gc = next) {
622 op = FROM_GC(gc);
624 next = gc->gc.gc_next;
703 gc = wrcb_to_call.gc.gc_next;
704 op = FROM_GC(gc);
722 * weakref was reachable to begin with, gc didn't already
730 if (wrcb_to_call.gc.gc_next == gc) {
732 gc_list_move(gc, old);
744 PySys_FormatStderr("gc: %s <%s %p>\n",
760 PyGC_Head *gc = finalizers->gc.gc_next;
765 Py_FatalError("gc couldn't create gc.garbage list");
767 for (; gc != finalizers; gc = gc->gc.gc_next) {
768 PyObject *op = FROM_GC(gc);
801 PyGC_Head *gc = collectable->gc.gc_next;
802 PyObject *op = FROM_GC(gc);
803 gc_list_move(gc, &seen);
804 if (!_PyGCHead_FINALIZED(gc) &&
807 _PyGCHead_SET_FINALIZED(gc, 1);
822 PyGC_Head *gc;
823 for (gc = collectable->gc.gc_next; gc != collectable;
824 gc = gc->gc.gc_next) {
825 _PyGCHead_SET_REFS(gc, Py_REFCNT(FROM_GC(gc)));
826 assert(_PyGCHead_REFS(gc) != 0);
829 for (gc = collectable->gc.gc_next; gc != collectable;
830 gc = gc->gc.gc_next) {
831 assert(_PyGCHead_REFS(gc) >= 0);
832 if (_PyGCHead_REFS(gc) != 0)
841 PyGC_Head *gc;
842 for (gc = collectable->gc.gc_next; gc != collectable;
843 gc = gc->gc.gc_next) {
844 _PyGCHead_SET_REFS(gc, GC_REACHABLE);
858 PyGC_Head *gc = collectable->gc.gc_next;
859 PyObject *op = FROM_GC(gc);
871 if (collectable->gc.gc_next == gc) {
873 gc_list_move(gc, old);
874 _PyGCHead_SET_REFS(gc, GC_REACHABLE);
912 PyGC_Head *gc;
918 PySys_WriteStderr("gc: collecting generation %d...\n",
920 PySys_WriteStderr("gc: objects in each generation:");
996 for (gc = unreachable.gc.gc_next; gc != &unreachable;
997 gc = gc->gc.gc_next) {
1000 debug_cycle("collectable", FROM_GC(gc));
1024 for (gc = finalizers.gc.gc_next;
1025 gc != &finalizers;
1026 gc = gc->gc.gc_next) {
1029 debug_cycle("uncollectable", FROM_GC(gc));
1035 PySys_WriteStderr("gc: done");
1038 "gc: done, %zd unreachable, %zd uncollectable",
1240 " DEBUG_SAVEALL - Save objects to gc.garbage rather than freeing them.\n"
1329 PyGC_Head *gc;
1332 for (gc = list->gc.gc_next; gc != list; gc = gc->gc.gc_next) {
1333 obj = FROM_GC(gc);
1534 "gc", /* m_name */
1582 /* API to invoke gc.collect() from C */
1636 message = "gc: %zd uncollectable objects at " \
1639 message = "gc: %zd uncollectable objects at " \
1640 "shutdown; use gc.set_debug(gc.DEBUG_UNCOLLECTABLE) to list them";
1644 if (PyErr_WarnExplicitFormat(PyExc_ResourceWarning, "gc", 0,
1645 "gc", NULL, message,
1678 /* extension modules might be compiled with GC support so these
1717 g->gc.gc_refs = 0;
1719 generations[0].count++; /* number of allocated GC objects */