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

Alec Orr Alec.Orr at wbemsolutions.com
Thu Feb 19 14:44:53 PST 2004


Thomas:

There maybe some simpler ways here to do what you want:

1.  There is a function GC_dump() which will display the memory layout. 
        I can't remember if it's included in gc.h, but if not, you can 
prototype it as follows, then call it:

void GC_dump(void);

2.  You can use the garbage collector is a leak detector (which will 
give the address of objects not cleaned since the last call to 
GC_gcollect() ).  To do this:

a. insert the following early in your code:

   GC_find_leak = 1

b.  set the environment variable GC_PRINT_STATS=1

As your module runs, and a garbage collect occurs, you should see 
something like:

Leaked composite object at 0x8094fb0
Leaked composite object at 0x8094fb8

I hope this helps,
Alec


Thomas Aeby wrote:

> Greetings!
> 
> 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
> GC_apply_to_all_blocks.
> 
> 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,
> Tom
> 




More information about the Gc mailing list