Java memory presentation

703 views

Published on

Published in: Software, Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
703
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
46
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Java memory presentation

  1. 1. Java;Memory Yury Bubnov zStore
  2. 2. Object o = new Object();
  3. 3. Object o = new Object(); java.lang.OutOfMemoryError:  Java  heap  space
  4. 4. Object o = new Object(); java.lang.OutOfMemoryError:  Java  heap  space
  5. 5. Heap
  6. 6. Heap How many?
  7. 7. Heap How many? Size?
  8. 8. class Structure{ byte b; short i; Object o; }
  9. 9. 1 2 4/8 class Structure{ byte b; short i; Object o; }
  10. 10. class Structure{ byte b; short i; Object o; } markmarkmark klass 2 1 1 4
  11. 11. class Structure{ byte b; short i; Object o; } 2 8 markmarkmark klass 2 1 1 4
  12. 12. class Structure{ byte b; short i; Object o; } markmarkmark klassklassklass 2 1 5 888
  13. 13. class Structure{ byte b; short i; Object o; } markmarkmark klassklassklass 2 1 5 888 4 8
  14. 14. Memory address ...01100100100111011001011000
  15. 15. Memory address ...01100100100111011001011000
  16. 16. Memory address ...01100100100111011001011000 32 bit pointer
  17. 17. Memory address ...01100100100111011001011000 32 bit pointer .... to 35 bit
  18. 18. Memory address ...01100100100111011001011000 32 bit pointer .... to 35 bit 2^35≈32GB (25-28GB Heap)
  19. 19. Memory address ...01100100100111011001011000 32 bit pointer .... to 35 bit 2^35≈32GB (25-28GB Heap) IBM J9: Java 6 SR1- not enabled by default Hotspot: since Java 6u14, by default since u23
  20. 20. class Structure{ byte b; short i; Object o; } markmarkmarkmark klass 1 2 1 4 444
  21. 21. class Structure{ byte b; short i; Object o; } 3 8 markmarkmarkmark klass 1 2 1 4 444
  22. 22. klassklass flagsflags monitormonitor 44 1 3 2 2 =24b klassklassklassklass flagsflags size*size* monitormonitormonitormonitor 8888 1 3 2 2 klass flagsflagsflags monitor 1 33 4 22 2 =40b =24b i386 x64 x64C IBM J9
  23. 23. What’s the object size? class Structure{ byte b; short i; Object o;}
  24. 24. What’s the object size? HS 32b 16b HS 64b before u14 32b HS 64b after u14 (u27) 24b J9 32b 24b J9 64b 40b J9 64b compressed 24b class Structure{ byte b; short i; Object o;}
  25. 25. Mind the gap
  26. 26. Mind the gap byte[][][] b = new byte[10][100][1000];
  27. 27. Mind the gap byte[][][] b = new byte[1000][100][10]; byte[][][] b = new byte[10][100][1000];
  28. 28. Mind the gap byte[][][] b = new byte[1000][100][10]; byte[][][] b = new byte[10][100][1000]; 1.032.344= 1.000.000+ 8.080(r)+20.220(h)+4.044(a)
  29. 29. Mind the gap byte[][][] b = new byte[1000][100][10]; byte[][][] b = new byte[10][100][1000]; 4.832.024= 1.000.000+ 808.000(r)+2.020.020(h)+1.004.004(a) 1.032.344= 1.000.000+ 8.080(r)+20.220(h)+4.044(a)
  30. 30. Mind the gap byte[][][] b = new byte[1000][100][10]; byte[][][] b = new byte[10][100][1000]; 4.832.024= 1.000.000+ 808.000(r)+2.020.020(h)+1.004.004(a) 1.032.344= 1.000.000+ 8.080(r)+20.220(h)+4.044(a) x100
  31. 31. Mind the gap byte[][][] b = new byte[1000][100][10]; byte[][][] b = new byte[10][100][1000]; 4.832.024= 1.000.000+ 808.000(r)+2.020.020(h)+1.004.004(a) 1.032.344= 1.000.000+ 8.080(r)+20.220(h)+4.044(a) x100 x100
  32. 32. Mind the gap byte[][][] b = new byte[1000][100][10]; byte[][][] b = new byte[10][100][1000]; 4.832.024= 1.000.000+ 808.000(r)+2.020.020(h)+1.004.004(a) 1.032.344= 1.000.000+ 8.080(r)+20.220(h)+4.044(a) x100 x100 x250
  33. 33. Heap
  34. 34. Heap Young/Eden Old/Tenured
  35. 35. Heap (HS) Young/Eden Old/Tenured Survivor 1 Survivor 2
  36. 36. Heap (HS)
  37. 37. Heap (HS)
  38. 38. Heap (HS) TLAB TLH
  39. 39. Heap (HS) TLAB TLH
  40. 40. Heap (HS) TLAB TLH
  41. 41. Heap (HS)
  42. 42. Heap (HS)
  43. 43. Heap (HS)
  44. 44. Heap (HS) X X X
  45. 45. Heap (HS)
  46. 46. Heap (HS)
  47. 47. Heap (HS)
  48. 48. Heap (HS) X XX XX X
  49. 49. Heap (HS)
  50. 50. Heap (HS)
  51. 51. Heap (HS)
  52. 52. Heap (HS) X XX XX X
  53. 53. Heap (HS)
  54. 54. Heap (J9) Young/Eden Old/Tenured
  55. 55. Heap (J9) Allocation Old/Tenured Survivor
  56. 56. Heap (J9)
  57. 57. Heap (J9)
  58. 58. Heap (J9)
  59. 59. Heap (J9)
  60. 60. Heap (J9)
  61. 61. Garbage Collection
  62. 62. Garbage Collection 1. Starts if allocation fails or System.gc()* called or condition met
  63. 63. Garbage Collection 1. Starts if allocation fails or System.gc()* called or condition met 2. Stop-of-the-world operation
  64. 64. Garbage Collection 1. Starts if allocation fails or System.gc()* called or condition met 2. Stop-of-the-world operation 3. Mark, Sweep and Compact*
  65. 65. Mark
  66. 66. Mark
  67. 67. Mark PermGen Stack JNI Stack Stack
  68. 68. Mark PermGen Stack JNI X X X X Stack Stack
  69. 69. Mark A B C DE
  70. 70. A B 0 0 0 C D E 0 0 0 0 0 0 0 0 0 0 Mark A B C DE
  71. 71. 1 A B 0 0 C D E 0 0 0 0 0 0 0 0 0 0 A Mark A B C DE
  72. 72. 1 A B 0 C D E 0 0 0 0 0 0 0 0 0 Mark A B C DE B C 1 1
  73. 73. 1 A B 0 C D E 0 0 0 0 0 0 0 0 Mark A B C DE CE 1 1 1
  74. 74. 1 A B 0 C D E 0 0 0 0 0 0 0 0 Mark A B C DE E 1 1 1
  75. 75. 1 A B 0 C D E 0 0 0 0 0 0 0 0 Mark A B C DE 1 1 1
  76. 76. 1 A B C D E 0 0 0 Mark A B C DE 1 1 11 1 1 1 1 1
  77. 77. 1 A B C D E 0 0 0 Mark A B C DE 1 1 11 1 1 1 1 1
  78. 78. References
  79. 79. References 1. Strong - always marked 2. Soft - not marked if too old or need memory 3. Weak - not marked if no strong reference 4. Phantom - correct implementation of finalize() method
  80. 80. Mark
  81. 81. MarkSerial
  82. 82. Mark
  83. 83. MarkParallel
  84. 84. Mark PermGen JNI Stack Stack Stack
  85. 85. Mark PermGen JNI Stack Stack Stack
  86. 86. Mark PermGen JNI Stack Stack Stack
  87. 87. Mark PermGen JNI Stack Stack Stack
  88. 88. Mark PermGen JNI Stack Stack Stack
  89. 89. Mark PermGen JNI Stack Stack Stack
  90. 90. Mark PermGen JNI Stack Stack Stack
  91. 91. Mark PermGen JNI Concurrent Stack Stack Stack
  92. 92. Sweep ... 1 0 0 1 1 1 0 0 0 1 1 ...
  93. 93. Sweep ... 1 0 0 1 1 1 0 0 0 1 1 ...
  94. 94. Sweep ... 1 0 0 1 1 1 0 0 0 1 1 ...
  95. 95. Sweep ... 1 0 0 1 1 1 0 0 0 1 1 ...
  96. 96. Sweep ... 1 0 0 1 1 1 0 0 0 1 1 ... Serial
  97. 97. Sweep ... 1 0 0 1 1 1 0 0 0 1 1 ... ... 1 0 0 1 1 1 0 0 0 1 1 ... ... 1 0 0 1 1 1 0 0 0 1 1 ...
  98. 98. Sweep ... 1 0 0 1 1 1 0 0 0 1 1 ... ... 1 0 0 1 1 1 0 0 0 1 1 ... ... 1 0 0 1 1 1 0 0 0 1 1 ...
  99. 99. Sweep ... 1 0 0 1 1 1 0 0 0 1 1 ... Parallel ... 1 0 0 1 1 1 0 0 0 1 1 ... ... 1 0 0 1 1 1 0 0 0 1 1 ...
  100. 100. Sweep ... 1 0 0 1 1 1 0 0 0 1 1 ...
  101. 101. Sweep ... 1 0 0 1 1 1 0 0 0 1 1 ...
  102. 102. Sweep ... 1 0 0 1 1 1 0 0 0 1 1 ...
  103. 103. Sweep ... 1 0 0 1 1 1 0 0 0 1 1 ...
  104. 104. Sweep ... 1 0 0 1 1 1 0 0 0 1 1 ...
  105. 105. Sweep ... 1 0 0 1 1 1 0 0 0 1 1 ... Concurrent
  106. 106. 1 1 0 0 1 1 1 0 0 0 1 1 ... Compact 1 1 1 1 1 1 1 0 0 0 0 0 ...
  107. 107. Garbage Collection Serial Parallel Concurrent Which one to choose?
  108. 108. Heap (J9) Allocation Old/Tenured Survivor
  109. 109. PermGen
  110. 110. PermGen Bootstrap System
  111. 111. PermGen Bootstrap System Ext
  112. 112. PermGen Bootstrap System Ext Web App
  113. 113. PermGen Bootstrap System Ext Web App Web App
  114. 114. PermGen Bootstrap System Ext Web App Web App Web App
  115. 115. PermGen Bootstrap System Ext Web App Web App Web App Web App
  116. 116. PermGen Bootstrap System Ext Web App Web App Web App Web App Web App
  117. 117. PermGen Bootstrap System Ext Web App Web App Web App Web App Web App java.lang.OutOfMemoryError:  PermGen  space
  118. 118. PermGen Bootstrap System Ext Web App Web App Web App Web App
  119. 119. PermGen Bootstrap System Ext Web App Web App Web App Web App Heap
  120. 120. PermGen Bootstrap System Ext Web App Web App Web App Web App Stack Heap
  121. 121. Stack
  122. 122. Stack
  123. 123. Stack
  124. 124. Stack
  125. 125. Stack
  126. 126. Stack
  127. 127. Stack java.lang.StackOverflowError
  128. 128. Memory
  129. 129. Memory Allocation Old/Tenured Survivor
  130. 130. Memory Allocation Old/Tenured Survivor PermGen
  131. 131. Memory Allocation Old/Tenured Survivor PermGen Stack Stack Stack
  132. 132. Memory Allocation Old/Tenured Survivor PermGen GC Stack Stack Stack
  133. 133. Memory Allocation Old/Tenured Survivor PermGen JNI GC Stack Stack Stack
  134. 134. Memory Allocation Old/Tenured Survivor PermGen JNI GC Net Stack Stack Stack
  135. 135. Memory Allocation Old/Tenured Survivor PermGen JNI GC Net NIO Stack Stack Stack
  136. 136. Memory Allocation Old/Tenured Survivor PermGen JNI GC Net NIO JIT Stack Stack Stack
  137. 137. Memory Allocation Old/Tenured Survivor PermGen JNI GC Net NIO JIT CL Stack Stack Stack
  138. 138. Memory Allocation Old/Tenured Survivor PermGen JNI GC Net NIO JIT CL Stack Stack Stack C++
  139. 139. Paging
  140. 140. Paging 1. Linux/Windows use Virtual memory and “paging” to reference physical 2. Pages mapped to physical only when referenced 3. OS manages pages
  141. 141. Real size of Java Process?
  142. 142. Real size of Java Process? 1. Architecture: 32 vs 64
  143. 143. Real size of Java Process? 1. Architecture: 32 vs 64 2. JVM vendor: Oracle vs IBM
  144. 144. Real size of Java Process? 1. Architecture: 32 vs 64 2. JVM vendor: Oracle vs IBM 3. JVM version incl. update
  145. 145. Real size of Java Process? 1. Architecture: 32 vs 64 2. JVM vendor: Oracle vs IBM 3. JVM version incl. update 4. JVM settings
  146. 146. Real size of Java Process? 1. Architecture: 32 vs 64 2. JVM vendor: Oracle vs IBM 3. JVM version incl. update 5. OS (above applies) 4. JVM settings
  147. 147. Real size of Java Process? 1. Architecture: 32 vs 64 2. JVM vendor: Oracle vs IBM 3. JVM version incl. update 5. OS (above applies) + Run under real load for long time 4. JVM settings
  148. 148. ?

×