classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cp-patches] Bug in java_nio_VMDirectByteBuffer.c


From: Archie Cobbs
Subject: Re: [cp-patches] Bug in java_nio_VMDirectByteBuffer.c
Date: Wed, 16 Mar 2005 08:48:29 -0600
User-agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.3) Gecko/20041129

Michael Koch wrote:
        * native/jni/java-nio/java_nio_VMDirectByteBuffer.c: use
        global native reference to wrap persistent jclass variable.

Thanks, Looks good. Can you point me to some explaining links on the web
for this? All I found via goolge was not very well explaining. I think
there are much more of these bugs in out JNI code and more in my
upcoming new code. Perhaps I can fix them before commiting new code when
I understand this more.

Here's the JNI spec section talking about references:

  http://java.sun.com/j2se/1.4.2/docs/guide/jni/spec/design.html#wp16785

One thing that's not immediately obvious from the JNI spec, but is obvious
once you read the details, is that a 'jclass' is the same as a 'jobject',
except that it is assumed to refer to a java.lang.Class object. This is
different from jfieldID and jmethodID which are "opaque" types [1].

Another common problem is using too many local native references, e.g.,
when creating and populating an array. You only get 16, and have to use
DeleteLocalRef() to free up the ones you don't need anymore.

By the way, my patch is not completely correct, because it never frees
the global reference. The only way to properly do that would be to write
a JNI_OnUnload() function and do it there. But in practice it will never
matter because libjavanio is going to be loaded by the bootstrap class
loader, which never gets unloaded.

-Archie

[1] Note that native code is responsible for maintaining a reference to
the associated class, to avoid it from being unloaded, while using jfieldID
and jmethodID variables:

  http://java.sun.com/j2se/1.4.2/docs/guide/jni/spec/design.html#wp17074
__________________________________________________________________________
Archie Cobbs      *        CTO, Awarix        *      http://www.awarix.com




reply via email to

[Prev in Thread] Current Thread [Next in Thread]