On Wed, 12 Mar 2025 08:09:04 GMT, Per Minborg <pminb...@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`? It's true that the storage can be flatter here -- that said, this can also be done as a later refactoring. One advantage of doing things the way @minborg did it here, is that it's fairly easy to prove that the code below is correct -- which makes the initial review easier. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/23972#discussion_r1991505367