Compiler Construction

Similar documents
Compiler Construction

Run-time Environments -Part 3

G Programming Languages - Fall 2012

Run-Time Environments/Garbage Collection

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

Garbage Collection Algorithms. Ganesh Bikshandi

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline

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

Programming Languages Third Edition. Chapter 10 Control II Procedures and Environments

CSE 307: Principles of Programming Languages

Compiler Construction

Compiler Construction

Run-time Environments - 3

Storage. Outline. Variables and updating. Copy vs. Ref semantics Lifetime. Dangling References Garbage collection

Garbage Collection (1)

Compiler Construction

CS 480 Fall Runtime Environments. Mike Lam, Professor. (a.k.a. procedure calls and heap management)

Compiler Construction

Compiler Construction

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

Lecture 13: Garbage Collection

Data Types. Outline. In Text: Chapter 6. What is a type? Primitives Strings Ordinals Arrays Records Sets Pointers 5-1. Chapter 6: Data Types 2

CS61C : Machine Structures

CMSC 330: Organization of Programming Languages

Name, Scope, and Binding. Outline [1]

Attributes, Bindings, and Semantic Functions Declarations, Blocks, Scope, and the Symbol Table Name Resolution and Overloading Allocation, Lifetimes,

CMSC 330: Organization of Programming Languages

Lecture 15 Garbage Collection

Data Types In Text: Ch C apter 6 1

Heap, Variables, References, and Garbage. CS152. Chris Pollett. Oct. 13, 2008.

Example. program sort; var a : array[0..10] of integer; procedure readarray; : function partition (y, z :integer) :integer; var i, j,x, v :integer; :

Lecture 13: Complex Types and Garbage Collection

Project. there are a couple of 3 person teams. a new drop with new type checking is coming. regroup or see me or forever hold your peace

Programming Languages Third Edition. Chapter 7 Basic Semantics

CS 345. Garbage Collection. Vitaly Shmatikov. slide 1

Chapter 5. Names, Bindings, and Scopes

Lecture Notes on Garbage Collection

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

Garbage Collection. Weiyuan Li

Programming Language Implementation

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

Storage. Outline. Variables and Updating. Composite Variables. Storables Lifetime : Programming Languages. Course slides - Storage

CS558 Programming Languages

Names, Bindings, Scopes

CS 430 Spring Mike Lam, Professor. Data Types and Type Checking

CS577 Modern Language Processors. Spring 2018 Lecture Garbage Collection

NOTE: Answer ANY FOUR of the following 6 sections:

Types II. Hwansoo Han

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

Compiler Construction Lecture 1: Introduction Winter Semester 2018/19 Thomas Noll Software Modeling and Verification Group RWTH Aachen University

CS61C : Machine Structures

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

Compiler Construction D7011E

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

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

Automatic Memory Management

CS 241 Honors Memory

G Programming Languages - Fall 2012

Garbage Collection. Lecture Compilers SS Dr.-Ing. Ina Schaefer. Software Technology Group TU Kaiserslautern. Ina Schaefer Garbage Collection 1

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

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

Lecture 14. No in-class files today. Homework 7 (due on Wednesday) and Project 3 (due in 10 days) posted. Questions?

Concepts Introduced in Chapter 7

Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types. Record Types. Pointer and Reference Types

Topic IV. Parameters. Chapter 5 of Programming languages: Concepts & constructs by R. Sethi (2ND EDITION). Addison-Wesley, 1996.

Run-time Environments

Run-time Environments

Compiler Construction Lecture 1: Introduction Summer Semester 2017 Thomas Noll Software Modeling and Verification Group RWTH Aachen University

6. Names, Scopes, and Bindings

Topic IV. Block-structured procedural languages Algol and Pascal. References:

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

CS321 Languages and Compiler Design I Winter 2012 Lecture 13

Programmin Languages/Variables and Storage

Garbage Collection Techniques

Garbage Collection. Steven R. Bagley

CS558 Programming Languages

Dynamic Memory Allocation

SE352b: Roadmap. SE352b Software Engineering Design Tools. W3: Programming Paradigms

Fifth Generation CS 4100 LISP. What do we need? Example LISP Program 11/13/13. Chapter 9: List Processing: LISP. Central Idea: Function Application

