Using switch patterns to rewrite Arrays.deepHashCode

John Rose john.r.rose at oracle.com
Sat Sep 11 18:42:02 UTC 2021


On Sep 11, 2021, at 6:48 AM, Brian Goetz <brian.goetz at oracle.com<mailto:brian.goetz at oracle.com>> wrote:

You would need to reorder this switch!  Because byte[] will be a subtype of Object[].

In Valhalla, that is.  Putting Object[] at the bottom
will absorb any and all “new primitives”.  In fact,
the “old primitives” will also be absorbed by Object[],
so in Valhalla the switch statement is not required,
but may be simply a hand-optimization (to get
hand-specialized code for some known types).
That sort of hand-optimization wants to be replaced
by JVM and language support for template-like
specialization.

Putting Object[] at the top forces a re-evaluation
when Valhalla comes, since the code will break.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20210911/e17c3e63/attachment.htm>


More information about the amber-spec-experts mailing list