[Gc] Can unions 'fool' the garbage collector?

Boehm, Hans hans.boehm at hp.com
Thu Jun 17 14:38:50 PDT 2004

This should be impossible.  The collector doesn't look at debug information
and has no way to even tell that there's a union on the stack.  (It knows about
the layout of heap objects only if you tell it.)  All it sees are bits.

If the presence of the union really makes a difference, I'd suspect a
compiler alignment bug.  But that seems unlikely, and easy to exclude
by looking at the address of the char * member.

There have been some bugs fixed since 6.2 that could conceivably cause
such a problem, at least if it's independent of the presence of the union.
But that also doesn't sound that likely to me.  I'm not sure what's
really going on.  If it's easy to try 6.3alpha6 that might help.

To debug this, you can start with a breakpoint in GC_finish_collection,
check that the pointer is really on the stack somewhere, and that
GC_is_marked(lost object) returns zero.


> -----Original Message-----
> From: gc-bounces at napali.hpl.hp.com
> [mailto:gc-bounces at napali.hpl.hp.com]On Behalf Of Alec Orr
> Sent: Thursday, June 17, 2004 2:17 PM
> To: gc at napali.hpl.hp.com
> Subject: [Gc] Can unions 'fool' the garbage collector? 
> Folks:
>    RH Linux 9.0
>    GC 6.2 (Still meaning to upgrade to 6.3)
>    No memory redirection.
>    Posix threads.
>    enable full debug/enable assertions
> Has anyone seen the following behavior with C unions?
> Declare a structure S with a union member on the stack
> GC_MALLOC returns address X
> Address X is assigned to a char* member of the union.
> Full World Garbage Collect.
> GC_MALLOC returns address X again (i.e the GC thinks address X is not 
> 'in-use').
> A subsequent free shows:
> GC_debug_free: found previously deallocated (?) object at 
> 0x805deb0 in 
> object at 0x805deb8 (<smashed>, appr. sz = 5)
> Anyone seen anything like this?
> Thanks folks,
> Alec Orr
> _______________________________________________
> Gc mailing list
> Gc at linux.hpl.hp.com
> https://www.hpl.hp.com/hosted/linux/mail-archives/gc/

More information about the Gc mailing list