More Related Content
More from Dmitry Buzdin (20)
Java7 Garbage Collector G1
- 3. What is GC?
Garbage Collector – reclaims unreachable
removes objects that you don’t need
anymore
Copyright © 2012 Accenture All rights reserved. Picture is the © of Disney 3
- 4. How does it works?
• Java Code • Heap
Copyright © 2012 Accenture All rights reserved. 4
- 5. How does it works?
• Java Code • Heap
Object x = new Object();
x
# of ref= 1
Copyright © 2012 Accenture All rights reserved. 5
- 6. How does it works?
• Java Code • Heap
Object x = new Object();
Object y = new Object();
x
# of ref= 1
y
# of ref= 1
Copyright © 2012 Accenture All rights reserved. 6
- 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= 0
Copyright © 2012 Accenture All rights reserved. 7
- 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 collected
Copyright © 2012 Accenture All rights reserved. 8
- 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= 1
Copyright © 2012 Accenture All rights reserved. 9
- 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= 1
Copyright © 2012 Accenture All rights reserved. 10
- 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 collected
Copyright © 2012 Accenture All rights reserved. 11
- 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 GC
Copyright © 2012 Accenture All rights reserved. 12
- 14. Generational GC
• Generations are of new or survived during GC objects
Copyright © 2012 Accenture All rights reserved. Picture taken from OpenFreak.com 14
- 15. Generational GC
• Generations are of new or survived during GC objects
• Heap divided in zones by age of the objects
eden survivor tenured
Copyright © 2012 Accenture All rights reserved. Picture taken from OpenFreak.com 15
- 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 tenured
Copyright © 2012 Accenture All rights reserved. Picture taken from OpenFreak.com 16
- 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 tenured
Copyright © 2012 Accenture All rights reserved. Picture taken from OpenFreak.com 17
- 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 tenured
Copyright © 2012 Accenture All rights reserved. Picture taken from OpenFreak.com 18
- 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 tenured
Copyright © 2012 Accenture All rights reserved. Picture taken from OpenFreak.com 19
- 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 tenured
Copyright © 2012 Accenture All rights reserved. Picture taken from OpenFreak.com 20
- 22. Types of generational GC in Java
• Serial Collector – always stop-the-world
Copyright © 2012 Accenture All rights reserved. 22
- 23. Types of generational GC in Java
• Throughput Collector
– Concurrent for minor GC
– Stop-the-world for major GC
Copyright © 2012 Accenture All rights reserved. 23
- 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 constraint
Copyright © 2012 Accenture All rights reserved. 24
- 25. GC Metrics
Primary Parameters
1. Throughput
– percentage of the total run time not spent performing GC
2. Pauses
– times when the application code stops running while GC is
performed
– number of pauses, their average duration and their maximum
duration
Secondary Parameters:
1. Footprint
– current heap size (amount of memory) being used
2. Promptness
– how quickly memory from objects no longer needed is freed
Copyright © 2012 Accenture All rights reserved. 25