Unit1_JVM
Unit1_JVM
JVM
The JVM is the virtual machine on which Java code executes. It's
responsible for converting byte code into machine-specific code.
Heap
The heap is the place where all objects are stored in JVM. The heap even
contains arrays because arrays are objects.
Execution Engine
The Execution Engine contains the JIT (Just In Time) Compiler and
Garbage Collector compiler, as well as the Interpreter
JIT Compiler
The JIT Compiler compiles bytecode to machine code at runtime and
improves the performance of Java applications.
Of course, JIT compilation does require processor time and memory
usage. When the JVM first starts up, lots of methods are called. Compiling
all of these methods might affect startup time significantly, though a
program ultimately might achieve good performance.
Methods are not compiled when they are called the first time. For each
and every method, the JVM maintains a call count, which is incremented
every time the method is called. The methods are interpreted by the JVM
until the call count exceeds the JIT compilation threshold (the JIT
compilation threshold improves performance and helps the JVM to start
quickly. The threshold has been selected carefully by Java developers
for optimal performance. The balance between startup times and long-
term performance is maintained).
Therefore, very frequently used methods are compiled as soon as the
JVM has started, and less frequently used methods are compiled later.
After a method is compiled, its call count is reset to zero, and subsequent
calls to the method increment its call count. When the call count of a
method reaches a JIT recompilation threshold, the JIT compiler compiles
method a second time, applying more optimizations as compared to
optimizations applied in the previous compilation. This process is
repeated until the maximum optimization level is reached. The most
frequently used methods are always optimized to maximize the
performance benefits of using the JIT compiler.
Let’s say the JIT recompilation threshold = 2.
After a method is compiled, its call count is reset to zero and subsequent
calls to the method increment its call count. When the call count of a
method reaches 2 (i.e. JIT recompilation threshold), the JIT compiler
compiles the method a second time, applying more optimizations.
Garbage Collector
Garbage collection is the process by which the JVM clears objects
(unused objects) from the heap to reclaim heap space.
Interpreter
Interpreter is responsible for reading the bytecode and then executing
the instructions.
Heap
JIT (Just In Time) Compiler and
Garbage collector
Diagram: key components of HotSpot JVM for performance.
Three components (the heap, JIT (Just In Time) compiler, and Garbage
collector) are related to JVM’s performance tuning.
All objects are stored in the heap, and the garbage collector manages the
heap at JVM initialization.
There are many VM (JVM) options for:
Increasing and decreasing the heap size for managing object for
best performance.
Selecting different garbage collectors, depending on your
requirement.
The JVM is a very powerful and flexible runtime platform for languages
such as Java, Groovy, Scala, and Clojure. The JVM provides a large
number of libraries and is completely interoperable with Java.