RFR: 8324972: (bf) Make DirectByteBuffer.Deallocator idempotent [v3]
Per Minborg
pminborg at openjdk.org
Thu Feb 8 09:42:55 UTC 2024
On Wed, 31 Jan 2024 17:58:04 GMT, Mark Sheppard <msheppar at openjdk.org> wrote:
>> Per Minborg has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Swith to using Unsafe
>
> src/java.base/share/classes/java/nio/Direct-X-Buffer.java.template line 99:
>
>> 97: public void run() {
>> 98: // Ensure idempotency (paranoia)
>> 99: if (Unsafe.getUnsafe().compareAndSetInt(this, INVOKED_OFFSET, 0, 1)) {
>
> a question for my edification: is this compound statement suitably atomic to ensure synchronzied serial access to freeMemory block ? There's no danger of concurrent interleaved execution resulting in inconsistent view of the member variable via the reflective access ?
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.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/17647#discussion_r1482677523
More information about the nio-dev
mailing list