The Generational Hypothesis

Similar documents
CMSC 330: Organization of Programming Languages

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

CMSC 330: Organization of Programming Languages

Lecture 13: Garbage Collection

Lecture 15 Garbage Collection

Optimizing Scheme, part I

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

Garbage Collection. Steven R. Bagley

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

Garbage Collection. Hwansoo Han

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

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

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

Heap Management. Heap Allocation

Managed runtimes & garbage collection

Deallocation Mechanisms. User-controlled Deallocation. Automatic Garbage Collection

Lecture 15 Advanced Garbage Collection

Garbage Collection (2) Advanced Operating Systems Lecture 9

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

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

Garbage Collection Algorithms. Ganesh Bikshandi

Azul Systems, Inc.

CS 241 Honors Memory

Implementation Garbage Collection

CS577 Modern Language Processors. Spring 2018 Lecture Garbage Collection

Simple Garbage Collection and Fast Allocation Andrew W. Appel

Java Performance Tuning

Automatic Memory Management

Running class Timing on Java HotSpot VM, 1

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

Concurrent Garbage Collection

Java Garbage Collection Best Practices For Tuning GC

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

1: Introduction to Object (1)

G Programming Languages - Fall 2012

Tick: Concurrent GC in Apache Harmony

Generational Garbage Collection Theory and Best Practices

Exploiting the Behavior of Generational Garbage Collector

Compiler construction 2009

A new Mono GC. Paolo Molaro October 25, 2006

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

Programming Language Implementation

JAVA An overview for C++ programmers

CS 345. Garbage Collection. Vitaly Shmatikov. slide 1

COSC 2P95. Procedural Abstraction. Week 3. Brock University. Brock University (Week 3) Procedural Abstraction 1 / 26

Robust Memory Management Schemes

Heap Arrays and Linked Lists. Steven R. Bagley

Operating Systems CMPSCI 377, Lec 2 Intro to C/C++ Prashant Shenoy University of Massachusetts Amherst

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

Register Allocation. Lecture 16

Cold, Hard Cache KV? On the implementation and maintenance of caches. who is

The Dynamic Typing Interlude

Virtual Memory (Real Memory POV)

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

Automatic Garbage Collection

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

CS370 Operating Systems

A Tour to Spur for Non-VM Experts. Guille Polito, Christophe Demarey ESUG 2016, 22/08, Praha

JVM Memory Model and GC

2016 All Rights Reserved


WACC Report. Zeshan Amjad, Rohan Padmanabhan, Rohan Pritchard, & Edward Stow

Java Without the Jitter

Inside the Garbage Collector

High-Level Language VMs

Chapter 3:: Names, Scopes, and Bindings

Page Replacement. (and other virtual memory policies) Kevin Webb Swarthmore College March 27, 2018

Garbage Collection. Weiyuan Li

Save time. Stay on Schedule. Reduce your work. Re-use Your Code with OS Changer

Advances in Memory Management and Symbol Lookup in pqr

CS558 Programming Languages

QUIZ on Ch.5. Why is it sometimes not a good idea to place the private part of the interface in a header file?

Structure of Programming Languages Lecture 10

D Programming Language

CPS221 Lecture: Threads

Common Lisp. In Practical Usage

CS61A Notes Week 6: Scheme1, Data Directed Programming You Are Scheme and don t let anyone tell you otherwise

Lecture 13: Complex Types and Garbage Collection

Spam. Time: five years from now Place: England

Today. Adding Memory Does adding memory always reduce the number of page faults? FIFO: Adding Memory with LRU. Last Class: Demand Paged Virtual Memory

Linked Lists and Abstract Data Structures A brief comparison

Section 0.3 The Order of Operations

THE TROUBLE WITH MEMORY

Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller

the Cornell Checkpoint (pre-)compiler

A JVM Does What? Eva Andreasson Product Manager, Azul Systems

Repetition Through Recursion

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

