Why access volatile variable is about 100 slower than member?
The volatile members are never cached, so they are read directly from the main memory.
Access to a volatile
variable prevents the CPU from re-ordering the instructions before and after the access, and this generally slows down execution.
Acess to volatile
prevents some JIT optimisaton. This is especially important if you have a loop which doesn't really do anything as the JIT can optimise such loops away (unless you have a volatile field) If you run the loops "long" the descrepancy should increase more.
In more realistic test, you might expect volatile
to take between 30% and 10x slower for cirtical code. In most real programs it makes very little difference because the CPU is smart enough to "realise" that only one core is using the volatile field and cache it rather than using main memory.