Java Reference
In-Depth Information
to compute a register number and leaveitonTOStoserveastheoperand
of a subsequent load instruction. While the zero-address approach is more
general, and runtime checks could be deployed to check the validity of a
load instruction, a more reliable and e
cient approach would check such
instructions prior to running the code.
As a compromise, the load instruction in the JVM is not zero-address, but
instead specifies the register number as an immediate operand of the instruc-
tion. For example, the instruction iload 5 causes the contents of register 5 to
be pushed on TOS. When the class file is loaded, the instruction is checked to
ensure that register 5 falls within the range of registers its method can access.
The instruction will always access register 5, because the immediate operands
of an instruction cannot be changed at runtime. Thus, by discovering that the
register reference is valid prior to running the code, no further checks of this
kind are necessary at runtime.
When a class file is loaded, many other checks are performed by the
bytecode verifier . The JVM instruction set and class file format are designed
to facilitate such checks.
10.2.2 Contents of a Class File
A JVMclass file is organized into sections called attributes that contain various
information about the compiled class. Here we cover only those attributes
that are most relevant to the code-generation topics discussed in Chapter 11.
Throughout this discussion we describe various aspects of the JVM using the
human-readable Jasmin syntax to denote the binary information contained in
aclassfile.
Types
Like Java, the JVM o
ers primitive and reference types. Types are generally
used to specify the signature of fields and methods, and most instructions
require inputs of a certain type. Primitive types in the JVM are designated by
a single character, as shown in Figure 10.4.
A reference type t is designated as L t ; with t specified as follows. Each
dot in the type is replaced by a forward slash, which results in a Unix R
ff
-like
file path to the class file for the type. The JVM uses such paths to locate a
class file at runtime. For example, the String type in Java is actually found
in the java.lang package. Its full type name is therefore java.lang.String
and it has the type designation Ljava/lang/String; in the JVM. Because of its
need to represent String constants e
ciently, the JVM is aware of the String
reference type, almost as if it were a primitive type.
 
 
Search WWH ::




Custom Search