Java Reference
In-Depth Information
QUICK SUMMARY
1. The code cache is a resource with a defined maximum size that affects the total
amount of compiled code the JVM can run.
2. Tiered compilation can easily use up the entire code cache in its default configura-
tion (particularly in Java 7); monitor the code cache and increase its size if neces-
sary when using tiered compilation.
Compilation Thresholds
This chapter has been somewhat vague in defining just what triggers the compilation of code.
The major factor involved here is how often the code is executed; once it is executed a cer-
tain number of times, its compilation threshold is reached, and the compiler deems that it has
enough information to compile the code.
There are tunings that affect these thresholds, which are discussed in this section. However,
this section is really designed to give you better insight into how the compiler works (and in-
troduce some terms). There is really only one case where the compilation thresholds might
need to be tuned; that is discussed at the end of this section.
Compilation is based on two counters in the JVM: the number of times the method has been
called, and the number of times any loops in the method have branched back. Branching
back can effectively be thought of as the number of times a loop has completed execution,
either because it reached the end of the loop itself or because it executed a branching state-
ment like continue .
When the JVM executes a Java method, it checks the sum of those two counters and decides
whether or not the method is eligible for compilation. If it is, the method is queued for com-
pilation (see Compilation Threads for more details about queuing). This kind of compilation
has no official name but is often called standard compilation.
But what if the method has a really long loop—or one that never exits and provides all the
logic of the program? In that case, the JVM needs to compile the loop without waiting for a
method invocation. So every time the loop completes an execution, the branching counter is
incremented and inspected. If the branching counter has exceeded its individual threshold,
then the loop (and not the entire method) becomes eligible for compilation.
Search WWH ::




Custom Search