Garbage Collection. Weiyuan Li

Similar documents
Garbage Collection Algorithms. Ganesh Bikshandi

Run-Time Environments/Garbage Collection

Sustainable Memory Use Allocation & (Implicit) Deallocation (mostly in Java)

Lecture 15 Garbage Collection

Runtime. The optimized program is ready to run What sorts of facilities are available at runtime

Lecture 13: Garbage Collection

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages

Garbage Collection. Akim D le, Etienne Renault, Roland Levillain. May 15, CCMP2 Garbage Collection May 15, / 35

CMSC 330: Organization of Programming Languages. Memory Management and Garbage Collection

Algorithms for Dynamic Memory Management (236780) Lecture 4. Lecturer: Erez Petrank

One-Slide Summary. Lecture Outine. Automatic Memory Management #1. Why Automatic Memory Management? Garbage Collection.

Compiler Construction

Run-time Environments -Part 3

Garbage Collection. Hwansoo Han

Managed runtimes & garbage collection. CSE 6341 Some slides by Kathryn McKinley

Managed runtimes & garbage collection

Lecture 15 Advanced Garbage Collection

Exploiting the Behavior of Generational Garbage Collector

Garbage Collection Techniques

Garbage Collection. Steven R. Bagley

Compiler Construction

Myths and Realities: The Performance Impact of Garbage Collection

Automatic Memory Management

Robust Memory Management Schemes

CS 345. Garbage Collection. Vitaly Shmatikov. slide 1

Lecture Notes on Garbage Collection

CSE P 501 Compilers. Memory Management and Garbage Collec<on Hal Perkins Winter UW CSE P 501 Winter 2016 W-1

ACM Trivia Bowl. Thursday April 3 rd (two days from now) 7pm OLS 001 Snacks and drinks provided All are welcome! I will be there.

Performance of Non-Moving Garbage Collectors. Hans-J. Boehm HP Labs

Design Issues. Subroutines and Control Abstraction. Subroutines and Control Abstraction. CSC 4101: Programming Languages 1. Textbook, Chapter 8

CS577 Modern Language Processors. Spring 2018 Lecture Garbage Collection

A new Mono GC. Paolo Molaro October 25, 2006

Automatic Garbage Collection

Garbage Collection (1)

Heap Compression for Memory-Constrained Java

Garbage Collection (2) Advanced Operating Systems Lecture 9

Book keeping. Will post HW5 tonight. OK to work in pairs. Midterm review next Wednesday

CS 4120 Lecture 37 Memory Management 28 November 2011 Lecturer: Andrew Myers

Acknowledgements These slides are based on Kathryn McKinley s slides on garbage collection as well as E Christopher Lewis s slides

CS842: Automatic Memory Management and Garbage Collection. Mark and sweep

Implementation Garbage Collection

Opera&ng Systems CMPSCI 377 Garbage Collec&on. Emery Berger and Mark Corner University of Massachuse9s Amherst

Motivation for Dynamic Memory. Dynamic Memory Allocation. Stack Organization. Stack Discussion. Questions answered in this lecture:

CA Compiler Construction

Memory Management. Memory Management... Memory Management... Interface to Dynamic allocation

Concurrent Garbage Collection

Mark-Sweep and Mark-Compact GC

