volatile boolean isDone in InfraControl

Nitsan Wakart nitsanw at yahoo.com
Sat Oct 1 12:38:45 UTC 2016


Hi James,Firstly, the isDone/volatileSpoiler effect is entirely intentional.It causes 2 things as you point out:1. Reload all fields in called benchmark method(which is force inlined)2. Prevent loop unrollingThis prevents the compiler from optimizing the method under measurement in an uncontrolled fashion (loop unroll count may vary, a non-volatile read will allow loads to be hoisted etc). The effects of allowing these optimizations to take place is confusing, misleading and fragile. JMH does the *right* thing for the general case by preventing this.This may not be exactly what you need for every case, but this is still the right choice for JMH(IMO). For more information on these decisions look for Shipilev talk on JMH from JVMLS and read through the unrolled look sample.Secondly, you ask how you may measure the cost of a register to register add. The answer IMO is to look it up in Agner Fog instruction cost tables, where you'll get a good approximation for each processor which added indication of reciprocal throughput (The average number of core clock cycles per instruction for a series of independent instructions of the same kind in the same thread). Measuring the cost of single instructions is not very meaningful IMO without the mix of instructions they get executed with on modern processors which can do crafty things like reordering of instructions, micro-op fusion and parallel execution of instructions.I'm not discouraging you from experimentation! you can have some very educational fun measuring stuff and refining your understanding of what the measurements mean, but measuring costs of the sub 10ns scale is tricky at best (in your context: ADD on a modern x86 is 1 cycle -> 0.25 to 0.5ns and the CPU can execute 4 or 5 in parallel).Good Luck,Nitsan


More information about the jmh-dev mailing list