Garbage Collection. Hwansoo Han

TYPES, VALUES AND DECLARATIONS

Types and Type Inference

Advances in Programming Languages: Regions

Compiler Construction

CS558 Programming Languages

Qualifying Exam in Programming Languages and Compilers

High-Level Language VMs

Structure of Programming Languages Lecture 10

Memory Allocation II. CSE 351 Autumn Instructor: Justin Hsia

Memory Management. Chapter Fourteen Modern Programming Languages, 2nd ed. 1

Class Information ANNOUCEMENTS

Compiler Construction

Programming Languages

Heap Management. Heap Allocation

CS558 Programming Languages

Pierce Ch. 3, 8, 11, 15. Type Systems

CS61C : Machine Structures

CS558 Programming Languages

Memory Allocation. Static Allocation. Dynamic Allocation. Dynamic Storage Allocation. CS 414: Operating Systems Spring 2008

Dynamic Memory Management! Goals of this Lecture!

Transcription:

Compiler Construction Thomas Noll Software Modeling and Verification Group RWTH Aachen University https://moves.rwth-aachen.de/teaching/ss-16/cc/

Recap: Static Data Structures Outline of Lecture 18 Recap: Static Data Structures Pseudo-Dynamic Data Structures Heap Management Memory Deallocation Garbage Collection Reference-Counting Garbage Collection Mark-and-Sweep Garbage Collection 2 of 24 Compiler Construction

Recap: Static Data Structures Modified Syntax of EPL Definition (Modified syntax of EPL) The modified syntax of EPL is defined as follows (where n 1): Z : z (* z is an integer *) B : b ::= true false (* b is a Boolean *) R : r (* r is a real number *) Con : c ::= z b r (* c is a constant *) Ide : I, J (* I, J are identifiers *) Type : T ::= bool int real I array[z 1..z 2 ] of T record I 1 :T 1 ;... ;I n :T n end Var : V ::= I V[E] V.I Exp : E ::= c V E 1 + E 2 E 1 < E 2 E 1 and E 2... Cmd : Dcl : Pgm : C ::= V:=E C 1 ;C 2 if E then C 1 else C 2 while E do C D ::= D C D T D V D C ::= ε const I 1 := c 1 ;... ;I n := c n ; D T ::= ε type I 1 := T 1 ;... ;I n := T n ; D V ::= ε var I 1 : T 1 ;... ;I n : T n ; P ::= D C 3 of 24 Compiler Construction

Pseudo-Dynamic Data Structures Outline of Lecture 18 Recap: Static Data Structures Pseudo-Dynamic Data Structures Heap Management Memory Deallocation Garbage Collection Reference-Counting Garbage Collection Mark-and-Sweep Garbage Collection 4 of 24 Compiler Construction

Pseudo-Dynamic Data Structures Variant Records Example 18.1 (Variant records in Pascal) TYPE Coordinate = RECORD nr: INTEGER; CASE type: (cartesian, polar) OF cartesian: (x, y: REAL); polar: (r : REAL; phi: INTEGER ) END END; VAR pt: Coordinate; pt.type := cartesian; pt.x := 0.5; pt.y := 1.2; 5 of 24 Compiler Construction

Pseudo-Dynamic Data Structures Variant Records Example 18.1 (Variant records in Pascal) TYPE Coordinate = RECORD nr: INTEGER; CASE type: (cartesian, polar) OF cartesian: (x, y: REAL); polar: (r : REAL; phi: INTEGER ) END END; VAR pt: Coordinate; pt.type := cartesian; pt.x := 0.5; pt.y := 1.2; Implementation: Allocate memory for biggest variant Share memory between variant fields 5 of 24 Compiler Construction

Pseudo-Dynamic Data Structures Dynamic Arrays Example 18.2 (Dynamic arrays in Pascal) FUNCTION Sum(VAR a: ARRAY OF REAL): REAL; VAR i: INTEGER; s: REAL; BEGIN s := 0.0; FOR i := 0 to HIGH(a) do s := s + a[i] END; Sum := s END 6 of 24 Compiler Construction

