7176485: (bf) Allow temporary buffer cache to grow to IOV_MAX
authoralanb
Fri, 15 Jun 2012 17:16:25 +0100
changeset 13024 ada1a7c54e84
parent 13023 2bb2271eadf6
child 13025 e070f58ad775
7176485: (bf) Allow temporary buffer cache to grow to IOV_MAX Reviewed-by: chegar, coffeys
jdk/make/java/nio/mapfile-linux
jdk/make/java/nio/mapfile-solaris
jdk/src/share/classes/sun/nio/ch/IOUtil.java
jdk/src/share/classes/sun/nio/ch/Util.java
jdk/src/solaris/native/sun/nio/ch/FileDispatcherImpl.c
jdk/src/solaris/native/sun/nio/ch/IOUtil.c
jdk/src/windows/native/sun/nio/ch/IOUtil.c
jdk/src/windows/native/sun/nio/ch/SocketDispatcher.c
jdk/src/windows/native/sun/nio/ch/nio_util.h
--- a/jdk/make/java/nio/mapfile-linux	Fri Jun 15 09:16:18 2012 -0400
+++ b/jdk/make/java/nio/mapfile-linux	Fri Jun 15 17:16:25 2012 +0100
@@ -88,6 +88,7 @@
                 Java_sun_nio_ch_IOUtil_fdVal;
 		Java_sun_nio_ch_IOUtil_fdLimit;
                 Java_sun_nio_ch_IOUtil_initIDs;
+		Java_sun_nio_ch_IOUtil_iovMax;
                 Java_sun_nio_ch_IOUtil_makePipe;
                 Java_sun_nio_ch_IOUtil_randomBytes;
                 Java_sun_nio_ch_IOUtil_setfdVal;
--- a/jdk/make/java/nio/mapfile-solaris	Fri Jun 15 09:16:18 2012 -0400
+++ b/jdk/make/java/nio/mapfile-solaris	Fri Jun 15 17:16:25 2012 +0100
@@ -76,6 +76,7 @@
 		Java_sun_nio_ch_IOUtil_fdLimit;
                 Java_sun_nio_ch_IOUtil_fdVal;
                 Java_sun_nio_ch_IOUtil_initIDs;
+		Java_sun_nio_ch_IOUtil_iovMax;
                 Java_sun_nio_ch_IOUtil_makePipe;
                 Java_sun_nio_ch_IOUtil_randomBytes;
                 Java_sun_nio_ch_IOUtil_setfdVal;
--- a/jdk/src/share/classes/sun/nio/ch/IOUtil.java	Fri Jun 15 09:16:18 2012 -0400
+++ b/jdk/src/share/classes/sun/nio/ch/IOUtil.java	Fri Jun 15 17:16:25 2012 +0100
@@ -36,6 +36,11 @@
 
 public class IOUtil {
 
+    /**
+     * Max number of iovec structures that readv/writev supports
+     */
+    static final int IOV_MAX;
+
     private IOUtil() { }                // No instantiation
 
     static int write(FileDescriptor fd, ByteBuffer src, long position,
@@ -111,7 +116,8 @@
 
             // Iterate over buffers to populate native iovec array.
             int count = offset + length;
-            for (int i=offset; i<count; i++) {
+            int i = offset;
+            while (i < count && iov_len < IOV_MAX) {
                 ByteBuffer buf = bufs[i];
                 int pos = buf.position();
                 int lim = buf.limit();
@@ -135,6 +141,7 @@
                     vec.putLen(iov_len, rem);
                     iov_len++;
                 }
+                i++;
             }
             if (iov_len == 0)
                 return 0L;
@@ -240,7 +247,8 @@
 
             // Iterate over buffers to populate native iovec array.
             int count = offset + length;
-            for (int i=offset; i<count; i++) {
+            int i = offset;
+            while (i < count && iov_len < IOV_MAX) {
                 ByteBuffer buf = bufs[i];
                 if (buf.isReadOnly())
                     throw new IllegalArgumentException("Read-only buffer");
@@ -264,6 +272,7 @@
                     vec.putLen(iov_len, rem);
                     iov_len++;
                 }
+                i++;
             }
             if (iov_len == 0)
                 return 0L;
@@ -336,11 +345,14 @@
 
     static native int fdLimit();
 
+    static native int iovMax();
+
     static native void initIDs();
 
     static {
         // Note that IOUtil.initIDs is called from within Util.load.
         Util.load();
+        IOV_MAX = iovMax();
     }
 
 }
--- a/jdk/src/share/classes/sun/nio/ch/Util.java	Fri Jun 15 09:16:18 2012 -0400
+++ b/jdk/src/share/classes/sun/nio/ch/Util.java	Fri Jun 15 17:16:25 2012 +0100
@@ -45,7 +45,7 @@
     // -- Caches --
 
     // The number of temp buffers in our pool
-    private static final int TEMP_BUF_POOL_SIZE = 8;
+    private static final int TEMP_BUF_POOL_SIZE = IOUtil.IOV_MAX;
 
     // Per-thread cache of temporary direct buffers
     private static ThreadLocal<BufferCache> bufferCache =
--- a/jdk/src/solaris/native/sun/nio/ch/FileDispatcherImpl.c	Fri Jun 15 09:16:18 2012 -0400
+++ b/jdk/src/solaris/native/sun/nio/ch/FileDispatcherImpl.c	Fri Jun 15 17:16:25 2012 +0100
@@ -94,9 +94,6 @@
 {
     jint fd = fdval(env, fdo);
     struct iovec *iov = (struct iovec *)jlong_to_ptr(address);
-    if (len > 16) {
-        len = 16;
-    }
     return convertLongReturnVal(env, readv(fd, iov, len), JNI_TRUE);
 }
 
@@ -126,9 +123,6 @@
 {
     jint fd = fdval(env, fdo);
     struct iovec *iov = (struct iovec *)jlong_to_ptr(address);
-    if (len > 16) {
-        len = 16;
-    }
     return convertLongReturnVal(env, writev(fd, iov, len), JNI_FALSE);
 }
 
--- a/jdk/src/solaris/native/sun/nio/ch/IOUtil.c	Fri Jun 15 09:16:18 2012 -0400
+++ b/jdk/src/solaris/native/sun/nio/ch/IOUtil.c	Fri Jun 15 17:16:25 2012 +0100
@@ -136,6 +136,16 @@
     }
 }
 
