Is there a way (in Eclipse, preferably) to simulate JIT optimizations of my code? I can use Bytecode Visualizer to see the non-optimized version, but what I also want to see is how the code changes over time with the JIT optimizations. I want to make sure that I'm writing JIT friendly code.
Asked
Active
Viewed 447 times
1
-
7Generally, efforts to write backend-friendly code are ill-advised. Write correct, clean, well-structured code using good algorithms but stay away from ideas of how to coddle optimizers. – laune Oct 01 '15 at 17:36
-
I can only second that: simply write clear, well-structured code. JIT optimisations are usually based on observing your code in action and making assumptions about it, so if your code behaves sensibly, the JIT is likelier to make the correct guess. – biziclop Oct 01 '15 at 17:38
-
1You can’t simulate JIT optimizations as these optimizations require actual execution of the code to gather the parameters for the optimization. The result isn’t the same in every run… – Holger Oct 01 '15 at 18:58
-
3@Holger So much so, that the same piece of code can be recompiled several times during the process' lifetime. – biziclop Oct 01 '15 at 19:18
-
1I've been thinking about this problem a lot over the past year. Perhaps I should rephrase the question: Is there anything I can use to see the roadblocks to JIT optimizations as I write code. For example, if I method goes too long, wouldn't it be nice to see a little warning that says this method is too long to be inlined (over 325 bytes, by default, I think)? – HesNotTheStig Oct 12 '16 at 14:31
2 Answers
4
Once JIT runs, the byte code is converted to machine code, so there is no "optimized" byte code to view.
Unless you're doing something in a really tight loop that's iterated millions of times, you're focusing on the wrong problem. If a profiler shows such a problem, you might post that code, and the expects on here might be able to help you.

Andreas
- 154,647
- 11
- 152
- 247
-
2You can however look at the compiled assembly code as explained [here](http://stackoverflow.com/questions/1503479/how-to-see-jit-compiled-code-in-jvm) – biziclop Oct 01 '15 at 17:36
-
Well, there might be in-between states where the code is neither, standard bytecode nor native machine code. – Holger Oct 01 '15 at 18:57
2
I believe what you're looking for is the JIT generated native code. There are some JVM arguments that will output this, although it doesn't work on all platforms. See How to see JIT-compiled code in JVM?