24
Just-In-Time Compiler 김 김 김 MASSLAB

Just in Time Compiler

  • Upload
    diranj

  • View
    27

  • Download
    0

Embed Size (px)

DESCRIPTION

Just in Time Compiler

Citation preview

  • Just-In-Time Compiler MASSLAB

  • ContentsJava Virtual MachineRuntime data areasJava instruction setpros & consJust-In-Time Compiler(JITC)Architecture System OverviewMulti-level recompilationCost/Benefit modelProfiling heuristicsperformanceConclusion

  • Java Virtual MachineAn abstract computing machineOwn instruction set (Java ISA)Memory manipulation at runtimeclassloaderexecutionengineHost OSThe Java APIs class fileuser class filesJVMbytecodesnative method invocation

  • Runtime Data AreasPC register each JVM thread has its own program counter the index in bytecode of the instructionJVM stackeach JVM thread has its own stacksinvoke method -> new frame is allocated on stackstore operand stack, local variables, state variablesOperand Stackused to pass argumentsreceive return resultsinterpreter is responsible for transferring return result to the caller operand stack

  • Runtime Data AreasLocal variablenumber of local variables in stack is determined at compile timelocal variables are numberedHeapone heap per one JVMcreated on VM start-upall class instance and arrays are allocated in heapConstant poolanalogous to symbol tablea collection of all symbolic data need by a classeach constant pool is private to its class

  • Java Instruction Setopcode is just one byte (256 combination possible) additional index bytesadditional data bytesopcodeopcodeindex1index2opcodedata

  • Java Instruction SetData movement instr.Stack manipulation instructionsex) bipush, pop, dup, Iconst_1, swapType conversionconvert one type of item on the stack to another ex) i2f, i2d, i2l, f2i, f2lFunctional instr.operands are always taken from the stack and results are placed on the stack ex) iadd, iandControl flow instr.conditional branches ex) ifeq, if_icmpequnconditional branches ex) jsr, jsr_w

  • Pros & cons of JVMProsWrite once, run everywhere!ConsBytecode interpret at runtimeLow performanceSolution: JITC & AOTC

  • JITC vs AOTCJust-In-Time Compiler (JITC)Compile bytecode to machine code at runtimeCompile time are included in execute timemake the maximum use of program execution information require some CPU and Memory resourcesex) Jikes RVM, DSVMAhead-Of-Time Compiler (AOTC)Compile bytecode to machine code before program executionAble to do heavy optimizationsCant know program execution informationex) LaTTe

  • Jikes RVM an example of JITCdeveloped at IBM T.J. Watson Research Centertargeting server applicationswritten in Javaemploys 2 strategiesbaseline compileroptimizing compiler (O0, O1, O2)A flexible online adaptive compilation infrastructure.

  • Jikes RVM

  • Architecture System Overview3 components of Adaptive Optimization System (AOS)Runtime measurements subsystemControllerRecompilation subsystem

  • Runtime Measurements SubsystemSubsystem which produce raw profiling dataMonitor the performance of individual methods from a hardware performance monitorOrganizers periodically process and analyze the raw datathe processes data is used by the Controller

  • ControllerOrchestrates and conducts the other components of AOS systembuild an compilation plan using profiling data to improve their performanceDetermines whether it is profitable to recompile the methodTo estimate cost of recompilation, linear model is usedthis model is calibrated offlineuse Cost/Benefit model to make this calculationanalytic model representing the cost and benefits of these tasks

  • Recompilation SubsystemRecompilation occurin separate threads from the application3 components of compilation planProfiling dataOptimization planInstrumentation plan

  • Multi-Level RecompilationLevel 0optimizations performed on-the-fly during the translation from bytecodes to the HIRRegister renaming for local variable, dead-code eliminationLevel 1addition local optimizationsCSE, array bound check elimination, redundant load eliminationflow-insensitive optimizationscopy and constant propagation, dead-assignment eliminationScalar replacement of aggregates and short arraysLevel 2SSA-based flow sensitive optimizationSSA-PRE, SSA-CSE

  • Cost/Benefit modelAssumptionsSample data determines how long a method has executedMethod will execute as much in the future as it has in the past Compilation cost and speedup are offline average

  • Cost/Benefit modelDefinitionscur, current optimization level for method mT(j), expected future execution time at optimization level j C(j), compilation cost at optimization level jChoose j > cur that minimizes T(j) + C(j)If T(j) + C(j) < T(cur)recompile at optimization level j.

  • Estimated Cost/Benefit

  • Profiling heuristicsHow to find candidates for optimizationcounterscall stack sampling

  • CountersInsert method-specific counter on method entry and loop back edge.Optimize method that surpasses threshold.Very popular approach : Self, Hotspot, DSVMIssues Overhead for incrementing counter can be significantsimple, but hard to tune

  • Call stack samplingPeriodically record which method(s) are on the top of call stack.Approximates amount of time spent in each methodUse Cost/Benefit modelex) Jikes RVM, JRocketIssueslow-overhead, but non-deterministic.

  • Performances

  • ConclusionJava Virtual Machine has good features, but its performance is low.We can overcome low performance of JVM with Just-In-Time Compiler.