Proposal for adding O_DIRECT support into JDK 9

Brian Burkhalter brian.burkhalter at oracle.com
Fri Sep 1 19:09:06 UTC 2017


Hi Lucy,

DirectIOTest fails for me on Linux, macOS, and Solaris with the message "java.lang.UnsatisfiedLinkError: no DirectIO in java.library.path.”

There is a compilation error on Windows which is fixed by the patch included below. With this patch applied however the four read/write direct tests fail with this error:

java.lang.IllegalArgumentException: Unit size not a power of two: -1
	at java.base/java.nio.ByteBuffer.alignmentOffset(ByteBuffer.java:1659)
	at java.base/java.nio.ByteBuffer.alignedSlice(ByteBuffer.java:1729)
	at java.base/sun.nio.ch.Util.getTemporaryAlignedDirectBuffer(Util.java:263)
	at java.base/sun.nio.ch.IOUtil.write(IOUtil.java:72)
	at java.base/sun.nio.ch.FileChannelImpl.write(FileChannelImpl.java:277)

Thanks,

Brian

On Aug 31, 2017, at 3:49 PM, Lu, Yingqi <yingqi.lu at intel.com> wrote:

> 1.      Following the example of stringPlatformChars, made the DirectIOTest native library being compiled automatically. Removed DirectIOTest.java, README file and Makefile.

--- a/src/java.base/windows/classes/sun/nio/ch/FileDispatcherImpl.java
+++ b/src/java.base/windows/classes/sun/nio/ch/FileDispatcherImpl.java
@@ -132,7 +132,7 @@
         CharBuffer buffer = CharBuffer.allocate(filePath.length());
         buffer.put(filePath);
         try {
-            result = setDirect0(buffer);
+            result = setDirect0(fd, buffer);
         } catch (IOException e) {
             throw new UnsupportedOperationException
                 ("Error setting up DirectIO", e);
@@ -195,5 +195,6 @@

     static native long duplicateHandle(long fd) throws IOException;

-    static native int setDirect0(CharBuffer buffer) throws IOException;
+    static native int setDirect0(FileDescriptor fd, CharBuffer buffer)
+        throws IOException;
 }
--- a/src/java.base/windows/native/libnio/ch/FileDispatcherImpl.c
+++ b/src/java.base/windows/native/libnio/ch/FileDispatcherImpl.c
@@ -459,11 +459,11 @@

 JNIEXPORT jint JNICALL
 Java_sun_nio_ch_FileDispatcherImpl_setDirect0(JNIEnv *env, jclass this,
-                                           jobject buffer)
+                                              jobject fdObj, jobject buffer)
 {
     jint result = -1;

-    HANDLE orig = (HANDLE)(handleval(env, fObj));
+    HANDLE orig = (HANDLE)(handleval(env, fdObj));

     HANDLE modify = ReOpenFile(orig, 0, 0,
             FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH);

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20170901/b36ac24f/attachment.html>


More information about the nio-dev mailing list