RFR: 8129776: The optimized Stream returned from Files.lines should unmap the mapped byte buffer (if created) when closed [v2]
Brian Burkhalter
bpb at openjdk.java.net
Tue Jan 26 20:06:41 UTC 2021
On Tue, 26 Jan 2021 19:53:45 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:
>> Marked as reviewed by rriggs (Reviewer).
>
> Looks good. There is some complexity because the `Spliterator` can be obtained from the `Stream` returned by `Files.lines()`. This is not a common case but unfortunately we need to deal with it, otherwise we could just unmap when the `Stream` is closed. There are edge cases where by splits may occur but they are not traversed, but i don't think we should be concerned about. This is on a good best-effort basis to free up the resource.
>
> Is unmapping via `nioAccess.unmapper(b).unmap();` wired up?
>
> In `Buffer`:
> @Override
> public UnmapperProxy unmapper(ByteBuffer bb) {
> if (bb instanceof MappedByteBuffer) {
> return ((MappedByteBuffer)bb).unmapper();
> } else {
> return null;
> }
> }
>
> In MappedByteBuffer:
> UnmapperProxy unmapper() {
> return fd != null ?
> new UnmapperProxy() {
> @Override
> public long address() {
> return address;
> }
>
> @Override
> public FileDescriptor fileDescriptor() {
> return fd;
> }
>
> @Override
> public boolean isSync() {
> return isSync;
> }
>
> @Override
> public void unmap() {
> throw new UnsupportedOperationException();
> }
> } : null;
> }
> I don't see where `unmapper` is overridden.
`unmapper` looks to be overridden in `sun.nio.ch.FileChannelImpl`. Specifically, `map()` obtains the `Unmapper` instance from `mapInternal()`.
-------------
PR: https://git.openjdk.java.net/jdk/pull/2229
More information about the nio-dev
mailing list