4

As I studied about JIT compiler from here: What does a just-in-time (JIT) compiler do? and

there's no *.exe or *.dll generated by the Java JIT for Windows. It writes the processor instructions to memory (RAM) and runs it from there. There's no need to create a separate PE file with file-headers and everything

My question is WHY doesn't JIT compiler ( Java ) save the results? Isn't it useful to store compiled code to save time for the next launch?

(My question is different from the mentioned above, because I emphasized on WHY)

Axel Coon
  • 85
  • 8
  • 1
    I don't think this is an inherently bad question, but only a developer of an actual JVM would be able to answer for certain. Most likely, it's because saving the internal JVM state would be an extremely tricky operation; that said, check into GraalVM. – chrylis -cautiouslyoptimistic- Jan 03 '19 at 07:49

1 Answers1

4

The ouput of a JIT may be different for each run - it can optimize for the current load pattern. This sometimes allows it to optimize more agressively than what would be possible for pre-compiled code that needs to be reusable.

If the load-pattern changes and the optimization is found to be sub-optimal or even adverse, a JIT can de-optimize and possibly attempt a different optimization

(see also About the dynamic de-optimization of HotSpot)

Now, it might sometimes save some performance to keep these results of various compiled versions around and reuse them later, but it would also require a significant amount of book-keeping to be able to find out if a section of code has already been compiled with currently relevant optimizations.

I suppose that is just not considered worth the effort. Its a tradeoff between doing file-IO and usually fast compilation of small sections of code.

Hulk
  • 6,399
  • 1
  • 30
  • 52