提交 8cae9bc7 编写于 作者: A alanb

7176485: (bf) Allow temporary buffer cache to grow to IOV_MAX

Reviewed-by: chegar, coffeys
上级 6bb8ec25
...@@ -88,6 +88,7 @@ SUNWprivate_1.1 { ...@@ -88,6 +88,7 @@ SUNWprivate_1.1 {
Java_sun_nio_ch_IOUtil_fdVal; Java_sun_nio_ch_IOUtil_fdVal;
Java_sun_nio_ch_IOUtil_fdLimit; Java_sun_nio_ch_IOUtil_fdLimit;
Java_sun_nio_ch_IOUtil_initIDs; Java_sun_nio_ch_IOUtil_initIDs;
Java_sun_nio_ch_IOUtil_iovMax;
Java_sun_nio_ch_IOUtil_makePipe; Java_sun_nio_ch_IOUtil_makePipe;
Java_sun_nio_ch_IOUtil_randomBytes; Java_sun_nio_ch_IOUtil_randomBytes;
Java_sun_nio_ch_IOUtil_setfdVal; Java_sun_nio_ch_IOUtil_setfdVal;
......
...@@ -76,6 +76,7 @@ SUNWprivate_1.1 { ...@@ -76,6 +76,7 @@ SUNWprivate_1.1 {
Java_sun_nio_ch_IOUtil_fdLimit; Java_sun_nio_ch_IOUtil_fdLimit;
Java_sun_nio_ch_IOUtil_fdVal; Java_sun_nio_ch_IOUtil_fdVal;
Java_sun_nio_ch_IOUtil_initIDs; Java_sun_nio_ch_IOUtil_initIDs;
Java_sun_nio_ch_IOUtil_iovMax;
Java_sun_nio_ch_IOUtil_makePipe; Java_sun_nio_ch_IOUtil_makePipe;
Java_sun_nio_ch_IOUtil_randomBytes; Java_sun_nio_ch_IOUtil_randomBytes;
Java_sun_nio_ch_IOUtil_setfdVal; Java_sun_nio_ch_IOUtil_setfdVal;
......
...@@ -36,6 +36,11 @@ import java.nio.ByteBuffer; ...@@ -36,6 +36,11 @@ import java.nio.ByteBuffer;
public class IOUtil { public class IOUtil {
/**
* Max number of iovec structures that readv/writev supports
*/
static final int IOV_MAX;
private IOUtil() { } // No instantiation private IOUtil() { } // No instantiation
static int write(FileDescriptor fd, ByteBuffer src, long position, static int write(FileDescriptor fd, ByteBuffer src, long position,
...@@ -111,7 +116,8 @@ public class IOUtil { ...@@ -111,7 +116,8 @@ public class IOUtil {
// Iterate over buffers to populate native iovec array. // Iterate over buffers to populate native iovec array.
int count = offset + length; 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]; ByteBuffer buf = bufs[i];
int pos = buf.position(); int pos = buf.position();
int lim = buf.limit(); int lim = buf.limit();
...@@ -135,6 +141,7 @@ public class IOUtil { ...@@ -135,6 +141,7 @@ public class IOUtil {
vec.putLen(iov_len, rem); vec.putLen(iov_len, rem);
iov_len++; iov_len++;
} }
i++;
} }
if (iov_len == 0) if (iov_len == 0)
return 0L; return 0L;
...@@ -240,7 +247,8 @@ public class IOUtil { ...@@ -240,7 +247,8 @@ public class IOUtil {
// Iterate over buffers to populate native iovec array. // Iterate over buffers to populate native iovec array.
int count = offset + length; 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]; ByteBuffer buf = bufs[i];
if (buf.isReadOnly()) if (buf.isReadOnly())
throw new IllegalArgumentException("Read-only buffer"); throw new IllegalArgumentException("Read-only buffer");
...@@ -264,6 +272,7 @@ public class IOUtil { ...@@ -264,6 +272,7 @@ public class IOUtil {
vec.putLen(iov_len, rem); vec.putLen(iov_len, rem);
iov_len++; iov_len++;
} }
i++;
} }
if (iov_len == 0) if (iov_len == 0)
return 0L; return 0L;
...@@ -336,11 +345,14 @@ public class IOUtil { ...@@ -336,11 +345,14 @@ public class IOUtil {
static native int fdLimit(); static native int fdLimit();
static native int iovMax();
static native void initIDs(); static native void initIDs();
static { static {
// Note that IOUtil.initIDs is called from within Util.load. // Note that IOUtil.initIDs is called from within Util.load.
Util.load(); Util.load();
IOV_MAX = iovMax();
} }
} }
...@@ -45,7 +45,7 @@ public class Util { ...@@ -45,7 +45,7 @@ public class Util {
// -- Caches -- // -- Caches --
// The number of temp buffers in our pool // 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 // Per-thread cache of temporary direct buffers
private static ThreadLocal<BufferCache> bufferCache = private static ThreadLocal<BufferCache> bufferCache =
......
...@@ -94,9 +94,6 @@ Java_sun_nio_ch_FileDispatcherImpl_readv0(JNIEnv *env, jclass clazz, ...@@ -94,9 +94,6 @@ Java_sun_nio_ch_FileDispatcherImpl_readv0(JNIEnv *env, jclass clazz,
{ {
jint fd = fdval(env, fdo); jint fd = fdval(env, fdo);
struct iovec *iov = (struct iovec *)jlong_to_ptr(address); struct iovec *iov = (struct iovec *)jlong_to_ptr(address);
if (len > 16) {
len = 16;
}
return convertLongReturnVal(env, readv(fd, iov, len), JNI_TRUE); return convertLongReturnVal(env, readv(fd, iov, len), JNI_TRUE);
} }
...@@ -126,9 +123,6 @@ Java_sun_nio_ch_FileDispatcherImpl_writev0(JNIEnv *env, jclass clazz, ...@@ -126,9 +123,6 @@ Java_sun_nio_ch_FileDispatcherImpl_writev0(JNIEnv *env, jclass clazz,
{ {
jint fd = fdval(env, fdo); jint fd = fdval(env, fdo);
struct iovec *iov = (struct iovec *)jlong_to_ptr(address); struct iovec *iov = (struct iovec *)jlong_to_ptr(address);
if (len > 16) {
len = 16;
}
return convertLongReturnVal(env, writev(fd, iov, len), JNI_FALSE); return convertLongReturnVal(env, writev(fd, iov, len), JNI_FALSE);
} }
......
...@@ -136,6 +136,16 @@ Java_sun_nio_ch_IOUtil_fdLimit(JNIEnv *env, jclass this) ...@@ -136,6 +136,16 @@ Java_sun_nio_ch_IOUtil_fdLimit(JNIEnv *env, jclass this)
} }
} }
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 */ /* Declared in nio_util.h for use elsewhere in NIO */
jint jint
......
...@@ -41,9 +41,6 @@ static jfieldID handle_fdID; ...@@ -41,9 +41,6 @@ static jfieldID handle_fdID;
/* field id for jint 'fd' in java.io.FileDescriptor used for socket fds */ /* field id for jint 'fd' in java.io.FileDescriptor used for socket fds */
static jfieldID fd_fdID; static jfieldID fd_fdID;
/* false for 95/98/ME, true for NT/W2K */
static jboolean onNT = JNI_FALSE;
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_sun_security_provider_NativeSeedGenerator_nativeGenerateSeed Java_sun_security_provider_NativeSeedGenerator_nativeGenerateSeed
(JNIEnv *env, jclass clazz, jbyteArray randArray); (JNIEnv *env, jclass clazz, jbyteArray randArray);
...@@ -55,13 +52,6 @@ Java_sun_security_provider_NativeSeedGenerator_nativeGenerateSeed ...@@ -55,13 +52,6 @@ Java_sun_security_provider_NativeSeedGenerator_nativeGenerateSeed
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_sun_nio_ch_IOUtil_initIDs(JNIEnv *env, jclass clazz) 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"); clazz = (*env)->FindClass(env, "java/io/FileDescriptor");
fd_fdID = (*env)->GetFieldID(env, clazz, "fd", "I"); fd_fdID = (*env)->GetFieldID(env, clazz, "fd", "I");
handle_fdID = (*env)->GetFieldID(env, clazz, "handle", "J"); handle_fdID = (*env)->GetFieldID(env, clazz, "handle", "J");
...@@ -80,6 +70,13 @@ Java_sun_nio_ch_IOUtil_randomBytes(JNIEnv *env, jclass clazz, ...@@ -80,6 +70,13 @@ Java_sun_nio_ch_IOUtil_randomBytes(JNIEnv *env, jclass clazz,
randArray); randArray);
} }
JNIEXPORT jint JNICALL
Java_sun_nio_ch_IOUtil_iovMax(JNIEnv *env, jclass this)
{
return 16;
}
jint jint
convertReturnVal(JNIEnv *env, jint n, jboolean reading) convertReturnVal(JNIEnv *env, jint n, jboolean reading)
{ {
...@@ -205,9 +202,3 @@ handleval(JNIEnv *env, jobject fdo) ...@@ -205,9 +202,3 @@ handleval(JNIEnv *env, jobject fdo)
{ {
return (*env)->GetLongField(env, fdo, handle_fdID); return (*env)->GetLongField(env, fdo, handle_fdID);
} }
jboolean
isNT()
{
return onNT;
}
...@@ -97,10 +97,6 @@ Java_sun_nio_ch_SocketDispatcher_readv0(JNIEnv *env, jclass clazz, jobject fdo, ...@@ -97,10 +97,6 @@ Java_sun_nio_ch_SocketDispatcher_readv0(JNIEnv *env, jclass clazz, jobject fdo,
return IOS_THROWN; return IOS_THROWN;
} }
if ((isNT() == JNI_FALSE) && (len > 16)) {
len = 16;
}
/* copy iovec into WSABUF */ /* copy iovec into WSABUF */
for(i=0; i<len; i++) { for(i=0; i<len; i++) {
jint iov_len = iovp[i].iov_len; jint iov_len = iovp[i].iov_len;
...@@ -208,10 +204,6 @@ Java_sun_nio_ch_SocketDispatcher_writev0(JNIEnv *env, jclass clazz, ...@@ -208,10 +204,6 @@ Java_sun_nio_ch_SocketDispatcher_writev0(JNIEnv *env, jclass clazz,
return IOS_THROWN; return IOS_THROWN;
} }
if ((isNT() == JNI_FALSE) && (len > 16)) {
len = 16;
}
/* copy iovec into WSABUF */ /* copy iovec into WSABUF */
for(i=0; i<len; i++) { for(i=0; i<len; i++) {
jint iov_len = iovp[i].iov_len; jint iov_len = iovp[i].iov_len;
......
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
jint fdval(JNIEnv *env, jobject fdo); jint fdval(JNIEnv *env, jobject fdo);
jlong handleval(JNIEnv *env, jobject fdo); jlong handleval(JNIEnv *env, jobject fdo);
jboolean isNT();
jint convertReturnVal(JNIEnv *env, jint n, jboolean r); jint convertReturnVal(JNIEnv *env, jint n, jboolean r);
jlong convertLongReturnVal(JNIEnv *env, jlong n, jboolean r); jlong convertLongReturnVal(JNIEnv *env, jlong n, jboolean r);
jboolean purgeOutstandingICMP(JNIEnv *env, jclass clazz, jint fd); jboolean purgeOutstandingICMP(JNIEnv *env, jclass clazz, jint fd);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册