RFR: 8324972: (bf) Make DirectByteBuffer.Deallocator idempotent [v4]

Mark Sheppard msheppar at openjdk.org
Sun Feb 11 14:05:02 UTC 2024


On Thu, 8 Feb 2024 10:58:05 GMT, Per Minborg <pminborg at openjdk.org> wrote:

>> This PR proposes to make deallocators and unmappers for memory regions idempotent. This is to prevent (likely very rare) duplicate invocations. 
>> 
>> There are no unit tests but it should be noted that the idempotent behavior (now correct) is similar to the  intended behavior before cf74b8c2a32f33019a13ce80b6667da502cc6722 but where idempotency was not guaranteed in a multi-threaded environment.
>> 
>> Passes tier1, 2, and 3 tests.
>
> Per Minborg has updated the pull request incrementally with two additional commits since the last revision:
> 
>  - Use existing UNSAFE static variable
>  - Remove unused import

https://bugs.openjdk.org/browse/JDK-8316337  made a change advocating thread safety.  That change had a flaw, incorrectly viewing Unsafe.freeMemory as idempotent, and as such is not thread safe, nor is it safe to multiple sequential invocation of the run method. 
The logic in the original incarnation of the run method, protected against multiple invocations (sequential or concurrent), and in particular multiple invocation of the lower level native  free (memory) function, encapsulated in the Unsafe.freeMemory abstraction.
The issue is raised to re-instate those semantics - idempotency, and additionally thread safety. 
The raised issue is about correct behaviour in the context of multiple concurrent and sequential access, regardless of whether there is the possibility of one thread or multiple threads.
Per's retitle of the issue is a good one,  appropriately elaborating the semantics of the change

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

PR Comment: https://git.openjdk.org/jdk/pull/17647#issuecomment-1937763194


More information about the nio-dev mailing list