Equality for values -- new analysis, same conclusion

Dan Smith daniel.smith at oracle.com
Mon Aug 12 18:17:51 UTC 2019

> On Aug 9, 2019, at 9:46 AM, Brian Goetz <brian.goetz at oracle.com> wrote:
> So if V <: Object, it feels we are still being “boxed” into the corner that == is a substitutability test.  But, in generic / dynamically typed code, we are likely to discourage broad use of Object==, since the most common case (fast path comparison) is no long as fast as it once was.  
> We have a few other options to mitigate the performance concerns here:
> - Live with legacy ACMP anomalies;
> - Re-explore a boxing relationship between V and Object.

Seems clear to me that a substitutability test is what makes the most semantic sense to most everyone, and we're just struggling to justify that it's "worth it". But before we jump to mitigation—up to and including redesigning the whole object model—do we have anything concrete to say about costs? Like, if every program got 5% slower in JDK X, obviously that would be bad. If programs that make heavy use of values have to recognize that equality is a little more expensive than they're used to, ... not even clear that's a problem.

(Shorter: benchmarks, please?)

> On Aug 10, 2019, at 12:57 PM, John Rose <john.r.rose at oracle.com> wrote:
>> - As a fast path for deeper equality comparisons (a == b || a.equals(b)), since the contract of equals() requires that == objects are equals().
> This is what I call L.I.F.E., the Legacy Idiom For Equality.  ID== is good here too.  FAST== would be fine here, and a JIT could perform that strength reduction if it notices that the == expression is post-dominated by Object.equals (on the false path).  I think that’s usually detectable.

Major caveat for this kind of optimization: it relies on a "well-behaved" 'equals' method. If 'equals' can thrown an exception or have some other side effect (even indirectly) when a == b, we can't just blindly execute that code.

Maybe the optimization you envision is able to cope with these possibilities. JIT is a mystery to me. But it seems like something that needs careful attention.

More information about the valhalla-spec-observers mailing list