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

Mark Sheppard msheppar at openjdk.org
Mon Feb 19 17:42:59 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

ok, well that's a bit of a subtle one.  So you are saying that passing a reference to a  Cleaner of the newly constructed Dealloactor doesn't guarantee that Cleaner has a consistent state of the Deallocator, as shown in the code below. That's a bit dubious, as that would imply that every Factory class, or factory method, or object Builder would suffer the same publication effect, when they hand out constructed objects ?

        try {
            cleaner = Cleaner.create(this, new Deallocator(base, size, cap));
        } catch (Throwable t) {
            // Prevent leak if the Deallocator or Cleaner fail for any reason
            UNSAFE.freeMemory(base);
            Bits.unreserveMemory(size, cap);
            throw t;
        }

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

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


More information about the nio-dev mailing list