Pseudo-Dynamic Data Structures Dynamic Arrays Example 18.2 (Dynamic arrays in Pascal) FUNCTION Sum(VAR a: ARRAY OF REAL): REAL; VAR i: INTEGER; s: REAL; BEGIN s := 0.0; FOR i := 0 to HIGH(a) do s := s + a[i] END; Sum := s END Implementation: Memory requirements unknown at compile time but determined by actual function/procedure parameters = no heap required Use array descriptor with following fields as parameter value: starting memory address of array size of array lower index of array (possibly fixed by 0) upper index of array (actually redundant) Use data stack or index register to access array elements 6 of 24 Compiler Construction

Heap Management Outline of Lecture 18 Recap: Static Data Structures Pseudo-Dynamic Data Structures Heap Management Memory Deallocation Garbage Collection Reference-Counting Garbage Collection Mark-and-Sweep Garbage Collection 7 of 24 Compiler Construction

Heap Management Dynamic Memory Allocation I Dynamically manipulated data structures (lists, trees, graphs,...) So far: creation of (static) objects by declaration Now: creation of (dynamic) objects by explicit memory allocation Access by (implicit or explicit) pointers Deletion by explicit deallocation or garbage collection (= automatic deallocation of unreachable objects) 8 of 24 Compiler Construction

Heap Management Dynamic Memory Allocation I Dynamically manipulated data structures (lists, trees, graphs,...) So far: creation of (static) objects by declaration Now: creation of (dynamic) objects by explicit memory allocation Access by (implicit or explicit) pointers Deletion by explicit deallocation or garbage collection (= automatic deallocation of unreachable objects) Implementation: runtime stack not sufficient (lifetime of objects generally exceeds lifetime of procedure calls) new data structure: heap Simplest form of organisation: Runtime stack Heap 0 SP (stack pointer) HP max (heap pointer) 8 of 24 Compiler Construction

Heap Management Dynamic Memory Allocation II Runtime stack Heap New instruction: NEW ( malloc,...) allocates n memory cells 0 SP (where n = topmost value of runtime stack) (stack pointer) returns address of first cell formal semantics (SP = stack pointer, HP = heap pointer, <.> = dereferencing): if HP - <SP> > SP then HP := HP - <SP>; <SP> := HP else error("memory overflow") HP max (heap pointer) 9 of 24 Compiler Construction

Heap Management Dynamic Memory Allocation II Runtime stack Heap New instruction: NEW ( malloc,...) allocates n memory cells 0 SP (where n = topmost value of runtime stack) (stack pointer) returns address of first cell formal semantics (SP = stack pointer, HP = heap pointer, <.> = dereferencing): if HP - <SP> > SP then HP := HP - <SP>; <SP> := HP else error("memory overflow") But: collision check required for every operation which increases SP (e.g., expression evaluations) Efficient solution: add extreme stack pointer EP points to topmost SP which will be used in the computation of current procedure statically computable at compile time set by procedure entry code modified semantics of NEW: if HP - <SP> > EP then HP := HP - <SP>; <SP> := HP else error("memory overflow") HP max (heap pointer) 9 of 24 Compiler Construction

Memory Deallocation Outline of Lecture 18 Recap: Static Data Structures Pseudo-Dynamic Data Structures Heap Management Memory Deallocation Garbage Collection Reference-Counting Garbage Collection Mark-and-Sweep Garbage Collection 10 of 24 Compiler Construction

Memory Deallocation Memory Deallocation Releasing memory areas that have become unused explicitly by programmer automatically by runtime system (garbage collection) 11 of 24 Compiler Construction

Memory Deallocation Memory Deallocation Releasing memory areas that have become unused explicitly by programmer automatically by runtime system (garbage collection) Management of deallocated memory areas by free list (usually doubly-linked list) goal: reduction of fragmentation (= heap memory split in large number of non-contiguous free areas) coalescing of contiguous areas allocation strategies: first-fit vs. best-fit 11 of 24 Compiler Construction

Memory Deallocation Explicit Deallocation Manually releasing memory areas that have become unused Pascal: dispose C: free 12 of 24 Compiler Construction

