Sun JDK 1.6 内存管理       实现篇        毕玄  2010-10、2010-11
目标• 掌握内存管理的通常实现方法• 了解Sun JDK是如何实现内存管理的,以及  做了哪些优化• 了解JRockit做了哪些优化
OS内存管理  图片来源于JavaOne 2010 《where does all native memory go》 Session
OS内存管理  图片来源于JavaOne 2010 《where does all native memory go》 Session
OS内存管理  图片来源于JavaOne 2010 《where does all native memory go》 Session
OS内存管理  图片来源于JavaOne 2010 《where does all native memory go》 Session
OS内存管理  图片来源于JavaOne 2010 《where does all native memory go》 Session
内存分配和回收• allocate     A       B    C   D
内存分配和回收• allocate     A       B    C   B                          freelist
内存分配和回收• fragmenation    A     B          C        B                                                freelist              ...
内存分配和回收• Compaction    A      C      B           B                free space pointer  – need update pointer
Discussion• how to find garbage and claim it..  – let’s talk about this question first
GC Algorithm• Reference Counting• Tracing  – Mark-Sweep  – Mark-Compact  – Copying
GC Algorithm Details• Reference Counting                图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session by ...
GC Algorithm Details• Reference Counting                图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session by ...
GC Algorithm Details• Reference Counting                图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session by ...
GC Algorithm Details• Reference Counting                图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session by ...
GC Algorithm Details• Reference Counting                图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session by ...
GC Algorithm Details• Reference Counting                图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session by ...
GC Algorithm Details• Reference Counting                图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session by ...
GC Algorithm Details• Reference Counting  – extra space,time overhead  – non-moving  – cyclic garbage
GC Algorithm Details• Advance Reference Counting  – two-bit reference counts     • when max count(3) is reached,object bec...
GC Algorithm Details• Tracing – Mark-Sweep                图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session b...
GC Algorithm Details• Tracing – Mark-Sweep                图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session b...
GC Algorithm Details• Tracing – Mark-Sweep                图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session b...
GC Algorithm Details• Tracing – Mark-Sweep                图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session b...
GC Algorithm Details• Tracing – Mark-Sweep                图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session b...
GC Algorithm Details• Tracing – Mark-Sweep                图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session b...
GC Algorithm Details• Tracing – Mark-Sweep  – need scan all objects,so if java heap becomes    larger,then gc slower  – 可清...
GC Algorithm Details• Tracing – Mark-Compact                图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session...
GC Algorithm Details• Tracing – Mark-Compact  – 没有内存碎片,分配高效  – 增加了回收需要耗费的时间  – 需要更新所有移动过的object的ref pointer  – 需要在一定时机触发
GC Algorithm Details• Tracing – Copying(a special case)                  图片来源于JavaOne 2010 《The Garbage Collection Mythbus...
GC Algorithm Details• Tracing – Copying(a special case)                  图片来源于JavaOne 2010 《The Garbage Collection Mythbus...
GC Algorithm Details• Tracing – Copying(a special case)                  图片来源于JavaOne 2010 《The Garbage Collection Mythbus...
GC Algorithm Details• Tracing – Copying(a special case)                  图片来源于JavaOne 2010 《The Garbage Collection Mythbus...
GC Algorithm Details• Tracing – Copying(a special case)                  图片来源于JavaOne 2010 《The Garbage Collection Mythbus...
GC Algorithm Details• Tracing – Copying(a special case)                  图片来源于JavaOne 2010 《The Garbage Collection Mythbus...
GC Algorithm Details• Tracing – Copying(a special case)  – only need scan live objects,so gc speed only    decided by lds ...
GC Algorithm Summary• Why gc need stop the world?  – Mark-Sweep,Mark-Compact     • if ref changes or new object created wh...
目标• 掌握内存管理的通常实现方法• 了解Sun JDK是如何实现内存管理的,以及  做了哪些优化• 了解JRockit做了哪些优化
GC in Hotspot• rootset  – runtime stack  – static or global variables  – jni handles  – jvm handles
GC in Hotspot• Generational GC  – most objects are temp-lived     • so JDK decide split heap into two generations to use g...
GC in Hotspot• how to stop the world  – safepoint at ref change     • safepoint is a memory page check     • compile  – wh...
GC in Hotspot• YGC  – allocate is slow,because need lock  – how to make allocate faster?     TLAB       Use CAS replace lo...
GC in Hotspot• YGC  – how to find live objects faster?    Live Maps             Scan Algorithm• do u have any other ideas?
GC in Hotspot• YGC  – how to handle object in old gen ref new gen    object  Write Barrier & Card table• do u have any oth...
GC in Hotspot• YGC  – how to make scan and copying faster?    Parallel    Adaptive based on runtime feedback• do u have an...
GC in Hotspot• FGC  – optimize for throughput     • parallel  – optimize for low latency     • concurrent
GC in Hotspot• FGC – parallel  – based on Mark-Compact  – allocate use the bump pointer
GC in Hotspot• FGC – parallel  – how to make mark phase faster?    Parallel• do u have any other ideas?
GC in Hotspot• FGC – parallel  – how to make compact phase faster?   Partial Compact when use ParallelOldGC• do u have any...
GC in Hotspot• FGC – concurrent  – based on mark-sweep  – when concurrent gc executes,ref may be changed    and new object...
GC in Hotspot• FGC – concurrent  – when concurrent gc executes,ref may be changed    and new objects may be created,how to...
GC in Hotspot• FGC – concurrent  – how to mark remark phase faster?   add a preclean phase• do u have any other ideas?
Futhermore – G1• Region-based GC• how to behave better?  garbage first  hot regions
目标• 掌握内存管理的通常实现方法• 了解Sun JDK是如何实现内存管理的,以及  做了哪些优化• 了解JRockit做了哪些优化
Futhermore – Open eyes• JRockit GC  – YGC     • pinned object for semi-long lived object     • keep area  – Mark     • Two...
目标• 掌握内存管理的通常实现方法• 了解Sun JDK是如何实现内存管理的,以及  做了哪些优化• 了解JRockit做了哪些优化
how to research jvm• JDK Source codes• References
References• JVM References
Upcoming SlideShare
Loading in …5
×

