[lworld] RFR: 8366214: [lworld] Use Objects.equals in HashMap and ConcurrentHashmap

Roger Riggs rriggs at openjdk.org
Wed Aug 27 19:46:29 UTC 2025


As observed in [JDK-8366043](https://bugs.openjdk.org/browse/JDK-8366043) [lworld] (LIFE = Legacy Idiom For Equality) causes performance regressions.
Updating HashMap and ConcurrentHashMap to use `java.util.Objects.equals` will make it easier to measure performance of options that remove or modify the use of `==`

Replace constructs like:

-                        ((k = e.key) == key || (key != null && key.equals(k))))
with:
+                        Objects.equals(key, k))


The changes in ConcurrentHashMap are a bit different due to the use of null as a sentinel.

The order of arguments to the .equals methods must remain the same to ensure compatibility.

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

Commit messages:
 - 8366214: [lworld] Use Objects.equals in HashMap and ConcurrentHashmap

Changes: https://git.openjdk.org/valhalla/pull/1536/files
  Webrev: https://webrevs.openjdk.org/?repo=valhalla&pr=1536&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8366214
  Stats: 45 lines in 2 files changed: 1 ins; 7 del; 37 mod
  Patch: https://git.openjdk.org/valhalla/pull/1536.diff
  Fetch: git fetch https://git.openjdk.org/valhalla.git pull/1536/head:pull/1536

PR: https://git.openjdk.org/valhalla/pull/1536


More information about the valhalla-dev mailing list