storing result of a Class getField call?
Marcus G. Daniels
mgd@swarm.org
Thu Jun 21 08:17:00 GMT 2001
>>>>> "Tom" == Tom Tromey <tromey@redhat.com> writes:
Marcus> In some JNI code that works with Sun JDK 1.3 and Kaffe 1.0.6,
Marcus> I'm stashing the results of a Class getField call in a
Marcus> variable and globalrefing it. By watching the unmark_for_gc
Marcus> call in jni.cc I can see that the reference to the Field is
Marcus> not explicitly removed from the JNI `ref_table', however, some
Marcus> time after caching the result of the getField call (when I
Marcus> wish to use and reuse and reuse the stashed Field), the object
Marcus> that is there has changed.
Tom> Offhand I couldn't say what is going on here. Given that it
Tom> works when you disable GC, I would guess that the object is being
Tom> collected.
I found that the problem was that I was holding references to Java
objects in malloced space. Even though these objects weren't been
dropped because ref_table was keeping them around, component objects
(e.g. Field objects) were moving around out from under my C-side references.
Now that I'm using GC_malloc_uncollectable instead of malloc,
GC_realloc instead of realloc, and GC_free instead of free, things are
working great under x86-linux with both GCC 3.0 and the branch.
Thanks!
More information about the Java
mailing list