Sun jdk 1.6内存管理 -实现篇 -毕玄

1,389 views

Published on

Published in: Technology, Art & Photos
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,389
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
48
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Sun jdk 1.6内存管理 -实现篇 -毕玄

  1. 1. Sun JDK 1.6 内存管理 实现篇 毕玄 2010-10、2010-11
  2. 2. 目标• 掌握内存管理的通常实现方法• 了解Sun JDK是如何实现内存管理的,以及 做了哪些优化• 了解JRockit做了哪些优化
  3. 3. OS内存管理 图片来源于JavaOne 2010 《where does all native memory go》 Session
  4. 4. OS内存管理 图片来源于JavaOne 2010 《where does all native memory go》 Session
  5. 5. OS内存管理 图片来源于JavaOne 2010 《where does all native memory go》 Session
  6. 6. OS内存管理 图片来源于JavaOne 2010 《where does all native memory go》 Session
  7. 7. OS内存管理 图片来源于JavaOne 2010 《where does all native memory go》 Session
  8. 8. 内存分配和回收• allocate A B C D
  9. 9. 内存分配和回收• allocate A B C B freelist
  10. 10. 内存分配和回收• fragmenation A B C B freelist sorry,no space i need allocate E
  11. 11. 内存分配和回收• Compaction A C B B free space pointer – need update pointer
  12. 12. Discussion• how to find garbage and claim it.. – let’s talk about this question first
  13. 13. GC Algorithm• Reference Counting• Tracing – Mark-Sweep – Mark-Compact – Copying
  14. 14. GC Algorithm Details• Reference Counting 图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session by tony,john
  15. 15. GC Algorithm Details• Reference Counting 图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session by tony,john
  16. 16. GC Algorithm Details• Reference Counting 图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session by tony,john
  17. 17. GC Algorithm Details• Reference Counting 图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session by tony,john
  18. 18. GC Algorithm Details• Reference Counting 图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session by tony,john
  19. 19. GC Algorithm Details• Reference Counting 图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session by tony,john
  20. 20. GC Algorithm Details• Reference Counting 图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session by tony,john
  21. 21. GC Algorithm Details• Reference Counting – extra space,time overhead – non-moving – cyclic garbage
  22. 22. GC Algorithm Details• Advance Reference Counting – two-bit reference counts • when max count(3) is reached,object becomes “sticky” – buffer reference updates – use a backup gc algorithm to handle cyclic garbage and “sticky” objects – complex,but still non-moving
  23. 23. GC Algorithm Details• Tracing – Mark-Sweep 图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session by tony,john
  24. 24. GC Algorithm Details• Tracing – Mark-Sweep 图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session by tony,john
  25. 25. GC Algorithm Details• Tracing – Mark-Sweep 图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session by tony,john
  26. 26. GC Algorithm Details• Tracing – Mark-Sweep 图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session by tony,john
  27. 27. GC Algorithm Details• Tracing – Mark-Sweep 图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session by tony,john
  28. 28. GC Algorithm Details• Tracing – Mark-Sweep 图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session by tony,john
  29. 29. GC Algorithm Details• Tracing – Mark-Sweep – need scan all objects,so if java heap becomes larger,then gc slower – 可清除所有的Garbage – 内存碎片,分配低效 – 需要在一定的时机触发
  30. 30. GC Algorithm Details• Tracing – Mark-Compact 图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session by tony,john
  31. 31. GC Algorithm Details• Tracing – Mark-Compact – 没有内存碎片,分配高效 – 增加了回收需要耗费的时间 – 需要更新所有移动过的object的ref pointer – 需要在一定时机触发
  32. 32. GC Algorithm Details• Tracing – Copying(a special case) 图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session by tony,john
  33. 33. GC Algorithm Details• Tracing – Copying(a special case) 图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session by tony,john
  34. 34. GC Algorithm Details• Tracing – Copying(a special case) 图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session by tony,john
  35. 35. GC Algorithm Details• Tracing – Copying(a special case) 图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session by tony,john
  36. 36. GC Algorithm Details• Tracing – Copying(a special case) 图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session by tony,john
  37. 37. GC Algorithm Details• Tracing – Copying(a special case) 图片来源于JavaOne 2010 《The Garbage Collection Mythbusters》 Session by tony,john
  38. 38. GC Algorithm Details• Tracing – Copying(a special case) – only need scan live objects,so gc speed only decided by lds – no fragmentation – need update object pointer – need keep an empty memory area
  39. 39. GC Algorithm Summary• Why gc need stop the world? – Mark-Sweep,Mark-Compact • if ref changes or new object created when marking; • compact need update pointer,so... – Copying • copying need update pointer,so...
  40. 40. 目标• 掌握内存管理的通常实现方法• 了解Sun JDK是如何实现内存管理的,以及 做了哪些优化• 了解JRockit做了哪些优化
  41. 41. GC in Hotspot• rootset – runtime stack – static or global variables – jni handles – jvm handles
  42. 42. GC in Hotspot• Generational GC – most objects are temp-lived • so JDK decide split heap into two generations to use gc algorithm properly Copying Mark-Sweep or Mark-Compact New Old
  43. 43. GC in Hotspot• how to stop the world – safepoint at ref change • safepoint is a memory page check • compile – when gc need execute,it submit “stop thread” request to jvm core,then jvm core set the memory page not readable – when code execute to safepoint, check the memory page if readable,if not then fail and stop
  44. 44. GC in Hotspot• YGC – allocate is slow,because need lock – how to make allocate faster? TLAB Use CAS replace lock• do u have any other ideas?
  45. 45. GC in Hotspot• YGC – how to find live objects faster? Live Maps Scan Algorithm• do u have any other ideas?
  46. 46. GC in Hotspot• YGC – how to handle object in old gen ref new gen object Write Barrier & Card table• do u have any other ideas?
  47. 47. GC in Hotspot• YGC – how to make scan and copying faster? Parallel Adaptive based on runtime feedback• do u have any other ideas?
  48. 48. GC in Hotspot• FGC – optimize for throughput • parallel – optimize for low latency • concurrent
  49. 49. GC in Hotspot• FGC – parallel – based on Mark-Compact – allocate use the bump pointer
  50. 50. GC in Hotspot• FGC – parallel – how to make mark phase faster? Parallel• do u have any other ideas?
  51. 51. GC in Hotspot• FGC – parallel – how to make compact phase faster? Partial Compact when use ParallelOldGC• do u have any other ideas?
  52. 52. GC in Hotspot• FGC – concurrent – based on mark-sweep – when concurrent gc executes,ref may be changed and new objects may be created,how to solve the question?
  53. 53. GC in Hotspot• FGC – concurrent – when concurrent gc executes,ref may be changed and new objects may be created,how to solve the question? Write Barrier & Card Table
  54. 54. GC in Hotspot• FGC – concurrent – how to mark remark phase faster? add a preclean phase• do u have any other ideas?
  55. 55. Futhermore – G1• Region-based GC• how to behave better? garbage first hot regions
  56. 56. 目标• 掌握内存管理的通常实现方法• 了解Sun JDK是如何实现内存管理的,以及 做了哪些优化• 了解JRockit做了哪些优化
  57. 57. Futhermore – Open eyes• JRockit GC – YGC • pinned object for semi-long lived object • keep area – Mark • Two-Color for prefetching – Compaction • partial,for example some objects not be compacted because many objects ref them. – Adjust gens,size adaptive based on runtime feedback
  58. 58. 目标• 掌握内存管理的通常实现方法• 了解Sun JDK是如何实现内存管理的,以及 做了哪些优化• 了解JRockit做了哪些优化
  59. 59. how to research jvm• JDK Source codes• References
  60. 60. References• JVM References

×