Memory Deallocation Explicit Deallocation Manually releasing memory areas that have become unused Pascal: dispose C: free Problems with manual deallocation: memory leaks: failing to eventually delete data that cannot be referenced anymore critical for long-running/reactive programs (operating systems, server code,...) dangling pointer dereference ( use after free ): referencing of deleted data may lead to runtime error (if deallocated pointer reset to nil) or produce side effects (if deallocated pointer keeps value and storage reallocated) 12 of 24 Compiler Construction

Memory Deallocation Explicit Deallocation Manually releasing memory areas that have become unused Pascal: dispose C: free Problems with manual deallocation: memory leaks: failing to eventually delete data that cannot be referenced anymore critical for long-running/reactive programs (operating systems, server code,...) dangling pointer dereference ( use after free ): referencing of deleted data may lead to runtime error (if deallocated pointer reset to nil) or produce side effects (if deallocated pointer keeps value and storage reallocated) Adopt programming conventions (object ownership) or use automatic deallocation 12 of 24 Compiler Construction

Garbage Collection Outline of Lecture 18 Recap: Static Data Structures Pseudo-Dynamic Data Structures Heap Management Memory Deallocation Garbage Collection Reference-Counting Garbage Collection Mark-and-Sweep Garbage Collection 13 of 24 Compiler Construction

Garbage Collection Garbage Collection Garbage = data that cannot be referenced (anymore) Garbage collection = automatic deallocation of unreachable data 14 of 24 Compiler Construction

Garbage Collection Garbage Collection Garbage = data that cannot be referenced (anymore) Garbage collection = automatic deallocation of unreachable data Supported by many programming languages: object-oriented: Java, Smalltalk functional: Lisp (first GC), ML, Haskell logic: Prolog scripting: Perl 14 of 24 Compiler Construction

Garbage Collection Garbage Collection Garbage = data that cannot be referenced (anymore) Garbage collection = automatic deallocation of unreachable data Supported by many programming languages: object-oriented: Java, Smalltalk functional: Lisp (first GC), ML, Haskell logic: Prolog scripting: Perl Design goals for garbage collectors: execution time: no significant increase of application runtime space usage: avoid memory fragmentation pause time: minimise maximal pause time of application program caused by garbage collection (especially in real-time applications) 14 of 24 Compiler Construction

Garbage Collection Preliminaries Object = allocated entity Object has type known at runtime, defining size of object references to other objects = excludes type-unsafe languages that allow manipulation of pointers (C, C++) 15 of 24 Compiler Construction

Garbage Collection Preliminaries Object = allocated entity Object has type known at runtime, defining size of object references to other objects = excludes type-unsafe languages that allow manipulation of pointers (C, C++) Reference always to address at beginning of object ( = all references to an object have same value) 15 of 24 Compiler Construction

Garbage Collection Preliminaries Object = allocated entity Object has type known at runtime, defining size of object references to other objects = excludes type-unsafe languages that allow manipulation of pointers (C, C++) Reference always to address at beginning of object ( = all references to an object have same value) Mutator = application program modifying objects in heap creation of objects by acquiring storage introduce/drop references to existing objects Objects become garbage when not (indirectly) reachable by mutator 15 of 24 Compiler Construction

Garbage Collection Reachability of Objects Root set = heap data that is directly accessible by mutator for Java: static field members and variables on stack yields directly reachable objects Every object with a reference that is stored in a reachable object is indirectly reachable 16 of 24 Compiler Construction

Garbage Collection Reachability of Objects Root set = heap data that is directly accessible by mutator for Java: static field members and variables on stack yields directly reachable objects Every object with a reference that is stored in a reachable object is indirectly reachable Mutator operations that affect reachability: object allocation: memory manager returns reference to new object creates new reachable object parameter passing and return values: passing of object references from calling site to called procedure or vice versa propagates reachability of objects reference assignment: assignments p := q with references p and q creates second reference to object referred to by q, propagating reachability destroys orginal reference in p, potentially causing unreachability procedure return: removes local variables potentially causes unreachability of objects 16 of 24 Compiler Construction

