Does Java JIT compile bytecode deterministically - same optimizations for every run on the same machine?

StackOverflow https://stackoverflow.com/questions/17370294

Question

Does Java JIT compile the bytecode with the same optimizations at every run on the same machine?

Does it take into consideration dynamic factors like CPU usage at a given moment, or it will make the same optimizations every time regardless of temporary factors?

Was it helpful?

Solution

No, the optimizations are non-deterministic. Even if you run the exact same single-threaded, fully deterministic program, the sampler used by the JIT to determine which methods to optimize could choose a different set.

Another thing that can change the generated machine code is the actual memory locations of certain constants that are referenced by the code. The JIT can emit machine instructions that directly access these memory locations, resulting in additional differences between the machine code on different passes.

Researchers using the Jikes RVM have addressed this problem for their benchmarks by using a feature called Compiler Replay.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top