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

Brian Burkhalter bpb at openjdk.java.net
Wed Oct 20 00:21:09 UTC 2021


On Tue, 19 Oct 2021 11:02:56 GMT, Alan Bateman <alanb at openjdk.org> wrote:

>> 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?

It does not look like it can. I will remove that check.

> 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.

I was looking at the file channel transfer as being a piece of logic at the same level as direct vs. trusted vs. arbitrary, not as a sub-case of direct. I think to change it as suggested would lead to some odd code:

        if (target instanceof FileChannelImpl fci) {
            if (!fileSupported)
                return transferToFileChannel(position, count, fci);
            targetFD = fci.fd;

> 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.

Agreed.

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

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


More information about the nio-dev mailing list