Java Reference
In-Depth Information
Phase 4: Bytecode Verification
In Phase 4, as the classes are loaded, the bytecode verifier examines their bytecodes to en-
sure that they're valid and do not violate Java's security restrictions (Fig. 1.9). Java enforces
strong security to make sure that Java programs arriving over the network do not damage
your files or your system (as computer viruses and worms might).
Primary
Memory
Bytecode verifier
confirms that all
bytecodes are valid and
do not violate Java's
security restrictions
Phase 4: Verify
Bytecode Verifier
Fig. 1.9 | Typical Java development environment—verification phase.
Phase 5: Execution
In Phase 5, the JVM executes the program's bytecodes, thus performing the actions specified
by the program (Fig. 1.10). In early Java versions, the JVM was simply an interpreter for Java
bytecodes. Most Java programs would execute slowly, because the JVM would interpret and
execute one bytecode at a time. Some modern computer architectures can execute several in-
structions in parallel. Today's JVMs typically execute bytecodes using a combination of in-
terpretation and so-called just-in-time (JIT) compilation . In this process, the JVM analyzes
the bytecodes as they're interpreted, searching for hot spots —parts of the bytecodes that exe-
cute frequently. For these parts, a just-in-time ( JIT ) compiler , such as Oracle's Java
HotSpot™ compiler , translates the bytecodes into the underlying computer's machine lan-
guage. When the JVM encounters these compiled parts again, the faster machine-language
code executes. Thus Java programs actually go through two compilation phases—one in
which source code is translated into bytecodes (for portability across JVMs on different com-
puter platforms) and a second in which, during execution, the bytecodes are translated into
machine language for the actual computer on which the program executes.
To execute the program, the
JVM reads bytecodes and
just-in-time (JIT) compiles
(i.e., translates) them into a
language that the computer
can understand. As the
program executes, it may store
data values in primary
memory.
Primary
Memory
Phase 5: Execute
Java Virtual Machine (JVM)
Fig. 1.10 | Typical Java development environment—execution phase.
Problems That May Occur at Execution Time
Programs might not work on the first try. Each of the preceding phases can fail because of
various errors that we'll discuss throughout this topic. For example, an executing program
 
 
Search WWH ::




Custom Search