On Fri, 1 Jul 2022 20:39:49 GMT, Сергей Цыпанов <d...@openjdk.org> wrote:

>> @Stable is only effective if the path leading to @Stable value can be 
>> constant-folded by JIT. In above test, you have an instance field Method 
>> method. This can not be constant-folded, so neither can @stable fiels in the 
>> Field object, nor array elements of a @stable array. You should replace that 
>> with "static final Method method = ..." and re-run the test.
>
> With `static` and without `@Stable` the benchmark yields
> 
> Benchmark                            Mode  Cnt  Score   Error  Units
> AccessParamsBenchmark.getParameter0  avgt   10  1,212 ± 0,083  ns/op
> AccessParamsBenchmark.getParameters  avgt   10  2,493 ± 0,076  ns/op
> 
> and with `@Stable`
> 
> Benchmark                            Mode  Cnt  Score   Error  Units
> AccessParamsBenchmark.getParameter0  avgt   40  0,427 ± 0,007  ns/op
> AccessParamsBenchmark.getParameters  avgt   40  2,123 ± 0,052  ns/op
> 
> so the annotation is useful.

hmm, is the faster getParameters (without explicit index access) a result of 
the annotation? getParameter0 shows the documented effect but isn't quite our 
use case here.

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

PR: https://git.openjdk.org/jdk/pull/9143

Reply via email to