Lecture 15 Garbage Collection

Similar documents
Lecture 15 Advanced Garbage Collection

Garbage Collection Algorithms. Ganesh Bikshandi

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

Run-Time Environments/Garbage Collection

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

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

Programming Language Implementation

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

Exploiting the Behavior of Generational Garbage Collector

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

CS 345. Garbage Collection. Vitaly Shmatikov. slide 1

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

Garbage Collection. Hwansoo Han

Automatic Memory Management

Garbage Collection. Weiyuan Li

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

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.

Lecture 13: Garbage Collection

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

Run-time Environments -Part 3

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

Implementation Garbage Collection

Compiler Construction

Garbage Collection. Steven R. Bagley

Automatic Garbage Collection

Concurrent Garbage Collection

Compiler Construction

Garbage Collection Techniques

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

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

Managed runtimes & garbage collection

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

Robust Memory Management Schemes

Garbage Collection (2) Advanced Operating Systems Lecture 9

Myths and Realities: The Performance Impact of Garbage Collection

Garbage Collection (1)

CS61C : Machine Structures

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

Garbage Collection. Vyacheslav Egorov

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

Deallocation Mechanisms. User-controlled Deallocation. Automatic Garbage Collection

Glacier: A Garbage Collection Simulation System

Lecture Outine. Why Automatic Memory Management? Garbage Collection. Automatic Memory Management. Three Techniques. Lecture 18

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

Heap Management. Heap Allocation

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

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

G Programming Languages - Fall 2012

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

The Generational Hypothesis

Older-First Garbage Collection in Practice: Evaluation in a Java Virtual Machine

Distributed Garbage Collection. Distributed Systems Santa Clara University

CS577 Modern Language Processors. Spring 2018 Lecture Garbage Collection

A new Mono GC. Paolo Molaro October 25, 2006

Heap Compression for Memory-Constrained Java

CS61C : Machine Structures

Java Performance Tuning

Automatic Memory Management

Lecture Notes on Garbage Collection

Tick: Concurrent GC in Apache Harmony

Running class Timing on Java HotSpot VM, 1

Review. Partitioning: Divide heap, use different strategies per heap Generational GC: Partition by age Most objects die young

Dynamic Memory Management

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

I J C S I E International Science Press

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

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

Compiler construction 2009

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

Hardware-Supported Pointer Detection for common Garbage Collections

CS61C : Machine Structures

CS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 11

CS61C : Machine Structures

Dynamic Memory Management! Goals of this Lecture!

THEORY OF COMPILATION

Garbage Collection. CS 351: Systems Programming Michael Saelee

Compilers. 8. Run-time Support. Laszlo Böszörmenyi Compilers Run-time - 1

Qualifying Exam in Programming Languages and Compilers

HOT-Compilation: Garbage Collection

CS61, Fall 2012 Section 2 Notes

Java without the Coffee Breaks: A Nonintrusive Multiprocessor Garbage Collector

Quantifying the Performance of Garbage Collection vs. Explicit Memory Management

Compiler Construction D7011E

CS61C : Machine Structures

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

Run-time Environments

CS2210: Compiler Construction. Runtime Environment

Run-time Environments

Short-term Memory for Self-collecting Mutators. Martin Aigner, Andreas Haas, Christoph Kirsch, Ana Sokolova Universität Salzburg

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

CS 241 Honors Memory

Partial Marking GC. A traditional parallel mark and sweep GC algorithm has, however,

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

Understanding Garbage Collection

Stack Tracing In A Statically Typed Language

Lecture 7 More Memory Management Slab Allocator. Slab Allocator

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

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

Transcription:

Lecture 15 Garbage Collection I. Introduction to GC -- Reference Counting -- Basic Trace-Based GC II. Copying Collectors III. Break Up GC in Time (Incremental) IV. Break Up GC in Space (Partial) Readings: Ch. 7.4-7.7.4 CS243: Advanced Garbage Collection 1

I. Why Automatic Memory Management? Perfect live dead not deleted ü --- deleted --- ü Manual management not deleted deleted live dead Assume for now the target language is Java 2

What is Garbage? 3

When is an Object not Reachable? Mutator (the program) New / malloc: (creates objects) Store p in a pointer variable or field in an object Load Object reachable from variable or object Loses old value of p, may lose reachability of -- object pointed to by old p, -- object reachable transitively through old p Procedure calls on entry: keeps incoming parameters reachable on exit: keeps return values reachable loses pointers on stack frame (has transitive effect) Important property once an object becomes unreachable, stays unreachable! 4

How to Find Unreachable Nodes? 5

