3장. Garbage Collection

9,731 views
9,660 views

Published on

Java Performance Fundamental 세미나 교재입니다. 3장은 Garbage Collection에 대해 설명하고 있습니다. 먼저 JVM에서 사용하는 Garbage Collection 뿐만 아니라 일반적인 Garbage Collection의 Algorithm을 상세히 알아봅니다. 그 후 Hotspot JVM의 Heap구조와 Garbage Collector를 설명하고 Generation별로 어떻게 동작하는 지에 대해 설명합니다. 이어 IBM JVM에 대한 Heap 구조와 Garbage Collector에 대해서도 설명합니다.

* Garbage Collection 이란?
* Garbage Collection 의 대상
* Garbage Collection 의 기본 Algorithm
* Hotspot JVM의 Garbage Collection
o Serial Collector
o Incremental Collector
o Parallel Collector
o CMS Collector
o Parallel Compaction Collector
o Garbage First Collector
* IBM JVM의 Garbage Collection
o Optimize for Throughput Collector
o Optimize for Pause Time Collector
o Generational Concurrent Collector
o Subpool Collector

Published in: Technology
1 Comment
22 Likes
Statistics
Notes
  • i want to ask you a quesiton about page P61 , the right picture i think may be object pool, you can see any object in the object pool has a pointer to the left one's index such A's pointer to the index 5,can you give some explanation of this pointer(in english ,my korea language is poor sorry)
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
9,731
On SlideShare
0
From Embeds
0
Number of Embeds
5,376
Actions
Shares
0
Downloads
262
Comments
1
Likes
22
Embeds 0
No embeds

