On Wed, 29 May 2024 15:20:15 GMT, Chen Liang <li...@openjdk.org> wrote:

>> 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.

In order to be eligible for constant folding, the benchmark must declare the 
`Method hashCodeMethod;` as `static final`.

It is hard for me to understand why a `@Stable` annotation should have a 
detrimental performance impact on an instance field.

Can we see a benchmark on Arm Neoverse N1 with the field declared `@Stable` 
compared to not declared `@Stable`? Also, if the field is `static final`, how 
would it look like?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/19433#discussion_r1627803876

Reply via email to