storing result of a Class getField call?
Marcus G. Daniels
mgd@swarm.org
Sun May 13 20:56:00 GMT 2001
In some JNI code that works with Sun JDK 1.3 and Kaffe 1.0.6, I'm
stashing the results of a Class getField call in a variable and
globalrefing it. By watching the unmark_for_gc call in jni.cc I can
see that the reference to the Field is not explicitly removed from the
JNI `ref_table', however, some time after caching the result of the
getField call (when I wish to use and reuse and reuse the stashed
Field), the object that is there has changed. Often it no longer says
it is a java.lang.reflect.Field, but various other objects. Or if it
is there, any use of it results in a crash.
I'm seeing this same behavior on Intel and Sparc.
Now, if I disable garbage collection, the problem doesn't occur. Likewise,
if I do a lookup of the Field immediately adjacent to the use I wish
to make, it also works.
It seems fishy that this last workaround works as well as it does
if there is more general GC problem. Any ideas?
More information about the Java
mailing list