Equality for values -- new analysis, same conclusion

Dan Smith daniel.smith at oracle.com
Tue Aug 13 20:39:25 UTC 2019


> On Aug 13, 2019, at 12:19 PM, John Rose <john.r.rose at oracle.com> wrote:
> 
> The JIT optimization requires skipping the SAME== check if the equals method will also carry that burden. For that to be valid we need to ensure that applying equals of the same value to itself is a constant true with no side effects. This is easy to argue for IMO since that is part of the contract of Object::equals.

I don't think Object.equals has anything to say about side effects?

> (a) classifying equals methods which are well behaved

What makes me nervous here: whoever does the classification needs to be very careful about things like exceptions. Once you do something more than 'instanceof', 'getfield', and '==', things get pretty fuzzy quickly (e.g., can I guarantee that some accessor method I call in a third party API won't NPE because of some internal state?)



More information about the valhalla-spec-observers mailing list