Transcript Document

Java Virtual Machine
Case Study on the Design of
JikesRVM
JVM
• JVM runs Java application in bytecode
– Other sources can also be compiled to
bytecode
– JVM is a process virtual machine
• Hardware support exists
– Execution by
• Interpreter
• JIT (just-in-time) compilation: HotSpot, JikesRVM
JikesRVM
• Originally Jalapeno
• A research compiler by IBM written mostly
in Java
– Why Java?
• Software engineering
• Bridging gap between runtime servers and user
code
• Most used research JVM in academics
Design Goals
• Exploitation of high-performance
processors
• SMP scalability
• Thread limits
• Continuous availability
• Rapid response
• Library usage
• Graceful degradation
Object Model and Memory Layout
• Field and array access should be fast
• Virtual method dispatch should be fast
• Null pointer checks should be performed
by the hardware
• Other Java operations should not be
prohibitively slow
Array and Scalar Object Layout
Object Header
• TIB (type information block)
– Reference to the object’s class
– An array of objects
• Class
• Compiled methods
– Array of instructions
• Status
– Locking field
– Hashing field
– Memory management
JTOC (JikesRVM Table of Contents)
Method Invocation Stack
Runtime Subsystem
•
•
•
•
Exceptions
Dynamic class loading
Input/Output
Reflection
Exceptions
• Exceptions
–
–
–
–
–
Null pointer exception by hardware
Out of bound
Divided by zero
Method invocation stack overflow
Software-generated exceptions
• Handling
– Caught by a C interrupt handler and pass to
deliverException method
– deliverException collects stack trace, transfer control
to “try” block if exists
Dynamic Class Loading
• Java can load classes during execution
• In JikesRVM, when a class not loaded is
referred
– Generate code to load, resolve and instantiate
the class before execution
• Subtleties for address resolution
Input and Output
• Use OS’ services through system routine
calls
Reflection
• Reflection: runtime access to fields and
runtime invocation of methods
– For fields, JVM keep tracks type information
– For method invocation, need to match the
signature
public int incrementField(String name, Object obj) throws...
{ Field field = obj.getClass().getDeclaredField(name);
int value = field.getInt(obj) + 1;
field.setInt(obj, value);
return value; }
Threads and Synchronization
• JikesRVM implemenst virtual processor as
pthreads
– Java threads are multiplexed on virtual processors
– One virtual processor for each physical processor
• Locks
– Processor lock ( a java object with a field denting
owner)
– Thin lock: use lock field on an object header
– Thick lock: object level lock with a queue of threads
waiting for thelock
Memory Management
• Java is an automatic memory managed
language
• Memory management is most critical for
Java
– We will spend several weeks on this topic
• In JikesRVM (obsolete)
– A family of memory managers
Choices
• Copying or non-copying collectors
• Incremental/concurrent or stop-the-world
• Generational collectors
– Most objects die young
– Minor collection, major collection
– Remember set
Compiler
• JikesRVM provides three compilers
– Baseline compiler
• More of an interpreter
• Easy to develop and verify
– Quick (fast) compiler
• Balance compile-time and execution time
– Optimizing compiler
• Deliver high-quality code with likely long
compilation time
Quick Compiler
• Compile each method as it executes for
the first time
• Apply a few highly effective optimizations
– Minimal transformation
– Decorate the byte code and optimized with
• Copy propagation
• Register allocation
Optimizing Compiler
• For frequently executed method
– Need a profiler
– Dynamic versus adaptive
Optimizing Compiler Structure
Optimizations
• HIR (n-tuple, register-based IR)
– Local optimizations: CSE, elimination of
redundant load
– Flow-insensitive optimizations: dead code
elimination
– In-lining
Optimizations
• LIR (adopt object layout and calling
convention)
– Larger than HIR
– Local CSE
• MIR (machine specific)
– Instruction selection using BURS
– Live variable analysis
– Register allocation (linear scan)
Compilation Speeds
Performance on SPEC JVM98
Extra
• Magic
• Boot image
Byteocde Example
int align2grain(int i, int grain)
{ return ((i + grain-1) & ~(grain-1)); }
Method int align2grain(int,int)
0 iload_1
1 iload_2
2 iadd
3 iconst_1
4 isub
5 iload_2
6 iconst_1
7 isub
8 iconst_m1
9 ixor
10 iand
11 ireturn