Java Reference
In-Depth Information
Method postlude: As a method finishes execution, some code may be re-
quired to prepare a return value, propagate an exception, or manage
structures that were created when the method began. Marker 23 gener-
ates such postlude code, which begins at the supplied label.
11.3 The MethodBodyVisitor
A MethodBodyVisitor is instantiated with the label of a sequence of code that
serves as postlude code for the method. This arrangement enables the code
generator to e
ect a method-return by transferring control to the specified
label. We present the elements of this visitor in an order that allows us to
construct a running example of how code is generated recursively by the
visitor.
ff
11.3.1 Constants
/
Visitor code for Marker 4
/
procedure
visit
(ConstReferencing n )
loc ← alloc
()
n . setResultLocal( loc )
L
ocal
24
( loc , n . getConstantValue())
call
emit
C
onstant
L
oad
25
end
Programs reference various constants, whose values can often be included
directly in an immediate instruction .Marker 24 computes a resource (register
or stack cell location) to hold the constant value, and the value is itself produced
by the code generated at Marker 25 . For a stack architecture like the JVM, the
resource to hold the result is the top-of-stack (TOS).
AST
JVM Instructions
ConstantIsh
sipush 250
250
n
There may be multiple instruction sequences that could generate a given con-
stant value. The instruction that takes the least time or instruction space is
typically chosen for this task. The box above features the sipush instruction,
 
 
 
Search WWH ::




Custom Search