sun.nio.ch.DirectBuffer and jdk9/jigsaw

Vitaly Davidovich vitalyd at gmail.com
Wed Feb 22 14:06:01 UTC 2017


On Wed, Feb 22, 2017 at 8:57 AM Alan Bateman <Alan.Bateman at oracle.com>
wrote:

> On 22/02/2017 13:46, Vitaly Davidovich wrote:
>
> > Hi all,
> >
> > What's the status of this interface with respect to Java 9 (and beyond)?
> It
> > wasn't added to the critical API list of JEP 260, and thus requires an
> > addExports flag to grant access.  I have a use case where just the
> > address() method is used in performance sensitive code.  Previously, the
> > code had used a JNI call to get the address of a DirectByteBuffer, but
> > address() has superior performance particularly because the JIT
> > devirtualizes all callsites I have (they only see DBB as receivers of
> this
> > call).
> >
> > So, has the fate of this interface been decided? Am I stuck with
> addExports
> > for Java 9? Is there a medium/long term replacement? Just to reiterate,
> I'd
> > like access to the address() with as little fuss as possible, and don't
> > care about the attachment() and cleaner() methods on it.
> >
> > Also, let me know if this best addressed to the nio-dev mailing list - it
> > *is* an NIO class, but my question is really geared towards working with
> > this interface in the modular/jigsaw world.
> >
> This interface has always been JDK-internal and has never been
> documented/supported. If you have something accessing the memory
> directly then maybe it would be better if you looked after the
> allocation/deallocation yourself and use NewDirectByteBuffer to wrap the
> regions that you need for I/O operations.

Hi Alan,

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.

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


More information about the jigsaw-dev mailing list