Java Reference
In-Depth Information
time on optimizing as the static compilers do because the time spent on optimizations adds
to the execution time. Also, because classes can be dynamically invoked or each method is
compiled on demand, it is dicult for JIT compilers to perform global optimizations.
When compared to interpretation, JIT compilation has another downside: methods are
entirely compiled before they are executed. If only a small part of a large method is executed,
JIT compilation may be time consuming [Kazi et al., 2000]. The memory usage is increased
as well because native code requires more space than the more compact JVM byte code.
The Oracle JVM uses a JIT compilation regimen called HotSpot. Knuth's nding, which
states that most programs spend the majority of time executing a small fraction of the
code [Knuth, 1971a], lays the foundation for a technique called adaptive optimization. Adap-
tive optimization was pioneered by the Jikes Research Virtual Machine 2 at IBM Watson
Research Center. Animorphic, a small start-up company, which was acquired by Sun Mi-
crosystems in 1997, adopted the technique and developed the Java HotSpot VM.
The Java HotSpot VM has both an interpreter and a byte code-to-native machine code
compiler. Instead of compiling every method it encounters, the VM first runs a profiling
interpreter to quickly gather run-time information, detect the critical \hot spots" in the
program that are executed most often, and collect information about the program behavior
so it may use it to optimize the generated native code in later stages of program execution.
The identified hot spots are then compiled into optimized native code, while infrequently
executed parts of the program continue to be interpreted. As a result, more time can be spent
on optimizing those performance-critical hot spots, and the optimizations are smarter than
static compiler optimizations because of all the information gathered during interpretation.
Hot spot monitoring continues during run-time to adapt the performance according to
program behavior.
There are two versions of the Java HotSpot VM: the Client VM [Kotzmann et al., 2008]
and the Server VM. These two VMs are identical in their run-time, interpreter, memory
model, and garbage collector components; they differ only in their byte code-to-native ma-
chine code compilers.
The client compiler, is simpler and focuses on extracting as much information as possible
from the byte code, like locality information and an initial control flow graph, to reduce
the compilation time. It aims to reduce the initial start-up time and memory footprint on
users' computers.
The server compiler on the other hand, is an advanced dynamic optimizing compiler
focusing on the run-time execution speed. It uses an advanced SSA-based IR 3 for opti-
mizations. The optimizer performs classic optimizations like dead code elimination, loop-
invariant hoisting, common sub-expression elimination and constant propagation, as well
as Java-specific optimizations such as null-check and range check elimination 4 . The register
allocator is a global graph coloring allocator 5 [Oracle, 2010]. However, the most impor-
tant optimizations performed by the Java HotSpot server compiler are method inlining and
dynamic de-optimization.
Static compilers cannot take full advantage of method inlining because they cannot
know if a method is overridden in a sub-class. A static compiler can conservatively inline
static, final, and private methods because such methods cannot be overridden, but there
is no such guarantee for public and protected methods. Moreover, classes can be loaded
dynamically during run-time and a static compiler cannot deal with such run-time changes
in the program structure [Wilson and Kesselman, 2000].
While method inlining can reduce both compilation time and execution time, it will
2 Initially called the Jalapeno project.
3 SSA stands forstaticsingleassignmentand IR stands forIntermediateRepresentation. See Chapter 6.
4 See Chapter 6 for various optimizations techniques.
5 See Chapter 7 for register allocation techniques, including graph-coloring allocation.
 
Search WWH ::




Custom Search