Professional Documents
Culture Documents
Felix Hernandez-Campos
COMP 144 Programming Language Concepts Lecture 32: The Java Virtual Machine
Reference
The content of this lecture is based on Inside the Java 2 Virtual Machine by Bill Venners
Chapter 1Introduction to Java's Architecture
http://www.artima.com/insidejvm/ed2/ch01IntroToJavasArchitect urePrint.html
Interactive Illustrations
http://www.artima.com/insidejvm/applets/index.html
Felix Hernandez-Campos
COMP 144 Programming Language Concepts Lecture 32: The Java Virtual Machine
Phases of Compilation
Felix Hernandez-Campos
COMP 144 Programming Language Concepts Lecture 32: The Java Virtual Machine
Local or Remote
Adaptive optimization
The interpreter monitors the activity of the program, compiling the heavily used part of the program into machine code It is much faster than simple interpretation The memory requirement is only slightly larger due to the 20%/80% rule of program execution (In general, 20% of the code is responsible for 80% of the execution)
COMP 144 Programming Language Concepts Felix Hernandez-Campos 8
Felix Hernandez-Campos
COMP 144 Programming Language Concepts Lecture 32: The Java Virtual Machine
Felix Hernandez-Campos
COMP 144 Programming Language Concepts Lecture 32: The Java Virtual Machine
Frame in Execution
Stack Frames
Stack frames have three parts:
Local variables Operand stack Frame data
Felix Hernandez-Campos
COMP 144 Programming Language Concepts Lecture 32: The Java Virtual Machine
Local Variables
class Example3a { public static int runClassMethod(int i, long runClassMethod( l, float f, double d, Object o, byte b) { return 0; } public int runInstanceMethod(char c, runInstanceMethod(char double d, short s, boolean b) { return 0; } }
COMP 144 Programming Language Concepts Felix Hernandez-Campos 13
Stack Frame
Operand Stack
Adding 2 numbers iload_0 iload_0 iload_1 iload_1 Iadd istore_2 istore_2
Stack Frame
Felix Hernandez-Campos
COMP 144 Programming Language Concepts Lecture 32: The Java Virtual Machine
Execution Model
Eternal Math Example
http://www.artima.com/insidejvm/applets/EternalMath.htm l
Frame Data
Stack Frame
Felix Hernandez-Campos
COMP 144 Programming Language Concepts Lecture 32: The Java Virtual Machine
Stack Frame
Native Method
A simulated stack of the target language (e.g. C) is created for JNI
Stack Frame
Felix Hernandez-Campos
COMP 144 Programming Language Concepts Lecture 32: The Java Virtual Machine
The Heap
Class instances and array are stores in a single, shared heap Each Java application has its own heap
Isolation But a JVM crash will break this isolation
Heap
Felix Hernandez-Campos
10
COMP 144 Programming Language Concepts Lecture 32: The Java Virtual Machine
Example
HeapOfFish
http://www.artima.com/insidejvm/applets/HeapOfFish.htm l
Felix Hernandez-Campos
11
COMP 144 Programming Language Concepts Lecture 32: The Java Virtual Machine
Memory/Speed Tradeoff
The Heap
The Heap
Arrays as Objects
Felix Hernandez-Campos
12
COMP 144 Programming Language Concepts Lecture 32: The Java Virtual Machine
Reading Assignment
Inside the Java 2 Virtual Machine by Bill Venners
Ch 1 Ch 5 Illustrations
Felix Hernandez-Campos
13