RFR: 8316493: Make immutable maps @ValueBased
Chen Liang
liach at openjdk.org
Tue Sep 19 23:51:44 UTC 2023
On Tue, 19 Sep 2023 18:38:06 GMT, ExE Boss <duke at openjdk.org> wrote:
>> This PR outlines a solution for making immutable maps `@ValueBased` by removing cacheing of certain values in `AbstractMap`.
>>
>> By removing these caching fields in `AbstractMap`, we can make the immutable maps `@ValueBased` and at the same time, performance is likely improved because the JVM is probably able to optimize away object creation anyway via escape analysis. Also, all maps will occupy less space as we get rid of a number of objects and references stored for each map.
>>
>> We need to benchmark this solution to better understand its implications.
>
> src/java.base/share/classes/java/util/AbstractMap.java line 375:
>
>> 373: */
>> 374: public Collection<V> values() {
>> 375: return new AbstractCollection<>() {
>
> Note that this causes `m.values().equals(m.values())` to no longer return `true`, as base `Collection::equals` is defined using reference equality.
Looking at the specification above:
> No synchronization is performed, so there is a slight chance that multiple calls to this method will not all return the same collection.
This should be an acceptable change to behavior.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/15614#discussion_r1330809662
More information about the core-libs-dev
mailing list