Chris Toshok wrote:
> precise gc is impossible with the possibility of arbitrary C code in native
> methods.
I don't think that's true. The stuff about local and global references in
the JNI spec makes provisions for this. Each reference that's passed into
a native method gets pushed onto a list of local references, and then
removed from that list when the method returns. If the native method
copies the reference somewhere else, and expects it not to be
garbage-collected, it needs to mark it as a global reference using the
provided routines. These lists of local and global references count as
part of the "root set" for garbage collection.
When a native method does something that retrieves a reference
(GetObjectField, etc.), that reference should be added to its list of
local references, too.
When the method exits, the _references_ on the local references list go
away, but not the objects themselves (although an object could go away if
the local reference was the last reference to it). I seem to remember
that there was some confusion about this before-- the spec may not be
worded very well, but this is clearly what they mean if the whole thing is
work at all.