Java Reference
In-Depth Information
AppendixD
JVM,ClassFiles,andthe CLEmitter
D.1 Introduction
In the rst instance, our compiler's target is the Java Virtual Machine (JVM), a virtual
byte-code machine. In this appendix, we provide a brief description of the JVM, and then
describe the CLEmitter , a high-level interface for producing the byte code.
D.2 Java Virtual Machine (JVM)
The JVM is an abstract architecture that can have any number of implementations. For
example, Oracle has implemented a Java Run-time Environment (JRE 1 ) that interprets
JVM programs, but uses Hotspot technology for further compiling code that is executed
repeatedly to native machine code. We say it is a byte-code machine, because the programs
it executes are sequences of bytes that represent the instructions and the operands.
Although virtual, the JVM has a definite architecture. It has an instruction set and it
has an internal organization.
The JVM starts up by creating an initial class, which is specified in an implementation-
dependent manner, using the bootstrap class loader. The JVM then links the initial class,
initializes it, and invokes its public class method voidmain(String[]args) . The invoca-
tion of this method drives all further execution. Execution of JVM instructions constituting
the main() method may cause linking (and consequently creation) of additional classes and
interfaces, as well as invocation of additional methods.
A JVM instruction consists of a one-byte opcode (operation code) specifying the oper-
ation to be performed, followed by zero or more operands supplying the arguments or data
that are used by the operation.
The inner loop of the JVM interpreter is effectively:
do{
fetchanopcode;
if(operands)fetchoperands;
executetheactionfortheopcode;
}while(thereismoretodo);
The JVM defines various run-time data areas that are used during execution of a pro-
gram. Some of these data areas are created at the JVM start-up and are destroyed only
when the JVM exits. Other data areas are per thread 2 . Per-thread data areas are created
when a thread is created and destroyed when the thread exits.
1 Available at http://www.oracle.com/technetwork/java/javase/downloads/ .
2 j--does not support implementation of multi-threaded programs.
315
 
Search WWH ::




Custom Search