+JNIEXPORT jint JNICALL
+Java_sun_nio_ch_IOUtil_iovMax(JNIEnv *env, jclass this)
+{
+    jlong iov_max = sysconf(_SC_IOV_MAX);
+    if (iov_max == -1)
+        iov_max = 16;
+    return (jint)iov_max;
+}
+
+
 /* Declared in nio_util.h for use elsewhere in NIO */
 
 jint
--- a/jdk/src/windows/native/sun/nio/ch/IOUtil.c	Fri Jun 15 09:16:18 2012 -0400
+++ b/jdk/src/windows/native/sun/nio/ch/IOUtil.c	Fri Jun 15 17:16:25 2012 +0100
@@ -41,9 +41,6 @@
 /* field id for jint 'fd' in java.io.FileDescriptor used for socket fds */
 static jfieldID fd_fdID;
 
-/* false for 95/98/ME, true for NT/W2K */
-static jboolean onNT = JNI_FALSE;
-
 JNIEXPORT jboolean JNICALL
 Java_sun_security_provider_NativeSeedGenerator_nativeGenerateSeed
 (JNIEnv *env, jclass clazz, jbyteArray randArray);
@@ -55,13 +52,6 @@
 JNIEXPORT void JNICALL
 Java_sun_nio_ch_IOUtil_initIDs(JNIEnv *env, jclass clazz)
 {
-    OSVERSIONINFO ver;
-    ver.dwOSVersionInfoSize = sizeof(ver);
-    GetVersionEx(&ver);
-    if (ver.dwPlatformId == VER_PLATFORM_WIN32_NT) {
-        onNT = JNI_TRUE;
-    }
-
     clazz = (*env)->FindClass(env, "java/io/FileDescriptor");
     fd_fdID = (*env)->GetFieldID(env, clazz, "fd", "I");
     handle_fdID = (*env)->GetFieldID(env, clazz, "handle", "J");
@@ -80,6 +70,13 @@
                                                                     randArray);
 }
 
+JNIEXPORT jint JNICALL
+Java_sun_nio_ch_IOUtil_iovMax(JNIEnv *env, jclass this)
+{
+    return 16;
+}
+
+
 jint
 convertReturnVal(JNIEnv *env, jint n, jboolean reading)
 {
@@ -205,9 +202,3 @@
 {
     return (*env)->GetLongField(env, fdo, handle_fdID);
 }
-
-jboolean
-isNT()
-{
-    return onNT;
-}
--- a/jdk/src/windows/native/sun/nio/ch/SocketDispatcher.c	Fri Jun 15 09:16:18 2012 -0400
+++ b/jdk/src/windows/native/sun/nio/ch/SocketDispatcher.c	Fri Jun 15 17:16:25 2012 +0100
@@ -97,10 +97,6 @@
         return IOS_THROWN;
     }
 
-    if ((isNT() == JNI_FALSE) && (len > 16)) {
-        len = 16;
-    }
-
     /* copy iovec into WSABUF */
     for(i=0; i<len; i++) {
         jint iov_len = iovp[i].iov_len;
@@ -208,10 +204,6 @@
         return IOS_THROWN;
     }
 
-    if ((isNT() == JNI_FALSE) && (len > 16)) {
-        len = 16;
-    }
-
     /* copy iovec into WSABUF */
     for(i=0; i<len; i++) {
         jint iov_len = iovp[i].iov_len;
--- a/jdk/src/windows/native/sun/nio/ch/nio_util.h	Fri Jun 15 09:16:18 2012 -0400
+++ b/jdk/src/windows/native/sun/nio/ch/nio_util.h	Fri Jun 15 17:16:25 2012 +0100
@@ -35,7 +35,6 @@
 
 jint fdval(JNIEnv *env, jobject fdo);
 jlong handleval(JNIEnv *env, jobject fdo);
-jboolean isNT();
 jint convertReturnVal(JNIEnv *env, jint n, jboolean r);
 jlong convertLongReturnVal(JNIEnv *env, jlong n, jboolean r);
 jboolean purgeOutstandingICMP(JNIEnv *env, jclass clazz, jint fd);