2/4/20161 GC16/3011 Functional Programming Lecture 20 Garbage Collection Techniques.

Slides:



Advertisements
Similar presentations
Garbage collection David Walker CS 320. Where are we? Last time: A survey of common garbage collection techniques –Manual memory management –Reference.
Advertisements

Note on malloc() and slab allocation CS-502 (EMC) Fall A Note on malloc() and Slab Allocation CS-502, Operating Systems Fall 2009 (EMC) (Slides include.
Garbage Collection Introduction What is garbage and how can we deal with it? Garbage collection schemes Reference Counting Mark and Sweep Stop and Copy.
CMSC 330: Organization of Programming Languages Memory and Garbage Collection.
PZ10B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ10B - Garbage collection Programming Language Design.
Lecture 10: Heap Management CS 540 GMU Spring 2009.
Garbage Collection What is garbage and how can we deal with it?
Free Space and Allocation Issues
Copying GC and Reference Counting Jonathan Kalechstain Tel Aviv University 11/11/2014.
CSE 5317/4305 L11: Storage Allocation1 Storage Allocation Leonidas Fegaras.
MC 2 : High Performance GC for Memory-Constrained Environments - Narendran Sachindran, J. Eliot B. Moss, Emery D. Berger Sowmiya Chocka Narayanan.
Garbage Collection  records not reachable  reclaim to allow reuse  performed by runtime system (support programs linked with the compiled code) (support.
Compiler construction in4020 – lecture 12 Koen Langendoen Delft University of Technology The Netherlands.
5. Memory Management From: Chapter 5, Modern Compiler Design, by Dick Grunt et al.
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.
MC 2 : High Performance GC for Memory-Constrained Environments N. Sachindran, E. Moss, E. Berger Ivan JibajaCS 395T *Some of the graphs are from presentation.
CPSC 388 – Compiler Design and Construction
Ceg860 (Prasad)L9GC1 Memory Management Garbage Collection.
Mark and Sweep Algorithm Reference Counting Memory Related PitFalls
CS 536 Spring Automatic Memory Management Lecture 24.
1 The Compressor: Concurrent, Incremental and Parallel Compaction. Haim Kermany and Erez Petrank Technion – Israel Institute of Technology.
CS 1114: Data Structures – memory allocation Prof. Graeme Bailey (notes modified from Noah Snavely, Spring 2009)
Garbage Collection Mooly Sagiv html://
Memory Management Professor Yihjia Tsai Tamkang University.
CSE 2501 Review Declaring a variable allocates space for the type of datum it is to store int x; // allocates space for an int int *px; // allocates space.
© Richard Jones, Eric Jul, mmnet GC & MM Summer School, July A Rapid Introduction to Garbage Collection Richard Jones Computing Laboratory.
Runtime The optimized program is ready to run … What sorts of facilities are available at runtime.
Garbage collection David Walker CS 320. Where are we? Last time: A survey of common garbage collection techniques –Manual memory management –Reference.
Incremental Garbage Collection
Memory Allocation and Garbage Collection. Why Dynamic Memory? We cannot know memory requirements in advance when the program is written. We cannot know.
1 An Efficient On-the-Fly Cycle Collection Harel Paz, Erez Petrank - Technion, Israel David F. Bacon, V. T. Rajan - IBM T.J. Watson Research Center Elliot.
Garbage collection (& Midterm Topics) David Walker COS 320.
Linked lists and memory allocation Prof. Noah Snavely CS1114
Uniprocessor Garbage Collection Techniques Paul R. Wilson.
Reference Counters Associate a counter with each heap item Whenever a heap item is created, such as by a new or malloc instruction, initialize the counter.
Using Generational Garbage Collection To Implement Cache- conscious Data Placement Trishul M. Chilimbi & James R. Larus מציג : ראובן ביק.
UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.
Garbage Collection Memory Management Garbage Collection –Language requirement –VM service –Performance issue in time and space.
A Parallel, Real-Time Garbage Collector Author: Perry Cheng, Guy E. Blelloch Presenter: Jun Tao.
1 Overview Assignment 6: hints  Living with a garbage collector Assignment 5: solution  Garbage collection.
SEG Advanced Software Design and Reengineering TOPIC L Garbage Collection Algorithms.
Garbage Collection. Terminology Heap – a finite pool of data cells, can be organized in many ways Roots - Pointers from the program into the Heap. – We.
Dynamic Memory Allocation Questions answered in this lecture: When is a stack appropriate? When is a heap? What are best-fit, first-fit, worst-fit, and.
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.
Fast Conservative Garbage Collection Rifat Shahriyar Stephen M. Blackburn Australian National University Kathryn S. M cKinley Microsoft Research.
1 Real-Time Replication Garbage Collection Scott Nettles and James O’Toole PLDI 93 Presented by: Roi Amir.
Incremental Garbage Collection Uwe Kern 23. Januar 2002
Memory Management II: Dynamic Storage Allocation Mar 7, 2000 Topics Segregated free lists –Buddy system Garbage collection –Mark and Sweep –Copying –Reference.
1 Lecture 22 Garbage Collection Mark and Sweep, Stop and Copy, Reference Counting Ras Bodik Shaon Barman Thibaud Hottelier Hack Your Language! CS164: Introduction.
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.
Runtime The optimized program is ready to run … What sorts of facilities are available at runtime.
® July 21, 2004GC Summer School1 Cycles to Recycle: Copy GC Without Stopping the World The Sapphire Collector Richard L. Hudson J. Eliot B. Moss Originally.
The Metronome Washington University in St. Louis Tobias Mann October 2003.
CS412/413 Introduction to Compilers and Translators April 21, 1999 Lecture 30: Garbage collection.
Simple Generational GC Andrew W. Appel (Practice and Experience, February 1989) Rudy Kaplan Depena CS 395T: Memory Management February 9, 2009.
Garbage Collection What is garbage and how can we deal with it?
Inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 7 – More Memory Management Lecturer PSOE Dan Garcia
Smalltalk Implementation: Memory Management and Garbage Collection
Concepts of programming languages
Automatic Memory Management
Strategies for automatic memory management
Chapter 12 Memory Management
Heap storage & Garbage collection
Heap storage & Garbage collection
Garbage collection Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 7 – More Memory Management Lecturer PSOE Dan Garcia
Reference Counting.
Garbage Collection What is garbage and how can we deal with it?
Presentation transcript:

2/4/20161 GC16/3011 Functional Programming Lecture 20 Garbage Collection Techniques

2/4/20162 Contents  Motivation  Mark-scan  Two-space copying  Reference counting  Comparison

2/4/20163 Motivation  Beta reduction in Miranda can cause heap cells to become detached from the program graph  Similar effects in Java  Fixed heap size – limited resources  How do we reuse (recycle) memory?

2/4/20164  We need to:  Find which cells are no longer required by the program  Make those cells available to the memory allocator  Unreferenced cells are called GARBAGE  Key technique: “GARBAGE COLLECTION”  Three popular variants:  Mark-scan  Two-space (or “semi-space”) copying  Reference counting

2/4/ Mark-scan  Triggered when program has used >80% of heap  Evaluation suspended until collector finished  May happen many times during program  Mark:  Follow pointers from root cell of program and mark all reachable cells (set “mark bit” to 1)  Scan:  All cells in the heap  if marked, set mark bit to 0 (ready for next mark)  else attach cell to free list

2/4/20166  Mark-scan uses a FREE LIST for allocation  A linked list of cells which are available for use by the program  Before program starts, ALL cells are on free list  Then program is loaded  Then program is run  Scanner re-creates the free list by linking all unused cells  Cells are unlinked from free list when allocated

2/4/ Two-space copying  Memory is managed as two separate heaps called FROM- space and TO-space  At first, program is loaded and run in FROM-space  THERE IS NO FREE LIST – just a pointer to the top of allocated memory in FROM-space (“TOP”).  When TOP exceeds, say, 80% of FROM-space, the collector is called  Evaluation is suspended until collector finished  May happen many times during program

2/4/20168  The two-space collector must:  Follow pointers from the root cell of the program in FROM space, COPY each cell into TO-space and update any pointers to that cell so they now point to the copy in TO-space.  Swap the names/roles of FROM-space and TO-space  Allow evaluation to proceed  Garbage is “left behind” after copying  Allocation is by simple (fast) pointer-increment

2/4/ Reference Counting  Each cell is extended with a reference count field  The reference count keeps track of how many pointers are pointing to this cell:  Each new pointer to this cell causes its reference count to be incremented  Each deletion of a pointer to this cell causes its reference count to be decremented  Any cell with a reference count of 0 is garbage.  All cells with reference count 0 are on FREE LIST

2/4/  Allocation is by unlinking cells from the free list  If a cell’s reference count drops to 0:  it must be put on the free list  If it contains any pointers, these must be deleted  This could cause an “avalanche” of garbage  Reference count field must normally be big enough to allow for ALL pointers to point to one cell

2/4/ Comparison  Overheads:  Mark-scan:  1 bit per cell  + a stack for traversal (or use pointer-reversal)  Copying:  100% space overhead  Reference count:  typically 32 bits per cell  + time overhead (when copy/delete pointer, must also read in and modify the cell it points to!)

2/4/  Compaction/fragmentation  Mark-scan:  Must run separate compactor (during scan phase) to reduce fragmentation  Copying:  Inherently compacting  No fragmentation immediately after copy (BUT remember 100% overhead)  Reference counting:  Must run separate compactor to reduce fragmentation

2/4/  Small program in big heap:  Mark-scan: visits ALL heap cells (slow)  Copying: only visits program cells (fast)  Reference count: only visits cells in use (fast)  Large program (nearly fills heap):  Mark-scan: performance degrades  Copying: performance degrades  Reference count: unaffected

2/4/  Cyclic structures in heap:  Mark-scan: unaffected  Copying: unaffected  Reference count: needs special attention!

2/4/ Summary  Motivation  Mark-scan  Two-space copying  Reference counting  Comparison