[Gc] Debugging: getting a list of objects in use dumped

Thomas Aeby aeby at graeff.com
Thu Feb 19 10:41:40 PST 2004


I'm trying to find out why one of my programs is badly leaking memory.
Since it's a GCJ compiled program and therefore memory allocation
is under control of Boehm GC my approach was to just add some
code dumping out a list of objects in use from time to time in the hope
that this will show me what objects might refuse to get collected.

Since I'm not very familiar with this GC implementation I just browsed
through the GC sources and came up with the following naive approach:

void _print_blockinfo( void *blkstart, int data ) {
    int at;

    int *starts = ((int *)blkstart);
    struct header *hdr = (struct header *)GC_find_header( blkstart );
    fprintf( stdout, "block at %X with object size %d\n", starts,
hdr->hb_sz*4 );
    for( at=0; (at + hdr->hb_sz <= BLOCKSZ) || !at; starts +=
hdr->hb_sz, at += hdr->hb_sz ) {
/*      if( mark_bit_from_hdr( hdr, at ) ) */
        if( GC_is_marked( starts ) )
          fprintf( stdout, "  object at %X starts with %X, size %d\n",
(int)starts, *starts, hdr->hb_sz*4 );

I'm using _print_blockinfo together with a call to

Well, this indeed prints out a huge list of objects which look like
real objects (wrote a little perl script trying to determine the
java class of each object - and the output looks ok).

Unfortunately I'm quite unsure if my approach really only lists the
objects in question since what I'm seeing are numerous objects that
I cannot imagine any reason why they shouldn't be collected for.

The program in question basically is a daemon doing some work from time
to time and having large periods of idling in between. I hoped that
even without caring about synchronization issues (incremental marking?!)
I might get a valid list. I also tried forcing a complete collection
just before dumping the object list - but haven't actually found out
how you force GC to do a complete mark (tried GC_collect_in_progress()
and GC_malloc() in a loop but I'm sure this is not the good(TM) way :-))

Does this code look like something that could do the job? Have you got
any hints on how I could get a list of objects in use otherwise?

BTW: I'm trying to do this without re-compiling GCJ - therefore any
changes directly made in the GC code is a no-no (at the moment ;-)).
The above procedure works linked to my program.

Many thanks in advance for any helping hand!

Best regards,

Thomas Aeby, Kirchweg 40, 1735 Giffers, Switzerland, Voice : (+41)26
Internet: aeby at graeff.com                           PGP public key
A LISP programmer knows the value of everything, but the cost of

More information about the Gc mailing list