8272047: java/nio/channels/FileChannel/Transfer2GPlus.java failed with Unexpected transfer size: 2147418112

Reviewed-by: naoto, alanb
This commit is contained in:
Brian Burkhalter 2021-08-09 16:50:50 +00:00
parent 41dc795d6c
commit b53828b7c2
2 changed files with 13 additions and 12 deletions
test/jdk
ProblemList.txt
java/nio/channels/FileChannel

@ -622,8 +622,6 @@ java/nio/channels/AsynchronousSocketChannel/StressLoopback.java 8211851 aix-ppc6
java/nio/channels/Selector/Wakeup.java 6963118 windows-all
java/nio/channels/FileChannel/Transfer2GPlus.java 8272047 linux-aarch64
############################################################################
# jdk_rmi

@ -47,8 +47,6 @@ import java.util.Random;
import jdk.test.lib.Platform;
public class Transfer2GPlus {
private static final int LINUX_MAX_TRANSFER_SIZE = 0x7ffff000;
private static final long BASE = (long)Integer.MAX_VALUE;
private static final int EXTRA = 1024;
private static final long LENGTH = BASE + EXTRA;
@ -83,22 +81,27 @@ public class Transfer2GPlus {
try (FileChannel srcCh = FileChannel.open(src)) {
try (FileChannel dstCh = FileChannel.open(dst,
StandardOpenOption.READ, StandardOpenOption.WRITE)) {
long n;
if ((n = srcCh.transferTo(0, LENGTH, dstCh)) < LENGTH) {
long total = 0L;
if ((total = srcCh.transferTo(0, LENGTH, dstCh)) < LENGTH) {
if (!Platform.isLinux())
throw new RuntimeException("Transfer too small: " + n);
throw new RuntimeException("Transfer too small: " + total);
if (n != 0x7ffff000)
throw new RuntimeException("Unexpected transfer size: " + n);
if ((n += srcCh.transferTo(n, LENGTH, dstCh)) != LENGTH)
throw new RuntimeException("Unexpected total size: " + n);
// If this point is reached we're on Linux which cannot
// transfer all LENGTH bytes in one call to sendfile(2),
// so loop to get the rest.
do {
long n = srcCh.transferTo(total, LENGTH, dstCh);
if (n == 0)
break;
total += n;
} while (total < LENGTH);
}
if (dstCh.size() < LENGTH)
throw new RuntimeException("Target file too small: " +
dstCh.size() + " < " + LENGTH);
System.out.println("Transferred " + n + " bytes");
System.out.println("Transferred " + total + " bytes");
dstCh.position(BASE);
ByteBuffer bb = ByteBuffer.allocate(EXTRA);