RFR: 8330465: Stable Values and Collections (Internal) [v20]
Jens Lidestrom
duke at openjdk.org
Mon May 20 09:53:08 UTC 2024
On Fri, 17 May 2024 09:31:33 GMT, Per Minborg <pminborg at openjdk.org> wrote:
>> # Stable Values & Collections (Internal)
>>
>> <img src="https://github.com/openjdk/jdk/assets/7457876/db4b22a1-af87-4914-adac-b05a87e7cb42" width=20% height=20%>
>>
>> ## Summary
>> This PR proposes to introduce an internal _Stable Values & Collections_ API, which provides immutable value holders where elements are initialized _at most once_. Stable Values & Collections offer the performance and safety benefits of final fields while offering greater flexibility as to the timing of initialization.
>>
>> ## Goals
>> * Provide an easy and intuitive API to describe value holders that can change at most once.
>> * Decouple declaration from initialization without significant footprint or performance penalties.
>> * Reduce the amount of static initializer and/or field initialization code.
>> * Uphold integrity and consistency, even in a multi-threaded environment.
>>
>> For more details, see the draft JEP: https://openjdk.org/jeps/8312611
>>
>> ## Performance
>> Performance compared to instance variables using two `AtomicReference` and two protected by double-checked locking under concurrent access by all threads:
>>
>>
>> Benchmark Mode Cnt Score Error Units
>> StableBenchmark.atomic thrpt 10 259.478 ? 36.809 ops/us
>> StableBenchmark.dcl thrpt 10 225.710 ? 26.638 ops/us
>> StableBenchmark.stable thrpt 10 4382.478 ? 1151.472 ops/us <- StableValue significantly faster
>>
>>
>> Performance compared to static variables protected by `AtomicReference`, class-holder idiom holder, and double-checked locking (all threads):
>>
>>
>> Benchmark Mode Cnt Score Error Units
>> StableStaticBenchmark.atomic thrpt 10 6487.835 ? 385.639 ops/us
>> StableStaticBenchmark.dcl thrpt 10 6605.239 ? 210.610 ops/us
>> StableStaticBenchmark.stable thrpt 10 14338.239 ? 1426.874 ops/us
>> StableStaticBenchmark.staticCHI thrpt 10 13780.341 ? 1839.651 ops/us
>>
>>
>> Performance for stable lists (thread safe) in both instance and static contexts whereby we access a single value compared to `ArrayList` instances (which are not thread-safe) (all threads):
>>
>>
>> Benchmark Mode Cnt Score Error Units
>> StableListElementBenchmark.instanceArrayList thrpt 10 5812.992 ? 1169.730 ops...
>
> Per Minborg has updated the pull request incrementally with two additional commits since the last revision:
>
> - Add benchmarks for memoized IntFunction and Function
> - Add benchmark for memoized supplier
src/java.base/share/classes/jdk/internal/lang/StableArray.java line 66:
> 64: * @throws IllegalArgumentException if the provided {@code length} is {@code < 0}
> 65: */
> 66: static <V> StableArray<V> of(int length) {
I interpret the method name `of` as a method that creates an object that contains the argument as some kind of member, in the way that `List.of` and friends work.
My intuitive interpretation of `StableArray.of(10)` is that it returns an array with the single element 10.
I think a method like this should be named `empty`, or `emptyOfLength` or something like that.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/18794#discussion_r1606529054
More information about the hotspot-compiler-dev
mailing list