RFR: 8292562: (fc) Use copy_file_range in FileChannel::transferTo on Linux

Alan Bateman alanb at openjdk.org
Fri Aug 19 06:47:44 UTC 2022


On Thu, 18 Aug 2022 18:50:30 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

> Add `copy_file_range(2)` to the native Linux implementation of `FileChannel::transferTo`.

src/java.base/unix/native/libnio/ch/FileChannelImpl.c line 182:

> 180:     jlong n;
> 181:     if (my_copy_file_range_func != NULL) {
> 182:         n = my_copy_file_range_func(srcFD, &offset, dstFD, NULL, count, 0);

I assume count will need to be cast to size_t for this to compile on all architectures.

src/java.base/unix/native/libnio/ch/FileChannelImpl.c line 186:

> 184:             switch (errno) {
> 185:                 case EINTR:
> 186:                 case EINVAL:

For EINVAL we could return IOS_INTERRUPTED if you want.

src/java.base/unix/native/libnio/ch/FileChannelImpl.c line 192:

> 190:                 default:
> 191:                     JNU_ThrowIOExceptionWithLastError(env, "Copy failed");
> 192:                     return IOS_THROWN;

Would you mind checking if we have tests that exercise transferTo when the target WritableByteChannel is to a file opened in append mode? Asking because copy_file_range will fall and I'm wondering what the existing behavior is.

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

PR: https://git.openjdk.org/jdk/pull/9925


More information about the nio-dev mailing list