RFR: 8129776: The optimized Stream returned from Files.lines should unmap the mapped byte buffer (if created) when closed
Roger Riggs
rriggs at openjdk.java.net
Tue Jan 26 15:19:43 UTC 2021
On Mon, 25 Jan 2021 23:55:02 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:
> Please review this proposed change to unmap the mapped buffer shared between the root and sub-spliterators used in the optimized `Stream` implementation returned by `Files.lines()`. A reference counter is added to track the total number of spliterators sharing the buffer. It is set to 1 when the shared buffer is created, and incremented each time a sub-spliterator is created. It is decremented when traversing begins or when the spliterator is closed. If the counter is zero after it is decremented then the shared buffer is unmapped.
Marked as reviewed by rriggs (Reviewer).
src/java.base/share/classes/java/nio/file/Files.java line 4128:
> 4126: return StreamSupport.stream(fcls, false)
> 4127: .onClose(Files.asUncheckedRunnable(fc))
> 4128: .onClose(() -> { fcls.close(); });
Typically, the brackets {} are omitted for a single expression.
-------------
PR: https://git.openjdk.java.net/jdk/pull/2229
More information about the nio-dev
mailing list