RFR: 8274112: (fc) Tune FileChannel.transferTo() [v3]

Alan Bateman alanb at openjdk.java.net
Tue Oct 19 11:05:53 UTC 2021


On Thu, 23 Sep 2021 02:07:30 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> Please consider this patch which would improve the performance of
>> `FileChannel.transferTo()` on macOS and Windows.
>
> Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
> 
>   8274112: Modify transfer_read_write() not to throw if read or write fails

src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java line 621:

> 619:         FileDescriptor targetFD = target.fd;
> 620:         if (targetFD == null)
> 621:             return IOStatus.UNSUPPORTED;

How can the target have a null file descriptor?

src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java line 762:

> 760:         // Attempt a transfer using native functions, if available
> 761:         if (target instanceof FileChannelImpl targetFCI)
> 762:             if ((n = transferToFileChannel(position, count, targetFCI)) >= 0)

The check for whether the target channel is a FileChannelImpl is already in transferToDirectly so I assume that's the place that should be calling transferToFileChannel.

src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java line 1448:

> 1446:     // Transfers from src to dst, or returns IOStatus.UNSUPPORTED (-4)
> 1447:     // or IOStatus.UNSUPPORTED_CASE (-6) if kernel can't do that
> 1448:     private static native long transferToFileChannel0(FileDescriptor src,

transferToFileChannel0 is static so we should probably change transferTo0 to keep the methods consistent.

-------------

PR: https://git.openjdk.java.net/jdk/pull/5623


More information about the nio-dev mailing list