SlideShare a Scribd company logo
1 of 61
Garbage Collection
Introduction and Overview
Christian Schulte
Programming Systems Lab
Universität des Saarlandes, Germany
schulte@ps.uni-sb.de
Purpose of Talk
 Explaining basic
 concepts
 terminology
 Garbage collection…
 …is simple
 …can be explained at a high-level
 Organization
Purpose of Talk
 Explaining basic
 concepts
 terminology
(never to be explained again)
 Garbage collection…
 …is simple
 …can be explained at a high-level
 Organization
Overview
 What is garbage collection
 objects of interest
 principal notions
 classic examples with assumptions and properties
 Discussion
 software engineering issues
 typical cost
 areas of usage
 why knowledge is profitable
 Organizational
 Material
 Requirements
Overview
 What is garbage collection
 objects of interest
 principal notions
 classic examples with assumptions and properties
 Discussion
 software engineering issues
 typical cost
 areas of usage
 why knowledge is profitable
 Organizational
 Material
 Requirements
Garbage Collection…
…is concerned with the automatic
reclamation of dynamically allocated
memory after its last use by a program
Garbage Collection…
 dynamically allocated memory
…is concerned with the automatic
reclamation of dynamically allocated
memory after its last use by a program
Garbage Collection…
 dynamically allocated memory
 last use by a program
…is concerned with the automatic
reclamation of dynamically allocated
memory after its last use by a program
Garbage Collection…
 dynamically allocated memory
 last use by a program
 automatic reclamation
…is concerned with the automatic
reclamation of dynamically allocated
memory after its last use by a program
Garbage collection…
 Dynamically allocated memory
 Last use by a program
 Examples for automatic reclamation
Kinds of Memory Allocation
static int i;
void foo(void) {
int j;
int* p = (int*) malloc(…);
}
Static Allocation
 By compiler (in text area)
 Available through entire runtime
 Fixed size
static int i;
void foo(void) {
int j;
int* p = (int*) malloc(…);
}
Automatic Allocation
 Upon procedure call (on stack)
 Available during execution of call
 Fixed size
static int i;
void foo(void) {
int j;
int* p = (int*) malloc(…);
}
Dynamic Allocation
 Dynamically allocated at runtime (on heap)
 Available until explicitly deallocated
 Dynamically varying size
static int i;
void foo(void) {
int j;
int* p = (int*) malloc(…);
}
Dynamically Allocated Memory
 Also: heap-allocated memory
 Allocation: malloc, new, …
 before first usage
 Deallocation: free, delete, dispose, …
 after last usage
 Needed for
 C++, Java: objects
 SML: datatypes, procedures
 anything that outlives procedure call
Getting it Wrong
 Forget to free (memory leak)
 program eventually runs out of memory
 long running programs: OSs. servers, …
 Free to early (dangling pointer)
 lucky: illegal access detected by OS
 horror: memory reused, in simultaneous use
 programs can behave arbitrarily
 crashes might happen much later
 Estimates of effort
 Up to 40%! [Rovner, 1985]
Nodes and Pointers
 Node n
 Memory block, cell
 Pointer p
 Link to node
 Node access: *p
 Children children(n)
 set of pointers to nodes referred by n
n
p
Mutator
 Abstraction of program
 introduces new nodes with pointer
 redirects pointers, creating garbage
 Nodes referred to by several pointers
 Makes manual deallocation hard
 local decision impossible
 respect other pointers to node
 Cycles instance of sharing
Shared Nodes
Garbage collection…
 Dynamically allocated memory
 Last use by a program
 Examples for automatic reclamation
Last Use by a Program
 Question: When is node M not any longer
used by program?
 Let P be any program not using M
 New program sketch:
Execute P; Use M;
 Hence:
M used  P terminates
 We are doomed: halting problem!
 So “last use” undecidable!
Safe Approximation
 Decidable and also simple
 What means safe?
 only unused nodes freed
 What means approximation?
 some unused nodes might not be freed
 Idea
 nodes that can be accessed by mutator
Reachable Nodes
 Reachable from root set
 processor registers
 static variables
 automatic variables (stack)
 Reachable from reachable nodes
root
Summary: Reachable Nodes
 A node n is reachable, iff
 n is element of the root set, or
 n is element of children(m) and m is
reachable
 Reachable node also called “live”
