volatile boolean isDone in InfraControl

Aleksey Shipilev shade at redhat.com
Mon Oct 3 09:42:00 UTC 2016


Hi James,

On 10/01/2016 12:09 AM, James Cheng wrote:
> For a benchmark as follows,
> 
>     public int i1 = 1, i2 = -2, i3 = 3, i4 = -4;
> 
>     @Benchmark
>     public void testArithAddInt() {
>         i1 += i4;
>         i2 += i1;
>         i3 += i2;
>         i4 += i3;
>     }

...

> 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.

That's completely intentional.

The first part of the story is constant fold elimination, which is
prevented in Hotspot by reading the volatile field:
 http://hg.openjdk.java.net/code-tools/jmh/file/34407adf3d94/jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_10_ConstantFold.java

The second part of the story is unrollable loops, which breaks benchmarking:
 http://hg.openjdk.java.net/code-tools/jmh/file/34407adf3d94/jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_11_Loops.java

> So this benchmark appeared to be dominated by memory ops
> rather than add ops.

Yes, measuring nanosecond-scale events requires creativity. But I think
you measure those for comparison for something else, not for the
"absolute performance" alone. While the base overhead is comparable or
larger than the operation itself, the difference against something else
should be clearly measurable.

Thanks,
-Aleksey



More information about the jmh-dev mailing list