Simple Generational GC Andrew W. Appel (Practice and Experience, February 1989) Rudy Kaplan Depena CS 395T: Memory Management February 9, 2009.

Slides:



Advertisements
Similar presentations
Background Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Logical.
Advertisements

Garbage collection David Walker CS 320. Where are we? Last time: A survey of common garbage collection techniques –Manual memory management –Reference.
Instruction Set Design
Lecture 10: Heap Management CS 540 GMU Spring 2009.
Garbage Collection What is garbage and how can we deal with it?
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 3 Memory Management Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Garbage Collection  records not reachable  reclaim to allow reuse  performed by runtime system (support programs linked with the compiled code) (support.
Garbage Collection CSCI 2720 Spring Static vs. Dynamic Allocation Early versions of Fortran –All memory was static C –Mix of static and dynamic.
By Jacob SeligmannSteffen Grarup Presented By Leon Gendler Incremental Mature Garbage Collection Using the Train Algorithm.
CPSC 388 – Compiler Design and Construction
CS 536 Spring Automatic Memory Management Lecture 24.
An Efficient Machine-Independent Procedure for Garbage Collection in Various List Structures, Schorr and Waite CACM August 1967, pp Curtis Dunham.
Chapter 8 Runtime Support. How program structures are implemented in a computer memory? The evolution of programming language design has led to the creation.
Memory Management. History Run-time management of dynamic memory is a necessary activity for modern programming languages Lisp of the 1960’s was one of.
CS 1114: Data Structures – memory allocation Prof. Graeme Bailey (notes modified from Noah Snavely, Spring 2009)
Garbage Collection Mooly Sagiv html://
Virtual Memory Primitives for User Programs Andrew W. Appel and Kai Li Presented by: Khanh Nguyen.
Generational Stack Collection And Profile driven Pretenuring Perry Cheng Robert Harper Peter Lee Presented By Moti Alperovitch
File Systems Implementation
Honors Compilers Addressing of Local Variables Mar 19 th, 2002.
CS 333 Introduction to Operating Systems Class 18 - File System Performance Jonathan Walpole Computer Science Portland State University.
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
The environment of the computation Declarations introduce names that denote entities. At execution-time, entities are bound to values or to locations:
Garbage collection (& Midterm Topics) David Walker COS 320.
Linked lists and memory allocation Prof. Noah Snavely CS1114
UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.
Memory Management Last Update: July 31, 2014 Memory Management1.
SEG Advanced Software Design and Reengineering TOPIC L Garbage Collection Algorithms.
Memory Allocation CS Introduction to Operating Systems.
Fast, Effective Code Generation in a Just-In-Time Java Compiler Rejin P. James & Roshan C. Subudhi CSE Department USC, Columbia.
CS3012: Formal Languages and Compilers The Runtime Environment After the analysis phases are complete, the compiler must generate executable code. The.
1 File Systems Chapter Files 6.2 Directories 6.3 File system implementation 6.4 Example file systems.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 8: Main Memory.
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.
CS533 - Concepts of Operating Systems Virtual Memory Primitives for User Programs Presentation by David Florey.
Memory Management 3 Tanenbaum Ch. 3 Silberschatz Ch. 8,9.
Chapter 8 – Main Memory (Pgs ). Overview  Everything to do with memory is complicated by the fact that more than 1 program can be in memory.
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
1 Address Translation Memory Allocation –Linked lists –Bit maps Options for managing memory –Base and Bound –Segmentation –Paging Paged page tables Inverted.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Chapter 4 Memory Management Virtual Memory.
11/26/2015IT 3271 Memory Management (Ch 14) n Dynamic memory allocation Language systems provide an important hidden player: Runtime memory manager – Activation.
UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.
University of Washington Wouldn’t it be nice… If we never had to free memory? Do you free objects in Java? 1.
CS333 Intro to Operating Systems Jonathan Walpole.
Lecture Topics: 11/24 Sharing Pages Demand Paging (and alternative) Page Replacement –optimal algorithm –implementable algorithms.
Processes and Virtual Memory
Memory Management -Memory allocation -Garbage collection.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Memory Management Overview.
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
2/4/20161 GC16/3011 Functional Programming Lecture 20 Garbage Collection Techniques.
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
CS412/413 Introduction to Compilers and Translators April 21, 1999 Lecture 30: Garbage collection.
An Efficient, Incremental, Automatic Garbage Collector P. Deutsch and D. Bobrow Ivan JibajaCS 395T.
Garbage Collection What is garbage and how can we deal with it?
Jonathan Walpole Computer Science Portland State University
Dynamic Memory Allocation
Rifat Shahriyar Stephen M. Blackburn Australian National University
Concepts of programming languages
Chapter 8: Main Memory.
Practice Six Chapter Eight.
Memory Management and Garbage Collection Hal Perkins Autumn 2011
Strategies for automatic memory management
Closure Representations in Higher-Order Programming Languages
Virtual Memory Hardware
Beltway: Getting Around Garbage Collection Gridlock
Chapter 12 Memory Management
Garbage Collection What is garbage and how can we deal with it?
Mooly Sagiv html:// Garbage Collection Mooly Sagiv html://
Presentation transcript:

Simple Generational GC Andrew W. Appel (Practice and Experience, February 1989) Rudy Kaplan Depena CS 395T: Memory Management February 9, 2009

2 Outline Motivation Idea Description Discussion Conclusion References The End

3 Motivation: Goals GC should be ….  Simple to implement Moon [1] requires special hardware [that’s not simple!]  Fast to allocate Use idea that young objects point to old objects Not other way around [that’s not expensive!]  Low cost overhead Algo should be incremental (i.e. - amortize collection cost)

4 Motivation: Mark-Sweep [2] From Vitaly Shmatikov’s Presentation in Spring 2008 on GC [ Heap space root set

5 Motivation: Mark-Sweep [2] From Vitaly Shmatikov’s Presentation in Spring 2008 on GC [ Heap space root set

6 Motivation: Mark-Sweep root set Heap space [2] From Vitaly Shmatikov’s Presentation in Spring 2008 on GC [

7 Motivation: Mark-Sweep root set Heap space Reset mark bit of marked cells Free unmarked cells [2] From Vitaly Shmatikov’s Presentation in Spring 2008 on GC [

8 Motivation: Mark-Sweep Good  Incremental Garbage Reclamation  Cost is amortized Bad  Memory Size Proportional To Time Time Memory Size

9 Motivation: Copying Good  Time Proportional to Number of Reachable Records  No Free List Bad  Can we be faster? Time # of Reachable Records

10 Idea Description: Improvements Two Observations  Pointers are acyclic Newer Records --> Older Records Older Records --> Newer Records a.k.a “assignment” Changing field in previously allocated record  Generational Hypothesis Young objects more likely to become garbage soon Generational GC is a variant of Copying GC Records kept in regions of similar age GC copies reachable objects in A[n] into new area A[n]’ w/o touching other areas

11 Idea Description: Assignment Table Lieberman & Hewitt’s Entry Table  Checking fetched values is done indirectly This is expensive  When region, An, is collected, the whole assignment tables must be examined This is overhead Moon and Ungar provide different alternatives Generational GC not good for PLs that have assignment as main mechanism for changing data structures.

12 Idea Description: Copying Algo Heart of Generational GC  Copy live data from one region (“source region”) to another (“destination region”) Forward Procedure  Copies source to destination and returns pointer  If previously copied, return copy w/o making new copy  Scan pointer successively increments thru destination region until scan catches up with next

13 7 link 9 p q r 37 right 12 left right 15 left 20 left right left right [3] From Mooly Sagiv’s Presentation on Memory Management [ ]

14 7 link p q r 37 right 12 left right left 20 left right left right 15 left scan next [3] From Mooly Sagiv’s Presentation on Memory Management [ ]

15 7 link p q r 37 right 12 left right left 20 left right 59 left right 15 left right 37 left scan next [3] From Mooly Sagiv’s Presentation on Memory Management [ ]

16 7 link 9 p q r 37 right left right left 20 left right left right 15 left right 37 left scan next 12 left right [3] From Mooly Sagiv’s Presentation on Memory Management [ ]

17 7 link 9 p q r 37 right 12 left right left 20 left right left right 15 left right 37 left scan next 12 left right [3] From Mooly Sagiv’s Presentation on Memory Management [ ]

18 Idea Description: Fast Allocation GC never touches garbage Unallocated memory always in contiguous region (i.e. - no free list ) (cons A B) 1.Test free space pointer against free space limit 2.If the limit is reached, call GC 3.Subtract 2 from free space ptr 4.Store A 5.Store B 6.Return current value of free-space pointer

19 Idea Description: Fast Allocation <-- free space ptr <-- free space limit 0xFFFFFFFF 0x

20 Idea Description: Fast Allocation <-- free space ptr <-- free space limit A 0xFFFFFFFF 0x

21 Idea Description: Fast Allocation <-- free space ptr <-- free space limit A B 0xFFFFFFFF 0x

22 Idea Description: Fast Allocation Use Virtual Memory hardware to make comparison  1. Test free-space ptr against free-space limit If we get a page fault from inaccessible page mapped just before free space, we will initiate garbage collection Free space pointer kept in register Instructions to allocate A and B in (cons A B) has little overhead on some platforms (e.g. - AIX)

23 Idea Description: Variable Sized Records Most PLs have various record sizes GC needs to know sizes in order to memory management efficiently. Many ways to do this …  Record can contain tag to explain format  Records of different formats stored in different areas of memory  PL with static type system (e.g.- Haskell, ML) can provide GC with map of type system which explains runtime format.

24 Idea Description: Arranging Generations Unix program break Page 8 on Appel’s “Simple Generational Garbage Collection and Fast Allocation”

25 Idea Description: Arranging Generations Page 9 on Appel’s “Simple Generational Garbage Collection and Fast Allocation”

26 Idea Description: Arranging Generations If program uses at most A words of live data, then size of memory M = 2A For Best performance, M > 2A Invariant  If A < M/2, then GC never runs out of space

27 Please Sir, May I Have Some More?  = ratio of memory size to live data  o = desired value of   < 2, algo will run out of space or degrade performance  ≥ 3 for good performance Ask OS for more space under following circumstances

28 Please Sir, May I Have Some More? Circumstances for request of more memory  After a major collection when  <  o  Collector runs out of space when trying to copy older region to reserve region  After minor collection cycle, free region is not much larger than requested by program.

29 Idea Description: Keeping Track of Assignments The GC uses the root set when it starts collecting the newest area It needs the root set to determine what is reachable We must maintain a list of every record assigned into This list can be maintained in software

30 Idea Description: Keeping Track of Assignments Upon instruction of form “assign p to record r” The compiler will insert “add r to assignment list” Assignment List We May Exhaust free space failing the operation

31 Idea Description: Handling Page Traps When does a Page Trap Happen?  When the mutator runs out of space The allocator tries to make a new record in an inaccessible page, leading to a “seg fault” Seg faults trigger GC Reset the free space pointer to appropriate value, and return from interrupt

32 Idea Description: Handling Page Traps When GC is invoked, roots are  Global Variables  Runtime stack  Machine registers  Assignment list When data is moved from newer to older region, these registers and placeholders get modified

33 Discussion: Space What if runtime system sampled ratio of live data versus total memory over multiple program runs and system consistently used a lot less memory than was available? Could we reduce space waste? What technologies would we be able to apply this technique to? What downfalls could this have?

34 Discussion: Security “The root objects are the entry points for a security [breach] …. The collector would have to access objects at various security levels; this would require the collector to be trusted” - Dieter Gollmann (Computer Security: ESORICS 94) Upon encounter of the assignment operation, we place a record on the assignment linked list.  If there is an “overflow, then more space for it can be allocated or the garbage-collector may be invoked” - Appel, Page 12 Could there be security hole? DOS attack?

35 Discussion: Portability “On a VAX the subtraction from the free-space pointer can be implemented by means of an auto-decrement addressing mode ….. [because] instructions take no more time than any other pair of stores into memory, the overhead attributable to an allocation from the heap is exactly zero” - Appel, 7 Are these portability restrictions necessary, or can we be more portable than this? Could we ever use this type of GC in languages like Java given these portability constraints?

36 Discussion: Portability Would other stack layouts work for this scheme?

37 Discussion: Other Languages How well will this scheme perform on other languages?  JavaScript  C#  etc …

38 Conclusions Generational GC is not for every language and can get expensive on assignments GC becomes fast so overhead of creating object is less than overhead to clean up mess This paper attempts to present simple and efficient arrangements of generational GC, while gaining speed through special instructions and other techniques

39 References [1] David A. Moon, “Garbage collection in a large LISP system,” ACM Symposium on LISP and Functional Programming, pp , ACM, 1984 [2] Vitaly Shmatikov, “Garbage Collection,” The University of Texas at Austin, Spring [3] Mooly Sagiv, “Memory Management”, Tel Aviv University [4] Dieter Gollmann, “Computer Security: ESORICS 94 : Third European Symposium on Research in Computer Security, Brighton, United Kingdom, November 7-9, 1994 : Proceedings