MyGarbageCollector
 Compute set of reachable nodes
 Free nodes known to be not reachable
 Known as mark-sweep
 in a second…
Reachability:
Safe Approximation
 Safe
 access to not reachable node impossible
 depends on language semantics
 but C/C++? later…
 Approximation
 reachable node might never be accessed
 programmer must know about this!
 have you been aware of this?
Garbage collection…
 Dynamically allocated memory
 Last use by a program
 Examples for automatic reclamation
Example Garbage Collectors
 Mark-Sweep
 Others
 Mark-Compact
 Reference Counting
 Copying
 skipped here
 read Chapter 1&2 of [Lins&Jones,96]
The Mark-Sweep Collector
 Compute reachable nodes: Mark
 tracing garbage collector
 Free not reachable nodes: Sweep
 Run when out of memory: Allocation
 First used with LISP [McCarthy, 1960]
Allocation
node* new() {
if (free_pool is empty)
mark_sweep();
…
Allocation
node* new() {
if (free_pool is empty)
mark_sweep();
return allocate();
}
The Garbage Collector
void mark_sweep() {
for (r in roots)
mark(r);
…
The Garbage Collector
void mark_sweep() {
for (r in roots)
mark(r);
…
all live nodes
marked
Recursive Marking
void mark(node* n) {
if (!is_marked(n)) {
set_mark(n);
…
}
}
Recursive Marking
void mark(node* n) {
if (!is_marked(n)) {
set_mark(n);
…
}
}
nodes reachable
from n marked
Recursive Marking
void mark(node* n) {
if (!is_marked(n)) {
set_mark(n);
for (m in children(n))
mark(m);
}
}
i-th recursion: nodes
on path with length i
marked
The Garbage Collector
void mark_sweep() {
for (r in roots)
mark(r);
sweep();
…
The Garbage Collector
void mark_sweep() {
for (r in roots)
mark(r);
sweep();
…
all nodes on heap
live
The Garbage Collector
void mark_sweep() {
for (r in roots)
mark(r);
sweep();
…
all nodes on heap
live
and not marked
Eager Sweep
void sweep() {
node* n = heap_bottom;
while (n < heap_top) {
…
}
}
Eager Sweep
void sweep() {
node* n = heap_bottom;
while (n < heap_top) {
if (is_marked(n)) clear_mark(n);
else free(n);
n += sizeof(*n);
}
}
The Garbage Collector
void mark_sweep() {
for (r in roots)
mark(r);
sweep();
if (free_pool is empty)
abort(“Memory exhausted”);
}
Assumptions
 Nodes can be marked
 Size of nodes known
 Heap contiguous
 Memory for recursion available
 Child fields known!
Assumptions: Realistic
 Nodes can be marked
 Size of nodes known
 Heap contiguous
 Memory for recursion available
 Child fields known
Assumptions: Conservative
 Nodes can be marked
 Size of nodes known
 Heap contiguous
 Memory for recursion available
 Child fields known
Mark-Sweep Properties
 Covers cycles and sharing
 Time depends on
 live nodes (mark)
 live and garbage nodes (sweep)
 Computation must be stopped
 non-interruptible stop/start collector
 long pause
 Nodes remain unchanged (as not moved)
 Heap remains fragmented
Variations of Mark-Sweep
 In your talk…
Implementation
 In your talk…
Efficiency Analysis
 In your talk…
Comparison
 In your talk…
Application
 In your talk…
Overview
 What is garbage collection
 objects of interest
 principal invariant
 classic examples with assumptions and properties
 Discussion
 software engineering issues
 typical cost
 areas of usage
 why knowledge is profitable
 Organizational
 Material
 Requirements
Software Engineering Issues
 Design goal in SE:
 decompose systems
 in orthogonal components
 Clashes with letting each component
do its memory management
 liveness is global property
 leads to “local leaks”
 lacking power of modern gc methods
Typical Cost
 Early systems (LISP)
up to 40% [Steele,75] [Gabriel,85]
 “garbage collection is expensive” myth
 Well engineered system of today
10% of entire runtime [Wilson, 94]
Areas of Usage
 Programming languages and systems
 Java, C#, Smalltalk, …
 SML, Lisp, Scheme, Prolog, …
 Modula 3, Microsoft .NET
 Extensions
 C, C++ (Conservative)
 Other systems
 Adobe Photoshop
 Unix filesystem
 Many others in [Wilson, 1996]
Understanding Garbage
Collection: Benefits
 Programming garbage collection
 programming systems
 operating systems
 Understand systems with garbage collection
(e.g. Java)
 memory requirements of programs
 performance aspects of programs
 interfacing with garbage collection (finalization)
Overview
 What is garbage collection
 objects of interest
 principal invariant
 classic examples with assumptions and properties
 Discussion
 software engineering issues
 typical cost
 areas of usage
 why knowledge is profitable
 Organizational
 Material
 Requirements
Material
 Garbage Collection. Richard Jones
and Rafael Lins, John Wiley & Sons,
1996.
 Uniprocessor garbage collection
techniques. Paul R. Wilson, ACM
Computing Surveys. To appear.
 Extended version of IWMM 92, St. Malo.
Organization
 Requirements
 Talk
 duration 45 min (excluding discussion)
 Attendance
 including discussion
 Written summary
 10 pages
 to be submitted in PDF until Mar 31st, 2002
 Schedule
 weekly
 starting Nov 14th, 2001
 next on Dec 5th, 2001
Topics For You!
 The classical methods
 Copying 1. [Brunklaus, Guido
Tack]
 Mark-Sweep 2. [Schulte, Hagen
Böhm]
 Mark-Compact 3. [Schulte, Jens Regenberg]
 Reference Counting 6. [Brunklaus, Regis
Newo]
 Advanced
 Generational 4. [Brunklaus, Mirko
Jerrentrup]
 Conservative (C/C++) 5. [Schulte, Stephan
Lesch]
 Incremental & Concurrent 7. [Brunklaus, Uwe Kern]
Invariants
 Only nodes with rc zero are freed
 RC always positive

More Related Content

Similar to garbage collection in c ++.ppt

.NET Fest 2018. Maarten Balliauw. Let’s refresh our memory! Memory management...
.NET Fest 2018. Maarten Balliauw. Let’s refresh our memory! Memory management....NET Fest 2018. Maarten Balliauw. Let’s refresh our memory! Memory management...
.NET Fest 2018. Maarten Balliauw. Let’s refresh our memory! Memory management...NETFest
 
Exploring .NET memory management - JetBrains webinar
Exploring .NET memory management - JetBrains webinarExploring .NET memory management - JetBrains webinar
Exploring .NET memory management - JetBrains webinarMaarten Balliauw
 
14.jun.2012
14.jun.201214.jun.2012
14.jun.2012Tech_MX
 
Eclipse Memory Analyzer - More Than Just a Heap Walker
Eclipse Memory Analyzer - More Than Just a Heap WalkerEclipse Memory Analyzer - More Than Just a Heap Walker
Eclipse Memory Analyzer - More Than Just a Heap Walkerguest62fd60c
 
LISP: How I Learned To Stop Worrying And Love Parantheses
LISP: How I Learned To Stop Worrying And Love ParanthesesLISP: How I Learned To Stop Worrying And Love Parantheses
LISP: How I Learned To Stop Worrying And Love ParanthesesDominic Graefen
 
SCAM 2012 Keynote Slides on Cooperative Testing and Analysis by Tao Xie
SCAM 2012 Keynote Slides on Cooperative Testing and Analysis by Tao XieSCAM 2012 Keynote Slides on Cooperative Testing and Analysis by Tao Xie
SCAM 2012 Keynote Slides on Cooperative Testing and Analysis by Tao XieTao Xie
 
Debugging With Id
Debugging With IdDebugging With Id
Debugging With Idguest215c4e
 
Eclipse Memory Analyzer
Eclipse Memory AnalyzerEclipse Memory Analyzer
Eclipse Memory Analyzernayashkova
 
DieHard: Probabilistic Memory Safety for Unsafe Languages
DieHard: Probabilistic Memory Safety for Unsafe LanguagesDieHard: Probabilistic Memory Safety for Unsafe Languages
DieHard: Probabilistic Memory Safety for Unsafe LanguagesEmery Berger
 
ScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyTypesafe
 
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Ovidiu Farauanu
 
Linux binary analysis and exploitation
Linux binary analysis and exploitationLinux binary analysis and exploitation
Linux binary analysis and exploitationDharmalingam Ganesan
 
Data analysis in R
Data analysis in RData analysis in R
Data analysis in RAndrew Lowe
 
Quantifying the Performance of Garbage Collection vs. Explicit Memory Management
Quantifying the Performance of Garbage Collection vs. Explicit Memory ManagementQuantifying the Performance of Garbage Collection vs. Explicit Memory Management
Quantifying the Performance of Garbage Collection vs. Explicit Memory ManagementEmery Berger
 
JetBrains Day Seoul - Exploring .NET’s memory management – a trip down memory...
JetBrains Day Seoul - Exploring .NET’s memory management – a trip down memory...JetBrains Day Seoul - Exploring .NET’s memory management – a trip down memory...
JetBrains Day Seoul - Exploring .NET’s memory management – a trip down memory...Maarten Balliauw
 
D3, TypeScript, and Deep Learning
D3, TypeScript, and Deep LearningD3, TypeScript, and Deep Learning
D3, TypeScript, and Deep LearningOswald Campesato
 
D3, TypeScript, and Deep Learning
D3, TypeScript, and Deep LearningD3, TypeScript, and Deep Learning
D3, TypeScript, and Deep LearningOswald Campesato
 
Designing A Project Using Java Programming
Designing A Project Using Java ProgrammingDesigning A Project Using Java Programming
Designing A Project Using Java ProgrammingKaty Allen
 
VRP2013 - Comp Aspects VRP
VRP2013 - Comp Aspects VRPVRP2013 - Comp Aspects VRP
VRP2013 - Comp Aspects VRPVictor Pillac
 

Similar to garbage collection in c ++.ppt (20)

.NET Fest 2018. Maarten Balliauw. Let’s refresh our memory! Memory management...
.NET Fest 2018. Maarten Balliauw. Let’s refresh our memory! Memory management....NET Fest 2018. Maarten Balliauw. Let’s refresh our memory! Memory management...
.NET Fest 2018. Maarten Balliauw. Let’s refresh our memory! Memory management...
 
Exploring .NET memory management - JetBrains webinar
Exploring .NET memory management - JetBrains webinarExploring .NET memory management - JetBrains webinar
Exploring .NET memory management - JetBrains webinar
 
14.jun.2012
14.jun.201214.jun.2012
14.jun.2012
 
Eclipse Memory Analyzer - More Than Just a Heap Walker
Eclipse Memory Analyzer - More Than Just a Heap WalkerEclipse Memory Analyzer - More Than Just a Heap Walker
Eclipse Memory Analyzer - More Than Just a Heap Walker
 
LISP: How I Learned To Stop Worrying And Love Parantheses
LISP: How I Learned To Stop Worrying And Love ParanthesesLISP: How I Learned To Stop Worrying And Love Parantheses
LISP: How I Learned To Stop Worrying And Love Parantheses
 
Software Security
Software SecuritySoftware Security
Software Security
 
SCAM 2012 Keynote Slides on Cooperative Testing and Analysis by Tao Xie
SCAM 2012 Keynote Slides on Cooperative Testing and Analysis by Tao XieSCAM 2012 Keynote Slides on Cooperative Testing and Analysis by Tao Xie
SCAM 2012 Keynote Slides on Cooperative Testing and Analysis by Tao Xie
 
Debugging With Id
Debugging With IdDebugging With Id
Debugging With Id
 
Eclipse Memory Analyzer
Eclipse Memory AnalyzerEclipse Memory Analyzer
Eclipse Memory Analyzer
 
DieHard: Probabilistic Memory Safety for Unsafe Languages
DieHard: Probabilistic Memory Safety for Unsafe LanguagesDieHard: Probabilistic Memory Safety for Unsafe Languages
DieHard: Probabilistic Memory Safety for Unsafe Languages
 
ScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin Odersky
 
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
 
Linux binary analysis and exploitation
Linux binary analysis and exploitationLinux binary analysis and exploitation
Linux binary analysis and exploitation
 
Data analysis in R
Data analysis in RData analysis in R
Data analysis in R
 
Quantifying the Performance of Garbage Collection vs. Explicit Memory Management
Quantifying the Performance of Garbage Collection vs. Explicit Memory ManagementQuantifying the Performance of Garbage Collection vs. Explicit Memory Management
Quantifying the Performance of Garbage Collection vs. Explicit Memory Management
 
JetBrains Day Seoul - Exploring .NET’s memory management – a trip down memory...
JetBrains Day Seoul - Exploring .NET’s memory management – a trip down memory...JetBrains Day Seoul - Exploring .NET’s memory management – a trip down memory...
JetBrains Day Seoul - Exploring .NET’s memory management – a trip down memory...
 
D3, TypeScript, and Deep Learning
D3, TypeScript, and Deep LearningD3, TypeScript, and Deep Learning
D3, TypeScript, and Deep Learning
 
D3, TypeScript, and Deep Learning
D3, TypeScript, and Deep LearningD3, TypeScript, and Deep Learning
D3, TypeScript, and Deep Learning
 
Designing A Project Using Java Programming
Designing A Project Using Java ProgrammingDesigning A Project Using Java Programming
Designing A Project Using Java Programming
 
VRP2013 - Comp Aspects VRP
VRP2013 - Comp Aspects VRPVRP2013 - Comp Aspects VRP
VRP2013 - Comp Aspects VRP
 

More from 02LabiqaIslam

lecture 30 @@@@@@.pptx
lecture 30 @@@@@@.pptxlecture 30 @@@@@@.pptx
lecture 30 @@@@@@.pptx02LabiqaIslam
 
lecture10 virtual reality and augmented reality.ppt
lecture10 virtual reality and augmented reality.pptlecture10 virtual reality and augmented reality.ppt
lecture10 virtual reality and augmented reality.ppt02LabiqaIslam
 
Lecture02-OOP-Review.ppt
Lecture02-OOP-Review.pptLecture02-OOP-Review.ppt
Lecture02-OOP-Review.ppt02LabiqaIslam
 
Chapter 3 software engineering.pptx
Chapter 3 software engineering.pptxChapter 3 software engineering.pptx
Chapter 3 software engineering.pptx02LabiqaIslam
 

More from 02LabiqaIslam (7)

lecture 30 @@@@@@.pptx
lecture 30 @@@@@@.pptxlecture 30 @@@@@@.pptx
lecture 30 @@@@@@.pptx
 
lecture10 virtual reality and augmented reality.ppt
lecture10 virtual reality and augmented reality.pptlecture10 virtual reality and augmented reality.ppt
lecture10 virtual reality and augmented reality.ppt
 
2 funda.ppt
2 funda.ppt2 funda.ppt
2 funda.ppt
 
Lecture02-OOP-Review.ppt
Lecture02-OOP-Review.pptLecture02-OOP-Review.ppt
Lecture02-OOP-Review.ppt
 
Testing method pptx
Testing method pptxTesting method pptx
Testing method pptx
 
Chapter 3 software engineering.pptx
Chapter 3 software engineering.pptxChapter 3 software engineering.pptx
Chapter 3 software engineering.pptx
 
labiqa'd.pptx
labiqa'd.pptxlabiqa'd.pptx
labiqa'd.pptx
 

Recently uploaded

Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 

Recently uploaded (20)

Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 

garbage collection in c ++.ppt

  • 1. Garbage Collection Introduction and Overview Christian Schulte Programming Systems Lab Universität des Saarlandes, Germany schulte@ps.uni-sb.de
  • 2. Purpose of Talk  Explaining basic  concepts  terminology  Garbage collection…  …is simple  …can be explained at a high-level  Organization
  • 3. Purpose of Talk  Explaining basic  concepts  terminology (never to be explained again)  Garbage collection…  …is simple  …can be explained at a high-level  Organization
  • 4. Overview  What is garbage collection  objects of interest  principal notions  classic examples with assumptions and properties  Discussion  software engineering issues  typical cost  areas of usage  why knowledge is profitable  Organizational  Material  Requirements
  • 5. Overview  What is garbage collection  objects of interest  principal notions  classic examples with assumptions and properties  Discussion  software engineering issues  typical cost  areas of usage  why knowledge is profitable  Organizational  Material  Requirements
  • 6. Garbage Collection… …is concerned with the automatic reclamation of dynamically allocated memory after its last use by a program
  • 7. Garbage Collection…  dynamically allocated memory …is concerned with the automatic reclamation of dynamically allocated memory after its last use by a program
  • 8. Garbage Collection…  dynamically allocated memory  last use by a program …is concerned with the automatic reclamation of dynamically allocated memory after its last use by a program
  • 9. Garbage Collection…  dynamically allocated memory  last use by a program  automatic reclamation …is concerned with the automatic reclamation of dynamically allocated memory after its last use by a program
  • 10. Garbage collection…  Dynamically allocated memory  Last use by a program  Examples for automatic reclamation
  • 11. Kinds of Memory Allocation static int i; void foo(void) { int j; int* p = (int*) malloc(…); }
  • 12. Static Allocation  By compiler (in text area)  Available through entire runtime  Fixed size static int i; void foo(void) { int j; int* p = (int*) malloc(…); }
  • 13. Automatic Allocation  Upon procedure call (on stack)  Available during execution of call  Fixed size static int i; void foo(void) { int j; int* p = (int*) malloc(…); }
  • 14. Dynamic Allocation  Dynamically allocated at runtime (on heap)  Available until explicitly deallocated  Dynamically varying size static int i; void foo(void) { int j; int* p = (int*) malloc(…); }
  • 15. Dynamically Allocated Memory  Also: heap-allocated memory  Allocation: malloc, new, …  before first usage  Deallocation: free, delete, dispose, …  after last usage  Needed for  C++, Java: objects  SML: datatypes, procedures  anything that outlives procedure call
  • 16. Getting it Wrong  Forget to free (memory leak)  program eventually runs out of memory  long running programs: OSs. servers, …  Free to early (dangling pointer)  lucky: illegal access detected by OS  horror: memory reused, in simultaneous use  programs can behave arbitrarily  crashes might happen much later  Estimates of effort  Up to 40%! [Rovner, 1985]
  • 17. Nodes and Pointers  Node n  Memory block, cell  Pointer p  Link to node  Node access: *p  Children children(n)  set of pointers to nodes referred by n n p
  • 18. Mutator  Abstraction of program  introduces new nodes with pointer  redirects pointers, creating garbage
  • 19.  Nodes referred to by several pointers  Makes manual deallocation hard  local decision impossible  respect other pointers to node  Cycles instance of sharing Shared Nodes
  • 20. Garbage collection…  Dynamically allocated memory  Last use by a program  Examples for automatic reclamation
  • 21. Last Use by a Program  Question: When is node M not any longer used by program?  Let P be any program not using M  New program sketch: Execute P; Use M;  Hence: M used  P terminates  We are doomed: halting problem!  So “last use” undecidable!
  • 22. Safe Approximation  Decidable and also simple  What means safe?  only unused nodes freed  What means approximation?  some unused nodes might not be freed  Idea  nodes that can be accessed by mutator
  • 23. Reachable Nodes  Reachable from root set  processor registers  static variables  automatic variables (stack)  Reachable from reachable nodes root
  • 24. Summary: Reachable Nodes  A node n is reachable, iff  n is element of the root set, or  n is element of children(m) and m is reachable  Reachable node also called “live”
  • 25. MyGarbageCollector  Compute set of reachable nodes  Free nodes known to be not reachable  Known as mark-sweep  in a second…
  • 26. Reachability: Safe Approximation  Safe  access to not reachable node impossible  depends on language semantics  but C/C++? later…  Approximation  reachable node might never be accessed  programmer must know about this!  have you been aware of this?
  • 27. Garbage collection…  Dynamically allocated memory  Last use by a program  Examples for automatic reclamation
  • 28. Example Garbage Collectors  Mark-Sweep  Others  Mark-Compact  Reference Counting  Copying  skipped here  read Chapter 1&2 of [Lins&Jones,96]
  • 29. The Mark-Sweep Collector  Compute reachable nodes: Mark  tracing garbage collector  Free not reachable nodes: Sweep  Run when out of memory: Allocation  First used with LISP [McCarthy, 1960]
  • 30. Allocation node* new() { if (free_pool is empty) mark_sweep(); …
  • 31. Allocation node* new() { if (free_pool is empty) mark_sweep(); return allocate(); }
  • 32. The Garbage Collector void mark_sweep() { for (r in roots) mark(r); …
  • 33. The Garbage Collector void mark_sweep() { for (r in roots) mark(r); … all live nodes marked
  • 34. Recursive Marking void mark(node* n) { if (!is_marked(n)) { set_mark(n); … } }
  • 35. Recursive Marking void mark(node* n) { if (!is_marked(n)) { set_mark(n); … } } nodes reachable from n marked
  • 36. Recursive Marking void mark(node* n) { if (!is_marked(n)) { set_mark(n); for (m in children(n)) mark(m); } } i-th recursion: nodes on path with length i marked
  • 37. The Garbage Collector void mark_sweep() { for (r in roots) mark(r); sweep(); …
  • 38. The Garbage Collector void mark_sweep() { for (r in roots) mark(r); sweep(); … all nodes on heap live
  • 39. The Garbage Collector void mark_sweep() { for (r in roots) mark(r); sweep(); … all nodes on heap live and not marked
  • 40. Eager Sweep void sweep() { node* n = heap_bottom; while (n < heap_top) { … } }
  • 41. Eager Sweep void sweep() { node* n = heap_bottom; while (n < heap_top) { if (is_marked(n)) clear_mark(n); else free(n); n += sizeof(*n); } }
  • 42. The Garbage Collector void mark_sweep() { for (r in roots) mark(r); sweep(); if (free_pool is empty) abort(“Memory exhausted”); }
  • 43. Assumptions  Nodes can be marked  Size of nodes known  Heap contiguous  Memory for recursion available  Child fields known!
  • 44. Assumptions: Realistic  Nodes can be marked  Size of nodes known  Heap contiguous  Memory for recursion available  Child fields known
  • 45. Assumptions: Conservative  Nodes can be marked  Size of nodes known  Heap contiguous  Memory for recursion available  Child fields known
  • 46. Mark-Sweep Properties  Covers cycles and sharing  Time depends on  live nodes (mark)  live and garbage nodes (sweep)  Computation must be stopped  non-interruptible stop/start collector  long pause  Nodes remain unchanged (as not moved)  Heap remains fragmented
  • 47. Variations of Mark-Sweep  In your talk…
  • 52. Overview  What is garbage collection  objects of interest  principal invariant  classic examples with assumptions and properties  Discussion  software engineering issues  typical cost  areas of usage  why knowledge is profitable  Organizational  Material  Requirements
  • 53. Software Engineering Issues  Design goal in SE:  decompose systems  in orthogonal components  Clashes with letting each component do its memory management  liveness is global property  leads to “local leaks”  lacking power of modern gc methods
  • 54. Typical Cost  Early systems (LISP) up to 40% [Steele,75] [Gabriel,85]  “garbage collection is expensive” myth  Well engineered system of today 10% of entire runtime [Wilson, 94]
  • 55. Areas of Usage  Programming languages and systems  Java, C#, Smalltalk, …  SML, Lisp, Scheme, Prolog, …  Modula 3, Microsoft .NET  Extensions  C, C++ (Conservative)  Other systems  Adobe Photoshop  Unix filesystem  Many others in [Wilson, 1996]
  • 56. Understanding Garbage Collection: Benefits  Programming garbage collection  programming systems  operating systems  Understand systems with garbage collection (e.g. Java)  memory requirements of programs  performance aspects of programs  interfacing with garbage collection (finalization)
  • 57. Overview  What is garbage collection  objects of interest  principal invariant  classic examples with assumptions and properties  Discussion  software engineering issues  typical cost  areas of usage  why knowledge is profitable  Organizational  Material  Requirements
  • 58. Material  Garbage Collection. Richard Jones and Rafael Lins, John Wiley & Sons, 1996.  Uniprocessor garbage collection techniques. Paul R. Wilson, ACM Computing Surveys. To appear.  Extended version of IWMM 92, St. Malo.
  • 59. Organization  Requirements  Talk  duration 45 min (excluding discussion)  Attendance  including discussion  Written summary  10 pages  to be submitted in PDF until Mar 31st, 2002  Schedule  weekly  starting Nov 14th, 2001  next on Dec 5th, 2001
  • 60. Topics For You!  The classical methods  Copying 1. [Brunklaus, Guido Tack]  Mark-Sweep 2. [Schulte, Hagen Böhm]  Mark-Compact 3. [Schulte, Jens Regenberg]  Reference Counting 6. [Brunklaus, Regis Newo]  Advanced  Generational 4. [Brunklaus, Mirko Jerrentrup]  Conservative (C/C++) 5. [Schulte, Stephan Lesch]  Incremental & Concurrent 7. [Brunklaus, Uwe Kern]
  • 61. Invariants  Only nodes with rc zero are freed  RC always positive