RFR: 8332249: Micro-optimize Method.hashCode
Chen Liang
liach at openjdk.org
Fri May 31 16:35:12 UTC 2024
On Wed, 29 May 2024 15:03:15 GMT, Sean Gwizdak <duke at openjdk.org> wrote:
>> src/java.base/share/classes/java/lang/reflect/Method.java line 99:
>>
>>> 97: private Method root;
>>> 98: // Hash code of this object
>>> 99: private int hash;
>>
>> We can declare this field `@Stable`, like the `methodAccessor`.
>
> This was something that I tried and I observed a performance regression on the ARM platform that I was testing. From my understanding, `@Stable` tells the compiler to trust the contents of this field which is only given when the field holder is a known constant. This is generally true for cases like `Enums` but not usually for `Method`.
>
>
> Benchmark Mode Cnt Score Error Units
> # Intel Skylake
> MethodHashCode.benchmarkHashCode avgt 5 1.113 ± 1.146 ns/op
> # Arm Neoverse N1
> MethodHashCode.benchmarkHashCode avgt 5 3.204 ± 0.001 ns/op
Interesting, don't know about hotspot internals so I can't diagnose the exact cause of this regression.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/19433#discussion_r1619080123
More information about the core-libs-dev
mailing list