Hardware Reference
In-Depth Information
Stack after
INVOKEVIRTUAL
Caller's LV
Caller's PC
SP
Space for
caller's local
variables
Stack before
INVOKEVIRTUAL
Stack base
after
INVOKEVIRTUAL
Parameter 3
Parameter 2
Parameter 1
OBJREF
Previous LV
Previous PC
SP
Parameter 3
Parameter 2
Parameter 1
Link ptr
Pushed
parameters
LV
Previous LV
Previous PC
Caller's
local
variables
Parameter 2
Parameter 1
Link ptr
Caller's
local
variables
Caller's
local
variable
frame
Stack base
before
INVOKEVIRTUAL
Parameter 2
Parameter 1
Link ptr
LV
(a)
(b)
Figure 4-12. (a) Memory before executing INVOKEVIRTUAL . (b) After executing it.
used to construct an index into the constant pool table (the first byte is the high-
order byte). The instruction computes the base address of the new local variable
frame by subtracting off the number of parameters from the stack pointer and set-
ting LV to point to OBJREF . At this location, overwriting OBJREF , the imple-
mentation stores the address of the location where the old PC is to be stored. This
address is computed by adding the size of the local variable frame (parameters +
local variables) to the address contained in LV . Immediately above the address
where the old PC is to be stored is the address where the old LV is to be stored. Im-
mediately above that address is the beginning of the stack for the newly called pro-
cedure. SP is set to point to the old LV , which is the address immediately below the
first empty location on the stack. Remember that SP always points to the top word
on the stack. If the stack is empty, it points to the first location below the end of
the stack because our stacks grow upward, toward higher addresses. In our figures,
stacks always grow upward, toward the higher address at the top of the page.
The last operation needed to carry out INVOKEVIRTUAL is to set PC to point to
the fifth byte in the method code space.
The IRETURN instruction reverses the operations of the INVOKEVIRTUAL in-
struction, as shown in Fig. 4-13. It deallocates the space that was used by the re-
turning method. It also restores the stack to its former state, except that (1) the
(now overwritten) OBJREF word and all the parameters have been popped from the
stack, and (2) the returned value has been placed at the top of the stack, at the
 
Search WWH ::




Custom Search