AW: volatile boolean isDone in InfraControl
ecki at zusammenkunft.net
ecki at zusammenkunft.net
Sat Oct 1 16:12:59 UTC 2016
Hello James,
I would think if you want to test unrolling and inlining effects inside loops it is best to have a loop inside your method under test: You dont have the volatile access then inside the hot code and can better emulate the structure of the code. (dont forget to actually return/blackhole a result from your loop)
Blackholes have similiar effects:
http://psy-lob-saw.blogspot.de/2014/08/the-volatile-read-suprise.html
I think Aleksey wrote something about isDone effects on iterated code, but I cant find it right now.
Gruss
Bernd
--
http://bernd.eckenfels.net
>From Win 10 Mobile
Von: James Cheng
Gesendet: Samstag, 1. Oktober 2016 00:39
An: jmh-dev at openjdk.java.net
Betreff: volatile boolean isDone in InfraControl
Hi,
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 generated testArithAddInt_thrpt_jmhStub() looks like this:
result.startTime = System.nanoTime();
do {
l_jgarith0_0.testArithAddInt();
operations++;
} 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
loop.
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?
Thanks,
-James
More information about the jmh-dev
mailing list