Archie Cobbs wrote:
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
Thank you, Archie, very clear explanation!
Actually Harmony classlib can be used in similar way, in Harmony's
classlib, there is a interface named as DirectBuffer, which is
implemented by all direct buffers(including MappedByteBuffer), and it
provides method to get a native address wrapper named as
PlatformAddress, which should be similar with Pointer32/64 in classpath
I believe. About the NewDirectByteBuffer, Harmony classlib can work in
similar way, create a PlatformAddress, and invoke
ReadWriteDirectBuffer's constructor.
But after all, the implementation details(class name, fields/methods,
etc) are different, so the idea is to provide the three JNI methods'
implementation in NIO module, and add them into VMI, so that VM vendor
can choose to add them into the JNI function table. I think this will
make it easier to integrate Harmony classlib and multi VMs.
Comments? ideas?
-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]
--
Paulex Yang
China Software Development Lab
IBM
---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]