Reference Counting Free objects as they transition from reachable to unreachable Keep a count of pointers to each object Zero reference -> not reachable When the reference count of an object = 0 delete object subtract reference counts of objects it points to recurse if necessary Not reachable -> zero reference? Cost overhead for each statement that changes ref. counts 6

Why is Trace-Based GC Hard? Reasons Requires complementing the reachability set - that s a large set Interacts with resource management: memory 7

Trace-based GC Reachable objects Root set: (directly accessible by prog. without deref ing pointers) objects on the stack, globals, static field members + objects reached transitively from ptrs in the root set. Complication due to compiler optimizations Registers may hold pointers Optimizations (e.g. strength reduction, common subexpressions) may generate pointers to the middle of an object Solutions ensure that a base pointer is available in the root set compiler writes out information to decipher registers and compiler-generated variables (may restrict the program points where GC is allowed) 8

Baker s Algorithm Data structures Free: a list of free space Unreached: a list of allocated objects, not Reached, not Scanned Unscanned: a work list: Reached, but not Scanned Scanned: a list of scanned objects: Reached and Scanned Algorithm Scanned = Move objects in root set from Unreached to Unscanned While Unscanned move object o from Unscanned to Scanned scan o, move newly reached objects from Unreached to Unscanned Free = Free Unreached Unreached = Scanned 9

Trace-Based GC: Memory Life-Cycle 10

When Should We GC? 11

Frequency of GC How many objects? Language dependent, for example, Java: all non-primitive objects are allocated on the heap all elements in an array are individually allocated Escape analysis is useful -- object escapes if it is visible to caller -- allocate object on the stack if it does not escape How long do objects live? Objects die young Cost of reachability analysis: depends on reachable objects Less frequent: faster overall, requires more memory 12

Performance Metric Space reclaimed Reference Counting Trace Based Overall execution time Space usage Pause time Program locality 13

II. Copying Collector To improve data locality place all live objects in contiguous locations Memory separated into 2 (semi-)spaces: From and To Allocate objects in one When (nearly) full, invoke GC, which copies reachable objects to the other space. Swap the roles of semi-spaces and repeat 14

Copying Collector (Continued) Algorithm UnScanned = Free = Start of To space Copy root set of objects space after Free, update Free; While UnScanned Free scan o, object at UnScanned copy all newly reached objects to space after Free, update Free update pointers in o update UnScanned 15

Trace-Based GC: Memory Life-Cycle 16

III. Incremental GC Interleaves GC with mutator action to reduce pause time Ideal = (R New) - Lost (R New) - Lost Answer (R New) 17

Effects of Mutation Reachable set changes as mutator runs R: set of reachable objects before the mutator runs Ideal: set of reachable objects at the end of the GC cycle New: set of newly created objects Lost: set of objects that become unreachable in the interim Ideal = (R New) - Lost Ideal: Very expensive Conservative Incremental GC: May misclassify some unreachable as reachable should not include objects unreachable before GC starts guarantees that garbage will be eliminated in the next round Ideal = (R New) - Lost Answer (R New) 18

Algorithm Proposal 1 Initial condition Scanned, Unscanned lists from before To resume GC Find root sets Place newly reached objects in unscanned list Continue to trace reachability without redoing scanned objects Did we find all reachable objects? 19

Missed Reachable Objects All reaching pointers are found in scanned objects Requires the occurrence of a 3-step sequence in the mutator: 20

Solution Intercept p in any of the three-step sequence Treat pointee of p as unscanned 21

Efficiency of Different Barriers Most efficient: Write barrier less instances than read barrier includes less unreachable objects than over-write barriers 22

IV. Partial GC Reduces pause time by collecting only objects in the target area: Algorithm New root set = original root set + pointers from Stable to Target set Change program to intercept all writes to Stable set Never misclassify reachable as unreachable May misclassify unreachable as reachable 23

Generational GC Observation: objects die young 80-98% die within a few million instructions or before 1 MB has been allocated Generational GC: collect newly allocated objects more often ith generation new root set = original root set + all pointers from generations j to i (j > i) When 1st generation fills up GC copies reachable objects into 2nd generation, and so on. 24

Properties Never misclassify reachable as unreachable Misclassify unreachable as reachable when pointers in earlier generations are overwritten eventually collect all garbage as generations get larger Effective: time spent on objects that are mostly garbage GC of mature objects takes longer Size of target set increases Eventually a full GC is performed 25

Conclusions Trace-based GC: find all reachable objects, complement to get unreachable 4 states: free, unreached, unscanned, scanned break up reachability analysis in time (incremental) in space (partial: generational) 26