Java7 Garbage Collector G1

3,260 views

Published on

Published in: Technology
1 Comment
4 Likes
Statistics
Notes
No Downloads
Views
Total views
3,260
On SlideShare
0
From Embeds
0
Number of Embeds
286
Actions
Shares
0
Downloads
66
Comments
1
Likes
4
Embeds 0
No embeds

No notes for slide

Java7 Garbage Collector G1

  1. 1. Java 7 Garbage Collector G1Antons Kranga, 3rd May 2012
  2. 2. Introduction to GC
  3. 3. What is GC?Garbage Collector – reclaims unreachableremoves objects that you don’t needanymoreCopyright © 2012 Accenture All rights reserved. Picture is the © of Disney 3
  4. 4. How does it works?• Java Code • HeapCopyright © 2012 Accenture All rights reserved. 4
  5. 5. How does it works?• Java Code • Heap Object x = new Object(); x # of ref= 1Copyright © 2012 Accenture All rights reserved. 5
  6. 6. How does it works?• Java Code • Heap Object x = new Object(); Object y = new Object(); x # of ref= 1 y # of ref= 1Copyright © 2012 Accenture All rights reserved. 6
  7. 7. How does it works?• Java Code • Heap Object x = new Object(); Object y = new Object(); y = x; x # of ref= 2 y # of ref= 0Copyright © 2012 Accenture All rights reserved. 7
  8. 8. How does it works?• Java Code • Heap Object x = new Object(); Object y = new Object(); y = x; x # of ref= 2 y # of ref= 0 object y can be collectedCopyright © 2012 Accenture All rights reserved. 8
  9. 9. How does it works?• Java Code • Heap Object x = new Object(); Object y = new Object(); y = x; x List z = new ArrayList(); # of ref= 3 z.add(x); y # of ref= 0 z # of ref= 1Copyright © 2012 Accenture All rights reserved. 9
  10. 10. How does it works?• Java Code • Heap { Object x = new Object(); Object y = new Object(); y = x; x List z = new ArrayList(); # of ref= 3 z.add(x); y } # of ref= 0 z # of ref= 1Copyright © 2012 Accenture All rights reserved. 10
  11. 11. How does it works?• Java Code • Heap { Object x = new Object(); Object y = new Object(); y = x; x List z = new ArrayList(); # of ref= 3 z.add(x); y } # of ref= 0 z # of ref= 1 objects in island of isolation can be collectedCopyright © 2012 Accenture All rights reserved. 11
  12. 12. What you need to know about GC• Garbage Collector is non deterministic• GC carried by separate daemon threat• Stop the World – pauses all threats during GCCopyright © 2012 Accenture All rights reserved. 12
  13. 13. Generational GCs
  14. 14. Generational GC• Generations are of new or survived during GC objectsCopyright © 2012 Accenture All rights reserved. Picture taken from OpenFreak.com 14
  15. 15. Generational GC• Generations are of new or survived during GC objects• Heap divided in zones by age of the objects eden survivor tenuredCopyright © 2012 Accenture All rights reserved. Picture taken from OpenFreak.com 15
  16. 16. Generational GC• Generations are of new or survived during GC objects• Heap divided in zones by age of the objects Objects experienced no GC (age 0) eden survivor tenuredCopyright © 2012 Accenture All rights reserved. Picture taken from OpenFreak.com 16
  17. 17. Generational GC• Generations are of new or survived during GC objects• Heap divided in zones by age of the objects experiences several GCs (2 spaces by default) eden survivor tenuredCopyright © 2012 Accenture All rights reserved. Picture taken from OpenFreak.com 17
  18. 18. Generational GC• Generations are of new or survived during GC objects• Heap divided in zones by age of the objects Objects survived multiple GCs eden survivor tenuredCopyright © 2012 Accenture All rights reserved. Picture taken from OpenFreak.com 18
  19. 19. Generational GC• Generations are of new or survived during GC objects• Heap divided in zones by age of the objects young generation tenured generation eden survivor tenuredCopyright © 2012 Accenture All rights reserved. Picture taken from OpenFreak.com 19
  20. 20. Generational GC• Generations are of new or survived during GC objects• Heap divided in zones by age of the objects young generation tenured generation objects objects collected by collected Minor and only by Full GC Full GC eden survivor tenuredCopyright © 2012 Accenture All rights reserved. Picture taken from OpenFreak.com 20
  21. 21. Objects survival rate statisticsCopyright © 2012 Accenture All rights reserved. 21
  22. 22. Types of generational GC in Java• Serial Collector – always stop-the-worldCopyright © 2012 Accenture All rights reserved. 22
  23. 23. Types of generational GC in Java• Throughput Collector – Concurrent for minor GC – Stop-the-world for major GCCopyright © 2012 Accenture All rights reserved. 23
  24. 24. Types of generational GC in Java• Concurrent Low Pause Collector – – Tenured gen: application paused for short periods during GC – Young gen: runs concurrently – the app. will have a large number of long-lived objects, and there is a pause time constraintCopyright © 2012 Accenture All rights reserved. 24
  25. 25. GC MetricsPrimary Parameters1. Throughput – percentage of the total run time not spent performing GC2. Pauses – times when the application code stops running while GC is performed – number of pauses, their average duration and their maximum durationSecondary Parameters:1. Footprint – current heap size (amount of memory) being used2. Promptness – how quickly memory from objects no longer needed is freedCopyright © 2012 Accenture All rights reserved. 25
  26. 26. To be continued

×