Garbage Collection Reachability of Objects Root set = heap data that is directly accessible by mutator for Java: static field members and variables on stack yields directly reachable objects Every object with a reference that is stored in a reachable object is indirectly reachable Mutator operations that affect reachability: object allocation: memory manager returns reference to new object creates new reachable object parameter passing and return values: passing of object references from calling site to called procedure or vice versa propagates reachability of objects reference assignment: assignments p := q with references p and q creates second reference to object referred to by q, propagating reachability destroys orginal reference in p, potentially causing unreachability procedure return: removes local variables potentially causes unreachability of objects Objects becoming unreachable can cause more objects to become unreachable 16 of 24 Compiler Construction

Garbage Collection Identifying Unreachable Objects Principal approaches: Catch program steps that turn reachable into unreachable objects = reference counting Periodically locate all reachable objects; others then unreachable = mark-and-sweep 17 of 24 Compiler Construction

Reference-Counting Garbage Collection Outline of Lecture 18 Recap: Static Data Structures Pseudo-Dynamic Data Structures Heap Management Memory Deallocation Garbage Collection Reference-Counting Garbage Collection Mark-and-Sweep Garbage Collection 18 of 24 Compiler Construction

Reference-Counting Garbage Collection Reference-Counting Garbage Collectors I Working principle Add reference count field to each heap object (= number of references to that object) 19 of 24 Compiler Construction

Reference-Counting Garbage Collection Reference-Counting Garbage Collectors I Working principle Add reference count field to each heap object (= number of references to that object) Mutator operations maintain reference count: object allocation: set reference count of new object to 1 parameter passing: increment reference count of each object passed to procedure reference assignment p := q: decrement/increment reference count of object referred to by p/q procedure return: decrement reference count of each object that a local variable refers to (multiple decrement if sharing) 19 of 24 Compiler Construction

Reference-Counting Garbage Collection Reference-Counting Garbage Collectors I Working principle Add reference count field to each heap object (= number of references to that object) Mutator operations maintain reference count: object allocation: set reference count of new object to 1 parameter passing: increment reference count of each object passed to procedure reference assignment p := q: decrement/increment reference count of object referred to by p/q procedure return: decrement reference count of each object that a local variable refers to (multiple decrement if sharing) Moreover: transitive loss of reachability when reference count of object becomes zero = decrement reference count of each object pointed to (and add object storage to free list) 19 of 24 Compiler Construction

Reference-Counting Garbage Collection Reference-Counting Garbage Collectors I Working principle Add reference count field to each heap object (= number of references to that object) Mutator operations maintain reference count: object allocation: set reference count of new object to 1 parameter passing: increment reference count of each object passed to procedure reference assignment p := q: decrement/increment reference count of object referred to by p/q procedure return: decrement reference count of each object that a local variable refers to (multiple decrement if sharing) Moreover: transitive loss of reachability when reference count of object becomes zero = decrement reference count of each object pointed to (and add object storage to free list) Example 18.3 (on the board) 19 of 24 Compiler Construction

Reference-Counting Garbage Collection Reference-Counting Garbage Collectors II Advantage: Incrementality collector operations spread over mutator s computation short pause times (good for real-time/interactive applications) immediate collection of garbage (low space usage) exception: transitive loss of reachability (reference removal may produce further garbage) but: recursive modification can be deferred 20 of 24 Compiler Construction

Reference-Counting Garbage Collection Reference-Counting Garbage Collectors II Advantage: Incrementality collector operations spread over mutator s computation short pause times (good for real-time/interactive applications) immediate collection of garbage (low space usage) exception: transitive loss of reachability (reference removal may produce further garbage) but: recursive modification can be deferred Disadvantages Incompleteness: cannot collect unreachable cyclic data structures (cf. Example 18.3) High overhead: additional operations for assignments and procedure calls/exits proportional to number of mutator steps (and not to number of heap objects) 20 of 24 Compiler Construction

Reference-Counting Garbage Collection Reference-Counting Garbage Collectors II Advantage: Incrementality collector operations spread over mutator s computation short pause times (good for real-time/interactive applications) immediate collection of garbage (low space usage) exception: transitive loss of reachability (reference removal may produce further garbage) but: recursive modification can be deferred Disadvantages Incompleteness: cannot collect unreachable cyclic data structures (cf. Example 18.3) High overhead: additional operations for assignments and procedure calls/exits proportional to number of mutator steps (and not to number of heap objects) Conclusion Use for real-time/interactive applications 20 of 24 Compiler Construction

