Hardware Reference
In-Depth Information
Stack before
IRETURN
Return value
SP
Previous LV
Previous PC
Caller's
local
variables
Stack base
before
IRETURN
Parameter 3
Parameter 2
Parameter 1
Link ptr
Previous LV
Previous PC
Stack after
IRETURN
LV
Return value
SP
Previous LV
Previous PC
Caller's
local
variables
Caller's
local
variables
Parameter 2
Parameter 1
Link ptr
Caller's
local
variable
frame
Stack base
after
IRETURN
Parameter 2
Parameter 1
Link ptr
LV
(a)
(b)
Figure 4-13. (a) Memory before executing IRETURN . (b) After executing it.
location formerly occupied by OBJREF . To restore the old state, the IRETURN in-
struction must be able to restore the PC and LV pointers to their old values. It does
this by accessing the link pointer (which is the word identified by the current LV
pointer). In this location, remember, where the OBJREF was originally stored, the
INVOKEVIRTUAL instruction stored the address containing the old PC . This word
and the word above it are retrieved to restore PC and LV , respectively, to their old
values. The return value, which is stored at the top of the stack of the terminating
method, is copied to the location where the OBJREF was originally stored, and SP
is restored to point to this location. Control is therefore returned to the instruction
immediately following the INVOKEVIRTUAL instruction.
So far, our machine does not have any input/output instructions. Nor are we
going to add any. It does not need them any more than the Java Virtual Machine
needs them, and the official specification for JVM never even mentions I/O. The
theory is that a machine that does no input or output is ''safe.'' (Reading and writ-
ing are performed in JVM by means of calls to special I/O methods.)
4.2.4 Compiling Java to IJVM
Let us now see how Java and IJVM relate to one another. In Fig. 4-14(a) we
show a simple fragment of Java code. When fed to a Java compiler, the compiler
would probably produce the IJVM assembly-language shown in Fig. 4-14(b). The
 
 
 
Search WWH ::




Custom Search