Java Reference
In-Depth Information
which can handle a signed value that fits in 16 bits. A single byte (bipush)
cannot hold the constant value 250,sothesipush instruction is used instead.
Because instruction specifications vary from VM to VM, we make use of
methods like
at Marker 25 to serve as an abstraction for
the actual VMinstructions that are generated. For example,
emit
C
onstant
L
oad
oad
is responsible for determining the appropriate instruction for loading the con-
stant represented by node n . For the JVM, choices for integer constants include
bipush, sipush, ldc,andiconst.
emit
C
onstant
L
11.3.2 References to Local Storage
/
Visitor code for Marker 5
/
procedure
visit
( LocalReferencing n )
loc ← alloc
()
n . setResultLocal( loc )
L
ocal
26
( loc , n . getLocation())
call
emit
L
ocal
L
oad
27
end
The code generated for a local storage reference causes the value stored at the
named reference to be fetched and placed in an accessible place for subsequent
operations. Marker 26 allocates the register to receive the value, and the code
to perform the fetch is generated at Marker 27 .
AST
JVM Instructions
LocalReferencing
iload 5
a
n
The box shows the resulting instruction generated for the JVM on behalf of a
local reference to the variable a. If the method's assigned storage location for
a is local number 5, then the iload 5 instruction fetches the value from local 5
and pushes it on TOS. A method can assign storage locations for its locals by
a visitor that intercepts LocalDeclaring. Each visit to a LocalDeclaringassigns
the next available storage location. The number of storage locations allocated
to the LocalDeclaringdepends on the type of the local. For example, all types
on the JVM take four bytes except double and long types, which take eight
bytes.
 
 
Search WWH ::




Custom Search