Paulex Yang wrote:
There is some enhancement on JNI spec in JDK 1.4[1], and three methods are related to java.nio.ByteBuffer.

   * |NewDirectByteBuffer|
<http://java.sun.com/j2se/1.4.2/docs/guide/jni/jni-14.html#NewDirectByteBuffer>

   * |GetDirectBufferAddress|
<http://java.sun.com/j2se/1.4.2/docs/guide/jni/jni-14.html#GetDirectBufferAddress>

   * |GetDirectBufferCapacity|
<http://java.sun.com/j2se/1.4.2/docs/guide/jni/jni-14.html#GetDirectBufferCapacity>

Because these methods are actually classlib dependent and JNI implementation must know some details of ByteBuffer implementation, current IBM VME hasn't them implemented, and seems DRLVM doesn't implemented thoroughly(please correct me if I made mistake here, seems DRLVM tries to get some non-api method/field of ByteBuffer, and if fails, it return NULL or -1 as JNI spec says). And I have no idea how Sable/JCHEVM/BootJVM deals with this issue yet.(anyone kindly let me know?)

FYI, here is how this is handled in Classpath-based VMs like JCHEVM.

The direct buffer classes derive from a common superclass containing
the well known fields "data" and "capacity". The latter is an int,
while the former is of type gnu.classpath.Pointer32 (or Pointer64),
which is just a container that stores a native pointer in an int/long.
The native pointer points to the native buffer. These two fields are
accessed by GetDirectBufferAddress() and GetDirectBufferCapacity().

There is also a constructor available for the JNI code to call,
taking: gnu.classpath.Pointer32/64, and int (capacity). This is
used for NewDirectByteBuffer().

The resulting JNI code is fairly simple. You can see it on line 2580 of
https://svn.apache.org/repos/asf/incubator/harmony/enhanced/jchevm/libjc/jni_native.c

-Archie

__________________________________________________________________________
Archie Cobbs      *        CTO, Awarix        *      http://www.awarix.com

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to