continuous JIT compiling?
843829Feb 21 2008 — edited Feb 22 2008Many of you know that hotspot starts by interpreting bytecodes, and then selectively "Just In Time" (JIT) compiles those methods which are called a lot (i.e.the hotspots).
My understanding is that while hotspot is still interpreting a method, it maintains profiling code on that method in order to gather statistics which will enable it to make really good dynamically optimized decisions (e.g. for memory alignment, cache sizes, branch predictions, etc).
But what happens once a method has been compiled by hotspot? Does it ever still maintain profiling code and go back to a compiled method and recompile it again, this time using even more aggressive optimizations? Or does it drop all profiling code for a method once it has been compiled?
I did a web search before posting this and found contradictory claims:
a) in the final post on this forum http://forums.java.net/jive/thread.jspa?threadID=33217&tstart=15, linuxhippy/Ig Clemens claims that continuous compiling is not done because maintaining the profiling code is too expensive.
b) stating a contrary opinion, this article http://www-128.ibm.com/developerworks/library/j-jtp12214/ states
Another interesting aspect of the HotSpot approach is that compilation is not an all-or-nothing proposition. After interpreting a code path a certain number of times, it is compiled into machine code. But the JVM continues profiling, and may recompile the code again later with a higher level of optimization if it decides the code path is particularly hot or future profiling data suggests opportunities for additional optimization. The JVM may recompile the same bytecodes many times in a single application execution.
Does anyone know what is really going on here? Sun hotspot programmers, feel free to speak up!
By the way, that last link above points out something very interesting that I never knew before: it has a whole section entitle "Dynamic deoptimization" which discusses how hotspot can deoptimize methods as well when optimization assumptions become invalid.
PS: I tried to make proper hyperlinks out of the urls above by clicking on the chain icon, but clicking on that icon does not seem ever do anything. Is there something that I am doing wrong, or is this a broken feature on these forums? (On other forums, I have gotten similar functionality to work.)