does optimization using JIT happens only once and remain forever or just during the lifecycle of the run?

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

Question

I was reading different articles on Just-in-time compilers and it is mentioned that JIT optimizes code fragments (hotspots) into direct native code (machine code). My question is does this optimization happens every time I run the .class file. On the otherhand, traditional compiled codes is optimized once and for-ever, not just during one execution (for example).

and where does this kind of hot-spot optimization "remembered" in the machine?

Was it helpful?

Solution

That could depend on the JRE implementation, but in general JIT optimization gets redone each time you launch the program. Among other things, hotspot environments may change their optimization based on runtime profiling with the input data actually being processed.

Yes, this is very different from traditionally compiled languages.

One thing to watch out for: Partly because it depends on input, there is no guarantee that a hotspot JIT will optimize the code the same way every time. This makes trying to hand-optimize Java code MUCH more difficult. You really need to do full profile analysis, and you need to do it over extended executions and a complete range of input data, or you're likely to fool yourself. I've seen 20% performance variation on the same machine running the same code over the same input, apparently because the JIT optimized in a different order and ran into limits on how much native code it was willing to produce.

OTHER TIPS

The JIT compiler produces artifacts which exist only in the working memory of the JVM process. Even within the same process the same code is often recompiled due to one optimistic assumption or other having been invalidated.

Take note that JIT-compilation can be (and on the HotSpot, is) more aggressive than static compilation—mostly due to the above-mentioned optimistic assumptions, which statically compiled code cannot afford.

The Just-In-Time translation exists only during the run of the program. When the program terminates the JIT instructions are gone (but they may be regenerated during the next execution - it depends on the "hot" path).

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