1 Languages and Compilers (SProg og Oversættere) Heap allocation and Garbage Collection.

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.
PZ10B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ10B - Garbage collection Programming Language Design.
Lecture 10: Heap Management CS 540 GMU Spring 2009.
Garbage Collection What is garbage and how can we deal with it?
1 Languages and Compilers (SProg og Oversættere) Lecture 12 Heap Management and Garbage Collection Bent Thomsen Department of Computer Science Aalborg.
CMSC 330: Organization of Programming Languages Memory and Garbage Collection.
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.
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++)
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
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.
CS 1114: Data Structures – memory allocation Prof. Graeme Bailey (notes modified from Noah Snavely, Spring 2009)
Memory Management Professor Yihjia Tsai Tamkang University.
CS 61C L07 More Memory Management (1) Garcia, Fall 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C.
CS 61C L06 Memory Management (1) A Carle, Summer 2006 © UCB inst.eecs.berkeley.edu/~cs61c/su06 CS61C : Machine Structures Lecture #6: Memory Management.
PZ10A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ10A - Heap storage Programming Language Design and.
Bent Thomsen Department of Computer Science Aalborg University
The environment of the computation Declarations introduce names that denote entities. At execution-time, entities are bound to values or to locations:
Linked lists and memory allocation Prof. Noah Snavely CS1114
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.
CS61C L07 More Memory Management (1) Garcia, Spring 2008 © UCB Lecturer SOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C.
SEG Advanced Software Design and Reengineering TOPIC L Garbage Collection Algorithms.
COP4020 Programming Languages
CS3012: Formal Languages and Compilers The Runtime Environment After the analysis phases are complete, the compiler must generate executable code. The.
1 Languages and Compilers (SProg og Oversættere) Lecture 11 Heap Management and Garbage Collection Bent Thomsen Department of Computer Science Aalborg.
Storage Bindings Allocation is the process by which the memory cell or collection of memory cells is assigned to a variable. These cells are taken from.
Storage Management. The stack and the heap Dynamic storage allocation refers to allocating space for variables at run time Most modern languages support.
1 Languages and Compilers (SProg og Oversættere) Lecture 12 Heap Management and Garbage Collection Bent Thomsen Department of Computer Science Aalborg.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. C H A P T E R F I V E Memory Management.
11/26/2015IT 3271 Memory Management (Ch 14) n Dynamic memory allocation Language systems provide an important hidden player: Runtime memory manager – Activation.
PZ10A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, Heap storage Dynamic allocation and stacks are generally.
Heap storage & Garbage collection Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001.
Garbage Collection and Memory Management CS 480/680 – Comparative Languages.
University of Washington Wouldn’t it be nice… If we never had to free memory? Do you free objects in Java? 1.
GARBAGE COLLECTION IN AN UNCOOPERATIVE ENVIRONMENT Hans-Juergen Boehm Computer Science Dept. Rice University, Houston Mark Wieser Xerox Corporation, Palo.
Objects and Variables Local variables – Confined to single context: allocated on stack – Primitive types such as int or object references – Must be initialized.
Memory Management -Memory allocation -Garbage collection.
Runtime Organization (Chapter 6) 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
Introduction to Garbage Collection. Garbage Collection It automatically reclaims memory occupied by objects that are no longer in use It frees the programmer.
Smart Pointers. Dumb Pointers Pointers Necessary – Dynamic memory – Sharing memory.
CS61C L07 More Memory Management (1) Garcia, Spring 2010 © UCB Lecturer SOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C.
Memory Management CSCI 2720 Spring What is memory management? “the prudent utilization of this scarce resource (memory), whether by conservation,
Data Types Chapter 6: Data Types Lectures # 13. Topics Chapter 6: Data Types 2 Introduction Primitive Data Types Character String Types Array Types Associative.
Storage Allocation Mechanisms
Garbage Collection What is garbage and how can we deal with it?
Storage 18-May-18.
Inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 7 – More Memory Management Lecturer PSOE Dan Garcia
Dynamic Memory Allocation
Storage Management.
CS 153: Concepts of Compiler Design November 28 Class Meeting
Concepts of programming languages
Storage.
Smart Pointers.
Strategies for automatic memory management
Chapter 12 Memory Management
Heap storage & Garbage collection
C H A P T E R F I V E Memory Management.
Heap storage & Garbage collection
Garbage collection Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 7 – More Memory Management Lecturer PSOE Dan Garcia
Automating Memory Management
Garbage Collection What is garbage and how can we deal with it?
Presentation transcript:

1 Languages and Compilers (SProg og Oversættere) Heap allocation and Garbage Collection

2 –Why may we need heap allocation? –Garbage collection strategies

3 Heap Storage Memory allocation under explicit programmatic control –C malloc, C++ / Pascal / Java new operation. Memory allocation implicit in language constructs –Lisp, Scheme, Haskel, SML, … most functional languages Deallocation under explicit programmatic control –C, C++, Pascal Deallocation implicit –Java, Lisp, …

4 Stacks and dynamic allocations are incompatible Why can’t we just do dynamic allocation within the stack? Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000

5 How does things become garbage? int *p, *q; … p = malloc(sizeof(int)); p = q; for(int i=0;i<10000;i++){ SomeClass obj= new SomeClass(i); System.out.println(obj); } Newly created space becomes garbage Creates objects, which becomes garbage just after the print

6 Heap Storage Deallocation Explicit versus Implicit Deallocation Examples: Implicit: Java, Scheme Explicit: Pascal and C To free heap memory a specific operation must be called. Pascal ==> dispose C ==> free In explicit memory management, the program must explicitly call an operation to release memory back to the memory management system. In implicit memory management, heap memory is reclaimed automatically by a “garbage collector”.

7 Where to put the heap? ST SB HB HT Stack memory area Heap memory area Stack grows downward Heap can expand upward

8 How to keep track of free memory? Stack is LIFO allocation => ST moves up/down everything above ST is in use/allocated. Below is free memory. This is easy! But … Heap is not LIFO, how to manage free space in the “middle” of the heap? HB HT Allocated ST SB Free Mixed: Allocated and Free reuse?

9 Heap Compaction To fight fragmentation, some memory management algorithms perform “heap compaction” once in a while. HB HT HF a b c HB HT a b d d c beforeafter

10 Classes of Garbage Collection Algorithms Direct Garbage Collectors: a record is associated with each node in the heap. The record for node N indicates how many other nodes or roots point to N. Indirect/Tracing Garbage Collectors: usually invoked when a user’s request for memory fails because the free list is exhausted. The garbage collector visits all live nodes, and returns all other memory to the free list. If sufficient memory has been recovered from this process, the user’s request for memory is satisfied.

11 Types of garbage collectors The “Classic” algorithms –Reference counting –Mark and sweep Copying garbage collection Incremental Tracing garbage collection Generational garbage collection