On Fri, 1 Jul 2022 10:48:32 GMT, Peter Levart <plev...@openjdk.org> wrote:
>> But, ... is any code path accessing the elements of the @Stable array by >> constant indexes? Only in that case would the annotation have any effect on >> the JIT-ed code. Otherwise it's just a waste of space. > > ... I can only see the array being cloned and not accessed directly. I don't > belive cloning a @stable array is any different in JIT-ed code as cloning > normal "mutable" array unless JIT "sees" through it and scalarizes the values > of the cloned array. For example, if you have the following: > > > static final Method method = ....; > > @Benchmark > public Object getParameter0() { > return method.getParameters()[0]; > } > > > ...would it run faster when the parameters field was marked as @stable as > opposed to not? @plevart I've checked it with and without `@stable`, it's the same: with Benchmark Mode Cnt Score Error Units AccessParamsBenchmark.getParameter0 avgt 50 6,196 ± 0,142 ns/op AccessParamsBenchmark.getParameters avgt 50 4,636 ± 0,075 ns/op without Benchmark Mode Cnt Score Error Units AccessParamsBenchmark.getParameter0 avgt 50 6,196 ± 0,142 ns/op AccessParamsBenchmark.getParameters avgt 50 4,636 ± 0,075 ns/op This seems logical as effects of `@Stable` aren not propagated into cloned array. This is the benchmark I used: @State(Scope.Thread) @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) @Fork(jvmArgsAppend = {"-Xms1g", "-Xmx1g"}) public class AccessParamsBenchmark { private final Method method; public AccessParamsBenchmark() { try { method = getClass().getMethod("foo", int.class, String.class); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } } @Benchmark public Object getParameters() { return method.getParameters(); } @Benchmark public Object getParameter0() { return method.getParameters()[0]; } public void foo(int parameter1, String parameter2) { } } So, should we rid the annotation from `parameters` field? ------------- PR: https://git.openjdk.org/jdk/pull/9143