sun.nio.ch.DirectBuffer and jdk9/jigsaw

Vitaly Davidovich vitalyd at gmail.com
Thu Feb 23 11:30:11 UTC 2017


On Thu, Feb 23, 2017 at 5:02 AM Alan Bateman <Alan.Bateman at oracle.com>
wrote:

> On 22/02/2017 14:06, Vitaly Davidovich wrote:
>
> :
>
>
>
> Yes, I know it's never been supported.  That's been fine and it has worked
> well ... until jigsaw came into the picture.  So my real question is really
> whether there can be a proper/supported API, with good performance
> characteristics, that would give access to the base address of a direct
> bytebuffer.  In other words, can we make the notion of a direct bytebuffer
> first class? That notion would carry the base address with it (amongst
> whatever else is deemed worthwhile).
>
> NewDirectByteBuffer is used on the JNI side already, but I need something
> at the Java level to get the base address so that field offsets can be
> calculated for reading data using Unsafe (yes, another performance hack
> because officially supported Java variants currently don't JIT well
> enough).  The use case is a "view" of native memory, attached to a DBB,
> used for IPC.
>
> If you are using NewDirectByteBuffer already then couldn't you use a map
> of ByteBuffer -> address?
>
The buffers are reused by having them point to different native memory
block addresses; those blocks are managed by native code.  As mentioned,
the ByteBuffer (DirectByteBuffer concretely) is used as the Java level
interface/view of native memory, allowing Java and native code to
communicate.

I don't see the point in trying to hide the elephant in the room: the whole
notion/concept of direct byte buffer.  It's fine if the concrete
DirectByteBuffer impl is package private, but it would make sense, IMO, to
have an interface to describe such a thing abstractly; DirectBuffer seemed
like a stab at it, granted unsupported.

>
>
> -Alan
>
-- 
Sent from my phone


More information about the jigsaw-dev mailing list