RFR: 8316660: (fs) Files.lines implementation can use MemorSegment for file mapping [v5]

Brian Burkhalter bpb at openjdk.org
Thu Sep 21 15:48:44 UTC 2023


On Thu, 21 Sep 2023 13:50:32 GMT, Per Minborg <pminborg at openjdk.org> wrote:

>> This PR proposes using a `MemorySegment` instead of a `ByteBuffer` in the `Files::lines` implementation (in the internal class `FileChannelLinesSpliterator`).
>> 
>> The old solution deterministically unmapped the `ByteBuffer` if closed. If not closed, the `ByteBuffer` would be GC:ed.
>> 
>> This proposal mimics the old behavior but may hold the mapped memory region slightly longer.
>> 
>> Tested and passed tier1, tier2, tier3
>
> Per Minborg has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Simplify constructor

src/java.base/share/classes/java/nio/file/FileChannelLinesSpliterator.java line 75:

> 73: 
> 74:     static final Set<Charset> SUPPORTED_CHARSETS = Set.of(
> 75:             UTF_8.INSTANCE,

Suggestion: change indentation of these three set elements back to what it was.

src/java.base/share/classes/java/nio/file/Files.java line 4138:

> 4136:             if (length > 0 && length <= Integer.MAX_VALUE) {
> 4137:                 FileChannelLinesSpliterator fcls =
> 4138:                     new FileChannelLinesSpliterator(fc, cs,(int) length);

Suggestion: `, (int) length` -> `, (int)length`.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/15814#discussion_r1333279733
PR Review Comment: https://git.openjdk.org/jdk/pull/15814#discussion_r1333277522


More information about the nio-dev mailing list