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

Chen Liang liach at openjdk.org
Mon Sep 18 14:34:45 UTC 2023


On Mon, 18 Sep 2023 12:19:42 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:
> 
>   Rename boolean variable and reformat

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

> 94:                 return;
> 95:             }
> 96:             deallocated = true;

Shouldn't this be an atomic compareAndSet instead? Thread A can read deallocated and pause before the field write, then thread B read deallocated, continue to set the field. There will be a double free when thread A resumes.

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

> 121:                     @Override
> 122:                     public long address() {
> 123:                         return address;

We can just declare a `final long address = MappedByteBuffer.this.address;` instead of a huge refactor, right?

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

> 1198:             if (address == 0 || unmapped)
> 1199:                 return;
> 1200:             unmapped = true;

Same question

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

PR Review Comment: https://git.openjdk.org/jdk/pull/15784#discussion_r1328816701
PR Review Comment: https://git.openjdk.org/jdk/pull/15784#discussion_r1328820849
PR Review Comment: https://git.openjdk.org/jdk/pull/15784#discussion_r1328818097


More information about the nio-dev mailing list