RFR: 8316156: (ch) Channels.newOutputStream(ch).write(bigByteArray) allocates a lot of direct memory
Vyom Tewari
vtewari at openjdk.org
Thu Sep 14 11:05:39 UTC 2023
On Thu, 14 Sep 2023 03:05:50 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:
> In `ChannelInputStream` and `ChannelOutputStream`, process small chunks of bytes in sequence to avoid running afoul of the `MaxDirectMemorySize`.
test/jdk/java/nio/channels/Channels/WriteFullyMemorySize.java line 52:
> 50: byte[] res = Files.readAllBytes(target);
> 51: if (!Arrays.equals(b, res))
> 52: throw new RuntimeException("Arrays are not equal");
Will this 'throw new RuntimeException("Arrays are not equal");' be ever thrown ?.
I tested without fix and 'java.lang.OutOfMemoryError' wiil be thrown at line 49(Files.copy) so even in failing case 'RuntimeException' will not be thrown.
By looking the test name 'WriteFullyMemorySize' it is not clear to me what it is trying to test. If you wants to test 'Files.readAllBytes' as well then i will suggest you to change the name of test or put some comment. It will help the future maintainer of the code.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/15733#discussion_r1325781083
More information about the nio-dev
mailing list