Garbage Collection Memory Management Garbage Collection –Language requirement –VM service –Performance issue in time and space.

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

Automatic Memory Management Noam Rinetzky Schreiber 123A /seminar/seminar1415a.html.
CMSC 330: Organization of Programming Languages Memory and Garbage Collection.
Lecture 10: Heap Management CS 540 GMU Spring 2009.
Automatic Storage Management Patrick Earl Simon Leonard Jack Newton.
CMSC 330: Organization of Programming Languages Memory and Garbage Collection.
Garbage Collection  records not reachable  reclaim to allow reuse  performed by runtime system (support programs linked with the compiled code) (support.
5. Memory Management From: Chapter 5, Modern Compiler Design, by Dick Grunt et al.
Memory Management Tom Roeder CS fa. Motivation Recall unmanaged code eg C: { double* A = malloc(sizeof(double)*M*N); for(int i = 0; i < M*N; i++)
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.
Efficient Concurrent Mark-Sweep Cycle Collection Daniel Frampton, Stephen Blackburn, Luke Quinane and John Zigman (Pending submission) Presented by Jose.
Parallel Garbage Collection Timmie Smith CPSC 689 Spring 2002.
CPSC 388 – Compiler Design and Construction
Ceg860 (Prasad)L9GC1 Memory Management Garbage Collection.
CS 536 Spring Automatic Memory Management Lecture 24.
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.
1 The Compressor: Concurrent, Incremental and Parallel Compaction. Haim Kermany and Erez Petrank Technion – Israel Institute of Technology.
G Robert Grimm New York University Cool Pet Tricks with… …Virtual Memory.
Garbage Collection Mooly Sagiv html://
Memory Management Chapter 5 Mooly Sagiv
Runtime The optimized program is ready to run … What sorts of facilities are available at runtime.
Lecture 36: Programming Languages & Memory Management Announcements & Review Read Ch GU1 & GU2 Cohoon & Davidson Ch 14 Reges & Stepp Lab 10 set game due.
Incremental Garbage Collection
Compilation 2007 Garbage Collection Michael I. Schwartzbach BRICS, University of Aarhus.
Age-Oriented Concurrent Garbage Collection Harel Paz, Erez Petrank – Technion, Israel Steve Blackburn – ANU, Australia April 05 Compiler Construction Scotland.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Garbage Collection Without Paging Matthew Hertz, Yi Feng, Emery Berger University.
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.
Garbage Collection Mooly Sagiv
Linked lists and memory allocation Prof. Noah Snavely CS1114
Uniprocessor Garbage Collection Techniques Paul R. Wilson.
UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.
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.
380C Lecture 17 Where are we & where we are going –Managed languages Dynamic compilation Inlining Garbage collection –Why you need to care about workloads.
Chapter 7 Run-Time Environments
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.
Ulterior Reference Counting: Fast Garbage Collection without a Long Wait Author: Stephen M Blackburn Kathryn S McKinley Presenter: Jun Tao.
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.
Copyright (c) 2004 Borys Bradel Myths and Realities: The Performance Impact of Garbage Collection Paper: Stephen M. Blackburn, Perry Cheng, and Kathryn.
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
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
September 11, 2003 Beltway: Getting Around GC Gridlock Steve Blackburn, Kathryn McKinley Richard Jones, Eliot Moss Modified by: Weiming Zhao Oct
Garbage Collection and Memory Management CS 480/680 – Comparative Languages.
UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.
David F. Bacon Perry Cheng V.T. Rajan IBM T.J. Watson Research Center ControllingFragmentation and Space Consumption in the Metronome.
A REAL-TIME GARBAGE COLLECTOR WITH LOW OVERHEAD AND CONSISTENT UTILIZATION David F. Bacon, Perry Cheng, and V.T. Rajan IBM T.J. Watson Research Center.
Runtime The optimized program is ready to run … What sorts of facilities are available at runtime.
Introduction to Garbage Collection. Garbage Collection It automatically reclaims memory occupied by objects that are no longer in use It frees the programmer.
2/4/20161 GC16/3011 Functional Programming Lecture 20 Garbage Collection Techniques.
® 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.
Reference Counting. Reference Counting vs. Tracing Advantages ✔ Immediate ✔ Object-local ✔ Overhead distributed ✔ Very simple Trivial implementation for.
GC Assertions: Using the Garbage Collector To Check Heap Properties Samuel Z. Guyer Tufts University Edward Aftandilian Tufts University.
An Efficient, Incremental, Automatic Garbage Collector P. Deutsch and D. Bobrow Ivan JibajaCS 395T.
Eliminating External Fragmentation in a Non-Moving Garbage Collector for Java Author: Fridtjof Siebert, CASES 2000 Michael Sallas Object-Oriented Languages.
Dynamic Compilation Vijay Janapa Reddi
Rifat Shahriyar Stephen M. Blackburn Australian National University
Concepts of programming languages
Memory Management and Garbage Collection Hal Perkins Autumn 2011
Strategies for automatic memory management
Memory Management Kathryn McKinley.
Chapter 12 Memory Management
Reference Counting.
Mooly Sagiv html:// Garbage Collection Mooly Sagiv html://
Presentation transcript:

Garbage Collection Memory Management Garbage Collection –Language requirement –VM service –Performance issue in time and space

Garbage Collection Outline Motivation for GC Basics of GC –How it works –Key design choices –Basic GCs A taxonomy of sorts GC Performance

Garbage Collection Outline Briefly introduce the challenges and key ideas in Memory Management –Explicit vs Automatic –Memory Organization Contiguous allocation (bump pointer) Free lists (analogous to pages in memory) –Reclamation Tracing Reference counting

Garbage Collection Memory Management Program Objects/Data occupy memory How does the runtime system efficiently create and recycle memory on behalf of the program? –What makes this problem important? –What makes this problem hard? –Why are researchers (e.g. me) still working on it?

Garbage Collection Dynamic memory allocation and reclamation Heap contains dynamically allocated objects Object allocation: malloc, new Deallocation: –Manual/explicit: free, delete –automatic: garbage collection

Garbage Collection Explicit Memory Management Challenges More code to maintain Correctness –Free an object too soon - core dump –Free an object too late - waste space –Never free - at best waste, at worst fail Efficiency can be very high Gives programmers “control”

Garbage Collection Garbage collection: Automatic memory management reduces programmer burden eliminates sources of errors integral to modern object-oriented languages, i.e., Java, C#,.net now part of mainstream computing Challenge: –performance efficiency

Garbage Collection Key Issues For both –Fast allocation –Fast reclamation –Low fragmentation (wasted space) –How to organize the memory space Garbage Collection –Discriminating live objects and garbage

Garbage Collection GC: How? Automatically collect dead objects Liveness  reachability –Root sets Unreachable  non-live  garbage –Compared to dead in compiler ‘Once garbage always garbage’ –(Always safe to collect unreachable objects)

Garbage Collection Liveness: the GC and VM/Compiler Contract GC Maps - identify what is live –Root set Live registers, walk the stack to enumerate stack variables, globals at any potential GC point –JIT/compiler generates a map for every program point where a GC may occur –Can constrain optimizations (derived pointers) –Required for type-accurate GC

Garbage Collection VM/Compiler GC contract Write/Read barriers for generational & incremental collection –JIT must insert barriers in generated code –Usually inlines barriers –Barriers trade-off GC and mutator costs Cooperative scheduling –In many VMs, all mutator threads must be stopped at GC points. One solution requires JITs to inject GC yieldpoints at regular intervals in the generated code

Garbage Collection Basic GC Techniques Reference Counting Tracing –Mark-sweep –Mark-compact –Copying

Garbage Collection Tracing/Reference Counting ‘Tracing’ (reachability) –Trace reachability from program ‘roots’ Registers Stacks Statics –Objects not traced are unreachable A Reference Count for each object −#incoming pointers −incremental −count = 0 (unreachability) –Notice removal of last reference to an object –Write barrier for implementation –Concerns –cycles are an issue –space for reference count –Efficiency (deferred reference counting)

Garbage Collection Mark-Sweep How it works –Tracing to “mark” live objects –Sweep to reclaim dead objects Dead objects linked to free-lists Concerns –Fragmentation –Cost proportional to heap size –Locality

Garbage Collection Mark-Compact How it works –Tracing to “mark” live (reachable) objects –Sliding compacting marked objects Concerns –Fragmentation solved –Cost Two or more scans of live objects –Locality problem ameliorated

Garbage Collection Copying GC Copy reachable objects to a contiguous area –e.g., Semispace with Cheney scan Fromspace Root set Tospace

Garbage Collection Copying GC Copy reachable objects to a contiguous area –e.g., Semispace with Cheney scan From space Root set To space

Garbage Collection Copying Garbage Collection ‘from space’‘to space’‘from space’‘to space’ ‘from space’ ‘to space’ ‘from space’

Garbage Collection Cheney Scan Root set A B C D E F scan free AB scan free AB scan free AB C DC

Garbage Collection Space Management Two broad approaches: –Copying Bump allocation & en masse reclamation –Fast allocation & reclaim –Space overhead, copy cost –Non-copying Free-list allocation & reclamation –Space efficiency –Fragmentation

Garbage Collection Bump-Pointer Fast (increment & bounds check)  Can't incrementally free & reuse: must free en masse  Relatively slow (consult list for fit) Can incrementally free & reuse cells Free-List Allocation Choices

Garbage Collection Allocation Choices Bump pointer – ~70 bytes IA32 instructions, 726MB/s Free list – ~140 bytes IA32 instructions, 654MB/s Bump pointer 11% faster in tight loop – < 1% in practical setting – No significant difference (?) Second order effects? – Locality?? – Collection mechanism??

Garbage Collection Generational GC Observation –Most objects die young –A small percentage long lived objects Avoid copying long-lived objects several times Generational GC segregates objects by age –Older object collects less often

Garbage Collection Generational GC Design Issues –Advancement policies When to advance a live object into next generation –Heap organization –Collection scheduling –Intergenerational references Remembered sets Page marking, word marking, card marking, store list

Garbage Collection Incremental/Concurrent Approaches For real time and interactive application –Guarantee pause time –Can generational collection work? Techniques –Reference counting –Tracing concurrency

Garbage Collection Incremental/Concurrent Approaches Approaches to coordinate the collector and the mutator –Tri-color marking Black, gray, white –Mutator cannot install a pointer from black to white Read barrier –Color an white object gray before the mutator access it Write barrier –Trap an object when a pointer is write into it

Garbage Collection Write Barrier Algorithms Snap-shot-at-beginning –No objects ever become in in accessible to the GC while collection is in progress Yussa’s: An overwriten value is first saved for later examination Objects are allocated black Incremental Update –Objects that die during GC before being reached by GC traversal are not traversed and marked –Objects are allocated white –Iteratively traverse black objects got pointers store into

Garbage Collection Baker’s Read Barrier Algorithms Incremental copying with Cheney scan Any fromspace object accessed by the mutator is copy to tospace –Use read barrier New objects allocated in tospace –black

Garbage Collection Taxonomy of Sorts or: Key Design Dimensions Incrementality Composability Concurrency Parallelism Distribution

Garbage Collection Incrementality ‘Full heap’ tracing: –‘Pause time’ goes up with heap size Incremental tracing: –Bounded tracing time –Conservative assumption: All objects in rest of heap are live –Remember pointers from rest of heap Add ‘remembered set’ to roots for tracing

Garbage Collection Composability Hybrids –Copy younger objects –Non-copying collection of older objects Hierarchies –Copying intra-partition (increment) –Reference counting inter-partition

Garbage Collection Concurrency ‘Mutator’ and GC operate concurrently ?

Garbage Collection Parallelism Concurrency among multiple GCs –Load balancing –Race conditions when tracing –Synchronization

Garbage Collection Distribution Typically implies: –Incrementality –Concurrency –Parallelism –Composability Detecting termination –When has a partition become isolated?

Garbage Collection GC Performance Three key dimensions: –Throughput (bandwidth) –Responsiveness (latency) –Space Measurement issues: –Selecting benchmarks –Understanding space time tradeoff