Java Reference
In-Depth Information
available, then a small table is typically generated that is indexed by
the receiver's runtime type. The table contains method pointers so that
the appropriate method is dispatched based on the receiver type. More
detail on this is presented in Section 13.1.3 on page 496.
We use o.foo(a, 250) as an example to illustrate the code generated on
behalf of an Invoking node. We assume o is an instance of MyClass,andis
allocated to local 4. The method foo in MyClass accepts two int parameters
and returns a boolean.AnASTforo.foo(a, 250) is shown in the box below.
The code generated for the AST treats o as if it were an extra parameter to foo,
evaluating it ahead of foo's specified parameters, and causing the contents of
local 4 to be pushed on the stack as an address (aload 4). Marker 39 visits the
parameters in left-to-right order, generating code to evaluate each and pushing
the resulting value on TOS.
AST
JVM Instructions
;
AST and code for invoking the
InvokeIsh
;
method foo from class MyClass:
foo
;
;
o.foo(a, 250)
n
;
;
Marker 38 emits code
LocalReferencing
o
;
for the instance o:
aload 4
params
;
Marker 39 emits code
;
for the parameters:
iload 5
sipush 250
ConstantIsh
LocalReferencing
;
The method call
invokevirtual MyClass/foo(II)Z
a
250
The JVM specified signature for foo is (II)Z. This indicates that foo has
two explicit int parameters (denoted by (II))andaboolean return value
(denoted by Z).
11.3.7 Field References
/
Visitor code for Marker 10
/
procedure
visit
(FieldReferencing n )
call n . getInstance() . accept( this )
call
41
( n . getType(), n . getName())
emit
F
ield
R
eference
end
 
 
Search WWH ::




Custom Search