RFR: 8316493: Make immutable maps @ValueBased

Claes Redestad redestad at openjdk.org
Tue Sep 19 07:10:07 UTC 2023


On Thu, 7 Sep 2023 11:13:44 GMT, Per Minborg <pminborg 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.

The microbenchmark is deliberately minimalist and mainly verifies that the JIT _can_ eliminate allocation of the `keySet` and `values` and is as such a good starting point for further analysis. Worth noting also that eliminating these two transient fields would save 8-16 bytes from every `HashMap`, `LinkedHashMap`, `Map.of(..)` et.c.

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

PR Comment: https://git.openjdk.org/jdk/pull/15614#issuecomment-1710352704


More information about the core-libs-dev mailing list