Strategies for automatic memory management

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

… an introduction Peter Varsanyi Garbage collector Confidential.
Automatic Memory Management Noam Rinetzky Schreiber 123A /seminar/seminar1415a.html.
Lecture 10: Heap Management CS 540 GMU Spring 2009.
Garbage Collection What is garbage and how can we deal with it?
CSE 5317/4305 L11: Storage Allocation1 Storage Allocation Leonidas Fegaras.
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.
Garbage Collection. Memory Management So Far ● Some items are preallocated and persist throughout the program: ● What are they? Some are allocated on.
Garbage Collection CSCI 2720 Spring Static vs. Dynamic Allocation Early versions of Fortran –All memory was static C –Mix of static and dynamic.
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
Mark and Sweep Algorithm Reference Counting Memory Related PitFalls
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.
Garbage Collection Mooly Sagiv html://
Memory Management Professor Yihjia Tsai Tamkang University.
MOSTLY PARALLEL GARBAGE COLLECTION Authors : Hans J. Boehm Alan J. Demers Scott Shenker XEROX PARC Presented by:REVITAL SHABTAI.
Runtime The optimized program is ready to run … What sorts of facilities are available at runtime.
Incremental Garbage Collection
Age-Oriented Concurrent Garbage Collection Harel Paz, Erez Petrank – Technion, Israel Steve Blackburn – ANU, Australia April 05 Compiler Construction Scotland.
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
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.
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.
1 Lecture 22 Garbage Collection Mark and Sweep, Stop and Copy, Reference Counting Ras Bodik Shaon Barman Thibaud Hottelier Hack Your Language! CS164: Introduction.
Compilation (Semester A, 2013/14) Lecture 13b: Memory Management Noam Rinetzky Slides credit: Eran Yahav 1.
Runtime System CS 153: Compilers. Runtime System Runtime system: all the stuff that the language implicitly assumes and that is not described in the program.
UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.
GARBAGE COLLECTION IN AN UNCOOPERATIVE ENVIRONMENT Hans-Juergen Boehm Computer Science Dept. Rice University, Houston Mark Wieser Xerox Corporation, Palo.
Consider Starting with 160 k of memory do: Starting with 160 k of memory do: Allocate p1 (50 k) Allocate p1 (50 k) Allocate p2 (30 k) Allocate p2 (30 k)
Runtime The optimized program is ready to run … What sorts of facilities are available at runtime.
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.
GARBAGE COLLECTION Student: Jack Chang. Introduction Manual memory management Memory bugs Automatic memory management We know... A program can only use.
Memory Management What if pgm mem > main mem ?. Memory Management What if pgm mem > main mem ? Overlays – program controlled.
CSC 533: Programming Languages Spring 2016
Garbage Collection What is garbage and how can we deal with it?
Topic: Java Garbage Collection
CSC 533: Programming Languages Spring 2015
Dynamic Compilation Vijay Janapa Reddi
Garbage collection for C
Inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 7 – More Memory Management Lecturer PSOE Dan Garcia
Smalltalk Implementation: Memory Management and Garbage Collection
Dynamic Memory Allocation
Rifat Shahriyar Stephen M. Blackburn Australian National University
Concepts of programming languages
Automatic Memory Management/GC
Automatic Memory Management
Automatic Memory Management/GC
Storage.
Cycle Tracing Chapter 4, pages , From: "Garbage Collection and the Case for High-level Low-level Programming," Daniel Frampton, Doctoral Dissertation,
Ulterior Reference Counting Fast GC Without The Wait
David F. Bacon, Perry Cheng, and V.T. Rajan
Memory Management and Garbage Collection Hal Perkins Autumn 2011
Memory Management Kathryn McKinley.
Created By: Asst. Prof. Ashish Shah, J.M.Patel College, Goregoan West
CS703 - Advanced Operating Systems
Inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 7 – More Memory Management Lecturer PSOE Dan Garcia
Automating Memory Management
CSC 533: Programming Languages Spring 2019
Reference Counting.
Garbage Collection What is garbage and how can we deal with it?
Mooly Sagiv html:// Garbage Collection Mooly Sagiv html://
Presentation transcript:

Strategies for automatic memory management Garbage collection Strategies for automatic memory management

Memory management Explicit memory management: i.e., malloc(..) and free(..) are both explicit. A dangerous source of bugs (dangling pointers, leaks). Performance still varies greatly by implementation. Unsuitable for functional programming. Garbage collection: fully automatic memory management. Complex/many strategies; non-deterministic; pauses.

Reference counting Add a field ref-count to every heap-allocated object. When allocated, set ref-count to 1. Whenever a new (non-transient) reference is established, increment the reference count by 1. Whenever a reference disappears (e.g., when a referring object is freed/reclaimed) decrement the count and check if it’s zero; when it’s zero, reclaim the object. Problem: reference counting is precise but incomplete.

Mark and sweep Invented by McCarthy for LISP in 1960 (1 page) Also called a tracing collector because it follows pointers to mark all reachable objects and then sweeps all others. First identifies a root set. Usually all values on the stack. Then a marking phase traverses the reachable obj graph. Finally a sweeping phase frees all unmarked objects.

Available heap space

Available heap space Call stack (root set)

Available heap space Call stack (root set)

Tagged vs tagless collection How do we know which words of memory are pointers? Some collectors tag the bottom bit of pointers. (Ocaml) Chez Scheme uses runtime type tagging and segregates these types into their own regions. Some collectors exploit static typing to compile linked specialized traversal routines with a function for each type. Some collectors are imprecise (but conservative).

Moving and copying Moving/compacting collectors perform a phase of global defragmentation after each sweep phase. Copying collection maintains two regions: New and Old. As objects are marked, they are copied into New region. All pointers are forwarded. New is defragmented. No need for a free list; New and Old are swapped.

Pointer reversal with copying

Pointer reversal with copying

Pointer reversal with copying

Pointer reversal with copying

Pointer reversal with copying

Pointer reversal with copying alloc ptr Now this becomes the New space. …and this becomes the Old space.

Generational Collection Most objects are short-lived; previous object lifespan is a good predictor of future object lifespan. GC maintains multiple generations; e.g., G0 or nursery space (“eden” in JVM), G1 (“survivor”), G2 (“tenured”), … Minor collections and rarer major collections. For the most part, new objects are only pointed to by other new objects. Where this isn’t true, a store list must be maintained with all mutated references in tenured memory.

Concurrent collection Baker (1981) proposed a pause-free O(1) copying collector. At every allocation of N bytes, the algorithm copies O(N) worth of reachable objects to the New space. Adds significant overhead to read instructions. Concurrent&real-time, but with very poor throughput. VCGC, very concurrent GC (Huelsbergen et al., 1998): Associates objects with epochs, uses them to pipeline mutation/allocation, marking, sweeping.

Conservative collection Boehm–Demers–Weiser GC (or just Boehm GC) “Garbage collection in an uncooperative environment” (Boehm, et al., 1988) Avoids allocating the lowest part of virtual address space. Doesn’t require tagging; aligned values are all pointers. Requires a free list, no moving/copying Go try it out! https://github.com/ivmai/bdwgc