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

1

6

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?

Discommode answered 28/6, 2013 at 17:20 Comment(5)
Which Java JIT compiler?Jactitation
I'm interested to know for HotSpotCheckerbloom
If your program has randomness and one run calls method A and another run calls method B, then no, you won't get the same optimizations.Monodrama
But what if the exact same code paths are taken?Checkerbloom
I am not sure if this is helpful to you, but you can force it to optimize your function in different ways. See: #19853347Rune
G
5

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.

Galliot answered 28/6, 2013 at 18:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.