changeset 5567:b43b874ea9ee

7176485: (bf) Allow temporary buffer cache to grow to IOV_MAX Reviewed-by: chegar, coffeys
author alanb
date Wed, 25 Jul 2012 05:12:10 +0100
parents c3039823f622
children 0d383753b6a0
files make/java/nio/mapfile-linux make/java/nio/mapfile-solaris src/share/classes/sun/nio/ch/IOUtil.java src/share/classes/sun/nio/ch/Util.java src/solaris/native/sun/nio/ch/FileDispatcherImpl.c src/solaris/native/sun/nio/ch/IOUtil.c src/windows/native/sun/nio/ch/IOUtil.c src/windows/native/sun/nio/ch/SocketDispatcher.c src/windows/native/sun/nio/ch/nio_util.h
diffstat 9 files changed, 34 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/make/java/nio/mapfile-linux	Tue Oct 02 13:00:49 2012 +0400
+++ b/make/java/nio/mapfile-linux	Wed Jul 25 05:12:10 2012 +0100
@@ -88,6 +88,7 @@
                 Java_sun_nio_ch_IOUtil_drain;
                 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/make/java/nio/mapfile-solaris	Tue Oct 02 13:00:49 2012 +0400
+++ b/make/java/nio/mapfile-solaris	Wed Jul 25 05:12:10 2012 +0100
@@ -76,6 +76,7 @@
                 Java_sun_nio_ch_IOUtil_drain;
                 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/src/share/classes/sun/nio/ch/IOUtil.java	Tue Oct 02 13:00:49 2012 +0400
+++ b/src/share/classes/sun/nio/ch/IOUtil.java	Wed Jul 25 05:12:10 2012 +0100
@@ -36,6 +36,11 @@
 
 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;
@@ -333,11 +342,14 @@
 
     static native void setfdVal(FileDescriptor fd, int value);
 
+    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/src/share/classes/sun/nio/ch/Util.java	Tue Oct 02 13:00:49 2012 +0400
+++ b/src/share/classes/sun/nio/ch/Util.java	Wed Jul 25 05:12:10 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/src/solaris/native/sun/nio/ch/FileDispatcherImpl.c	Tue Oct 02 13:00:49 2012 +0400
+++ b/src/solaris/native/sun/nio/ch/FileDispatcherImpl.c	Wed Jul 25 05:12:10 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/src/solaris/native/sun/nio/ch/IOUtil.c	Tue Oct 02 13:00:49 2012 +0400
+++ b/src/solaris/native/sun/nio/ch/IOUtil.c	Wed Jul 25 05:12:10 2012 +0100
@@ -144,6 +144,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 */
 
 jlong
--- a/src/windows/native/sun/nio/ch/IOUtil.c	Tue Oct 02 13:00:49 2012 +0400
+++ b/src/windows/native/sun/nio/ch/IOUtil.c	Wed Jul 25 05:12:10 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/src/windows/native/sun/nio/ch/SocketDispatcher.c	Tue Oct 02 13:00:49 2012 +0400
+++ b/src/windows/native/sun/nio/ch/SocketDispatcher.c	Wed Jul 25 05:12:10 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/src/windows/native/sun/nio/ch/nio_util.h	Tue Oct 02 13:00:49 2012 +0400
+++ b/src/windows/native/sun/nio/ch/nio_util.h	Wed Jul 25 05:12:10 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);