[Gc] segmentation violation

Scott L. Burson Scott at solidcore.com
Mon Nov 29 12:59:41 PST 2004


On Mon November 29 2004 10:50 am, Boehm, Hans wrote:
> It's unfortunately, not very surprising that this fails.  Mixing garbage
> collectors is tricky, to say the least.  Problems include:

> - You need each GC to treat the other heaps as roots

I'll hazard a guess that pointers from the C heap back to the Java heap are 
not an issue.  If that's right, then you could maintain an explicit rootset 
on the C side, with each entry proxied by a Java object.  A finalizer on that 
object would delete the corresponding entry in the C rootset.  (Actually, 
this can be done in both directions, but you have to be careful not to create 
cycles spanning the two heaps, as Hans points out.)

But the coexistence problems may be insurmountable.

Seems to me the big question here is how much code is involved, and how much 
of it you control.  If you're trying to interface two substantial existing 
subsystems, one of which was built to use the Boehm GC, I think you'll 
probably have to put them in separate processes with some form of IPC.  If, 
however, you're writing the JNI library yourself, perhaps you could get by 
with less than a fully general GC.  For instance, if you can restrict the set 
of heap objects which you need to collect (by doing manual deallocation on 
the remainder), and you can live with explicitly invoking the collection at 
particular points in your code where you know no local variables point to any 
of the objects in question, you can write a very simple mark-sweep collector 
yourself.

-- Scott


More information about the Gc mailing list