On Tue, 11 Mar 2025 16:15:10 GMT, Quan Anh Mai <qa...@openjdk.org> wrote:
>> Can you please elaborate a bit more on your proposal @merykitty? > > 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`? >> Yes we can. However, I am uncertain if the added complexity can motivate any >> performance benefits. Perhaps on ARM? I can do a benchmark on it. > > You can probably use `acquire` only for the first `get` as it is in the fast > path. For other I guess `volatile` is fine. Yeah. Maybe that could strike a balance. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/23972#discussion_r1990908235 PR Review Comment: https://git.openjdk.org/jdk/pull/23972#discussion_r1991599680