Java Reference
In-Depth Information
Augmented Machine Code
Far more often, compilers generate code for a machine architecture that is
augmented with operating system routines and runtime language support
routines. The execution of a program generated by such a compiler requires
that a particular operating system be present on the target machine and a
collection of language-specific runtime support routines (I
O, storage alloca-
tion, mathematical functions, etc.) be available to the program. Most Fortran
compilers use such software support only for I
/
O and mathematical functions.
Other compilers assume a much larger range of available functionality. These
may include data transfer instructions (such as, to move bit fields), procedure
call instructions (to pass parameters, save registers, allocate stack space, etc.),
and dynamic storage instructions (to provide for heap allocation).
/
Virtual Machine Code
The third type of code generated is composed entirely of virtual instructions.
This approach is particularly attractive as a technique for producing code
that can be run easily on a variety of computers. This level of portability
is achieved by writing an interpreter for the virtual machine (VM) on any
target architecture of interest. Code generated by the compiler can then be
run on any architecture for which a VM interpreter is available. Java is an
example of a language for which a VM (the Java Virtual Machine (JVM)
and its bytecode instructions) was defined to accompany the language. Java
applications produce predictable results on any computer for which a JVM
interpreter is available. Similarly, Java applets can be run in any web browser
provisioned with a JVM interpreter.
The advantages of portability obtained by using a VM instruction set can
also make the compiler itself easy to port. For the purposes of this discussion,
assume that the compiler accepts some source language L .Anyinstanceof
this compiler can translate a program written in L into the VM instructions.
If the compiler itself is written in L , then the compiler can compile itself into
VM instructions, which can be executed on any architecture that hosts the VM
interpreter. If the VM is kept simple and clean, the interpreter can be relatively
easy to write. The process of porting such a compiler from one architecture
to another is called bootstrapping and is illustrated in Figure 1.2. The very
first instance of an L compiler cannot compile itself, since no such compiler
exists yet. However, the first instance can be written in a language K for which
a compiler or assembler already exists. As shown in Figure 1.2, the result
of that compilation is the first executable instance of a compiler for L .That
first instance is usually discarded after the reference compiler, written in L ,is
functioning correctly.
Examples of compilers that target a VM for portability include the early
Pascal compilers and the Java compiler included in the Java Development
 
Search WWH ::




Custom Search