volatile boolean isDone in InfraControl

James Cheng james.cheng at oracle.com
Fri Sep 30 22:09:14 UTC 2016


For a benchmark as follows,

     public int i1 = 1, i2 = -2, i3 = 3, i4 = -4;

     public void testArithAddInt() {
         i1 += i4;
         i2 += i1;
         i3 += i2;
         i4 += i3;

the generated testArithAddInt_thrpt_jmhStub() looks like this:

         result.startTime = System.nanoTime();
         do {
         } while(!control.isDone);
         result.stopTime = System.nanoTime();

In jmh/runner/InfraControl.java, there are:

     public volatile boolean isDone;
     public volatile boolean volatileSpoiler;

The problem we have is that the volatile boolean isDone appeared to cause the
JIT compiler not to unroll the loop and to spill/refill those variables in every
iteration.  So this benchmark appeared to be dominated by memory ops rather than
add ops.

Other modes like "avgt" and "sample" also use InfraControl.isDone.  The "ss" mode
doesn't use InfraControl.isDone, but it uses InfraControl.volatileSpoiler in the

Is InfraControl.isDone used here for currency control, avoiding some compiler
optimizations on the measurement loop, or both?  Is there a different mode/way
for benchmarking something like the register-to-register add operation?


More information about the jmh-dev mailing list