RFR: 8330681: Explicit hashCode and equals for java.lang.runtime.SwitchBootstraps$TypePairs

Chen Liang liach at openjdk.org
Sat Apr 20 04:28:27 UTC 2024


On Fri, 19 Apr 2024 23:56:00 GMT, ExE Boss <duke at openjdk.org> wrote:

>> We can reduce overhead of first use of a switch bootstrap by moving `typePairToName` into `TypePairs` and by explicitly overriding `hashCode` and `equals`. The first change avoids loading and initializing the `TypePairs` class in actual cases, the second remove some excess code generation from happening on first use.
>
> src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java line 699:
> 
>> 697: 
>> 698:         public boolean equals(Object other) {
>> 699:             if (other instanceof TypePairs otherPair) {
> 
> To match the behaviour of the `equals` method body generated by `java​.lang​.runtime​.ObjectMethods​::bootstrap`, this should include a fast path check for `this == other`:
> Suggestion:
> 
>             if (this == other) {
>                 return true;
>             }
>             if (other instanceof TypePairs otherPair) {

No, see https://www.youtube.com/watch?v=kuzjX_efuDs; this fast path is faster for == matching case but significantly slows down all other branches.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/18865#discussion_r1573146432


More information about the core-libs-dev mailing list