RFR: 8324972: (bf) Make DirectByteBuffer.Deallocator idempotent [v3]
Per Minborg
pminborg at openjdk.org
Thu Feb 8 12:03:02 UTC 2024
On Thu, 8 Feb 2024 10:02:45 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:
>> The CAS operation establishes a happens-before relation between the CAS operation itself and any following operations (such as `freeMemory()`). Also, only one thread will succeed in changing the value from zero to one.
>
> CAS block provides mutual exclusion here, as in, only one thread would ever execute the `freeMemory`/`unreserveMemory` block, which also does not modify any of the fields here. The only (?) thing we might be concerned with is that while one thread is running in the block, another thread would come and bypass the block. If anything relies on memory being actually freed after we exit `run()`, it might subtly misbehave -- accounting code, maybe? I guess a safer way to do this would be acquiring a lock, and checking `invoked` while holding it? Not sure if that is a problem.
The behavior in this PR is now like the intended behavior in Java 21 (and before) but thread-safe. So, by induction, this should be as safe or safer as we had in <= 21. Adding blocking might introduce other problems in a multi-threaded environment.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/17647#discussion_r1482855731
More information about the nio-dev
mailing list