8274112: (fc) Tune FileChannel.transferTo()

Reviewed-by: alanb, lancea, rriggs
This commit is contained in:
Brian Burkhalter 2022-05-04 14:33:16 +00:00
parent 7424f47557
commit 17cc7131ab
3 changed files with 121 additions and 47 deletions

View file

@ -574,6 +574,10 @@ public class FileChannelImpl
}
}
// Size threshold above which to use a mapped buffer;
// transferToArbitraryChannel() is faster for smaller transfers
private static final long TRUSTED_TRANSFER_THRESHOLD = 16L*1024L;
// Maximum size to map when using a mapped buffer
private static final long MAPPED_TRANSFER_SIZE = 8L*1024L*1024L;
@ -581,6 +585,9 @@ public class FileChannelImpl
WritableByteChannel target)
throws IOException
{
if (count < TRUSTED_TRANSFER_THRESHOLD)
return IOStatus.UNSUPPORTED_CASE;
boolean isSelChImpl = (target instanceof SelChImpl);
if (!((target instanceof FileChannelImpl) || isSelChImpl))
return IOStatus.UNSUPPORTED;
@ -1372,9 +1379,10 @@ public class FileChannelImpl
// Removes an existing mapping
private static native int unmap0(long address, long length);
// Transfers from src to dst, or returns -2 if kernel can't do that
private native long transferTo0(FileDescriptor src, long position,
long count, FileDescriptor dst);
// Transfers from src to dst, or returns IOStatus.UNSUPPORTED (-4) or
// IOStatus.UNSUPPORTED_CASE (-6) if the kernel does not support it
private static native long transferTo0(FileDescriptor src, long position,
long count, FileDescriptor dst);
// Retrieves the maximum size of a transfer
private static native int maxDirectTransferSize0();