Upload
moris-emory-ray
View
215
Download
2
Tags:
Embed Size (px)
Citation preview
A Real-Time Garbage Collector Based on the Lifetimes of Objects
Henry Lieberman and Carl Hewitt
(CACM, June 1983)
Rudy Kaplan Depena
CS395T: Memory Management
February 2, 2009
Motivation: Internal Thinking
“Programs Do A Lot of Internal Thinking”- Lieberman and Hewitt
public void printAll(ArrayList list){Iterator it = new list.iterator();Object temp;while( it.hasNext() ){
temp = it.next();System.out.println( temp );
}}
Code snippet from Mike Scott’s lecture on Iterators[http://www.cs.utexas.edu/~scottm/cs307/handouts/Slides/Topic15Iterators.pdf]
Motivation: Reference Counting
Reference Counting claims young objects quickly
head Node Node Node
next nextnext
refCount = 2 refCount = 1 refCount = 1
Example from “Data Structures and Algorithms with Object-Oriented Design Patterns in Java”[http://www.brpreiss.com/books/opus5/html/page423.html]
Motivation: Ref Counting w/ Cycles
Houston We Have A Problem!
head Node Node Node
next nextnext
refCount = 1 refCount = 1 refCount = 1
Example from “Data Structures and Algorithms with Object-Oriented Design Patterns in Java”[http://www.brpreiss.com/books/opus5/html/page423.html]
Motivation: Cycles Are Needed
But Circular Structures are important programming technique for ….GraphicsCompilersOther Problem Spaces
So What Do We Do???
Real Time GC [Baker’s Algorithm]
QuickTime™ and a decompressor
are needed to see this picture.
Graphics from Lieberman and Hewitt[“A Real-Time Garbage Collector Based on the Lifetimes of Objects” - CACM June 1983]
What’s Wrong With Baker?
Perhaps Too Slow?Total Garbage Collection Time?
Not Space Efficient?
Generational Hypothesis
“Recently created regions contain high % of garbage” while older regions do not
- Lieberman and HewittImprove Baker’s Algorithm
Optimize for scavenging short lived objectsScavenge long-lived objects less frequently
Rental CostStorage management cost of an object is proportional to the time during which the object is used
Inspired by Maria Jump’s Presentation in Fall 2003 on Generational GC[http://www.cs.utexas.edu/users/mckinley/395Tmm-2003/talks/LH83.pdf]
Modify Baker’s Algorithm
Address space broken up into generationsSmall set of pages (relative to address space)
Parallels between Baker Algo and Generational GCEvacuating <=> Condemning Regionfromspace <=> Obsolete Regiontospace <=> Non-Obsolete RegionEvacuating objects the same way
Inspired by Maria Jump’s Presentation in Fall 2003 on Generational GC[http://www.cs.utexas.edu/users/mckinley/395Tmm-2003/talks/LH83.pdf]
In Action
1960.0
Regions are tagged with generation and version number
From Maria Jump’s Presentation in Fall 2003 on Generational GC[http://www.cs.utexas.edu/users/mckinley/395Tmm-2003/talks/LH83.pdf]
In Action
1960.0
Allocation occurs in creation region
From Maria Jump’s Presentation in Fall 2003 on Generational GC[http://www.cs.utexas.edu/users/mckinley/395Tmm-2003/talks/LH83.pdf]
In Action
1960.0
… until the creation region is full
From Maria Jump’s Presentation in Fall 2003 on Generational GC[http://www.cs.utexas.edu/users/mckinley/395Tmm-2003/talks/LH83.pdf]
In Action
1960.0
… the new creation region is created
From Maria Jump’s Presentation in Fall 2003 on Generational GC[http://www.cs.utexas.edu/users/mckinley/395Tmm-2003/talks/LH83.pdf]
1970.0
• CONS composes existing components into objects• creates a backward pointer
In Action
1960.0
… and so on
From Maria Jump’s Presentation in Fall 2003 on Generational GC[http://www.cs.utexas.edu/users/mckinley/395Tmm-2003/talks/LH83.pdf]
1970.0
In Action
1960.0
… and so on
From Maria Jump’s Presentation in Fall 2003 on Generational GC[http://www.cs.utexas.edu/users/mckinley/395Tmm-2003/talks/LH83.pdf]
1970.0 1980.0
In Action
1960.0
GC is initiated by condemning a region (making it obsolete) and creating an evacuation region
From Maria Jump’s Presentation in Fall 2003 on Generational GC[http://www.cs.utexas.edu/users/mckinley/395Tmm-2003/talks/
LH83.pdf]
1970.0 1980.0
1970.1
In Action
1960.0
This requires that younger generations also be condemnedWHY ?????
Modified from Maria Jump’s Presentation in Fall 2003 on Generational GC[http://www.cs.utexas.edu/users/mckinley/395Tmm-2003/talks/
LH83.pdf]
1970.0 1980.0
1970.1 1980.1
In Action
1960.0
Accessibile objects in condemned region(s) are incrementally evacuated using Baker’s Algorithm
From Maria Jump’s Presentation in Fall 2003 on Generational GC[http://www.cs.utexas.edu/users/mckinley/395Tmm-2003/talks/LH83.pdf]
1970.0 1980.0
1970.1 1980.1
In Action
1960.0
… and the memory is recycled!
From Maria Jump’s Presentation in Fall 2003 on Generational GC[http://www.cs.utexas.edu/users/mckinley/395Tmm-2003/talks/LH83.pdf]
1970.1 1980.1
Varying GC Rates
Younger generations contain high percentages of garbage They should be collected frequently
Older generation contains relatively permanent data Older objects collected seldomly
Getting the most “Bang for your Buck” Scavange where there is high proportion of
inaccessible objects Minimize amount of scavenging needed per
inaccessible object Why is this important?
Modified from Maria Jump’s Presentation in Fall 2003 on Generational GC[http://www.cs.utexas.edu/users/mckinley/395Tmm-2003/talks/LH83.pdf]
Scavanging is Expensive!
We must restrict the storage that has to be scanned to find and update obsolete references
We restrict pointers from older generations to newer generations This means it will be faster to reclaim regions
in recent generations since little storage needs to be scavenged
What happens when an attempt is made to create a pointer from
older to younger generation????
Entry Tables
1960.0 1970.0 1980.0
In Lisp, RPLACA can assign a new pointer as a component to an older object
creates a forward pointer Add entry table to record forward pointers Adds a level of indirection for some pointers Won’t have to scan entire heap GC uses entry table entries as roots to the region
From Maria Jump’s Presentation in Fall 2003 on Generational GC[http://www.cs.utexas.edu/users/mckinley/395Tmm-2003/talks/LH83.pdf]
Weak PointersWeak pointers are …
Pointers in program which do not protect objects from being collected.Small in NumberUse entry tableWeak Pointers => Forward PointersForward Pointers > Weak PointersWeak Pointers are not persistently updated if object (i.e. - pointee) is garbage collected.Forward Pointers (which are NOT weak pointers) are persistently updated after GC occurs
Some Bad News
Fragmentation results from partially filled regions ….
How do we deal with this ???
Choose region sizes to minimize fragmentation Coalesce older regions reducing the amount of wasted space Perhaps use hybrid incremental collection sparingly
An Optimization? -Value Cells & Stacks
Lisp implementations involve internal stacksHolds state info and variables
Stack must be scavenged for pointers to non-user-accessible objects Young objects lifetime correlated with pushing and popping the stack.
Suggests that good time to expect a lot of garbage when returning from function (remember printAll()?)
An Optimization?-Flavors of new
Providing different allocators for different regions? Can users direct the flavor of allocation? Can compiler analysis change flavor of allocation? Can runtime information change flavor of allocation?
From Maria Jump’s Presentation in Fall 2003 on Generational GC[http://www.cs.utexas.edu/users/mckinley/395Tmm-2003/talks/LH83.pdf]
Aspects of Program Behavior
Rate of object creation How fast are objects created?
Average lifetimes of objects How fast do objects become inaccessible
Proportion of forward vs backward pointers High % of pointing to old objects bodes well for this scheme
Average “length” of pointers What’s the locality like? Close locality would be nice :)
Modified from Maria Jump’s Presentation in Fall 2003 on Generational GC[http://www.cs.utexas.edu/users/mckinley/395Tmm-2003/talks/LH83.pdf]
System.out.println(“The End!”);