Initialization of @Param's in nested @State classes
Gleb Smirnov
me at gvsmirnov.ru
Sat Nov 15 15:13:45 UTC 2014
Hi All,
Given the following test case:
public class NestedStateBenchmark {
@State(Scope.Benchmark)
public static class NestedState {
@Param({"0", "1"})
public int foo;
}
@State(Scope.Thread)
public static class OuterState {
public int bar;
@Setup
public void setup(NestedState nestedState) {
this.bar = -nestedState.foo;
}
}
@Benchmark
public int measure(OuterState state) {
return state.bar;
}
}
One would expect the `measure` method to be returning 0 or 1, with respect
to
the param `foo`.
However, what actually happens is the benchmark crashing with the following
exception:
java.lang.IllegalStateException: The value for the parameter "foo" is not
set.
at
org.openjdk.jmh.runner.InfraControlL2.getParam(InfraControl.java:190)
at
org.openjdk.jmh.runner.InfraControl.getParam(InfraControl.java:39)
at
generated.NestedStateBenchmark_measure._jmh_tryInit_f_nestedstate3_G(NestedStateBenchmark_measure.java:331)
at
generated.NestedStateBenchmark_measure.measure_Throughput(NestedStateBenchmark_measure.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
org.openjdk.jmh.runner.LoopBenchmarkHandler$BenchmarkTask.call(LoopBenchmarkHandler.java:199)
at
org.openjdk.jmh.runner.LoopBenchmarkHandler$BenchmarkTask.call(LoopBenchmarkHandler.java:181)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown
Source)
at java.lang.Thread.run(Unknown Source)
This is a bug, a person familiar with the matter said
(https://twitter.com/shipilev/status/533565238407618560)
Reproducible with JMH 1.3.
--
Gleb
More information about the jmh-dev
mailing list