This action might not be possible to undo. Are you sure you want to continue?
Java Virtual Machine
Runtime data areas Java instruction set pros & cons
Architecture System Overview Multi-level recompilation Cost/Benefit model Profiling heuristics performance
Java Virtual Machine An abstract computing machine Own instruction set (Java ISA) Memory manipulation at runtime user class files class loader bytecodes The Java API’s class file JVM execution engine native method invocation Host OS .
Runtime Data Areas PC register each JVM thread has its own program counter the index in bytecode of the instruction JVM stack each JVM thread has its own stacks invoke method -> new frame is allocated on stack store operand stack. state variables Operand Stack used to pass arguments receive return results interpreter is responsible for transferring return result to the caller operand stack . local variables.
Runtime Data Areas Local variable number of local variables in stack is determined at compile time local variables are numbered Heap one heap per one JVM created on VM start-up all class instance and arrays are allocated in heap Constant pool analogous to ‘symbol table’ a collection of all symbolic data need by a class each constant pool is private to its class .
Java Instruction Set opcode is just one byte (256 combination possible) additional index bytes additional data bytes opcode opcode opcode index1 data index2 .
f2l… Functional instr. iand Control flow instr. i2d. Stack manipulation instructions ex) bipush. i2l. operands are always taken from the stack and results are placed on the stack ex) iadd. Iconst_1. f2i. conditional branches ex) ifeq. pop. if_icmpeq unconditional branches ex) jsr. swap Type conversion convert one type of item on the stack to another ex) i2f. dup.Java Instruction Set Data movement instr. jsr_w .
Pros & cons of JVM Pros Write once. run everywhere! Cons Bytecode interpret at runtime Low performance Solution: JITC & AOTC .
JITC vs AOTC Just-In-Time Compiler (JITC) Compile bytecode to machine code at runtime Compile time are included in execute time make the maximum use of program execution information require some CPU and Memory resources ex) Jikes RVM. DSVM Ahead-Of-Time Compiler (AOTC) Compile bytecode to machine code before program execution Able to do heavy optimizations Can’t know program execution information ex) LaTTe .
J.Jikes RVM – an example of JITC developed at IBM T. . O2) A flexible online adaptive compilation infrastructure. Watson Research Center targeting server applications written in Java employs 2 strategies baseline compiler optimizing compiler (O0. O1.
Jikes RVM .
Architecture System Overview 3 components of Adaptive Optimization System (AOS) Runtime measurements subsystem Controller Recompilation subsystem .
Runtime Measurements Subsystem Subsystem which produce raw profiling data Monitor the performance of individual methods from a hardware performance monitor Organizers periodically process and analyze the raw data the processes data is used by the Controller .
linear model is used • this model is calibrated offline use Cost/Benefit model to make this calculation • analytic model representing the cost and benefits of these tasks .Controller Orchestrates and conducts the other components of AOS system build an compilation plan using profiling data to improve their performance Determines whether it is profitable to recompile the method To estimate cost of recompilation.
Recompilation Subsystem Recompilation occur in separate threads from the application 3 components of compilation plan Profiling data Optimization plan Instrumentation plan .
dead-code elimination Level 1 addition local optimizations • CSE. redundant load elimination flow-insensitive optimizations • copy and constant propagation. SSA-CSE .Multi-Level Recompilation Level 0 optimizations performed on-the-fly during the translation from bytecodes to the HIR • Register renaming for local variable. dead-assignment elimination Scalar replacement of aggregates and short arrays Level 2 SSA-based flow sensitive optimization • SSA-PRE. array bound check elimination.
Cost/Benefit model Assumptions Sample data determines how long a method has executed Method will execute as much in the future as it has in the past Compilation cost and speedup are offline average .
current optimization level for method m T(j). expected future execution time at optimization level j C(j).Cost/Benefit model Definitions cur. compilation cost at optimization level j Choose j > cur that minimizes T(j) + C(j) If T(j) + C(j) < T(cur) recompile at optimization level j. .
Estimated Cost/Benefit .
Profiling heuristics How to find candidates for optimization counters call stack sampling .
Hotspot. but hard to tune . DSVM Issues Overhead for incrementing counter can be significant simple. Optimize method that surpasses threshold. Very popular approach : Self.Counters Insert method-specific counter on method entry and loop back edge.
but non-deterministic. .Call stack sampling Periodically record which method(s) are on the top of call stack. Approximates amount of time spent in each method Use Cost/Benefit model ex) Jikes RVM. JRocket Issues low-overhead.
. but its performance is low. We can overcome low performance of JVM with Just-In-Time Compiler.Conclusion Java Virtual Machine has good features.