Java Reference
In-Depth Information
The getfield instruction pushes the value of a particular instance field
on TOS. The syntax for a getfield instruction is exactly the syntax of the
getstatic instruction: a name and type are specified as immediate operands.
However, because the instruction also requires an instance of the accessed field,
the semantics of the instruction specify that the TOS must contain a reference
to the instance whose field is to be accessed.
getfield
10
Consider a Point class such that each instance has int
fields: x and y. Consider a particular instance that has
10 and 20 values for its x and y, respectively.
The example shows a Point reference (
·
)onTOS.The
instruction
getfield Point/x I
·
retrieves the value of
's x field, making sure it is an
int, and pushes the value (10) on TOS.
Before
After
The putfield instruction is the instance-specific version of the putstatic
instruction.
·
putfield
431
In the example, the object reference (
) refers to an
instance of a Point object. The instruction
putfield Point/x I
pops two values from TOS. The first is the value (431)
that should be stored at the field (x)specifiedinthe
putfield instruction. The second is a reference to a
Point object, shown as
·
. When the instruction com-
·
pletes,
's x field will have the value 431, and the stack
will have two fewer items.
Before
After
Branching
The JVM provides instructions to alter the control flow of the executing pro-
gram. Control can be transferred unconditionally to the instruction at location
q by a goto instruction. The instruction occupies 3 bytes: one byte specifies the
goto opcode and the other two bytes are concatenated to form a signed 16-bit
o
.If p is the location of the current goto instruction,
control is transferred to the opcode at q = p
ff
set denoted here as
Δ
sets are computed
automatically and targets are specified symbolically using labels. There is also
a5-bytegoto w instruction, which provisions 4 bytes to hold
.InJasmin,o
ff
Δ
(see Exercise 7).
 
Search WWH ::




Custom Search