This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: storing result of a Class getField call?
- To: tromey at redhat dot com
- Subject: Re: storing result of a Class getField call?
- From: mgd at swarm dot org (Marcus G. Daniels)
- Date: 21 Jun 2001 09:18:38 -0600
- Cc: java at gcc dot gnu dot org
- References: <m2lmo0eg6l.fsf@marcus.santafe.edu> <87n179ip9o.fsf@creche.redhat.com>
>>>>> "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!