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

Daniel Fuchs dfuchs at openjdk.org
Thu Feb 15 15:02:55 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

Cleaner and Cleanable are very clear that the cleaning action will be invoked at most once.
https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/ref/Cleaner.html

As long as the Deallocator cannot be accessed from anywhere else (and that seems the case), it doesn't really need to be idempotent. Making it idempotent is a kind of defense in depth fix - that strictly speaking is not needed. If Cleaner/Cleanable could allow the cleaning action to be invoked twice that would be a major bug - as according to the specification, this should not happen, and therefore most of cleaning actions wouldn't guard against it.
If the Deallocator was accessible from anywhere else than the cleaning action then making it idempotent would indeed be necessary.

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

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


More information about the nio-dev mailing list