RFR: 8129776: The optimized Stream returned from Files.lines should unmap the mapped byte buffer (if created) when closed [v2]
Paul Sandoz
psandoz at openjdk.java.net
Tue Jan 26 19:56:40 UTC 2021
On Tue, 26 Jan 2021 15:16:52 GMT, Roger Riggs <rriggs at openjdk.org> wrote:
>> Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
>>
>> 8129776: Remove brackets {} around single expression lambda
>
> 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.
-------------
PR: https://git.openjdk.java.net/jdk/pull/2229
More information about the nio-dev
mailing list