Re: [Gc] Is there a way to walk the entire heap of live objects
Bruce Hoult <[email protected]> Fri, 6 Jun 2014 16:41:16 +1200
| Newsgroups | gmane.comp.programming.garbage-collection.boehmgc |
|---|---|
| Message-ID | <CAMU+EkzF9b2T+Vzs0PO_Z1FOG2kOasmty3pQ9-s7Ym3ytnJVQA@mail.gmail.com> |
Right. Without thinking hard about every line that looks plausible (and it must be pretty ok if it's working for you), and effectively uses the end results of the last GC mark phase. One thing, I expect it'll miss anything you've allocated since the last GC. The object order will also be pretty random — in a fresh heap each block will have objects in order of allocation of objects of that size. Once there's been some churn it'll be a lot more mixed up. My idea (which I should mention I haven't tested), will give some approximation to a pre-order traversal of the object graph. Actually, if you want to recreate the DAG, it might be more useful to put your debug callback *before* the SET_MARK_BIT_EXIT_IF_SET line. On Fri, Jun 6, 2014 at 4:16 PM, Peter Wang <[email protected]> wrote: > On Thu, 05 Jun 2014 07:57:53 -0400, Christian Schafmeister < > [email protected]> wrote: > > Hi there, > > > > Is there any functionality in the Boehm GC that would allow me to > > freeze the garbage collector and walk the heap of live objects? I’d > > like to take an inventory of all of the live objects to determine the > > source of my current memory problems (30 GB of virtual memory used > > after 4 hours of runtime). > > Hi, > > We do something like that in the Mercury project using the following > function. > > I am not an expert on Boehm GC internals, and the code is only used in a > special memory profiling grade, so not heavily exercised. > Please let me know if there is something wrong with it. > > Peter > > (in reclaim.c) > > STATIC void GC_mercury_do_enumerate_reachable_objects(struct hblk *hbp, > word dummy) > { > struct hblkhdr * hhdr = HDR(hbp); > size_t sz = hhdr -> hb_sz; > size_t bit_no; > char *p, *plim; > > if (GC_block_empty(hhdr)) { > return; > } > > p = hbp->hb_body; > bit_no = 0; > if (sz > MAXOBJBYTES) { /* one big object */ > plim = p; > } else { > plim = hbp->hb_body + HBLKSIZE - sz; > } > /* Go through all words in block. */ > while (p <= plim) { > if (mark_bit_from_hdr(hhdr, bit_no)) { > GC_mercury_callback_reachable_object((GC_word *)p, > BYTES_TO_WORDS(sz)); > } > bit_no += MARK_BIT_OFFSET(sz); > p += sz; > } > } > > GC_INNER void GC_mercury_enumerate_reachable_objects(void) > { > GC_ASSERT(GC_mercury_callback_reachable_object); > GC_apply_to_all_blocks(GC_mercury_do_enumerate_reachable_objects, > (word)0); > } > _______________________________________________ > bdwgc mailing list > [email protected] > https://lists.opendylan.org/mailman/listinfo/bdwgc > -- > This message has been scanned for viruses and > dangerous content by MailScanner, and is > believed to be clean. > > _______________________________________________ bdwgc mailing list [email protected] https://lists.opendylan.org/mailman/listinfo/bdwgc