Question on "Control" class contract

Осипов Алексей osipov.av at gmail.com
Tue Sep 20 00:41:54 UTC 2016


Hello,

I've run into an issue with JMH "org.openjdk.jmh.infra. Control" class 
and can't find any source of documentation on it other than JavaDoc for 
the class.

I've took "PingPong" example from here: 
http://hg.openjdk.java.net/code-tools/jmh/file/8c20adb08b2d/jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_18_Control.java
and modified it a bit. So my benchmark looks like this:

@State(Scope.Group)
@BenchmarkMode(Mode.Throughput)
@Measurement(time =5, iterations =1)
@Warmup(time =5, iterations =1)
public class MyBenchmark {
     @Benchmark @Group("pingpong")
     public void ping(Control cnt) {
         while (!cnt.stopMeasurement) {
             // this body is intentionally left blank }
     }
     @Benchmark @Group("pingpong")
     public void pong(Control cnt) {
         while (!cnt.stopMeasurement) {
             // this body is intentionally left blank }
     }
}

So I've removed CAS part and left only busy loops on "stopMeasurement" 
field of "Control" class.
I've expected that this benchmark will end after 5 seconds. However it 
looks like "stopMeasurement" never switches to True and benchmark 
invocations never finish.

I've checked code for the generated class and it seems like 
"stopMeasurement" is updated only after iteration finishes so it can't 
change during invocation. And that's contradicts original "PingPong" 
benchmark description. So I'm quite confused.

Am I missing something? Is there any additional information on behavior 
contract of JMH "Control" class other than JavaDocs?

Best regards,
Alexei Osipov.



More information about the jmh-dev mailing list