Initialization of @Param's in nested @State classes
Aleksey Shipilev
aleksey.shipilev at oracle.com
Mon Nov 17 14:15:26 UTC 2014
Should be fixed now with:
http://hg.openjdk.java.net/code-tools/jmh/rev/c60c03ff0993
-Aleksey.
On 11/15/2014 06:19 PM, Aleksey Shipilev wrote:
> Thanks, so recorded:
> https://bugs.openjdk.java.net/browse/CODETOOLS-7901105
>
> -Aleksey.
>
> On 11/15/2014 06:13 PM, Gleb Smirnov wrote:
>> 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.
>
>
More information about the jmh-dev
mailing list