RFR: 8359936: StableValues can release the underlying function after complete computation [v2]

Viktor Klang vklang at openjdk.org
Thu Jun 19 09:02:52 UTC 2025


On Thu, 19 Jun 2025 06:59:31 GMT, Per Minborg <pminborg at openjdk.org> wrote:

>> This PR proposes to release the underlying function if a stable function or collection has invoked its underlying supplier exhaustively so that it can be collected.
>> 
>> This PR passes tier1, tier2, and tier3 testing on multiple platforms.
>
> Per Minborg has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Fix performance regression

src/java.base/share/classes/jdk/internal/lang/stable/StableValueImpl.java line 150:

> 148:                 // The mutex is not reentrant so we know newValue should be returned
> 149:                 wrapAndSet(newValue);
> 150:                 if (underlyingHolder != null) {

Under what circumstances can the underlyingHolder be null here?

src/java.base/share/classes/jdk/internal/lang/stable/UnderlyingHolder.java line 35:

> 33:         this.counter = counter;
> 34:         // Safe publication
> 35:         UNSAFE.storeStoreFence();

This may actually be substitutable by making the initial write to counter a volatile write:

Suggestion:

        Unsafe.putIntVolatile(this, COUNTER_OFFSET, counter); // Safe publication of underlying and counter

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

PR Review Comment: https://git.openjdk.org/jdk/pull/25878#discussion_r2156504893
PR Review Comment: https://git.openjdk.org/jdk/pull/25878#discussion_r2156509309


More information about the core-libs-dev mailing list