RFR: 8316337: (bf) Concurrency issue in DirectByteBuffer.Deallocator [v2]

Alan Bateman alanb at openjdk.org
Mon Sep 18 11:52:41 UTC 2023


On Mon, 18 Sep 2023 11:30:28 GMT, Per Minborg <pminborg at openjdk.org> wrote:

>> This PR proposes to make fields of implementations of the interface `DirectByteBuffer.Deallocator` `final` ensuring safe publication and immutability.
>
> Per Minborg has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Make the unmapper of MappedByteBuffer safe

src/java.base/share/classes/java/nio/Direct-X-Buffer.java.template line 85:

> 83:         private final long size;
> 84:         private final int capacity;
> 85:         private volatile boolean completed;

Using a volatile flag here okay but something like "deallocated" might be clearer than "completed". While you there, maybe remove the spurious blank left at L81, it doesn't help readability in this tiny class.

src/java.base/share/classes/java/nio/MappedByteBuffer.java line 125:

> 123: 
> 124:     private final class BufferUnmapperProxy implements UnmapperProxy {
> 125: 

This blank line can be removed too,

src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java line 1165:

> 1163:         private final FileDescriptor fd;
> 1164:         private final int pagePosition;
> 1165:         private volatile boolean completed;

"unmapped" would be better here.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/15784#discussion_r1328592780
PR Review Comment: https://git.openjdk.org/jdk/pull/15784#discussion_r1328593381
PR Review Comment: https://git.openjdk.org/jdk/pull/15784#discussion_r1328594504


More information about the nio-dev mailing list