Java Virtual Machine Case Study on the Design of JikesRVM.
-
Upload
justina-gibson -
Category
Documents
-
view
227 -
download
0
Transcript of Java Virtual Machine Case Study on the Design of JikesRVM.
![Page 1: Java Virtual Machine Case Study on the Design of JikesRVM.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649ec75503460f94bd2d85/html5/thumbnails/1.jpg)
Java Virtual Machine
Case Study on the Design of JikesRVM
![Page 2: Java Virtual Machine Case Study on the Design of JikesRVM.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649ec75503460f94bd2d85/html5/thumbnails/2.jpg)
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
![Page 3: Java Virtual Machine Case Study on the Design of JikesRVM.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649ec75503460f94bd2d85/html5/thumbnails/3.jpg)
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
![Page 4: Java Virtual Machine Case Study on the Design of JikesRVM.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649ec75503460f94bd2d85/html5/thumbnails/4.jpg)
Design Goals
• Exploitation of high-performance processors
• SMP scalability• Thread limits• Continuous availability• Rapid response• Library usage• Graceful degradation
![Page 5: Java Virtual Machine Case Study on the Design of JikesRVM.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649ec75503460f94bd2d85/html5/thumbnails/5.jpg)
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
![Page 6: Java Virtual Machine Case Study on the Design of JikesRVM.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649ec75503460f94bd2d85/html5/thumbnails/6.jpg)
Array and Scalar Object Layout
![Page 7: Java Virtual Machine Case Study on the Design of JikesRVM.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649ec75503460f94bd2d85/html5/thumbnails/7.jpg)
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
![Page 8: Java Virtual Machine Case Study on the Design of JikesRVM.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649ec75503460f94bd2d85/html5/thumbnails/8.jpg)
JTOC (JikesRVM Table of Contents)
![Page 9: Java Virtual Machine Case Study on the Design of JikesRVM.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649ec75503460f94bd2d85/html5/thumbnails/9.jpg)
Method Invocation Stack
![Page 10: Java Virtual Machine Case Study on the Design of JikesRVM.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649ec75503460f94bd2d85/html5/thumbnails/10.jpg)
Runtime Subsystem
• Exceptions
• Dynamic class loading
• Input/Output
• Reflection
![Page 11: Java Virtual Machine Case Study on the Design of JikesRVM.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649ec75503460f94bd2d85/html5/thumbnails/11.jpg)
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
![Page 12: Java Virtual Machine Case Study on the Design of JikesRVM.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649ec75503460f94bd2d85/html5/thumbnails/12.jpg)
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
![Page 13: Java Virtual Machine Case Study on the Design of JikesRVM.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649ec75503460f94bd2d85/html5/thumbnails/13.jpg)
Input and Output
• Use OS’ services through system routine calls
![Page 14: Java Virtual Machine Case Study on the Design of JikesRVM.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649ec75503460f94bd2d85/html5/thumbnails/14.jpg)
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; }
![Page 15: Java Virtual Machine Case Study on the Design of JikesRVM.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649ec75503460f94bd2d85/html5/thumbnails/15.jpg)
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
![Page 16: Java Virtual Machine Case Study on the Design of JikesRVM.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649ec75503460f94bd2d85/html5/thumbnails/16.jpg)
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
![Page 17: Java Virtual Machine Case Study on the Design of JikesRVM.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649ec75503460f94bd2d85/html5/thumbnails/17.jpg)
Choices
• Copying or non-copying collectors
• Incremental/concurrent or stop-the-world
• Generational collectors– Most objects die young– Minor collection, major collection– Remember set
![Page 18: Java Virtual Machine Case Study on the Design of JikesRVM.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649ec75503460f94bd2d85/html5/thumbnails/18.jpg)
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
![Page 19: Java Virtual Machine Case Study on the Design of JikesRVM.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649ec75503460f94bd2d85/html5/thumbnails/19.jpg)
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
![Page 20: Java Virtual Machine Case Study on the Design of JikesRVM.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649ec75503460f94bd2d85/html5/thumbnails/20.jpg)
Optimizing Compiler
• For frequently executed method– Need a profiler – Dynamic versus adaptive
![Page 21: Java Virtual Machine Case Study on the Design of JikesRVM.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649ec75503460f94bd2d85/html5/thumbnails/21.jpg)
Optimizing Compiler Structure
![Page 22: Java Virtual Machine Case Study on the Design of JikesRVM.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649ec75503460f94bd2d85/html5/thumbnails/22.jpg)
Optimizations
• HIR (n-tuple, register-based IR)– Local optimizations: CSE, elimination of
redundant load– Flow-insensitive optimizations: dead code
elimination– In-lining
![Page 23: Java Virtual Machine Case Study on the Design of JikesRVM.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649ec75503460f94bd2d85/html5/thumbnails/23.jpg)
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)
![Page 24: Java Virtual Machine Case Study on the Design of JikesRVM.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649ec75503460f94bd2d85/html5/thumbnails/24.jpg)
Compilation Speeds
![Page 25: Java Virtual Machine Case Study on the Design of JikesRVM.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649ec75503460f94bd2d85/html5/thumbnails/25.jpg)
Performance on SPEC JVM98
![Page 26: Java Virtual Machine Case Study on the Design of JikesRVM.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649ec75503460f94bd2d85/html5/thumbnails/26.jpg)
Extra
• Magic
• Boot image
![Page 27: Java Virtual Machine Case Study on the Design of JikesRVM.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649ec75503460f94bd2d85/html5/thumbnails/27.jpg)
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