Proposal for adding O_DIRECT support into JDK 9

Lu, Yingqi at
Wed Nov 2 23:34:49 UTC 2016

Hi All,

Our most recent DirectIO patch is available at

In this version, we made following changes:

1. Removed the flag "direct" from FileDescriptor class. Instead, moved it to the FileChannelImpl class.

2. Provided a way for user to allocate a page aligned direct ByteBuffer.
    1) Added a constructor DirectByteBuffer(int cap, boolean direct) to allocate a direct ByteBuffer that is aligned to the page size. 
    2) Added Util.getTemporaryAlignedDirectBuffer(int size)
    3) Added DirectByteBuffer.isAligned(int pos) to check if the buffer is aligned before doing native IO with it.

3. Moved all the alignment check from C code to Java code (mainly FileChannelImpl and

4. Made the DirectIO functionality consistent between read and write operations. With current version of the patch, user would be responsible for the alignment with file offset and IO size. 

5. Made the API for DirectIO more extensible to all the supporting platforms.
    1) Unix OS specific code are done through and FileChannelImpl.c.
    2) Coded and tested for Linux and OS X (OS X testing is done through VirtualBox with OS X VM on top of Linux OS).
    3) Coded for Solaris. We do not have environment to test it so that we commented the changes out. 

6. We added 4 test cases following the existing non-direct IO examples.

7. We did jtreg test for the entire nio package and no errors were found due to our changes.

Please let us know your feedback and comment. Thank you very much for your time and consideration!


>-----Original Message-----
>From: Alan Bateman [mailto:Alan.Bateman at]
>Sent: Monday, October 17, 2016 7:59 AM
>To: Lu, Yingqi < at>
>Cc: nio-dev at; Kaczmarek, Eric <eric.kaczmarek at>;
>Kharbas, Kishor <kishor.kharbas at>
>Subject: Re: Proposal for adding O_DIRECT support into JDK 9
>On 12/10/2016 17:41, Lu, Yingqi wrote:
>> :
>> You are correct about the "extra copy" with DirectIO. Will it be acceptable if we
>add a function "Util.getAlignedTemporaryDirectBuffer" and use that for the
>DirectIO operation? In this case, I think we should be able to avoid the additional
>Yes, that should work but it still lacks a way for the user to get an aligned buffer
>and so you will always be copying in and out of an aligned buffer. The other thing
>is the sizing of the I/O operation where I think you will also need a way to expose
>the multiple (or block size) to the user.

More information about the nio-dev mailing list