5장. Execution Engine

7,844 views

Published on

Java Performance Fundamental 세미나 교재입니다. 5장은 Execution Engine에 대한 내용을 다루고 있습니다. Class파일에 저장되어 있는 Bytecode를 해석하는 방법을 JIT Compiler와 Hotspot Compiler의 동작과정을 통해 자세히 알아봅니다.

* Execution Engine
* IBM JIT Compiler
* Hotspot Compiler

Published in: Technology
0 Comments
16 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
7,844
On SlideShare
0
From Embeds
0
Number of Embeds
5,217
Actions
Shares
0
Downloads
136
Comments
0
Likes
16
Embeds 0
No embeds

No notes for slide
  • 5장. Execution Engine

    1. 1. Java Performance artdb@ex-em.com | performeister.tistory.com | twitter @novathinker Execution Engine
    2. 2. Java Performance 2 artdb@ex-em.com | performeister.tistory.com | twitter @novathinker Execution Engine 1) Execution Engine 2) Interpreter 3) JIT Compiler 4) Execution Engine IBM JIT Compiler 1) JIT Compiler 2) Mixed Mode Interpreter 3) JIT Compiler Optimization 4) JIT Compiler Hotspot Compiler 1) Hotspot Compiler 2) Hotspot Compiler Optimization 3) Hotspot Compiler Option
    3. 3. Java Performance artdb@ex-em.com | performeister.tistory.com | twitter @novathinker Execution Engine
    4. 4. Java Performance 4 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Execution Engine • Execution Engine Bytecode Runtime Module • Instruction – Bytecode = Instruction – Execution Engine Instruction • Instruction = Opcode + Operand • Execution Engine opcode fetch opcode fetch
    5. 5. Java Performance 5 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Execution Engine • Instruction – Bytecode method level • Method return Exception – Instruction • opcode opcode • Goto return opcode • Exception catch opcode
    6. 6. Java Performance 6 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Execution Engine – Bytecode mnemonic >javap –c classfile (bytecode) Java Source Code Method offset Instruction Mnemonic Operand
    7. 7. Java Performance 7 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Execution Engine • JVM (Source: Sun Microsystems) http://java.sun.com/developer/technicalArticles/Networking/HotSpot/
    8. 8. Execution Engine Java Performance Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com 8 • Execution Engine – Bytecode Runtime Module Java Source Classfile .java .class Javac .java JVM Runtime Interpreting Execution Bytecode Data Area Engine Stream ClassLoader
    9. 9. Java Performance 9 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Execution Engine • Execution Engine – Bytecode Interpreting – Interpreting • Interpreter • JIT Compile
    10. 10. Java Performance 10 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Execution Engine • Interpreter – Bytecode compile – Bytecode – Bytecode – – JVM Bytecode interpreter
    11. 11. Java Performance 11 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Execution Engine • JIT(Just-in-time) Compiler – Bytecode native code – Native code compile – Native Code Cache – Interpreter – Lazy fashion
    12. 12. Java Performance 12 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Execution Engine • JIT(Just-in-time) Compiler bytecode Class a{ Heap Method Table a.f1(); f1() a.f3(); ptr f1() f3() } f2() Object A f3() JIT f1() native f4() code f3() …
    13. 13. Java Performance 13 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Execution Engine • JIT(Just-in-time) Compiler Source code bytecode Native code int a; iload_0 ld [$fp-0] , $r0 st $r0, [$sp+0] int b; iload_1 ld [$fp-4] , $r1 st $r1, [$sp+4] int c = a + b; iadd ld [$sp+0] , $r0 ld [$sp+0] , $r1 add $r0, $r1, $r2 st $r2, [$sp+0]
    14. 14. Java Performance 14 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Execution Engine • Execution Engine – Loop bytecode
    15. 15. Java Performance 15 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Execution Engine • Execution Engine – • Java • Array_ptr Stack A[0][0] Object_ptr A[0] Object_ptr A[0][1] length A[1] length A[1][0] Class_ptr Class_ptr A[1][1] Object_ptr Heap Class_ptr length Method Area Class runtime type Class runtime type info Method block Method block
    16. 16. Java Performance 16 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Execution Engine • Execution Engine – •2 5 • Dimension
    17. 17. Java Performance artdb@ex-em.com | performeister.tistory.com | twitter @novathinker IBM JIT Compiler 17
    18. 18. Java Performance 18 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com IBM JIT Compiler • JIT Compiler – JIT compiler method (1) Method Method table JIT compiler (2) JIT Compiler Method Native Code Cache (3) Method (4) Method table Native Code Code – JVM Method Call
    19. 19. Java Performance 19 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com IBM JIT Compiler • JIT Compiler Java Application Java VM(Interpreter) bytecode JIT compiler native code
    20. 20. Java Performance 20 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com IBM JIT Compiler • JIT Compiler – JIT Enable • JVM Startup Applet – JIT Disable • JVM Bytecode interpret – IBM JVM Mixed Mode Interpreter(MMI)
    21. 21. Java Performance 21 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com IBM JIT Compiler • Mixed Mode Interpreter(MMI) – 1.4 – JVM Runtime – Fast Assembler bytecode interpreter – JIT – Method count threshold compile – Low-usage method compile compile
    22. 22. Java Performance 22 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com IBM JIT Compiler • Mixed Mode Interpreter(MMI) – 1.4.2 JIT, MMI JVM – JIT shared library(libjitc.so) – Java5 JIT JVM component MMI – Java5 MMI
    23. 23. Java Performance 23 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com IBM JIT Compiler • Mixed Mode Interpreter(MMI) Java Application Java VM(Interpreter) bytecode JIT compiler MMI native code threshold
    24. 24. Java Performance 24 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com IBM JIT Compiler • Mixed Mode Interpreter(MMI) – • Method call compile • count • Count Compilation Threshold compile • Compile count 0 • Count • JIT Recompile Threshold compile Optimization recompile • method
    25. 25. Java Performance 25 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com IBM JIT Compiler • Mixed Mode Interpreter(MMI) – JIT/MMI Mode MODE JIT MMI Effect •JVM , default ON ON •Method Interpret JIT Compile • IBM_MIXED_MODE_THRESHOLD=0 MMI ON OFF Disable • Method JIT Compile •JVM •-Xint • -Djava.compiler=NONE JIT • JAVA_COMPILER=NONE OFF OFF Disable • Interpret JVM Runtime •JIT compile MMI
    26. 26. Java Performance 26 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com IBM JIT Compiler • Mixed Mode Interpreter(MMI) – MMI Threshold • IBM_MIXED_MODE_THRESHOLD=<x>[,<y>] • <x> interpret – method – Default OS 500 1000 • <y> compile seed – compile method – y x Threshold – default 0
    27. 27. Java Performance 27 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com IBM JIT Compiler • JIT Compiler Optimization
    28. 28. Java Performance 28 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com IBM JIT Compiler • Optimization Level – Optimization – -Xjit – JVM Adaptive noOpt cold Warm hot veryHot scorching
    29. 29. Java Performance 29 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com IBM JIT Compiler • Optimization Level – Adaptive compilation • Methods interpret interpreted •N ‘warm’ level compile warm • Sampling thread hot methods hot • Methods ‘hot’ ‘scorching’ recompile profiling • Temporary profiling step ‘scorching’ scorching
    30. 30. Java Performance 30 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com IBM JIT Compiler • Optimization Phase (~1.4.2) – 1.4.2 4 • Bytecode Optimization : bytecode – Flow analysis – Static method inlining – Virtual method inlining – Idiomatic translation – Field privatization – Stack and register analysis – bytecode quad native code – conventional native compiler
    31. 31. Java Performance 31 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com IBM JIT Compiler • Optimization Phase(~1.4.2) • Quad Optimization – Control flow optimization – Data flow optimization – Escape analysis – Loop analysis – Data flow analysis – Quad Optimization • DAG(Direct Acyclic Graph) Optimization – Induction analysis – Loop Versioning – Loop Striding – Induction removal – Dead storage analysis
    32. 32. Java Performance 32 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com IBM JIT Compiler • Optimization Phase(~1.4.2) • Native code Generation – Bytecode Quad Quad DAG Native Code
    33. 33. Java Performance 33 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com IBM JIT Compiler • Optimization Phase (Java5~) – Java5 5 phase – Bytecode Method tree Native Code – Compile code cache
    34. 34. Java Performance 34 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com IBM JIT Compiler • Optimization Phase (Java5~) • Inlining – caller inlining – Trivial inlining – Call graph inlining – Tail recursion elimination – Virtual call guard optimization
    35. 35. IBM JIT Compiler Java Performance Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com 35 • Optimization Phase (Java5~) • Local optimization – – Local data flow analysis and optimizations – Register usage optimization – Simplification of Java Idioms • Control flow optimizations – Method control flow – Code reordering, splitting and removal – Loop reduction and inversion – Loop Striding and loop-invariant code motion – Loop unrolling and peeling – Loop versioning and specialization – Exception-directed optimization - Switch analysis
    36. 36. IBM JIT Compiler Java Performance Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com 36 • Optimization Phase (Java5~) • Global Optimization – method – Expensive – Global data flow analysis and optimizations – Partial redundancy elimination – Escape analysis – GC and memory allocation optimizations – Synchronization optimization • Native code generation – Method tree machine code – Platform
    37. 37. IBM JIT Compiler Java Performance Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com 37 • JIT Compiler – • IBM_MIXED_MODE_THRESHOLD • JITC_COMPILEOPT – NMMI2JIT : hot Method compile – NINLINING : Inline code – NQOPTIMIZE : Quad – NDOPT : DAG – NBCOPT : Bytecode – NALL : Optimization – Java5
    38. 38. IBM JIT Compiler Java Performance Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com 38 • JIT Compiler – JVM Parameter • -Xint : interpret only • -Xjit[:<parameter>=<value>,…] – count=<n> : compile , n=0 method compile – limitFile=(<Filename>,<m>,<n>) : m n compile – optlevel=[noOpt | cold | warm | hot | veryHot | scorching] : Method Optimization level – Verbose : JIT Compiler method compile
    39. 39. Java Performance artdb@ex-em.com | performeister.tistory.com | twitter @novathinker • Class Sharing JVM1
    40. 40. Java Performance artdb@ex-em.com | performeister.tistory.com | twitter @novathinker • Class Sharing JVM1
    41. 41. Java Performance artdb@ex-em.com | performeister.tistory.com | twitter @novathinker • Class Sharing Cached Classes JVM1
    42. 42. Java Performance artdb@ex-em.com | performeister.tistory.com | twitter @novathinker • Class Sharing Cached Classes JVM2
    43. 43. Java Performance artdb@ex-em.com | performeister.tistory.com | twitter @novathinker • Class Sharing Cached Classes JVM2 JVM3 JVM4
    44. 44. Java Performance artdb@ex-em.com | performeister.tistory.com | twitter @novathinker • Class Sharing Cached Classes Cached Classes JVM2 JVM3 JVM4
    45. 45. Java Performance artdb@ex-em.com | performeister.tistory.com | twitter @novathinker • Class Sharing Shared Cache 1 Shared Cache 2 AOT Code AOT Code Cached Classes Cached Classes JVM2 JVM3 JVM4
    46. 46. Java Performance artdb@ex-em.com | performeister.tistory.com | twitter @novathinker -Xscminaot AOT Code -Xscmaxaot -Xscmaxaot AOT Code -Xscmx Shared Classes Metadata
    47. 47. Java Performance artdb@ex-em.com | performeister.tistory.com | twitter @novathinker Hotspot Compiler
    48. 48. Java Performance 42 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot Compiler • Hotspot Compiler – Mixed Mode system • Interpreter JIT Compiler • Bytecode interpreted • Profiling Dynamic Compile • recompile interpreted Interpreted Recompile Profiling Interpreted Again Dynamic Compilation
    49. 49. Java Performance 43 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot Compiler • Hotspot Compiler – Mixed Mode system • Hotspot Default • Hotspot – Profiling Hot Code compile – Compile – Hot code Optimization – Compile
    50. 50. Java Performance 44 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot Compiler • Hotspot Compiler – Hotspot VM – Client Server – Compiler Java Hotspot Server VM Java Hotspot Performance Engine Java Hotspot Client VM
    51. 51. Java Performance 45 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot Compiler • Hotspot Compiler – Server VM • Advanced Adaptive Compiler – Client VM • Compile Client Server C1 Compiler C2 Compiler Runtime Runtime
    52. 52. Hotspot Compiler Java Performance Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com 46 • Hotspot Compiler – Client Compiler • C1 Compiler • Optimization • Value Numbering, inlining, class analysis • Static Compile • Profiling Counting Value Numbering
    53. 53. Hotspot Compiler Java Performance Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com 47 • Hotspot Compiler – Server Compiler • Opto C2 Compiler • High optimizing bytecode compiler • ‘Intermediate’ optimizing compiler • Interpreter Profiling Optimization • Inlining – CHA Profiling Data Inline Decision • Loop Optimization • Loop Unrolling
    54. 54. Hotspot Compiler Java Performance Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com48 • Hotspot Compiler Optimization – Server Compiler • Common Sub-expression Elimination – tmp = b * c; a = b * c + g; a = tmp + g; d = b * c * d; CSE d = tmp * d; e = b * c; e = tmp; • Loop unrolling – Loop array[0] = 0; for (int i; i < 3; i++) array[i] = i; Loop Unrolling array[1] = 1; array[2] = 2;
    55. 55. Hotspot Compiler Java Performance Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com 49 • Hotspot Compiler Optimization – Server Compiler • On Stack Replacement – Loop Interpreted code Compiled code • Main method 1 • Main loop • 10000 compile • main interpreting • 14000 OSR • loop Compile code
    56. 56. Hotspot Compiler Java Performance Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com 50 • Hotspot Compiler Optimization – Server Compiler • array-bounds check elimination – Array range check – Array Index , • Dead Code Elimination – code compile
    57. 57. Hotspot Compiler Java Performance Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com 51 • Hotspot Compiler Optimization – Server Compiler • Code Hoisting – (hoist) Hoisting • Data Flow Analysis – Data • Deoptimization – Hotspot – Compile Interpret
    58. 58. Hotspot Compiler Java Performance Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com 52 • Hotspot Compiler Option • -Xint : Interpret Mode • -XX:+AggressiveOpts (+ Java5 update 6) : Compile Optimization • -XX:CompileThreshold=<value> : compile (Client 1500, Server 10000) • -Xcomp : code
    59. 59. Hotspot Compiler Java Performance Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com 53 • Hotspot Compiler Option • -Xbatch : background compilation Method compile background process • -XX:+AlwaysCompileLoopMethods : Default false Loop method Compile • -XX:+BackgroundCompilation : background JIT Compile enable compile interpreted code
    60. 60. Hotspot Compiler Java Performance Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com 54 • Hotspot Compiler Option • -XX:CICompilerCount=<value> : Maximum concurrent compile Thread • -XX:+Cltime : JIT Compiler Print • -XX:+PrintCompilation : Method Compile
    61. 61. Java Performance 55 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com

    ×