2장. Runtime Data Areas

9,602 views

Published on

Java Performance Fundamental 세미나 교재입니다
2장은 JVM의 메모리 구조인 Runtime Data Areas에 대한 설명을 하고 있습니다. 크게는4개의 모듈로 나누어 지는 Runtime Data Areas를 부분 별로 자세히 다루고 있습니다. 그리고 나서 우리가 프로그램을 수행할 때 Runtime Data Areas에서는 어떻게 데이터들이 움직이는 지를 간단한 예제를 통해 알아보고자 합니다.

* Runtime Data Areas의 구조
* PC Register
* Java Virtual Machine Stacks
* Native Method Stack
* Method Area
* Java Heap
* Runtime Data Areas Simulation

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

No Downloads
Views
Total views
9,602
On SlideShare
0
From Embeds
0
Number of Embeds
5,534
Actions
Shares
0
Downloads
213
Comments
0
Likes
26
Embeds 0
No embeds

No notes for slide
  • 2장. Runtime Data Areas

    1. 1. Java Performance artdb@ex-em.com | performeister.tistory.com | twitter @novathinker Runtime Data Areas
    2. 2. Java Performance 2 artdb@ex-em.com | performeister.tistory.com | twitter @novathinker 1) Runtime Data Area 2) PC Register 3) Java Stacks 4) Method Area 5) Java Heap 6) Native Method Stacks 7) Runtime Memory
    3. 3. Java Performance 3 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Runtime Data Area •Runtime Data Area Class libraries Class loader Class files subsystem Java Stacks Method Area Heap Pc Registers Native Method Stacks runtime data areas native Execution native method interface method engine libraries
    4. 4. Java Performance 4 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com PC register •PC Register Thread PC register (Program Counter) Start Create Java Method Call { … } Native Pointer or Current Instruction Address (native pointer or method bytecode Native Method Call undefined
    5. 5. Java Performance 5 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Virtual Machine Stacks •Java Virtual Machine Stack
    6. 6. Java Performance 5 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Virtual Machine Stacks •Java Virtual Machine Stack Java Stack Thread
    7. 7. Java Performance 5 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Virtual Machine Stacks •Java Virtual Machine Stack Java Stack Thread Java Stack Thread
    8. 8. Java Performance 5 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Virtual Machine Stacks •Java Virtual Machine Stack Java Stack Thread Java Stack Thread Java Stack Thread
    9. 9. Java Performance 5 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Virtual Machine Stacks •Java Virtual Machine Stack Java Stack Stack Frame • Java Stack Thread • Stack Frame Push, Pop Java Stack Thread Java Stack Java Stack • Thread 1 Stack Area • Stack Thread Thread • Thread Java Stack • Implement JVM Vendor Thread Thread • Stack Frame
    10. 10. Java Performance 6 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Virtual Machine Stacks • Stack Frame • Local Variable Section, Operand Local Variable Section Stack Compile Time Operand Stack • Frame Data Frame Data • Method call Class Data Stack Frame Stack Frame Java Stack
    11. 11. Java Performance 7 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Virtual Machine Stacks • Stack Frame – Local Variable Section • Zero base Array 0 1 Local Variable Section • Index data access 2 3 -Method Parameters 4 -Local variable • Method Parameter 5 index • Local Variable Compiler
    12. 12. Java Performance 8 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com • Java Virtual Machine Stacks • Stack Frame – Local Variable Section
    13. 13. Java Performance 9 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Virtual Machine Stacks • Stack Frame – Local Variable Section 0 reference hidden this 1 int int a 2 int char b class JvmInternal { 3 long c public int testMethod (int a, char b, long long c, float d, Object e, double f, String g, byte h, short i, boolean j) { 5 float float d return 0; 6 reference Object e } 7 double f } double 9 reference String g 10 int byte h 11 int short i 12 int boolean j
    14. 14. Java Performance 10 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Virtual Machine Stacks • Stack Frame – Operand Stack • Zero base Array Operand Stack • Instruction pop -JVM Work Space • Push • Data Type Local Variable
    15. 15. Java Performance 11 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Virtual Machine Stacks public void operandStack(); class JvmInternal2 { Code: public void operandStack() { 0: iconst_5 int a, b, c; 1: istore_1 a = 5; 2: bipush 6 b = 6; 4: istore_2 c = a + b; 5: iload_1 } 6: iload_2 } 7: iadd 8: istore_3 9: return istore_1istore_2iload_1 iload_2 iadd istore_3 6 Operand Stack 5 5 11 int c 3 11 Local Variable int b 2 6 6 6 6 6 Section int a 1 5 5 5 5 5 5 hidden this ref 0 ref ref ref ref ref ref
    16. 16. Java Performance 12 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Virtual Machine Stacks • Stack Frame – Frame Data Frame Data -Constant pool Resolution -Normal Method Return -Exception Dispatch
    17. 17. Java Performance 12 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Virtual Machine Stacks • Stack Frame • Constant Pool Entry – Frame Data • Constant Pool Symbolic Reference Frame Data -Constant pool Resolution -Normal Method Return -Exception Dispatch
    18. 18. Java Performance 12 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Virtual Machine Stacks • Stack Frame • Constant Pool Entry – Frame Data • Constant Pool Symbolic Reference Frame Data -Constant pool Resolution -Normal Method Return -Exception Dispatch • Method stack frame pc register instruction pointer • operand stack push
    19. 19. Java Performance 12 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Virtual Machine Stacks • Stack Frame • Constant Pool Entry – Frame Data • Constant Pool Symbolic Reference Frame Data -Constant pool Resolution -Normal Method Return -Exception Dispatch • Method stack frame • Exception pc Frame Data Exception Table register instruction pointer • operand stack push
    20. 20. Java Performance 13 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Virtual Machine Stacks • Stack Frame – Frame Data public void operandStack(); Code: 0: iconst_5 class JvmInternal2 { 1: istore_1 public void operandStack() { 2: bipush 6 int a, b, c; 4: istore_2 a = 5; 5: iload_1 b = 6; 6: iload_2 try { 7: iadd c = a + b; 8: istore_3 } 9: goto 16 catch (NullPointerException e) { 12: astore 4 c = 0; 14: iconst_0 } 15: istore_3 } 16: return } Exception table: from to target type 5 9 12 Class java/lang/ NullPointerException
    21. 21. Java Performance 14 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Native Method Stack •Native Method Stack Java Stacks Native Method Stack
    22. 22. Java Performance 14 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Native Method Stack •Native Method Stack Java Stacks Native Method Stack Stack Java Method 1 Frame
    23. 23. Java Performance 14 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Native Method Stack •Native Method Stack Java Stacks Native Method Stack Stack Java Method 1 Frame Native Method 1 Stack Frame
    24. 24. Java Performance 14 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Native Method Stack •Native Method Stack Java Stacks Native Method Stack Stack Java Method 1 Frame Native Method 1 Stack Frame
    25. 25. Java Performance 14 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Native Method Stack •Native Method Stack Java Stacks Native Method Stack Stack Java Method 1 Frame Native Method 1 Stack Frame Native Function Call
    26. 26. Java Performance 14 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Native Method Stack •Native Method Stack Java Stacks Native Method Stack Stack Java Method 1 Frame Native Method 1 Stack Frame Native Function Call Stack Frame
    27. 27. Java Performance 14 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Native Method Stack •Native Method Stack Java Stacks Native Method Stack Stack Java Method 1 Frame Native Method 1 Stack Frame Native Function Call Stack Frame Stack Java Method 2 Frame
    28. 28. Java Performance 15 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Method Area •Method Area JVM • Class Loader Load Type Method Area • JVM • Thread Class Data • Class file type Class Data Method Area Class • GC Data • Method Area Vendor Class Data  Sun Permanent Area Generation Heap Share Thread Thread  IBM Heap Thread
    29. 29. Java Performance 16 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Method Area Type Information Constant Pool Class metadata in Field Information Method Area Method Information Class Variables Reference to ClassLoader class Reference to Class class
    30. 30. Java Performance 17 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Method Area • Type Information Type Information • Type (Package + Class ) • Type Superclass (Type interface java.lang.object class superclass ) • Type class interface • Type modifier (public, abstract, final) • interface ( )
    31. 31. Java Performance 17 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Method Area • Type Information Type Information • Type (Package + Class ) • Type Superclass (Type interface java.lang.object class superclass ) • Type class interface • Type modifier (public, abstract, final) • interface ( ) Type  Java Class, Interface Java Class File  Java Type Standard Binary Format
    32. 32. Java Performance 18 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Method Area • Constant Pool • Constant Pool Type Constant Ordered Set • Literal Constant, Type, Field, Method Symbolic Reference • Constant Pool Entry Array index • Type Type, Method, Field Symbolic Reference Dynamic Linking
    33. 33. Java Performance 19 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Method Area • Field Information Field  Member Variable, Class Variable Type Field Field Information • Field • Field Type • Field Modifier (public, private, protected, static, final, volatile, transient)
    34. 34. Java Performance 20 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Method Area • Method Information Type Method Method Method Information • Method • Method Return Type (or void) • Method Parameter Type ( ) • Method Modifier (public, private, protected, static, final, syncronized, native, abstract)
    35. 35. Java Performance 20 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Method Area • Method Information Type Method Method Method Information Native or abstract • Method • Method bytecode • Method Return Type (or void) • Method Stack Frame • Method Parameter Type ( ) Operand Stack Local • Method Modifier variable Section (public, private, protected, static, final, • Exception Table syncronized, native, abstract)
    36. 36. Java Performance 21 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Method Area • Class Variable Class Variable Class • Class = Static • instance Instance • Instance Class Instance S ha re • Class Instance Instance • Final Class Constant Pool Instance
    37. 37. Java Performance 22 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Method Area • Reference to class ‘ClassLoader’ Reference ClassLoader class • Type Type JVM ClassLoader • Type Classloader • User-Defined Classloader reference • Bootstrap Classloader null • JVM Dynamic Linking Class Classloader Load
    38. 38. Java Performance 23 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Method Area • Reference to class ‘Class’ java.lang.class Reference class • Type load java.lang.class instance • getClass, forClass, isInterface Method Reference
    39. 39. Java Performance 24 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Method Area • Method Table Method Area • Class Method direct Class reference • Method Method Table • Method • Type interface abstract class Method class • Class Method Field superclass Method Constant reference Pool • Class Loading
    40. 40. Java Performance 25 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Method Area • Method Table Class A Class A { void a1() {…} 1 direct reference of a2() int a2() {…} 0 direct reference of a1() } Class B extends A{ Class B void a1() {…} 2 direct reference of b1() char b1() {…} 1 direct reference of a2() } 0 direct reference of a1()
    41. 41. Java Performance 26 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Method Area • Method Table Heap Class A { Class B extends A{ void a1() {…} void a1() {…} int a2() {…} char b1() {…} B instance1 } } Method Area A instance2 Class B … 2 direct reference of b1() 1 direct reference of a2() bi 0 direct reference of a1()
    42. 42. Java Performance 27 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Heap •Java Heap JVM • Instance Array • Thread Java Heap • JVM Heap instruction (new, newarray, Object Instance anewarray, multianewarray) Data • java code Class Pointer byte code Array Garbage Collection • Share • Java Heap Vendor Thread Thread  JVM Vendor Heap Thread Garbage Collection, Garbage Collector
    43. 43. Java Performance 28 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Heap • Hotspot JVM Heap Layout – Generational Heap
    44. 44. Java Performance 29 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Heap • Hotspot JVM Heap Layout Allocation Young Generation Promotion Old Generation
    45. 45. Java Performance 30 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Heap • IBM JVM Heap Layout – One-Heap : IBM JVM Default Heap Layout heapbase heaplimit heaptop Heap K Cluster P Cluster Wilderness Heap cache or LOA
    46. 46. Java Performance 31 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Heap • IBM JVM Heap Layout – Kcluster : Pinned Class Object • Default 1280 class entries • 1 Class Entry 300byte(32it), 560byte(64bit) – Pcluster : Pinned Object – Kcluster Pcluster – Pcluster 2KB Pluster – Pcluster Heap  Fragmentation
    47. 47. Java Performance 32 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Heap • IBM JVM Heap Layout – Cache : Cache Allocation – Object Thread • Thread Heap Heap Lock • Heap Lock Thread • – Object Cache Allocation – 512 Bytes Object –
    48. 48. Java Performance 33 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Heap • IBM JVM Heap Layout – Large Object Area • Large Object • 64KB Object • Heap • -Xloratio LOA (0.5 ~ 0.95 ) • 1MB Object
    49. 49. Java Performance 34 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Heap • IBM JVM Heap Layout – Heap Garbage Object Live Object
    50. 50. Java Performance 35 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Heap • IBM JVM Heap Layout – Sub pool • Java 1.4 • 16 Core SMP Allocation • Free Chunk FreeList
    51. 51. Java Performance 36 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Heap • IBM JVM Heap Layout – Sub Pool Pool 1 Small Size Freelist Middle Size Freelist 2 3 4 5 … Large Size Freelist n
    52. 52. Java Performance 37 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Heap • IBM JVM Heap Layout – Java 5 Heap – Heap Generational Heap – -Xgcpolicy: gencon Allocation Space Survivor Space Tenured Space Nursery Tenured
    53. 53. Java Performance 38 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Heap • Hotspot JVM Object Layout • Object Mark Word, Class Address Mark Word Class Address Object Data Header • Array Size Header ! Class Address Mark Word Array Size • Header 1 Word Array Data 1Word = 4bytes(32bit) 8bytes(64bit)
    54. 54. Java Performance 39 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Heap • Hotspot JVM Object Layout – Mark Word : Garbage Collection, Synchronization Hash Code (0) Mark Word Thread ID (1) Age Biased Tag 23 bit 6 bit 1 bit 2 bit Hash Code (0) Age Biased Tag Biased bit Tag Thread ID (1) 0 01 Unlocked (000) Lock Record Address 0 00 Light-weight locked (010) Monitor Address 0 10 Heavy-weight locked 0 11 Marked for GC (011) Forwarding Address 1 01 Biased / Biasable
    55. 55. Java Performance 40 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Heap • Hotspot JVM Object Layout Class Address Method Area Object Class Reference Array Size Array Object Array Data
    56. 56. Java Performance 41 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Heap • IBM JVM Object Layout – Object Array – header 1 Word Garbage Collection (2bits) bit (2bits) Pinned Size+Flags Object Size G P mptr Class pointer or array size Thread Index Count Array bit (1bit) locknflags S H T A Monitor Index Type(5bits) Monitor Shape bit Object Data Hash code state (2bits) (1bit) Hash code
    57. 57. Java Performance 42 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Heap • IBM JVM Object Layout – Size+Flag • 28 Bits : Object Size • 2 Bits : Multipinned Bit, Garbage Collection - Compaction Swapped Bit • Pinned Bit : 1 Bit • Dosed Bit : 1 Bit Garbage Collection (2bits) Object Size G P Pinned bit (2bits)
    58. 58. Java Performance 43 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Heap • IBM JVM Object Layout – mptr : Method Pointer – 1word 8byte – Object Method Table Pointer – Array Array mptr
    59. 59. Java Performance 44 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Heap • IBM JVM Object Layout – locknflags : lock – 1 word – Fat Lock Monitor Index 23 bits – Thin Lock 15 Bits Thread Index, 8 bits count – 5 Bits Lock Thread Index Count Array bit (1bit) locknflags S H T A Monitor Index Type(5bits) Monitor Shape bit (1bit) Hash code state (2bits)
    60. 60. Java Performance 45 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Heap • IBM JVM Object Layout (Java 5~) – header 1 Word Lock word VTable Object Data Lock word Array Size VTable Array Data
    61. 61. Java Performance 46 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Heap • IBM JVM Object Layout (Java5 ~) – Vtable Pointer – Vtable Object Information Table Pointer Object Information • Debug Data VTable OI • Class name • Object Type (Array, Object) • Reference field • Object Size Array Element • Offset Information
    62. 62. Java Performance 47 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Heap • IBM JVM Object Layout (Java5 ~) – Lock Word – 1 bit : Object on  Fat Lock – Fat Lock : 20 bits Monitor Index – Reserved Mode : Thread ID (15 bits), Count(5 bits) – Reserved Mode Locked 1 – Garbage Collector Hash Code (10 bits) Recursion Count (5 bits) Thread ID (15 bits) Count Hash Code 0 1 (10 bits) Monitor index (20 bits) Contention Bit (1bit) Reservation Bit (1bit)
    63. 63. Java Performance 48 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Heap • Array in Heap – Array Object Heap – Array Array Class instance – Type Array Class data – Array Instance data – Array Array Array – Class Data Naming Convention • ‘[‘ Type Description String
    64. 64. Java Performance 49 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Heap • Array in Heap – Type Description String Descriptor Type Array Class Data B Byte byte[] [B C Char char[][] [[C D Double double[] [D F Float float[][] [[F I Int int[][][] [[[I J Long long[] [J S Short short[][] [[S Z Boolean boolean[][][] [[[Z L Object java.lang.String[] [Ljava/lang/String
    65. 65. Java Performance 50 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Java Heap • Array in Heap Java Heap Class Data Pointer Length (=2) Class Data Pointer ar1[0][0] ( int ) ar1[0][1] ( int ) Length ( =2) ar1[0] (array reference) Class Data Pointer ar1[1] (array reference) Length (=2) ar1[1][0] ( int ) ar1[1][1] ( int ) Method Area ar1 Array Reference Class Class Data Data int [][] ar1 = new int [2][2] [[I [I
    66. 66. Java Performance 51 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Runtime Memory • Java Variables – Class Variables – Member Variables – Parameter Variables – Local Variables D:EXEM>type VariableArrange.java class VariableArrange { static int ci = 3; // Class Variable static String cs = "Static"; // Class Variable int mi = 4; // Member Variable String ms = "Member"; // Member Variable void method(int pi, String ps) { // Parameter Variable int li = 5; // Local Variable String ls = "Local"; // Local Variable } }
    67. 67. Java Performance 52 Java Performance Fundamental | twitter @novathinker Runtime Memory artdb@ex-em.com | performeister.tistory.com Java Stack Java Heap Method Area [Ljava/lang/String VariableArrange Instance method frame VariableArrange Local Variable mi = 4 ms = ref2 class Field Information 3 ls=ref4 String Instance : ref1 “Static” Class Variable 2 li=5 ci 3 String Instance : ref2 “Member” 1 ps method informations String Instance : ref3 VariableArrange(); 0 pi void method(int, String); static {}; String Instance : ref4 “Local” Constant Pool int Integer …
    68. 68. Java Performance 53 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Runtime Memory JvmInternal.java JvmInternal.class Bytecode
    69. 69. Java Performance 54 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Runtime Memory Source class JvmInternal { } bytecode Java Stack Java Heap Method Area JvmInternal frame Frame Data JvmInternal Instance Operand Stack JvmInternal class Field Information Local Variable Class Variable main method information addTwoArgs method information Constant Pool 0 args fcv 100
    70. 70. Java Performance 55 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Runtime Memory Source static int cv = 0; bytecode 0: iconst_0 Java Stack Java Heap Method Area JvmInternal frame Frame Data JvmInternal Instance [Ljava/lang/String Operand Stack JvmInternal class Field Information Local Variable Class Variable main method Length = 2 information addTwoArgs method args[1] “20” information args[0] “10” Constant Pool 0 args fcv 100 ICONST - Push value between -1, ..., 5, other values cause an exception
    71. 71. Java Performance 56 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Runtime Memory Source static int cv = 0; bytecode 1: putstatic Java Stack Java Heap Method Area JvmInternal frame Frame Data JvmInternal Instance [Ljava/lang/String Operand Stack JvmInternal class Field Information Local Variable Class Variable main method Length = 2 information addTwoArgs method args[1] “20” information args[0] “10” Constant Pool 0 args fcv 100 PUTSTATIC - Put static field in class #4; //Field cv:I
    72. 72. Java Performance 57 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Runtime Memory Source JvmInternal(); bytecode 0: aload_0 Java Stack Java Heap Method Area JvmInternal frame Frame Data JvmInternal Instance [Ljava/lang/String Operand Stack JvmInternal class args Field Information Class Variable Local Variable main method Length = 2 information addTwoArgs method args[1] “20” information args[0] “10” Constant Pool 0 args fcv 100 ALOAD - Load reference from local variable
    73. 73. Java Performance 58 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Runtime Memory Source public static void main(java.lang.String[]); bytecode 1: invokespecial Java Stack Java Heap Method Area JvmInternal frame main frame Frame Data Frame Data JvmInternal Instance [Ljava/lang/String Operand Stack Operand Stack JvmInternal class args Field Information Local Variable Local Variable Class Variable 3 main method Length = 2 information 2 addTwoArgs method args[1] “20” information 1 args[0] “10” Constant Pool 0 args 0 args fcv 100 INVOKESTATIC - Invoke instance method; special handling for superclass, private and instance initialization method invocations #1; //Method java/lang/Object."<init>":()V
    74. 74. Java Performance 59 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Runtime Memory Source a = Integer.parseInt(args[0]); bytecode 0: aload_0 Java Stack Java Heap Method Area main frame Frame Data JvmInternal Instance [Ljava/lang/String Operand Stack JvmInternal class args Field Information Local Variable Class Variable 3 main method Length = 2 information 2 addTwoArgs method args[1] “20” information 1 args[0] “10” Constant Pool 0 args fcv 100 ALOAD - Load reference from local variable
    75. 75. Java Performance 60 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Runtime Memory Source a = Integer.parseInt(args[0]); bytecode 1: iconst_0 Java Stack Java Heap Method Area main frame Frame Data JvmInternal Instance [Ljava/lang/String Operand Stack JvmInternal class args[0] Field Information Local Variable Class Variable 3 main Method Length = 2 information 2 addTwoArgs method args[1] “20” information 1 args[0] “10” Constant Pool 0 args fcv 100 ICONST - Push value between -1, ..., 5, other values cause an exception
    76. 76. Java Performance 61 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Runtime Memory Source a = Integer.parseInt(args[0]); bytecode 2: aaload Java Stack Java Heap Method Area main frame Frame Data JvmInternal Instance [Ljava/lang/String Operand Stack JvmInternal class “10” args[0] Field Information Local Variable Class Variable 3 main Method Length = 2 information 2 addTwoArgs method args[1] “20” information 1 args[0] “10” Constant Pool 0 args fcv 100 AALOAD - Load reference from array
    77. 77. Java Performance 62 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Runtime Memory Source a = Integer.parseInt(args[0]); bytecode 3: invokestatic Java Stack Java Heap Method Area main frame java/lang/Integer Frame Data JvmInternal Instance [Ljava/lang/String Operand Stack JvmInternal class 10 Field Information Local Variable Class Variable 3 main Method Length = 2 information 2 addTwoArgs method args[1] “20” information 1 args[0] “10” Constant Pool 0 args fcv 100 INVOKESTATIC - Invoke a class (static) method #2; //Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
    78. 78. Java Performance 63 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Runtime Memory Source a = Integer.parseInt(args[0]); bytecode 6: istore_1 Java Stack Java Heap Method Area main frame java/lang/Integer Frame Data JvmInternal Instance [Ljava/lang/String Operand Stack JvmInternal class 10 Field Information Local Variable Class Variable 3 main Method Length = 2 information 2 addTwoArgs method args[1] 20 information 1 a=10 args[0] 10 Constant Pool 0 args fcv 100 ISTORE - Store int from stack into local variable
    79. 79. Java Performance 64 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Runtime Memory Source b = Integer.parseInt(args[1]); bytecode 7: aload_0 Java Stack Java Heap Method Area main frame java/lang/Integer Frame Data JvmInternal Instance [Ljava/lang/String Operand Stack JvmInternal class args Field Information Local Variable Class Variable 3 main method Length = 2 information 2 addTwoArgs method args[1] “20” information 1 a=10 args[0] “10” Constant Pool 0 args fcv 100 ALOAD - Load reference from local variable
    80. 80. Java Performance 65 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Runtime Memory Source b = Integer.parseInt(args[1]); bytecode 8: iconst_1 Java Stack Java Heap Method Area main frame java/lang/Integer Frame Data JvmInternal Instance [Ljava/lang/String Operand Stack JvmInternal class args[1] Field Information Local Variable Class Variable 3 main Method Length = 2 information 2 addTwoArgs method args[1] “20” information 1 a=10 args[0] “10” Constant Pool 0 args fcv 100 ICONST - Push value between -1, ..., 5, other values cause an exception
    81. 81. Java Performance 66 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Runtime Memory Source b = Integer.parseInt(args[1]); bytecode 9: aaload Java Stack Java Heap Method Area main frame java/lang/Integer Frame Data JvmInternal Instance [Ljava/lang/String Operand Stack JvmInternal class “20” args[1] Field Information Local Variable Class Variable 3 main Method Length = 2 information 2 addTwoArgs method args[1] “20” information 1 a=10 args[0] “10” Constant Pool 0 args fcv 100 AALOAD - Load reference from array
    82. 82. Java Performance 67 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Runtime Memory Source b = Integer.parseInt(args[1]); bytecode 10: invokestatic Java Stack Java Heap Method Area main frame java/lang/Integer Frame Data JvmInternal Instance [Ljava/lang/String Operand Stack JvmInternal class 20 Field Information Local Variable Class Variable 3 main Method Length = 2 information 2 addTwoArgs method args[1] “20” information 1 a=10 args[0] “10” Constant Pool 0 args fcv 100 INVOKESTATIC - Invoke a class (static) method #2; //Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
    83. 83. Java Performance 68 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Runtime Memory Source b = Integer.parseInt(args[1]); bytecode 13: istore_2 Java Stack Java Heap Method Area main frame java/lang/Integer Frame Data JvmInternal Instance [Ljava/lang/String Operand Stack JvmInternal class 20 Field Information Local Variable Class Variable 3 main Method Length = 2 information 2 b=20 addTwoArgs method args[1] 20 information 1 a=10 args[0] 10 Constant Pool 0 args fcv 100 ISTORE - Store int from stack into local variable
    84. 84. Java Performance 69 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Runtime Memory Source c = addTwoArgs(a,b); bytecode 14: iload_1 Java Stack Java Heap Method Area main frame java/lang/Integer Frame Data JvmInternal Instance [Ljava/lang/String Operand Stack JvmInternal class 10 Field Information Local Variable Class Variable 3 main Method Length = 2 information 2 b=20 addTwoArgs method args[1] 20 information 1 a=10 args[0] 10 Constant Pool 0 args fcv 100 ILOAD - Load int from local variable onto stack
    85. 85. Java Performance 70 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Runtime Memory Source c = addTwoArgs(a,b); bytecode 15: iload_2 Java Stack Java Heap Method Area main frame java/lang/Integer Frame Data JvmInternal Instance [Ljava/lang/String Operand Stack JvmInternal class 20 10 Field Information Local Variable Class Variable 3 main Method Length = 2 information 2 b=20 addTwoArgs method args[1] 20 information 1 a=10 args[0] 10 Constant Pool 0 args fcv 100 ILOAD - Load int from local variable onto stack
    86. 86. Java Performance 71 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Runtime Memory Source c = addTwoArgs(a,b); bytecode 16: Java Stack Java Heap Method Area main frame addTwoArgs frame java/lang/Integer Frame Data Frame Data JvmInternal Instance [Ljava/lang/String Operand Stack main ref JvmInternal class 20 10 Operand Stack Field Information Local Variable Class Variable 3 main Method Length = 2 information Local Variable 2 b=20 addTwoArgs method args[1] 20 information 1 a=10 1 args[0] 10 Constant Pool 0 args 0 fcv 100 INVOKESTATIC - Invoke instance method; special handling for superclass, private and instance initialization method invocations #3; //Method addTwoArgs:(II)I
    87. 87. Java Performance 72 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Runtime Memory Source static int addTwoArgs(int, int); bytecode 16: Java Stack Java Heap Method Area main frame addTwoArgs frame java/lang/Integer Frame Data Frame Data JvmInternal Instance [Ljava/lang/String Operand Stack main ref JvmInternal class 20 10 Operand Stack Field Information Local Variable Class Variable 3 main Method Length = 2 information Local Variable 2 b=20 addTwoArgs method args[1] 20 information 1 a=10 1 20 args[0] 10 Constant Pool 0 args 0 10 fcv 100 INVOKESTATIC - Invoke instance method; special handling for superclass, private and instance initialization method invocations #3; //Method addTwoArgs:(II)I
    88. 88. Java Performance 73 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Runtime Memory Source cv = fcv ; bytecode 0: bipush Java Stack Java Heap Method Area main frame addTwoArgs frame java/lang/Integer Operand Stack Frame Data JvmInternal Instance [Ljava/lang/String main ref JvmInternal class ref Operand Stack Field Information Local Variable Class Variable 100 3 main Method Length = 2 information Local Variable 2 b=20 addTwoArgs method args[1] 20 information 1 a=10 1 20 args[0] 10 Constant Pool 0 args 0 10 fcv 100 BIPUSH - Push byte on stack, (-128~127)
    89. 89. Java Performance 74 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Runtime Memory Source cv = fcv ; bytecode 2: putstatic Java Stack Java Heap Method Area main frame addTwoArgs frame java/lang/Integer Frame Data Frame Data JvmInternal Instance [Ljava/lang/String Operand Stack main ref JvmInternal class ref Operand Stack Field Information Class Variable Local Variable cv 100 100 3 main Method Length = 2 information Local Variable 2 b=20 addTwoArgs method args[1] 20 information 1 a=10 1 20 args[0] 10 Constant Pool 0 args 0 10 fcv 100 PUTSTATIC - Put static field in class #4; //Field cv:I
    90. 90. Java Performance 75 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Runtime Memory Source return ( x + y ); bytecode 5: iload_0 Java Stack Java Heap Method Area main frame addTwoArgs frame java/lang/Integer Frame Data Frame Data JvmInternal Instance [Ljava/lang/String Operand Stack main ref JvmInternal class ref Operand Stack Field Information Local Variable Class Variable 10 3 main Method Length = 2 information Local Variable 2 b=20 addTwoArgs method args[1] 20 information 1 a=10 1 20 args[0] 10 Constant Pool 0 args 0 10 fcv 100 ILOAD - Load int from local variable onto stack
    91. 91. Java Performance 76 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Runtime Memory Source return ( x + y ); bytecode 6: iload_1 Java Stack Java Heap Method Area main frame addTwoArgs frame java/lang/Integer Frame Data Frame Data JvmInternal Instance [Ljava/lang/String Operand Stack main ref JvmInternal class ref Operand Stack Field Information 20 Local Variable Class Variable 10 3 main Method Length = 2 information Local Variable 2 b=20 addTwoArgs method args[1] 20 information 1 a=10 1 20 args[0] 10 Constant Pool 0 args 0 10 fcv 100 ILOAD - Load int from local variable onto stack
    92. 92. Java Performance 77 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Runtime Memory Source return ( x + y ); bytecode 7: iadd Java Stack Java Heap Method Area main frame addTwoArgs frame java/lang/Integer Frame Data Frame Data JvmInternal Instance [Ljava/lang/String Operand Stack main ref JvmInternal class ref Operand Stack Field Information Local Variable Class Variable 30 3 main Method Length = 2 information Local Variable 2 b=20 addTwoArgs method args[1] 20 information 1 a=10 1 20 args[0] 10 Constant Pool 0 args 0 10 fcv 100 IADD - Add ints
    93. 93. Java Performance 78 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Runtime Memory Source return ( x + y ); bytecode 8: ireturn Java Stack Java Heap Method Area main frame addTwoArgs frame java/lang/Integer Frame Data Frame Data JvmInternal Instance [Ljava/lang/String JvmInternal() ref 30 main ref ref JvmInternal class Operand Stack Operand Stack Field Information pop Class Variable Local Variable cv 100 30 3 main Method Length = 2 information Local Variable 2 b=20 addTwoArgs method args[1] 20 information 1 a=10 1 20 args[0] 10 Constant Pool 0 args 0 10 fcv 100 IRETURN - Return int from method
    94. 94. Java Performance 79 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Runtime Memory Source c = addTwoArgs(a,b); bytecode 19: istore_3 Java Stack Java Heap Method Area main frame java/lang/Integer Frame Data JvmInternal Instance [Ljava/lang/String Operand Stack JvmInternal class 30 Field Information Class Variable Local Variable cv 100 3 c=30 main Method Length = 2 information 2 b=20 addTwoArgs method args[1] 20 information 1 a=10 args[0] 10 Constant Pool 0 args fcv 100 ISTORE - Store int from stack into local variable
    95. 95. Java Performance 80 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com

    ×