September 15th, Finagle + Java. A love story (

Java & Coherence Simon Cook - Sales Consultant, FMW for Financial Services

Heap Arrays. Steven R. Bagley

Incremental GC for Ruby interpreter

Fundamentals of GC Tuning. Charlie Hunt JVM & Performance Junkie

Memory Management: Virtual Memory and Paging CS 111. Operating Systems Peter Reiher

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Run-Time Environments/Garbage Collection

CS 4349 Lecture October 18th, 2017

Compilers: The goal. Safe. e : ASM

Relational inductive biases, deep learning, and graph networks

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

Transcription:

Generational GC 1

The Generational Hypothesis Hypothesis: most objects "die young" i.e., they are only needed for a short time, and can be collected soon A great example of empirical systems work Found to hold for programs in practice Regardless of programming style! (functional, imperative, OO, etc.) 2

The Generational Hypothesis (define (euclidian-norm v) (sqrt (foldl + 0 (map square v)))) square produces foats which are only used until the addition map produces a whole list which is only used until we fold over it + produce a whole lot of intermediate foats which are only used for the next addition 3

The Generational Hypothesis So, how can we use this to guide GC design? Young objects have a high chance of being garbage But they re only a small portion of all objects So if we focus our efforts on them, can free a lot of space in not much time! Have a separate region for young objects: nursery Allocate new objects there When we run out of space, collect there (only!) When objects get old enough, migrate them to the main heap When we run out of space in the main heap, only then do we GC it 4

Ok, so how to GC? Generational Garbage Collection Clearly want copying GC for nursery Cost proportional to # of live objects Which should be few in nursery Use the main heap as to-space! And don t swap spaces! Always in the same direction Can use the whole heap with a copying GC! Survivors get copied out of the nursery naturally! Surviving a GC = old enough to move out What about main heap? Could be anything. Mark-and-sweep is fne. Doesn t matter as much (stay tuned) 5

diagrams go here 6

Generational Garbage Collection If the generational hypothesis holds Then we ll collect the nursery pretty often But only collect the main heap rarely Collecting the nursery is cheap Can keep it fairly small, so not many objects Will be mostly dead objects, and copying GC has cost proportional to live objects! can afford to do it often; pauses will be short Collecting the main heap is slow It will be large; needs to hold all our data A lot of it will be live, and will need to be traced/copied but that s ok, don t do it very often 7

The Snag When we GC the nursery, what do we use as roots? Want to use registers, globals, etc. Sure. But we may also have pointers to nursery objects from the main heap! These nursery objects may be live too! Only matters if the object in the main heap is live But can t know unless we mark all of main heap Which is what we were trying to avoid in the frst place! 8

The Solution Track pointers from main heap to nursery And just assume they re live, conservative So treat them as roots How do we keep track? Write barriers Can only get a pointer from main heap to nursery by using mutation Can t have an old object point to a new one naturally Latter wasn t around when the old one was allocated! So whenever we mutate, we look out for that case, and keep track Doesn t happen much in practice Requires a particular mutation pattern So ok to be conservative 9

Variants Can have N generations Containing progressively older and older objects Can migrate generations only after surviving N GCs Reduces the number of short-lived objects that only survive because we happened to GC during their (short) lifetime Can use some spare bits in the objects to store count (bit overloading, think mark bit) 1

In Practice Most production GCs are generational in some form It s that good Generational hypothesis: self-fulflling prophecy / virtuous circle Generational GC is effcient because most objects are short-lived Generational GC makes short-lived objects cheap Programmers use more short-lived objects because they re cheap Lather, rinse, repeat 11

History Came from the Self language (late 80s, early 90s) Self is little-known today, but hugely infuential JS is basically Self Implementation technology (JITs, PICs, OSR, adaptive deopts, etc.) is used all over the place 12

Cheney on the MTA 13

Charlie on the MTA 1940s: Massachusetts Transit Association (MTA) has both entry and exit fares on trains 1949: Walter A. O Brien runs for mayor of Boston His campaign: get folk singers to write songs about items on his platform Then blare them from a truck going around town (got fned 10$ for that) One such song is about Charlie, who has enough money to get on the train, but not off So he never returned 1959: The song itself becomes a hit 2006: MBTA (former MTA) introduces the Charlie card 2009: I move to Boston, and fnally get the joke 14

Continuation-Passing Style We ve seen continuation-passing style Wrote an interpreter that way In CPS, the last thing a function does is always call another function If the function is done with its own work, it calls its continuation Otherwise,passes it along to whoever it calls So our functions never return They just keep calling until the end, then everything just returns Compilers for language with higher-order functions often convert object programs to CPS Easier to implement control (e.g., return, exceptions, etc.) Makes a lot of transformations and optimizations easier 15

Cheney on the MTA Two-space copying collection = Cheney s algorithm Our object programs are in CPS Their functions never return! Just like Charlie! So their stack just keeps growing and growing (In CPS, all calls are tail calls, so could reuse stack frames and solve that problem, which is how most compilers solve the problem. But not here!) 16

Cheney on the MTA Key idea: use the stack as the nursery for a generational GC! Grow the stack until we run out of stack space Then GC, copying live objects into the heap Then restart the stack from 0! Nothing ever returns, so we don t need return addresses! And all the useful data has been copied away! Analogy: instead hopping on a trampoline on every function call We sometimes jump over the Empire State Building (Trampolines are the canonical solution for "reusing" stack frames for tail calls) 17

diagrams go here 18

For More Information Chicken Scheme uses this implementation strategy CONS Should Not CONS Its Arguments, Part II: Cheney on the M.T.A., Henry Baker, 1994 http://home.pipeline.com/~hbaker1/cheneymta.html 19