My understanding is that an optimization is valid if it has no observable effect that contradicts the JLS. So for example, the JIT compiler can optimize away "do nothing" code in an inner loop.
But I don't recalling a definitive statement to this effect.
Does anyone know of a definitive statement (i.e. in the JLS or a document of similar standing) of when a Java optimization (e.g. performed by the native code compiler) is valid?