Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 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

2 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]

3 Motivation: Reference Counting Reference Counting claims young objects quickly headNode next refCount = 2refCount = 1 Example from “Data Structures and Algorithms with Object-Oriented Design Patterns in Java” [http://www.brpreiss.com/books/opus5/html/page423.html]

4 Motivation: Ref Counting w/ Cycles Houston We Have A Problem! headNode next refCount = 1 Example from “Data Structures and Algorithms with Object-Oriented Design Patterns in Java” [http://www.brpreiss.com/books/opus5/html/page423.html]

5 Motivation: Cycles Are Needed  But Circular Structures are important programming technique for ….  Graphics  Compilers  Other Problem Spaces So What Do We Do???

6 Real Time GC [Baker’s Algorithm] Graphics from Lieberman and Hewitt [“A Real-Time Garbage Collector Based on the Lifetimes of Objects” - CACM June 1983]

7 What’s Wrong With Baker?  Perhaps Too Slow?  Total Garbage Collection Time?  Not Space Efficient?

8 Generational Hypothesis  “Recently created regions contain high % of garbage” while older regions do not - Lieberman and Hewitt  Improve Baker’s Algorithm  Optimize for scavenging short lived objects  Scavenge long-lived objects less frequently  Rental Cost  Storage 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]

9 Modify Baker’s Algorithm  Address space broken up into generations  Small set of pages (relative to address space)  Parallels between Baker Algo and Generational GC  Evacuating Condemning Region  fromspace Obsolete Region  tospace Non-Obsolete Region  Evacuating 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]

10 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]

11 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]

12 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]

13 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

14 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

15 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.01980.0

16 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.01980.0 1970.1

17 In Action 1960.0 This requires that younger generations also be condemned WHY ????? 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.01980.0 1970.11980.1

18 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.01980.0 1970.11980.1

19 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.11980.1

20 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]

21 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????

22 Entry Tables 1960.0 1970.01980.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]

23 Weak Pointers  Weak pointers are …  Pointers in program which do not protect objects from being collected.  Small in Number  Use entry table  Weak Pointers => Forward Pointers  Forward Pointers  > Weak Pointers  Weak 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

24 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

25 An Optimization? -Value Cells & Stacks  Lisp implementations involve internal stacks  Holds 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() ?)

26 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]

27 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]

28 System.out.println(“The End!”);


Download ppt "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."

Similar presentations


Ads by Google