On Thu, 19 Jun 2025 08:57:44 GMT, Viktor Klang <[email protected]> wrote:
>> 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?
If we call this method via the public `StableValue::orElseSet`, the underlying
holder will be `null`. In this case, there is no underlying function stored.
Instead, it is typically a lambda or an anonymous class provided on the fly.
> 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
True. We could also use piggybacking.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25878#discussion_r2156518370
PR Review Comment: https://git.openjdk.org/jdk/pull/25878#discussion_r2156520221