Information Technology Reference
In-Depth Information
The semantic function for the instruction
(invokevirtual "
class
name
""
"
n
)
is shown below.
Invokevirtual
is the most complicated instruction on the
TJVM. It invokes a named method,
name
,onagivennumber,
n
, of parameters.
The
parameters are obtained from the operand stack. But the method invoked
is determined by \method resolution," which is a function of the class of the
object to which the method is applied. This object is denoted, both in Java and
the TJVM, by the value of the variable symbol
this
. The \this" object is in
essence an
n
+1
st
parameter and is the deepest one on the operand stack at the
time of call but it is special because of its role in method resolution.
n
(defun execute-INVOKEVIRTUAL (
inst s
)
(let* ((
name
(arg2
inst
))
(
n
(arg3
inst
))
(
ref
(top (popn
n
(stack (top-frame
s
)))))
(
class
(class-name-of-ref
ref
(heap
s
)))
(
method
(lookup-method
name
class
(class-table
s
)))
(
vars
(cons 'this (method-formals
method
)))
(
prog
(method-program
method
)))
(make-state
(push (make-frame 0
(reverse
(bind-formals (reverse
vars
)
(stack (top-frame
s
))))
nil
prog
)
(push (make-frame (+ 1 (pc (top-frame
s
)))
(locals (top-frame
s
))
(popn (length
vars
)
(stack (top-frame
s
)))
(program (top-frame
s
)))
(pop (call-stack
s
))))
(heap
s
)
(class-table
s
))))
In the ACL2 function above,
are the name of the method to be
invoked and the number of parameters (not counting the \this" object). The
instruction obtains a reference,
name
and
n
, to the \this" object of the invocation by
looking down the operand stack an appropriate distance, given
ref
n
, the number of
formals of the named method. It then obtains the class,
class
, of the referenced
object and uses the given method
name
and object
class
to determine the nearest
appropriate method,
, using the ACL2 function
lookup-method
, which
formalizes method resolution. Let
method
vars
be the formal parameters of the resolved
method
, extended with one additional formal, named
this
, and let
prog
be the
byte code program for
.
The instruction then modies the existing top frame of the call stack by
incrementing the program counter and popping
method
n
+1 items o the operand stack.
Search WWH ::
Custom Search