Does the JVM ever re-compiles compiled code?
Krystal Mo
krystal.mo at oracle.com
Thu Apr 11 22:40:32 PDT 2013
Hi Ion,
Remi has explained it quite nicely. I'll just add a few points.
On 04/11/2013 01:39 PM, Ion Ionascu wrote:
> Hi,
>
>
> I hope this is the right mailing list to ask this question.
>
Yes, it is if you're looking for HotSpot VM specific information.
HotSpot VM is just one implementation of the JVM spec, and there are
other vendors that may take a different approach than we do.
> Could you please tell me if the JVM ever re-compiles already compiled
> bytecode?
Yes, just as Remi said in his reply. HotSpot's JIT compilers can make
aggressive assumptions of the program and optimize accordingly, e.g.
Class Hierarchy Analysis, implicit null-pointer checking, etc. When
those assumptions are broken after a method has been JIT compiled, then
the compiled code will be thrown away, and execution in the compiled
code will be "deoptimized" to run in (1) the interpreter in non-tiered
mode; (2) maybe in lower tier code in tiered mode.
You can confirm that by specifying the -XX:+PrintCompilation VM flag,
and watch for messages like "made not entrant". That's the sign of
deoptimization happening.
> And, is the compiled code ever brought back to a state where it is
> just interpreted?
>
Yes. An interesting example you might not have guessed is that even in
-Xcomp mode, HotSpot may run a lot of code in the interpreter. That's
because C2 (HotSpot server compiler) doesn't (and can't) load Java
classes, and doesn't generate code to load Java classes; so if it sees a
Java class that is not yet loaded in a method when that method is being
compiled, then C2 generates an uncommon trap there. When the uncommon
trap is hit, it'll deoptimize and go back into the interpreter to load
the class. And then this method may be compiled again later.
> I am curious about re-compilation because the server compiler is set
> by default to compile code after 10000 accesses in order to
> statistically guarantee that enough information has been gathered to
> do the best optimisations. But, does the JVM continue to track code
> usage after it is compiled?
>
Right now in HotSpot, no. HotSpot instruments the interpreter (and lower
tier compiled code in tiered mode) with counters to trigger compilation.
C2 compiled code don't have such counters. And HotSpot doesn't do
sampling-based profiling that feeds into the JITs now.
Other JVM vendors may take tradeoffs differently, though.
- Kris
>
> Thank you,
> Ion Ionascu
>
> www.ionionascu.eu <http://www.ionionascu.eu>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/attachments/20130411/4c08e11f/attachment.html
More information about the hotspot-compiler-dev
mailing list