View
2.643
Download
1
Category
Tags:
Preview:
Citation preview
Java 7 Garbage Collector G1Antons Kranga, 3rd May 2012
Introduction to GC
Copyright © 2012 Accenture All rights reserved. 3
Garbage Collector – reclaims unreachable
removes objects that you don’t need anymore
What is GC?
Picture is the © of Disney
Copyright © 2012 Accenture All rights reserved. 4
• Java Code • Heap
How does it works?
Copyright © 2012 Accenture All rights reserved. 5
• Java Code
Object x = new Object();
• Heap
How does it works?
x
# of ref= 1
Copyright © 2012 Accenture All rights reserved. 6
• Java Code
Object x = new Object();
Object y = new Object();
• Heap
How does it works?
x
# of ref= 1
y
# of ref= 1
Copyright © 2012 Accenture All rights reserved. 7
• Java Code
Object x = new Object();
Object y = new Object();
y = x;
• Heap
How does it works?
x
# of ref= 2
y
# of ref= 0
Copyright © 2012 Accenture All rights reserved. 8
• Java Code
Object x = new Object();
Object y = new Object();
y = x;
• Heap
How does it works?
x
# of ref= 2
y
# of ref= 0
object y can be collected
Copyright © 2012 Accenture All rights reserved. 9
• Java Code
Object x = new Object();
Object y = new Object();
y = x;
List z = new ArrayList();
z.add(x);
• Heap
How does it works?
x
# of ref= 3
y
# of ref= 0z
# of ref= 1
Copyright © 2012 Accenture All rights reserved. 10
• Java Code
{
Object x = new Object();
Object y = new Object();
y = x;
List z = new ArrayList();
z.add(x);
}
• Heap
How does it works?
x
# of ref= 3
y
# of ref= 0z
# of ref= 1
Copyright © 2012 Accenture All rights reserved. 11
• Java Code
{
Object x = new Object();
Object y = new Object();
y = x;
List z = new ArrayList();
z.add(x);
}
• Heap
How does it works?
x
# of ref= 3
y
# of ref= 0z
# of ref= 1objects in
island of isolation can be collected
Copyright © 2012 Accenture All rights reserved. 12
• Garbage Collector is non deterministic
• GC carried by separate daemon threat
• Stop the World – pauses all threats during GC
What you need to know about GC
Generational GCs
Copyright © 2012 Accenture All rights reserved. 14
• Generations are of new or survived during GC objects
Generational GC
Picture taken from OpenFreak.com
Copyright © 2012 Accenture All rights reserved. 15
• Generations are of new or survived during GC objects
• Heap divided in zones by age of the objects
Generational GC
Picture taken from OpenFreak.com
eden survivor tenured
Copyright © 2012 Accenture All rights reserved. 16
• Generations are of new or survived during GC objects
• Heap divided in zones by age of the objects
Generational GC
Picture taken from OpenFreak.com
eden survivor
Objects experienced no
GC (age 0)
tenured
Copyright © 2012 Accenture All rights reserved. 17
• Generations are of new or survived during GC objects
• Heap divided in zones by age of the objects
Generational GC
Picture taken from OpenFreak.com
eden survivor
experiences several GCs
(2 spaces by default)
tenured
Copyright © 2012 Accenture All rights reserved. 18
• Generations are of new or survived during GC objects
• Heap divided in zones by age of the objects
Generational GC
Picture taken from OpenFreak.com
eden survivor
Objects survived multiple GCs
tenured
Copyright © 2012 Accenture All rights reserved. 19
• Generations are of new or survived during GC objects
• Heap divided in zones by age of the objects
Generational GC
Picture taken from OpenFreak.com
eden survivor
young generation tenured generation
tenured
Copyright © 2012 Accenture All rights reserved. 20
• Generations are of new or survived during GC objects
• Heap divided in zones by age of the objects
Generational GC
Picture taken from OpenFreak.com
eden survivor tenured
young generation tenured generation
objects collected byMinor and
Full GC
objects collected only byFull GC
Copyright © 2012 Accenture All rights reserved. 21
Objects survival rate statistics
Copyright © 2012 Accenture All rights reserved. 22
• Serial Collector – always stop-the-world
Types of generational GC in Java
Copyright © 2012 Accenture All rights reserved. 23
• Throughput Collector – Concurrent for minor GC– Stop-the-world for major GC
Types of generational GC in Java
Copyright © 2012 Accenture All rights reserved. 24
• 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
Types of generational GC in Java
Copyright © 2012 Accenture All rights reserved. 25
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:
3. Footprint– current heap size (amount of memory) being used
4. Promptness– how quickly memory from objects no longer needed is freed
GC Metrics
To be continued
Recommended