diff --git a/src/java.base/share/classes/sun/nio/ch/SocketChannelImpl.java b/src/java.base/share/classes/sun/nio/ch/SocketChannelImpl.java index 6f3e8b443dc..8cb3bb704cb 100644 --- a/src/java.base/share/classes/sun/nio/ch/SocketChannelImpl.java +++ b/src/java.base/share/classes/sun/nio/ch/SocketChannelImpl.java @@ -73,6 +73,9 @@ extends SocketChannel implements SelChImpl { + // The maximum number of bytes to read/write when using a socket adaptor + private static final int MAX_ADAPTOR_BUFFER_SIZE = 128 * 1024; + // Used to make native read and write calls private static final NativeDispatcher nd = new SocketDispatcher(); @@ -1373,6 +1376,7 @@ int blockingRead(byte[] b, int off, int len, long nanos) throws IOException { // nothing to do return 0; } + len = Math.min(len, MAX_ADAPTOR_BUFFER_SIZE); readLock.lock(); try { @@ -1469,7 +1473,7 @@ void blockingWriteFully(byte[] b, int off, int len) throws IOException { beginWrite(true); configureSocketNonBlockingIfVirtualThread(); while (pos < end && isOpen()) { - int size = end - pos; + int size = Math.min(end - pos, MAX_ADAPTOR_BUFFER_SIZE); int n = tryWrite(b, pos, size); while (IOStatus.okayToRetry(n) && isOpen()) { park(Net.POLLOUT);