No notes for slide
  • 3장. Garbage Collection

    1. 1. Java Performance artdb@ex-em.com | performeister.tistory.com | twitter @novathinker Garbage Collection
    2. 2. Java Performance 2 artdb@ex-em.com | performeister.tistory.com | twitter @novathinker 1) Garbage Collection 2) Garbage Collection Algorithm 3) Hotspot JVM Garbage Collection 4) IBM JVM Garbage Collection
    3. 3. Java Performance 3 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection • Garbage Collection – Garbage Collector – Unreferenced Memory – – Fragmentation “Heap storage for objects is reclaimed by an automatic storage management system (typically a garbage collector); objects are never explicitly deallocated.” - Java Virtual Machine Speculation, Section 3.5.3 [JVMS2 1999]
    4. 4. Java Performance 4 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection ! Garbage Collector
    5. 5. Java Performance 4 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection ! object Garbage Collector Heap memory .
    6. 6. Java Performance 4 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection ! object Garbage Collector Heap memory . Garbage Collection Memory Recycling Heap Fragmentation .
    7. 7. Java Performance 4 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection ! object Garbage Collector Heap memory . Garbage Collection Memory Recycling Heap Fragmentation . • JVM heap new, newarray, anewarray, multianewarray instruction instruction • Garbage Collection • JVM Spec Garbage Collection Algorithm
    8. 8. Java Performance 5 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection ! Garbage Collector
    9. 9. Java Performance 5 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Memory ! Memory System Garbage Collector crash .
    10. 10. Java Performance 5 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Memory ! Memory System Garbage Collector crash . Program CPU Time Scheduling .
    11. 11. Java Performance 6 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection • Garbage Collection – Garbage Collection
    12. 12. Java Performance 7 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection
    13. 13. Java Performance 7 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection ROOT SET
    14. 14. Java Performance 7 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection ROOT SET Local Variable, Operand Stack
    15. 15. Java Performance 7 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection ROOT SET Local Variable, Operand Stack Class Constant Pool Reference
    16. 16. Java Performance 7 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection ROOT SET Local Variable, Unreleased Native Operand Stack Method Object Reference Class Constant Pool Reference
    17. 17. Java Performance 8 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Colletion • Root Set
    18. 18. Java Performance 9 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Colletion • Memory Leak class Main{ public static void main (String args[]) { Leak lk = new Leak(); for(int a=0; a<9000000; a++) { lk.addList(a); lk.removeStr(a); } } } class Leak { ArrayList lst = new ArrayList(); public void addList(int a) { lst.add(" "+a); } public void removeStr(int i) { Object obj = lst.get(i); obj = null; } }
    19. 19. Java Performance 9 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Colletion • Memory Leak class Main{ public static void main (String args[]) { Leak lk = new Leak(); for(int a=0; a<9000000; a++) { lk.addList(a); lk.removeStr(a); } } Why leak? } class Leak { ArrayList lst = new ArrayList(); public void addList(int a) { lst.add(" "+a); } public void removeStr(int i) { Object obj = lst.get(i); obj = null; } }
    20. 20. Java Performance 10 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm
    21. 21. Java Performance 11 artdb@ex-em.com | performeister.tistory.com | twitter @novathinker Garbage Collection Algorithm 1) Reference Counting Algorithm 2) Mark-and-Sweep Algorithm 3) Mark-and-Compacting Algorithm 4) Copying Algorithm 5) Generational Algorithm 6) Train Algorithm 7) Adaptive Algorithm
    22. 22. Java Performance 12 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm • Garbage Collection Algorithm
    23. 23. Java Performance 12 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm • Garbage Collection Algorithm Garbage Object Detection • Live Object : Root Set • Garbage Object
    24. 24. Java Performance 12 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm • Garbage Collection Algorithm Garbage Object Detection • Live Object : Root Set • Garbage Object Garbage Object • Heap Memory Reclaim
    25. 25. Java Performance 13 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm • Reference Counting Algorithm • Mark-and-Sweep Algorithm • Copying Algorithm • Mark-and-Compacting Algorithm • Generational Algorithm • Train Algorithm • Adaptive Algorithm
    26. 26. Java Performance 14 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm • Reference Counting Algorithm – GC – Object Reference count – Reference Count 0 GC – Object GC Object Object Object Count Count
    27. 27. Java Performance 15 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Integer RefCnt 00 Integer RefCnt 00 Integer RefCnt 00
    28. 28. Java Performance 15 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Integer Object a = new Ingeter(1); RefCnt 00 Integer RefCnt 00 Integer RefCnt 00
    29. 29. Java Performance 15 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Integer Object a = new Ingeter(1); a 1 RefCnt 01 0 Integer RefCnt 00 Integer RefCnt 00
    30. 30. Java Performance 15 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Integer Object a = new Ingeter(1); a 1 Object b = a; RefCnt 01 0 Integer RefCnt 00 Integer RefCnt 00
    31. 31. Java Performance 15 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Integer Object a = new Ingeter(1); a 1 Object b = a; b RefCnt 01 0 2 Integer RefCnt 00 Integer RefCnt 00
    32. 32. Java Performance 15 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Integer Object a = new Ingeter(1); a 1 Object b = a; b RefCnt 01 0 2 Integer Object a = new Ingeter(1); RefCnt 00 Integer RefCnt 00
    33. 33. Java Performance 15 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Integer Object a = new Ingeter(1); a 1 Object b = a; b RefCnt 01 0 2 Integer a 1 Object a = new Ingeter(1); 0 RefCnt 01 Integer RefCnt 00
    34. 34. Java Performance 15 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Integer Object a = new Ingeter(1); a 1 Object b = a; b RefCnt 01 0 2 Integer a 1 Object a = new Ingeter(1); 0 RefCnt 01 Object b = new Ingeter(2); Integer RefCnt 00
    35. 35. Java Performance 15 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Integer Object a = new Ingeter(1); a 1 Object b = a; b RefCnt 01 0 2 Integer a 1 Object a = new Ingeter(1); 0 RefCnt 01 Object b = new Ingeter(2); Integer 2 b RefCnt 01 0
    36. 36. Java Performance 15 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Integer Object a = new Ingeter(1); a 1 Object b = a; b RefCnt 01 0 2 Integer a 1 Object a = new Ingeter(1); 0 RefCnt 01 Object b = new Ingeter(2); Integer a = b; 2 b RefCnt 01 0
    37. 37. Java Performance 15 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Integer Object a = new Ingeter(1); a 1 Object b = a; b RefCnt 01 0 2 Integer a 1 Object a = new Ingeter(1); 0 RefCnt 01 Object b = new Ingeter(2); Integer a = b; 2 b RefCnt 01 0 2
    38. 38. Java Performance 16 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm
    39. 39. Java Performance 16 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Object a = new TwoIngeter(new Integer(1), new Integer(2));
    40. 40. Java Performance 16 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Object a = new TwoIngeter(new Integer(1), new Integer(2)); Integer 1 TwoInteger RefCnt 00 1 ref a RefCnt 00 1 Integer 2 RefCnt 01 0
    41. 41. Java Performance 16 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Object a = new TwoIngeter(new Integer(1), new Integer(2)); a = null; Integer 1 TwoInteger RefCnt 00 1 ref a RefCnt 00 1 Integer 2 RefCnt 01 0
    42. 42. Java Performance 16 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Object a = new TwoIngeter(new Integer(1), new Integer(2)); a = null; Integer 1 TwoInteger RefCnt 00 1 ref a RefCnt 00 1 Integer 2 RefCnt 01 0
    43. 43. Java Performance 16 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Object a = new TwoIngeter(new Integer(1), new Integer(2)); a = null; Integer 1 TwoInteger RefCnt 00 1 ref a GC RefCnt 00 1 Integer 2 RefCnt 01 0
    44. 44. Java Performance 16 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Object a = new TwoIngeter(new Integer(1), new Integer(2)); a = null; Integer 1 RefCnt 00 1 a Integer 2 RefCnt 01 0 0
    45. 45. Java Performance 17 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm • Reference Counting Algorithm • Garbage Object • Garbage • Garbage Collector ( ) • Reference Count • Linked List Reference Count 0 Leak
    46. 46. Java Performance 18 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm a Linked List next ref RefCnt 02 Linked List next ref RefCnt 11 Linked List next ref RefCnt 01
    47. 47. Java Performance 18 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm a Linked List next ref 2 RefCnt 01 Linked List next ref RefCnt 11 Linked List next ref RefCnt 01
    48. 48. Java Performance 19 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm • Mark-and-Sweep Algorithm – Root Set Reference – Tracing Algorithm – Mark Sweep • Mark : Live Object Mark (Object flag or bitmap table ) • Sweep : Heap Mark
    49. 49. Java Performance 20 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm R ref ref ref  flag  flag  flag ref ref ref  flag  flag  flag ref ref ref  flag  flag  flag
    50. 50. Java Performance 20 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Mark Phase R ref ref ref  flag  flag  flag ref ref ref  flag  flag  flag ref ref ref  flag  flag  flag
    51. 51. Java Performance 20 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Mark Phase R ref ref ref   flag   flag   flag ref ref ref  flag  flag   flag ref ref ref  flag   flag   flag
    52. 52. Java Performance 20 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Sweep Phase R ref ref ref   flag   flag   flag ref ref ref  flag  flag   flag ref ref ref  flag   flag   flag
    53. 53. Java Performance 20 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Sweep Phase R ref ref ref   flag   flag   flag ref   flag ref ref   flag   flag
    54. 54. Java Performance 20 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm R ref ref ref   flag   flag   flag ref   flag ref ref   flag   flag
    55. 55. Java Performance 20 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm R ref ref ref  flag  flag  flag ref  flag ref ref  flag  flag
    56. 56. Java Performance 21 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm • Mark-and-Sweep Algorithm • Reference • Reference Overhead • Suspend • Fragmentation  Memory
    57. 57. Java Performance 22 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm • Mark-and-Compacting Algorithm – Fragmentation Memory Algorithm – Mark Compaction • Mark Phase : Live Object Mark • Compaction : Live Object Memory – Handle • Mark Phase : Handle Marking • Compaction : Object Handle Update
    58. 58. Java Performance 23 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm • Mark-and-Compacting Algorithm – Compaction Arbitrary Worst 4 1 2 3 1 2 3 4 Linear 1 3 4 2 • Arbitrary : Sliding • Linear : Pointer 1 2 3 4 • Sliding : Allocation Best
    59. 59. Java Performance 24 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm 2 Handle 0  flag 1  flag T22 A 5 Z 1 2  flag T11 3  flag T12 B 9 W 7 4  flag 5  flag T21 6  flag Q 3 C 2 7  flag T31 8  flag 9  flag T32
    60. 60. Java Performance 24 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm 2 Mark Phase Handle 0  flag 1  flag T22 A 5 Z 1 2  flag T11 3  flag T12 B 9 W 7 4  flag 5  flag T21 6  flag Q 3 C 2 7  flag T31 8  flag 9  flag T32
    61. 61. Java Performance 24 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm 2 Mark Phase Handle 0  flag 1  flag T22 A 5 Z 1  2  flag T11 3  flag T12 B 9 W 7 4  flag  5  flag T21 6  flag Q 3 C 2 7  flag T31 8  flag  9  flag T32
    62. 62. Java Performance 24 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm 2 Mark Phase Handle 0  flag 1  flag T22 A 5 Z 1  2  flag T11 3  flag T12 B 9 W 7 4  flag  5  flag T21 6  flag Q 3 C 2 7  flag T31 8  flag  9  flag T32
    63. 63. Java Performance 24 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm 2 Mark Phase Handle 0  flag 1  flag T22 A 5 Z 1  2  flag T11 3  flag T12 B 9 W 7 4  flag  5  flag T21 6  flag Q 3 C 2 7  flag T31 8  flag  9  flag T32
    64. 64. Java Performance 24 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm 2 Compation Phase Handle 0  flag 1  flag T22 A 5 Z 1  2  flag T11 3  flag T12 B 9 W 7 4  flag  5  flag T21 6  flag Q 3 C 2 7  flag T31 8  flag  9  flag T32
    65. 65. Java Performance 24 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm 2 Compation Phase Handle 0  flag 1  flag T22 A 5  2  flag T11 3  flag T12 B 9 4  flag  5  flag T21 6  flag C 2 7  flag T31 8  flag  9  flag T32
    66. 66. Java Performance 24 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm 2 Compation Phase Handle 0  flag 1  flag T22 A 5 B 9  2  flag T11 3  flag T12 4  flag  5  flag T12 T21 6  flag C 2 7  flag T31 8  flag  9  flag T32
    67. 67. Java Performance 24 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm 2 Compation Phase Handle 0  flag 1  flag T22 A 5 B 9  2  flag T11 3  flag T12 C 2 4  flag  5  flag T12 T21 6  flag 7  flag T31 8  flag  9  flag T21 T32
    68. 68. Java Performance 24 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm 2 Handle 0  flag 1  flag T22 A 5 B 9 2  flag T11 3  flag T12 C 2 4  flag 5  flag T12 T21 6  flag 7  flag T31 8  flag 9  flag T21 T32
    69. 69. Java Performance 25 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm • Mark-and-Compacting Algorithm • Fragmentation • Memory • Reference Object Access Overhead • Suspend
    70. 70. Java Performance 26 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm • Copying Algorithm – Stop-the-Copy Algorithm – Heap Active Inactive – Active Object – Active Live Object Inactive Copy
    71. 71. Java Performance 27 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Active Area A C B R Inactive Area
    72. 72. Java Performance 27 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Active Area A C null null B null R Inactive Area
    73. 73. Java Performance 27 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Active Area A C null B null R A’ null Inactive Area
    74. 74. Java Performance 27 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Active Area A C null B R A’ B’ null null Inactive Area
    75. 75. Java Performance 27 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Active Area A C B R A’ B’ C’ null null null Inactive Area
    76. 76. Java Performance 27 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Inactive Area R A’ B’ C’ null null null Active Area
    77. 77. Java Performance 28 Java Performance Fundamental | twitter @novathinker Garbage Collection Algorithm artdb@ex-em.com | performeister.tistory.com • Copying Algorithm • Fragmentation  Inactive Copy • GC Suspend • Copy Overhead •
    78. 78. Java Performance 29 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm • Generational Algorithm – Copying Algorithm • Copy • Object • Object • Long Lived Object – Heap age sub heap Youngest Generation Sub heap GC – Object Age
    79. 79. Java Performance 30 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Youngest Generation Sub Heap Matured Live Live Dead Dead Live Matured Dead Live Dead Dead Live Dead Dead Matured Tenured Generation Sub Heap
    80. 80. Java Performance 30 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Youngest Generation Sub Heap Live Live Dead Dead Live Dead Live Dead Dead Live Dead Dead Tenured Generation Sub Heap GC Matured Matured Matured
    81. 81. Java Performance 30 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Youngest Generation Sub Heap Live Live Live Live Live Tenured Generation Sub Heap GC Matured Matured Matured
    82. 82. Java Performance 30 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Youngest Generation Sub Heap Matured Matured Dead Live Matured Dead Live Matured Live Tenured Generation Sub Heap Matured Matured Matured
    83. 83. Java Performance 31 Java Performance Fundamental | twitter @novathinker Garbage Collection Algorithm artdb@ex-em.com | performeister.tistory.com • Generational Algorithm • Sub Heap Mark-and-Sweep Copying Algorithm Fragmentation, Memory , Copy • JVM
    84. 84. Java Performance 32 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm • Train Algorithm – Incremental Algorithm – Memory Mark-and-Copy GC – GC Suspend Idea
    85. 85. Java Performance 33 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm • Train Algorithm Car : Memory Block , Fixed Size RememberSet RememberSet Car root A B C A’ B’ C’ set Train : Car( ) Car
    86. 86. Java Performance 34 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Car 1-1 Car 1-2 Train 1 {R1,E} A B C D E F R1 Car 2-1 Train 2 {R2,B} R2 G
    87. 87. Java Performance 34 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Free Car Car 1-1 Car 1-2 Train 1 {C} D E F C R1 Car 2-1 Train 2 {R2,B} R2 G Car 3-1 Train 3 {R1} A B
    88. 88. Java Performance 34 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm Free Car Free Car Free Car Free Train R1 Car 2-1 Train 2 {R2,B} R2 G Car 3-1 Train 3 {R1} A B
    89. 89. Java Performance 35 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm • Train Algorithm • Suspend • Suspend • Fragmentation
    90. 90. Java Performance 36 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Garbage Collection Algorithm • Adaptive Algorithm – Algorithm Trade Off  Algorithm – Adaptive Algorithm Algorithm – Heap Algorithm – Hotspot Ergonomic , IBM Tilt – Application
    91. 91. Java Performance artdb@ex-em.com | performeister.tistory.com | twitter @novathinker Hotspot JVM
    92. 92. Java Performance 38 artdb@ex-em.com | performeister.tistory.com | twitter @novathinker Hotspot JVM Garbage Collection 1) Garbage Collection of Hotspot JVM 2) Heap of Hotspot JVM 3) Garbage Collector 4) Serial Collector 5) Incremental Collector 6) Parallel Collector 7) Parallel Compacting Collector 8) CMS Collector 9) Garbage First Collector
    93. 93. Java Performance 39 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Garbage Collection of Hotspot JVM – Weak Generational Hypothesis • High Infant Mortality • Few References from Older to Younger Objects Exists – Young Generation GC Algorithm • Speed – Fast Allocation & TLAB – Old Generation GC Algorithm • – Card Table & Write Barrier
    94. 94. Java Performance 40 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Fast Allocation & TLAB T T T T T Synchronization 1 2 3 4 5 Wait Allocation T T T T T 1 2 3 4 5 TLAB Allocation Allocation Allocation Allocation Allocation
    95. 95. Java Performance 41 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Fast Allocation & TLAB – Memory – Bump-the-Pointer – Multi Thread – Hotspot JVM TLAB (Thread Local Allocation Buffer) • Thread • TLAB • Allocation code – 10 native instructions
    96. 96. Java Performance 42 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Card Table Write Barrier – 1 Byte Card / 512 Byte of Old Generation – Old to Young Reference – Write Barrier • Bytecode Interpreter • 2 native instructions Young Generation Old Generation Card Table
    97. 97. Java Performance 43 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Garbage Collection of Hotspot JVM – Garbage Collection • Minor Collection : Young Generation • Major Collection : Old Generation – Full Collection – Method Area GC Major Full
    98. 98. Java Performance 44 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Heap of Hotspot JVM Survivor 1 Survivor 2 Eden Tenured Permanent Young Generation Old Generation Method Area GC
    99. 99. Java Performance 45 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • JVM Option – Standard Option : JVM Option :- – Non-Standard Option • JVM • , Parameter • -X Option : Macro • -XX Option : Micro
    100. 100. Java Performance 46 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Automatic Selection – Java5 Garbage Collector, Heap Size – Hardware Resource OS – Sever Class Client Class
    101. 101. Java Performance 47 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Automatic Selection – Server Class • :2 CPU, 2GB Physical Mem. • 32bit Windows • Default Garbage Collector Parallel Collector • Initial Heap Size – 1GB 1/64 * Physical Memory – 1GB 32MB • Max Heap Size : 1GB ¼ * Physical Mem. • Server Runtime Compiler
    102. 102. Java Performance 48 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Automatic Selection – Client Class • Server Class • Default Garbage Collector Serial Collector • Initial Heap Size : 4MB • Max Heap Size : 64MB • Client Runtime Compiler
    103. 103. Java Performance 49 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Automatic Selection – Option • -server : Server Class • -client : Client Class
    104. 104. Java Performance 50 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Garbage Collector – Serial Collector • Hotspot JVM Default Garbage Collector • Default Collector • Young Generation : Generational Algorithm • Old Generation : Mark-and-Compacting Algorithm
    105. 105. Java Performance 51 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Garbage Collector – Parallel Collector • (Throughput) Garbage Collector • Throughput Garbage Collector • Young Generation • Young Generation : Parallel Copy Algorithm • Old Generation : Mark-and-Compacting Algorithm
    106. 106. Java Performance 52 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Garbage Collector – Parallel Compacting Collector • Parallel Collector Old Generation • Java SE 5.0 update 6 • Young Generation : Parallel Copy Algorithm • Old Generation : Parallel Compacting Algorithm
    107. 107. Java Performance 53 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Garbage Collector – CMS Collector • CMS : Concurrent Mark-Sweep • • Old Generation Pause Time (Low Pause Garbage Collector) • Young Generation : Parallel Copy Algorithm • Old Generation : Concurrent Mark-and- Sweep Algorithm
    108. 108. Java Performance 54 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Garbage Collector – Incremental Collector • Low Pause Garbage Collector • Train Collector • Young Generation : Generational Algorithm • Old Generation : Train Algorithm
    109. 109. Java Performance 55 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Garbage Collector – Garbage First Collector • Java SE 6 Update 14 • Train Algorithm • Generation • Heap Region Young , Old Area • Realtime Low Pause
    110. 110. Java Performance 56 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Serial Collector – Young, Old Generation Serial (Single CPU Use) – Suspend during Collecting – Client Class Collector –
    111. 111. Java Performance 57 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Serial Collector – Young Generation Collection : Generational Young Eden A Survivor1 - From Survivor2 - To B C Empty Old
    112. 112. Java Performance 57 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Serial Collector – Young Generation Collection : Generational Minor GC Young Eden A Survivor1 - From Survivor2 - To B C A’ B’ C’ Old
    113. 113. Java Performance 57 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Serial Collector – Young Generation Collection : Generational Young Eden Empty Survivor1 - From Survivor2 - To Empty A’ B’ C’ Old
    114. 114. Java Performance 58 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Serial Collector Young Eden A Survivor1 - To Survivor2 - From Empty B M Old
    115. 115. Java Performance 58 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Serial Collector Minor GC Young Eden Empty Survivor1 - To Survivor2 - From A’ B’ Empty Old M’
    116. 116. Java Performance 59 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Serial Collector – Old Generation Collection : Mark-and-Compacting Old
    117. 117. Java Performance 59 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Serial Collector – Old Generation Collection : Mark-and-Compacting Mark Old √ √ √
    118. 118. Java Performance 59 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Serial Collector – Old Generation Collection : Mark-and-Compacting Sweep Old √ √ √
    119. 119. Java Performance 59 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Serial Collector – Old Generation Collection : Mark-and-Compacting Sliding Compaction Old √ √ √ Sliding Compaction : Fragmentation
    120. 120. Java Performance 60 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Serial Collector – JVM Option • -XX:+UseSerialGC : J2SE5.0, update 6 Serial Collector • -XX:MaxTenuringThreshold=<value> : Aging , default 31 • -XX:PretenureSizeThreshold=<value> : Old Generation directly Allocation • -XX:+PrintTenuringDistribution : Promotion
    121. 121. Java Performance 61 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Parallel Collector – Memory, Multi-CPU – GC Multi Thread – Large Young Generation – Server Class Default Garbage Collector (CPU 1 ) – Old Generation Collection : Serial Collector
    122. 122. Java Performance 62 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Parallel Collector – Young Generation Collection : Parallel Copy Serial Collector Parallel Collector Stop & Copy
    123. 123. Java Performance 62 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Parallel Collector – Young Generation Collection : Parallel Copy Serial Collector Parallel Collector Stop & Copy
    124. 124. Java Performance 62 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Parallel Collector – Young Generation Collection : Parallel Copy Serial Collector Parallel Collector Stop & Copy
    125. 125. Java Performance 63 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Parallel Collector – Promotion Buffer • Parallel Local Allocation Buffer(PLAB) • Thread • Promotion Thread Promotion Buffer • Fragmentation – GC Thread – Old Generation Size
    126. 126. Java Performance 64 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Parallel Collector – Promotion Buffer T1 T2 T1 T2 Promotion Buffer
    127. 127. Java Performance 65 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Parallel Collector – Option • -XX:+UseParallelGC : Parallel Collector (CMS Collector ) • -XX:ParallelGCThreads=<value> : GC Thread default CPU
    128. 128. Java Performance 66 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Parallel Collector – Ergonomics Option • -XX:MaxGCPauseMills=<value> (1.5+) : Maximum Pause Time Goal Pause Time • -XX:GCTimeRatio=<value> (1.5+) : Throughput Goal , default 1% GC Time • -XX:+UseAdaptiveSizePolicy (1.4.1+) : Young/Old Sizing
    129. 129. Java Performance 67 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Parallel Collector • -XX:YoungGenerationSizeIncrement=<value> : Young Growing Percent, Default = 20 (1.5+) •- XX:TenuredGenerationSizeIncrement=<value> : Old Growing Percent, Default = 20 (1.5+) •- XX:AdaptiveSizeDecrementScaleFactor=<value > : Growing Shrink , Default = 4 (1.5+) • -XX:+AggressiveHeap : Physical Memory Max Heap Hardware Resource
    130. 130. Java Performance 68 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Parallel Collector • -XX:GCHeapFreeLimit=<value> (1.4.1+) : GC Free Space Heap (default 5) -XX:+UseParallelGC GC OOME • -XX:GCTimeLimit=<value> (1.4.1+) : GC (default 90) -XX:+UseParallelGC GC OOME
    131. 131. Java Performance 69 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Parallel Compacting Collector – Parallel Collector Old Generation Collection Algorithm – Parallel Collector – Multi CPU – Old Generation Collection – Young Generation Collection • Parallel Collector • Parallel Copy Algorithm
    132. 132. Java Performance 70 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Parallel Compacting Collector – Old Generation Collection : Parallel Compaction Parallel Compacting Collector Mark Phase Summary Phase Compaction Phase
    133. 133. Java Performance 70 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Parallel Compacting Collector – Old Generation Collection : Parallel Compaction Parallel Compacting Collector Mark Phase Summary Phase Compaction Phase
    134. 134. Java Performance 70 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Parallel Compacting Collector – Old Generation Collection : Parallel Compaction Parallel Compacting Collector Mark Phase Summary Phase Compaction Phase
    135. 135. Java Performance 70 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Parallel Compacting Collector – Old Generation Collection : Parallel Compaction Parallel Compacting Collector Mark Phase Summary Phase Compaction Phase
    136. 136. Java Performance 70 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Parallel Compacting Collector – Old Generation Collection : Parallel Compaction Parallel Compacting Collector Mark Phase Summary Phase Compaction Phase
    137. 137. Java Performance 70 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Parallel Compacting Collector – Old Generation Collection : Parallel Compaction Parallel Compacting Collector Mark Phase Summary Phase Compaction Phase
    138. 138. Java Performance 71 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Parallel Compacting Collector – Mark Phase • Generation Region • Live Object Marking • Parallel Work
    139. 139. Java Performance 71 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Parallel Compacting Collector – Mark Phase • Generation Region • Live Object Marking • Parallel Work       
    140. 140. Java Performance 72 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Parallel Compacting Collector – Summary Phase • Region Operation • Single Work • Density • Dense Prefix • Dense Prefix GC       
    141. 141. Java Performance 72 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Parallel Compacting Collector – Summary Phase • Region Operation • Single Work • Density • Dense Prefix • Dense Prefix GC        Dense Prefix
    142. 142. Java Performance 72 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Parallel Compacting Collector – Summary Phase • Region Operation • Single Work • Density • Dense Prefix • Dense Prefix GC        Dense Prefix
    143. 143. Java Performance 73 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Parallel Compacting Collector – Compaction Phase • Thread Region Collecting • Source, Destination • Live Object Destination Compaction       
    144. 144. Java Performance 73 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Parallel Compacting Collector – Compaction Phase • Thread Region Collecting • Source, Destination • Live Object Destination Compaction Destination Source       
    145. 145. Java Performance 73 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Parallel Compacting Collector – Compaction Phase • Thread Region Collecting • Source, Destination • Live Object Destination Compaction Destination Source        T1 T2
    146. 146. Java Performance 73 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Parallel Compacting Collector – Compaction Phase • Thread Region Collecting • Source, Destination • Live Object Destination Compaction Destination Source        T1
    147. 147. Java Performance 73 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Parallel Compacting Collector – Compaction Phase • Thread Region Collecting • Source, Destination • Live Object Destination Compaction       
    148. 148. Java Performance 74 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • Parallel Compacting Collector – Option • -XX:+UseParallelOldGC (+Java6) : Parallel Compaction Collector • -XX:+UseParallelOldGCCompacting (+Java6) : Parallel Compaction , Default True • -XX:+UseParallelDensePrefixUpdate (+Java6) : Dense Prefix , Default True
    149. 149. Java Performance 75 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • CMS Collector – Fast Elapsed Time – Old Generation – Low Latency Collector – – GC Pause Time – Young Generation Collection • Parallel Collector
    150. 150. Java Performance 76 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • CMS Collector – Old Generation Collection : Concurrent Mark-Sweep Concurrent Mark-Sweep Collector
    151. 151. Java Performance 76 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • CMS Collector – Old Generation Collection : Concurrent Mark-Sweep Concurrent Mark-Sweep Collector Initial Mark Phase
    152. 152. Java Performance 76 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • CMS Collector – Old Generation Collection : Concurrent Mark-Sweep Concurrent Mark-Sweep Collector Initial Mark Phase Concurrent Mark Phase
    153. 153. Java Performance 76 Java Performance Fundamental | twitter @novathinker artdb@ex-em.com | performeister.tistory.com Hotspot JVM • CMS Collector – Old Generation Collection : Concurrent Mark-Sweep Concurrent Mark-Sweep Collector Initial Mark Phase Concurrent Mark Phase Remark Phase

    ×