For execution of a single thread, the rules are simple. The Java Language Specification requires a Java Virtual Machine to observe "within-thread as-if-serial" semantics. The runtime (which, in this case, usually refers to the dynamic compiler, the processor and the memory subsystem) is free to introduce any useful execution optimizations as long as the result of the thread in isolation is guaranteed to be exactly the same as it would have been had all the statements been executed in the order the statements occurred in the program (also called program order).