Garbage Collection  records not reachable  reclaim to allow reuse  performed by runtime system (support programs linked with the compiled code) (support.

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

Introduction to Memory Management. 2 General Structure of Run-Time Memory.
Garbage Collection Introduction What is garbage and how can we deal with it? Garbage collection schemes Reference Counting Mark and Sweep Stop and Copy.
CMSC 330: Organization of Programming Languages Memory and Garbage Collection.
Lecture 10: Heap Management CS 540 GMU Spring 2009.
Garbage Collection What is garbage and how can we deal with it?
CMSC 330: Organization of Programming Languages Memory and Garbage Collection.
Compiler construction in4020 – lecture 12 Koen Langendoen Delft University of Technology The Netherlands.
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++)
Run-time organization  Data representation  Storage organization: –stack –heap –garbage collection Programming Languages 3 © 2012 David A Watt,
Garbage Collection CSCI 2720 Spring Static vs. Dynamic Allocation Early versions of Fortran –All memory was static C –Mix of static and dynamic.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 18.
CPSC 388 – Compiler Design and Construction
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.
Garbage Collection Mooly Sagiv html://
Memory Management Professor Yihjia Tsai Tamkang University.
Memory Management Chapter 5 Mooly Sagiv
© Richard Jones, Eric Jul, mmnet GC & MM Summer School, July A Rapid Introduction to Garbage Collection Richard Jones Computing Laboratory.
Runtime The optimized program is ready to run … What sorts of facilities are available at runtime.
Garbage collection David Walker CS 320. Where are we? Last time: A survey of common garbage collection techniques –Manual memory management –Reference.
Incremental Garbage Collection
Compilation 2007 Garbage Collection Michael I. Schwartzbach BRICS, University of Aarhus.
Garbage collection (& Midterm Topics) David Walker COS 320.
Garbage Collection Mooly Sagiv
Uniprocessor Garbage Collection Techniques Paul R. Wilson.
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.
Using Generational Garbage Collection To Implement Cache- conscious Data Placement Trishul M. Chilimbi & James R. Larus מציג : ראובן ביק.
UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.
Garbage Collection Memory Management Garbage Collection –Language requirement –VM service –Performance issue in time and space.
1 Overview Assignment 6: hints  Living with a garbage collector Assignment 5: solution  Garbage collection.
Memory Management Last Update: July 31, 2014 Memory Management1.
SEG Advanced Software Design and Reengineering TOPIC L Garbage Collection Algorithms.
Chapter 7 Run-Time Environments
CS3012: Formal Languages and Compilers The Runtime Environment After the analysis phases are complete, the compiler must generate executable code. The.
GC Algorithm inside.NET Luo Bingqiao 5/22/2009. Agenda 1. 经典基本垃圾回收算法 2.CLR 中垃圾回收算法介绍 3.SSCLI 中 Garbage Collection 源码分析.
Simulated Pointers Limitations Of Java Pointers May be used for internal data structures only. Data structure backup requires serialization and deserialization.
Incremental Garbage Collection Uwe Kern 23. Januar 2002
Runtime Environments. Support of Execution  Activation Tree  Control Stack  Scope  Binding of Names –Data object (values in storage) –Environment.
OOPLs /FEN March 2004 Object-Oriented Languages1 Object-Oriented Languages - Design and Implementation Java: Behind the Scenes Finn E. Nordbjerg,
Compilation (Semester A, 2013/14) Lecture 13b: Memory Management Noam Rinetzky Slides credit: Eran Yahav 1.
CSE 425: Control Abstraction I Functions vs. Procedures It is useful to differentiate functions vs. procedures –Procedures have side effects but usually.
UniProcessor Garbage Collection Techniques Paul R. Wilson University of Texas Presented By Naomi Sapir Tel-Aviv University.
University of Washington Wouldn’t it be nice… If we never had to free memory? Do you free objects in Java? 1.
More Distributed Garbage Collection DC4 Reference Listing Distributed Mark and Sweep Tracing in Groups.
Memory Management -Memory allocation -Garbage collection.
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.
2/4/20161 GC16/3011 Functional Programming Lecture 20 Garbage Collection Techniques.
Simulated Pointers Limitations Of C++ Pointers May be used for internal data structures only. Data structure backup requires serialization and deserialization.
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.
Runtime Environments Chapter 7. Support of Execution  Activation Tree  Control Stack  Scope  Binding of Names –Data object (values in storage) –Environment.
Memory Management CSCI 2720 Spring What is memory management? “the prudent utilization of this scarce resource (memory), whether by conservation,
Eliminating External Fragmentation in a Non-Moving Garbage Collector for Java Author: Fridtjof Siebert, CASES 2000 Michael Sallas Object-Oriented Languages.
Garbage Collection What is garbage and how can we deal with it?
Dynamic Compilation Vijay Janapa Reddi
Dynamic Memory Allocation
Concepts of programming languages
Smart Pointers.
Simulated Pointers.
Strategies for automatic memory management
Binding Times Binding is an association between two things Examples:
Chapter 12 Memory Management
CS703 - Advanced Operating Systems
Automating Memory Management
Run-time environments
Reference Counting.
Garbage Collection What is garbage and how can we deal with it?
Presentation transcript:

Garbage Collection  records not reachable  reclaim to allow reuse  performed by runtime system (support programs linked with the compiled code) (support programs linked with the compiled code)

Record Types  live – will be used in the future  not live – will not be used in the future  reachable – able to be accessed via programs

Types of Algorithms  Mark-And-Sweep Collection  Reference Counts  Copying Collection  Generational Collection  Incremental Collection  Baker’s Algorithm

Mark-And-Sweep Collection  Program variables and heap records form a directed graph  Roots are the variables  node n is reachable if r -> … -> n r -> … -> n  Depth first search marks reachable nodes  Any node not marked is garbage

Cost of Garbage Collection  Depth first search takes time proportional to the number of reachable nodes  Sweep phase takes time proportional to the size of the heap

Maintaining Free Space  Create a list of free space  Search for a space of size N might be long  Maintain several free lists of differing sizes  External fragmentation a problem  Internal fragmentation can also be a problem

Reference Counts  Count the number of pointers point to each record  Store the reference count with each record  If p addresses an alternate record, decrement the old and increment the new  If count reaches 0, free record

When to Decrement Instead of decrementing the counts a record references when the record is placed on the free list, it is better to do this when the record is removed from the free list. Instead of decrementing the counts a record references when the record is placed on the free list, it is better to do this when the record is removed from the free list.

Why  Breaks the recursive decrementing work into shorter pieces  Compiler emits code to check whether the count has reached 0, but the recursive decrementing will be done only in one place, in the allocator

Problems with Reference Count  Cycles of garbage cannot be reclaimed  Incrementing the reference counts is very expensive

Solutions-Cycles, Expensive  Require the programmer to break the cycle  Combine reference counting with mark-sweep  No solution for it being expensive  Problems outweigh advantages, thus rarely used

Copying Collection  Reachable part is a directed graph with records as nodes, pointers as edges, and variables as roots  Copy the graph from “from-space” to “to-space”  Delete all “from-space”qq