6.172 Performance Engineering of Software Systems Spring Lecture 9. P after. Figure 1: A diagram of the stack (Image by MIT OpenCourseWare.

CS61C : Machine Structures

Programming Language Implementation

Hard Real-Time Garbage Collection in Java Virtual Machines

Run-time Environments - 3

CS 241 Honors Memory

CS61C : Machine Structures

A.Arpaci-Dusseau. Mapping from logical address space to physical address space. CS 537:Operating Systems lecture12.fm.2

JVM Troubleshooting MOOC: Troubleshooting Memory Issues in Java Applications

Lecture Conservative Garbage Collection. 3.2 Precise Garbage Collectors. 3.3 Other Garbage Collection Techniques

Shenandoah An ultra-low pause time Garbage Collector for OpenJDK. Christine H. Flood Roman Kennke

Agenda. CSE P 501 Compilers. Java Implementation Overview. JVM Architecture. JVM Runtime Data Areas (1) JVM Data Types. CSE P 501 Su04 T-1

Glacier: A Garbage Collection Simulation System

Dynamic Memory Allocation II October 22, 2008

Memory Management 3/29/14 21:38

CS61C : Machine Structures

Automatic Memory Management

CS61C : Machine Structures

Programmer Directed GC for C++ Michael Spertus N2286= April 16, 2007

Parallel GC. (Chapter 14) Eleanor Ainy December 16 th 2014

Simple Garbage Collection and Fast Allocation Andrew W. Appel

Precise Garbage Collection for C. Jon Rafkind * Adam Wick + John Regehr * Matthew Flatt *

Memory management has always involved tradeoffs between numerous optimization possibilities: Schemes to manage problem fall into roughly two camps

Memory Allocation. Static Allocation. Dynamic Allocation. Dynamic Storage Allocation. CS 414: Operating Systems Spring 2008

JVM Memory Model and GC

CS Computer Systems. Lecture 8: Free Memory Management

Lecture Notes on Garbage Collection

IBM Research Report. Efficient Memory Management for Long-Lived Objects

Fundamentals of GC Tuning. Charlie Hunt JVM & Performance Junkie

Lecture 7 More Memory Management Slab Allocator. Slab Allocator

G Programming Languages - Fall 2012

Deallocation Mechanisms. User-controlled Deallocation. Automatic Garbage Collection

Garbage Collection. Vyacheslav Egorov

Java Performance Tuning

Garbage-First Garbage Collection by David Detlefs, Christine Flood, Steve Heller & Tony Printezis. Presented by Edward Raff

Quantifying the Performance of Garbage Collection vs. Explicit Memory Management

Harmony GC Source Code

Reference Counting. Reference counting: a way to know whether a record has other users

Manual Allocation. CS 1622: Garbage Collection. Example 1. Memory Leaks. Example 3. Example 2 11/26/2012. Jonathan Misurda

Dynamic Storage Allocation

Dynamic Memory Allocation

:.NET Won t Slow You Down

Real-Time Garbage Collection for Java

Heap Management. Heap Allocation

Shenandoah: An ultra-low pause time garbage collector for OpenJDK. Christine Flood Roman Kennke Principal Software Engineers Red Hat

Lecture Notes on Advanced Garbage Collection

Copying Garbage Collection in the Presence of Ambiguous References

Name, Scope, and Binding. Outline [1]

Memory Allocation II. CSE 351 Autumn Instructor: Justin Hsia

The Garbage-First Garbage Collector

A Generational Mostly-concurrent Garbage Collector. Tony Printezis and David Detlefs

Today. Dynamic Memory Allocation: Advanced Concepts. Explicit Free Lists. Keeping Track of Free Blocks. Allocating From Explicit Free Lists

Transcription:

Garbage Collection Weiyuan Li

Why GC exactly? - Laziness - Performance - free is not free - combats memory fragmentation - More flame wars

Basic concepts - Type Safety - Safe: ML, Java (not really) - Unsafe: C/C++ - Reachability - Root set

Reference Counting GC - Identifies garbage as an object changes from reachable to unreachable. - Each object keeps a count. Once the count falls to zero, the object can be freed

Reference Counting GC (cont.) - High overhead - additional operations - extra space - not evenly-distributed (so is manual memory management) - Cannot handle self-referencing structures - no TSP for Perl - cycle detection (Python)

Reference Counting GC (cont.) - Simple enough, works in most situations - Cyclic data structures are not that common - One huge benefit - No more close/closedir

Trace-Based GC - Runs periodically - Starting from the root set, find all reachable objects and reclaim the rest - Stop-the-world style

Mark-and-sweep - Chunks are presumed unreachable, unless proven reachable by tracing - Marking phase - Sweeping phase

Free, Unreached, Unscanned, Scanned Mutator runs: Marking: Free Free Unreached Unreached Scanned Unscanned Sweeping: Free Unreached Scanned

Baker s mark-and-sweep GC - Avoids examining the entire heap by maintaining a list of allocated objects (Unreached) - Returns modified Free and Unreached lists

Mark-and-compact - Moves reachable objects around to eliminate fragmentation - Allocation is fast - Better locality

Copying collector - Divide the heap into two semispaces. - Marking phase: find reachable objects - Copy phase: copy all reachables the other semispace - Improved: Cheney s collector

Comparison Basic Mark-and-sweep # of memory chunks in heap Baker s algorithm # of reached objects Basic Mark-and-copy # of chunks + reached objects Cheney s collector # of reached objects

More... - Adaptive collector - Incremental garbage collection - Partial-collection - Objects die young - Generational collector (copying partial-collection) - The Train Algorithm - handles mature objects better

Boehm Garbage Collection - A conservative GC for C/C++ - Why special? - Not type safe - Uncooperative: no good way to tell pointer from plain data - Memory layout restriction - <gc_cpp.h> - overloads operator new for POD (plain old data) and classes without destructors - class gc overrides new and delete for classes with destructors

Boehm Garbage Collection (cont.) - Metadata - Boehm GC stores objects in special memory chunks - Chunks store metadata in their headers - Objects are metadata-free - GC also maintains a list of allocated chunks - All chunks are aligned in memory

Boehm Garbage Collection (cont.) - Simple heuristics to identify pointers - Rule out: integers greater than the largest heap memory address and smaller than the smallest one - Metadata contains pointer to the entry in the chunk list - Use size info to check if pointer is valid

Boehm Garbage Collection (cont.) - Not perfect (duh!) - Likely to leak memory - Cannot handle fragmentation - Acceptable overhead - Still has marking and sweeping phases - Can be used as a leak detector

Go Lang 1.0 mark-and-sweep (parallel implementation) non-generational non-compacting mostly precise stop-the-world bitmap-based representation zero-cost when the program is not allocating memory (that is: shuffling pointers around is as fast as in C, although in practice this runs somewhat slower than C because the Go compiler is not as advanced as C compilers such as GCC) supports finalizers on objects there is no support for weak references

Go Lang 1.4 (expected) hybrid stop-the-world/concurrent collector stop-the-world part limited by a 10ms deadline CPU cores dedicated to running the concurrent collector tri-color mark-and-sweep algorithm non-generational non-compacting fully precise incurs a small cost if the program is moving pointers around lower latency, but most likely also lower throughput, than Go 1.3 GC

OCaml - Functional programming style involve large amount of small allocation - Generational GC - Minor heap: small, fixed-size - Major heap: larger, variable-size - Heap compaction cycles

References 1. Alfred V. Aho, Monica S. Lam, Ravi Sethi, and Jeffrey D. Ullman Compilers: Principles, Techniques, and Tools, Second Edition Pearson Addison-Wesley, 2007, ISBN 0-321-48681-1 2. Hickey, Yaron Minsky. Anil Madhavapeddy. Jason. Real World OCaml; O'Reilly Media, Inc., 2013. 3. Brian Goetz Java theory and practice: A brief history of garbage collection http://www.ibm. com/developerworks/library/j-jtp10283/index.html 4. Jez Ng How the Boehm Garbage Collector Works http://discontinuously.com/2012/02/how-the-boehm-garbage-collector-works/ 5. Vijay Saraswat Java is not type-safe http://www.cis.upenn.edu/~bcpierce/courses/629/papers/saraswat-javabug.html 6. An Introduction to Garbage Collection by Richard Gillam http://icu-project.org/docs/papers/cpp_report/an_introduction_to_garbage_collection_part_i.html