JDK-8371497 : Simplify java.util.Object.equals - remove the identity comparison
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 25
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2025-11-07
  • Updated: 2025-12-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Description
The typical implementation of the `equals` method for a class, test for object identity using the `== operator` and then compares the state with the other object's state.
In a very small fraction of the comparisons, the other object has the same identity and there is some benefit to the extra `==` comparison. The rest of the time that identity comparison is wasted effort.

This enhancement proposes to drop the un-beneficial use of `==` when followed by calling `equals`.

The `java.util.Objects.equals` utility for comparing two objects, uses the same pattern, testing for identity before delegating to the object's `equals` method. There is even less benefit in this case, since many implementations of `equals` also use `==` as the first condition.  The redundant identity comparison should be reduced.

The Valhalla project tested this premise and did not see a performance regression as a result of removing the identity comparison from `Objects.equals`.
Comments
Removing the identity semantics from Objects.equals may cause breakage in cases where the callers are depending on identity and the .equals method does not.
17-12-2025

This change may have subtle compatibility risks. Meanwhile, the JVM does a pretty good job of optimizing the LIFE (which is the expression inside the method, that includes both acmp and invokevirtual of .equals). What if we could get better optimization of Objects.equals, more on a par with hand-writing the LIFE? Would that reduce the need for this possibly-incompatible change? JDK-8373467 points out some technical debt in the optimization of Objects.equals, which if addressed might make this RFE less urgent.
10-12-2025

This change has to stand on its own in the mainline, unrelated to Valhalla.
08-11-2025

Adding a "valhalla" label - this appears on mainline issues that have some lworld implications but is not themselves part of the lworld effort.
08-11-2025