I am learning about JMM and the optimizations made by the JVM are getting in the way of observing JMM functionality. How can I turn off JVM optimizations?
1 Answer
The "-Xint" option runs with the JIT compiler disabled. That is the closest you will get to "turning off optimization".
However, there is nothing in the documentation that says what effect this has on the JMM.
If you are trying to understand the JMM, then observing behavior (i.e. black box testing with -Xint) can never prove that a positive hypothesis is correct. Especially since the effect of -Xint on the JMM is not specified. All testing can do is to demonstrate behaviors that differ and therefore1 are not guaranteed by the JMM / JLS.
If you want to actually reason about the JMM, use logic. Read and understand the specification, and apply that knowledge in your reasoning.
1 - modulo bugs in the JVM, JIT compiler, hardware (!), etc.