Mark-and-Sweep Garbage Collection Outline of Lecture 18 Recap: Static Data Structures Pseudo-Dynamic Data Structures Heap Management Memory Deallocation Garbage Collection Reference-Counting Garbage Collection Mark-and-Sweep Garbage Collection 21 of 24 Compiler Construction

Mark-and-Sweep Garbage Collection Mark-and-Sweep Garbage Collectors I Working principle Mutator runs and makes allocation requests Collector runs periodically (typically when space exhausted/below critical threshold) computes set of reachable objects reclaims storage for objects in complement set 22 of 24 Compiler Construction

Mark-and-Sweep Garbage Collection Mark-and-Sweep Garbage Collectors II Algorithm 18.4 (Mark-and-sweep garbage collection) Input: heap Heap, root set Root, free list Free 23 of 24 Compiler Construction

Mark-and-Sweep Garbage Collection Mark-and-Sweep Garbage Collectors II Algorithm 18.4 (Mark-and-sweep garbage collection) Input: heap Heap, root set Root, free list Free Procedure: 1. (* Marking phase *) for each o in Heap, let r o := true iff o referenced by Root (* initialise r flags *) 2. let W := {o r o = true} (* working set *) 3. while o W do i. let W := W \ {o} ii. for each o referenced by o with r o = false, let r o = true; W := W {o } 4. (* Sweeping phase *) for each o in Heap with r o = false, add o to Free 23 of 24 Compiler Construction

Mark-and-Sweep Garbage Collection Mark-and-Sweep Garbage Collectors II Algorithm 18.4 (Mark-and-sweep garbage collection) Input: heap Heap, root set Root, free list Free Procedure: 1. (* Marking phase *) for each o in Heap, let r o := true iff o referenced by Root (* initialise r flags *) 2. let W := {o r o = true} (* working set *) 3. while o W do i. let W := W \ {o} ii. for each o referenced by o with r o = false, let r o = true; W := W {o } 4. (* Sweeping phase *) for each o in Heap with r o = false, add o to Free Output: modified free list 23 of 24 Compiler Construction

Mark-and-Sweep Garbage Collection Mark-and-Sweep Garbage Collectors II Algorithm 18.4 (Mark-and-sweep garbage collection) Input: heap Heap, root set Root, free list Free Procedure: 1. (* Marking phase *) for each o in Heap, let r o := true iff o referenced by Root (* initialise r flags *) 2. let W := {o r o = true} (* working set *) 3. while o W do i. let W := W \ {o} ii. for each o referenced by o with r o = false, let r o = true; W := W {o } 4. (* Sweeping phase *) for each o in Heap with r o = false, add o to Free Output: modified free list Example 18.5 (on the board) 23 of 24 Compiler Construction

Mark-and-Sweep Garbage Collection Mark-and-Sweep Garbage Collectors III Advantages Completeness: identifies all unreachable objects Time complexity proportional to number of objects in heap 24 of 24 Compiler Construction

Mark-and-Sweep Garbage Collection Mark-and-Sweep Garbage Collectors III Advantages Completeness: identifies all unreachable objects Time complexity proportional to number of objects in heap Disadvantage: stop-the-world style May introduce long pauses into mutator execution (sweeping inspects complete heap) 24 of 24 Compiler Construction

Mark-and-Sweep Garbage Collection Mark-and-Sweep Garbage Collectors III Advantages Completeness: identifies all unreachable objects Time complexity proportional to number of objects in heap Disadvantage: stop-the-world style May introduce long pauses into mutator execution (sweeping inspects complete heap) Conclusion: refine to short-pause garbage collection Incremental collection: divide work in time by interleaving mutation and collection Partial collection: divide work in space by collecting subset of garbage at a time see Chapter 7 of A.V. Aho, M.S. Lam, R. Sethi, J.D. Ullman: Compilers Principles, Techniques, and Tools; 2nd ed., Addison-Wesley, 2007 24 of 24 Compiler Construction