RFR: 8351565: Implement JEP 502: Stable Values (Preview)

Quan Anh Mai qamai at openjdk.org
Thu Mar 13 11:20:14 UTC 2025


On Wed, 12 Mar 2025 08:09:04 GMT, Per Minborg <pminborg at openjdk.org> wrote:

>> If you have an `@Stable Object[]`, then the elements are also considered `@Stable`. Then you can do something like:
>> 
>>     ReentrantLock[] locks;
>> 
>>     T get(int idx) {
>>         Object x = backing[idx];
>>         if (x == null) {
>>             return compute(idx);
>>         }
>>         return unwrap(x);
>>     }
>> 
>>     T compute(int idx) {
>>         ReentrantLock lock = locks[idx];
>>         lock.lock();
>>         try {
>>             Object x = backing[idx];
>>             if (x != null) {
>>                 return unwrap(x);
>>             }
>>             T obj = ...;
>>             backing[idx] = wrap(obj);
>>             return obj;
>>         } finally {
>>             lock.unlock();
>>         }
>>     }
>
> What would be the difference between `@Stable StableValueImpl<E>[] backing` and `@Stable Object[] backing`?

For an `Object[]`, you only need to load the object from the array and it is probably what you need. For a `StableValueImpl[]`, you need to load the `StableValueImpl` from the array, and load the value from that `StableValueImpl`, which is 2 levels of indirections.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/23972#discussion_r1990993459


More information about the compiler-dev mailing list