RFR: 8360884: Better scoped values

Chen Liang liach at openjdk.org
Fri Jun 27 15:15:42 UTC 2025


On Fri, 27 Jun 2025 14:32:11 GMT, Andrew Haley <aph at openjdk.org> wrote:

> Scoped values cannot be used early in the JDK boot process because of some dependencies on System.getProperty(). This dependency should be removed in a way that allows scoped values to be created (but not necessarily bound) at any stage during boot.
> 
> Also, Scoped Value's constructor has a synchronized block, which limits the use of scoped values at runtime. Constructing a scoped value should be a thread-local operation.

I looked at the existing code: the reason ScopedValue creation requires getProperty in Cache is that `generateKey` uses `Cache.primarySlot(x)` and `Cache.secondarySlot(x)`. Why did you choose to factor out `getProperty` into a new class instead of adding `primaryIndex` and `secondaryIndex` to the root `ScopedValue` to avoid early initialization of `Cache`?

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

PR Comment: https://git.openjdk.org/jdk/pull/26019#issuecomment-3013419457


More information about the core-libs-dev mailing list