This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
RE: JNI memory allocation
- From: "Boehm, Hans" <hans_boehm at hp dot com>
- To: "'Simon Gornall'" <gcj at gornall dot net>, java at gcc dot gnu dot org
- Cc: "Boehm, Hans" <hans_boehm at hp dot com>
- Date: Wed, 18 Jun 2003 14:06:53 -0700
- Subject: RE: JNI memory allocation
> -----Original Message-----
> From: Simon Gornall [mailto:gcj@gornall.net]
> Sent: Tuesday, June 17, 2003 2:33 AM
> To: java@gcc.gnu.org
> Cc: Boehm, Hans
> Subject: Re: JNI memory allocation
>
>
> Boehm, Hans wrote:
>
> >4) The collector should handle the interior pointer into the
> array object correctly,
> >but only if the pointer is in an automatic (stack) variable.
> That makes this a bit
> >brittle for my taste. _Jv_AllocBytes wouldn't have this problem.
> >
> I don't really follow what you said there...
>
> ATB,
> Simon
>
The problem is that JvNewByteArray returns a pointer to an object that contains
a header with a length field at the beginning. You're passing around a pointer
to the elements part of this object. Thus if the pointer to the array is X,
the garbage collector actually sees only a value of X+8 instead of a pointer
to the base of the array.
The collector (as configured for gcj) views X+8 as a valid pointer to X if
it finds X+8 in a register or on the stack. If it sees X+8 stored in a heap
object, it assumes it's not a pointer. This is generally the right thing,
since compiler optimizations may result in the collector seeing something
like X+8, even if the source code only uses pointers to the base of heap objects.
Hans