RFR: 8274112: (fc) Tune FileChannel.transferTo()
Brian Burkhalter
bpb at openjdk.java.net
Wed Sep 22 16:40:55 UTC 2021
On Wed, 22 Sep 2021 13:29:19 GMT, Alan Bateman <alanb at openjdk.org> wrote:
>> Please consider this patch which would improve the performance of
>> `FileChannel.transferTo()` on macOS and Windows.
>
> src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java line 559:
>
>> 557: int thisFDVal = IOUtil.fdVal(fd);
>> 558: int targetFDVal = IOUtil.fdVal(targetFD);
>> 559: if (thisFDVal != -1 && targetFDVal != -1 && thisFDVal == targetFDVal)
>
> How can the fd values be -1 here, we must have an issue somewhere else if this happens.
On Windows this can happen.
> src/java.base/windows/native/libnio/ch/FileChannelImpl.c line 177:
>
>> 175: if (WriteFile(dst, &buf, nr, &nw, NULL) == 0) {
>> 176: JNU_ThrowIOExceptionWithLastError(env, "WriteFile failed");
>> 177: return IOS_THROWN;
>
> If ReadFile or WriteFile fails then I assume we should return tw when > 0.
In the macOS code if `read()` or `write()` fails then an exception is thrown. I suppose the two read-write versions should be consistent one way or the other.
-------------
PR: https://git.openjdk.java.net/jdk/pull/5623
More information about the nio-dev
mailing list