real-time garbage collectionos.inf.tu-dresden.de/ezag/old/ss2005/abstracts/talk-20050701-2.pdf ·...
TRANSCRIPT
Introduction Garbage Collection Methods Summary
Real-Time Garbage Collection
Bertram Felgenhauer
01.07.2004 / Echtzeit-AG
Bertram Felgenhauer
Real-Time Garbage Collection 1/18
Introduction Garbage Collection Methods Summary
Outline
Introduction
Garbage Collection Methods
Summary
Bertram Felgenhauer
Real-Time Garbage Collection 2/18
Introduction Garbage Collection Methods Summary
History of Garbage Collection
1958: Garbage Collection for LISP by John McCarthy
1975: parallel GC by Edsger W. Dijkstra and others
1978: real-time GC by Henry G. Baker
1992: noncopying real-time GC by Henry G. Baker
1995: Java announced
Bertram Felgenhauer
Real-Time Garbage Collection 3/18
Introduction Garbage Collection Methods Summary
History of Garbage Collection
1958: Garbage Collection for LISP by John McCarthy
1975: parallel GC by Edsger W. Dijkstra and others
1978: real-time GC by Henry G. Baker
1992: noncopying real-time GC by Henry G. Baker
1995: Java announced
Bertram Felgenhauer
Real-Time Garbage Collection 3/18
Introduction Garbage Collection Methods Summary
History of Garbage Collection
1958: Garbage Collection for LISP by John McCarthy
1975: parallel GC by Edsger W. Dijkstra and others
1978: real-time GC by Henry G. Baker
1992: noncopying real-time GC by Henry G. Baker
1995: Java announced
Bertram Felgenhauer
Real-Time Garbage Collection 3/18
Introduction Garbage Collection Methods Summary
History of Garbage Collection
1958: Garbage Collection for LISP by John McCarthy
1975: parallel GC by Edsger W. Dijkstra and others
1978: real-time GC by Henry G. Baker
1992: noncopying real-time GC by Henry G. Baker
1995: Java announced
Bertram Felgenhauer
Real-Time Garbage Collection 3/18
Introduction Garbage Collection Methods Summary
History of Garbage Collection
1958: Garbage Collection for LISP by John McCarthy
1975: parallel GC by Edsger W. Dijkstra and others
1978: real-time GC by Henry G. Baker
1992: noncopying real-time GC by Henry G. Baker
1995: Java announced
Bertram Felgenhauer
Real-Time Garbage Collection 3/18
Introduction Garbage Collection Methods Summary
Programming Languages Using Garbage Collection
I LISP, SchemeI Python, PerlI Haskell, MLI Modula-3I Smalltalk, Self, Java
I many applications implement their own GC
Bertram Felgenhauer
Real-Time Garbage Collection 4/18
Introduction Garbage Collection Methods Summary
Programming Languages Using Garbage Collection
I LISP, SchemeI Python, PerlI Haskell, MLI Modula-3I Smalltalk, Self, Java
I many applications implement their own GC
Bertram Felgenhauer
Real-Time Garbage Collection 4/18
Introduction Garbage Collection Methods Summary
Programming Languages Using Garbage Collection
I LISP, SchemeI Python, PerlI Haskell, MLI Modula-3I Smalltalk, Self, Java
I many applications implement their own GC
Bertram Felgenhauer
Real-Time Garbage Collection 4/18
Introduction Garbage Collection Methods Summary
Programming Languages Using Garbage Collection
I LISP, SchemeI Python, PerlI Haskell, MLI Modula-3I Smalltalk, Self, Java
I many applications implement their own GC
Bertram Felgenhauer
Real-Time Garbage Collection 4/18
Introduction Garbage Collection Methods Summary
Programming Languages Using Garbage Collection
I LISP, SchemeI Python, PerlI Haskell, MLI Modula-3I Smalltalk, Self, Java
I many applications implement their own GC
Bertram Felgenhauer
Real-Time Garbage Collection 4/18
Introduction Garbage Collection Methods Summary
Programming Languages Using Garbage Collection
I LISP, SchemeI Python, PerlI Haskell, MLI Modula-3I Smalltalk, Self, Java
I many applications implement their own GC
Bertram Felgenhauer
Real-Time Garbage Collection 4/18
Introduction Garbage Collection Methods Summary
Why Do We Need Garbage Collection?
I Memory is limited.I Many programs use complex, dynamic data structures.I avoid dangling pointers
I avoid memory leaks
Bertram Felgenhauer
Real-Time Garbage Collection 5/18
Introduction Garbage Collection Methods Summary
Why Do We Need Garbage Collection?
I Memory is limited.I Many programs use complex, dynamic data structures.I avoid dangling pointers
I avoid memory leaks
Bertram Felgenhauer
Real-Time Garbage Collection 5/18
Introduction Garbage Collection Methods Summary
Why Do We Need Garbage Collection?
I Memory is limited.I Many programs use complex, dynamic data structures.I avoid dangling pointers
I avoid memory leaks
Bertram Felgenhauer
Real-Time Garbage Collection 5/18
Introduction Garbage Collection Methods Summary
Why Do We Need Garbage Collection?
I Memory is limited.I Many programs use complex, dynamic data structures.I avoid dangling pointers
I avoid memory leaks
Bertram Felgenhauer
Real-Time Garbage Collection 5/18
Introduction Garbage Collection Methods Summary
Why Do We Need Garbage Collection?
I Memory is limited.I Many programs use complex, dynamic data structures.I avoid dangling pointers
I avoid memory leaks
Bertram Felgenhauer
Real-Time Garbage Collection 5/18
Introduction Garbage Collection Methods Summary
Why Do We Need Garbage Collection?
I Memory is limited.I Many programs use complex, dynamic data structures.I avoid dangling pointers
I avoid memory leaks
???
Bertram Felgenhauer
Real-Time Garbage Collection 5/18
Introduction Garbage Collection Methods Summary
How Does Garbage Collection Work?
I distinguish live and dead objectsI Live objects are reachable through a chain of references
starting from a root set.I All other objects are dead and can be freed (collected).I This is a safe approximation for unused objects.I The general problem reduces to the halting problem.
Bertram Felgenhauer
Real-Time Garbage Collection 6/18
Introduction Garbage Collection Methods Summary
How Does Garbage Collection Work?
I distinguish live and dead objectsI Live objects are reachable through a chain of references
starting from a root set.I All other objects are dead and can be freed (collected).I This is a safe approximation for unused objects.I The general problem reduces to the halting problem.
Bertram Felgenhauer
Real-Time Garbage Collection 6/18
Introduction Garbage Collection Methods Summary
How Does Garbage Collection Work?
I distinguish live and dead objectsI Live objects are reachable through a chain of references
starting from a root set.I All other objects are dead and can be freed (collected).I This is a safe approximation for unused objects.I The general problem reduces to the halting problem.
Bertram Felgenhauer
Real-Time Garbage Collection 6/18
Introduction Garbage Collection Methods Summary
How Does Garbage Collection Work?
I distinguish live and dead objectsI Live objects are reachable through a chain of references
starting from a root set.I All other objects are dead and can be freed (collected).I This is a safe approximation for unused objects.I The general problem reduces to the halting problem.
Bertram Felgenhauer
Real-Time Garbage Collection 6/18
Introduction Garbage Collection Methods Summary
How Does Garbage Collection Work?
I distinguish live and dead objectsI Live objects are reachable through a chain of references
starting from a root set.I All other objects are dead and can be freed (collected).I This is a safe approximation for unused objects.I The general problem reduces to the halting problem.
Bertram Felgenhauer
Real-Time Garbage Collection 6/18
Introduction Garbage Collection Methods Summary
Reference Counting
I data structure with reference counts
1
1
1
3
I does not collect cyclesI Freeing objects can take very long.
Bertram Felgenhauer
Real-Time Garbage Collection 7/18
Introduction Garbage Collection Methods Summary
Reference Counting
I A reference count drops to zero.
1
1
30
I does not collect cyclesI Freeing objects can take very long.
Bertram Felgenhauer
Real-Time Garbage Collection 7/18
Introduction Garbage Collection Methods Summary
Reference Counting
I The object is freed. Reference counts are decremented.
30
0
0
I does not collect cyclesI Freeing objects can take very long.
Bertram Felgenhauer
Real-Time Garbage Collection 7/18
Introduction Garbage Collection Methods Summary
Reference Counting
I Two more objects are freed.
00
0
1
I does not collect cyclesI Freeing objects can take very long.
Bertram Felgenhauer
Real-Time Garbage Collection 7/18
Introduction Garbage Collection Methods Summary
Reference Counting
I Two more objects are freed.
00
0
1
I does not collect cyclesI Freeing objects can take very long.
Bertram Felgenhauer
Real-Time Garbage Collection 7/18
Introduction Garbage Collection Methods Summary
Reference Counting
I Two more objects are freed.
00
0
1
I does not collect cyclesI Freeing objects can take very long.
Bertram Felgenhauer
Real-Time Garbage Collection 7/18
Introduction Garbage Collection Methods Summary
Reference Counting in Real-Time
I Allocating an object takes constant time using a free list.I Adding references takes constant time.
I Removing references can take long.idea: Collect objects incrementally.
Bertram Felgenhauer
Real-Time Garbage Collection 8/18
Introduction Garbage Collection Methods Summary
Reference Counting in Real-Time
I Allocating an object takes constant time using a free list.I Adding references takes constant time.
I Removing references can take long.idea: Collect objects incrementally.
Bertram Felgenhauer
Real-Time Garbage Collection 8/18
Introduction Garbage Collection Methods Summary
Reference Counting in Real-Time
I Allocating an object takes constant time using a free list.I Adding references takes constant time.
I Removing references can take long.idea: Collect objects incrementally.
Bertram Felgenhauer
Real-Time Garbage Collection 8/18
Introduction Garbage Collection Methods Summary
Reference Counting in Real-Time, ctd.
I A reference count drops to zero.
free list
1
1
30
Bertram Felgenhauer
Real-Time Garbage Collection 9/18
Introduction Garbage Collection Methods Summary
Reference Counting in Real-Time, ctd.
I The object is inserted into the free list.
free list
1
1
3
Bertram Felgenhauer
Real-Time Garbage Collection 9/18
Introduction Garbage Collection Methods Summary
Reference Counting in Real-Time, ctd.
I The object is allocated. Reference counts are updated.
free list
3
0
0
1
Bertram Felgenhauer
Real-Time Garbage Collection 9/18
Introduction Garbage Collection Methods Summary
Reference Counting in Real-Time, ctd.
I The free list is updated.
free list
31
Bertram Felgenhauer
Real-Time Garbage Collection 9/18
Introduction Garbage Collection Methods Summary
Assumptions of Real-Time Garbage Collection
I The number of reachable objects is limited by a constant Mat any given moment in time.
I There is enough memory in the system:I For reference counting, this is M + ε.I For other methods it may be more.
I For reference counting, the program must notcreate cycles.
Bertram Felgenhauer
Real-Time Garbage Collection 10/18
Introduction Garbage Collection Methods Summary
Assumptions of Real-Time Garbage Collection
I The number of reachable objects is limited by a constant Mat any given moment in time.
I There is enough memory in the system:I For reference counting, this is M + ε.I For other methods it may be more.
I For reference counting, the program must notcreate cycles.
Bertram Felgenhauer
Real-Time Garbage Collection 10/18
Introduction Garbage Collection Methods Summary
Assumptions of Real-Time Garbage Collection
I The number of reachable objects is limited by a constant Mat any given moment in time.
I There is enough memory in the system:I For reference counting, this is M + ε.I For other methods it may be more.
I For reference counting, the program must notcreate cycles.
Bertram Felgenhauer
Real-Time Garbage Collection 10/18
Introduction Garbage Collection Methods Summary
Assumptions of Real-Time Garbage Collection
I The number of reachable objects is limited by a constant Mat any given moment in time.
I There is enough memory in the system:I For reference counting, this is M + ε.I For other methods it may be more.
I For reference counting, the program must notcreate cycles.
Bertram Felgenhauer
Real-Time Garbage Collection 10/18
Introduction Garbage Collection Methods Summary
Assumptions of Real-Time Garbage Collection
I The number of reachable objects is limited by a constant Mat any given moment in time.
I There is enough memory in the system:I For reference counting, this is M + ε.I For other methods it may be more.
I For reference counting, the program must notcreate cycles.
Bertram Felgenhauer
Real-Time Garbage Collection 10/18
Introduction Garbage Collection Methods Summary
Copying Garbage Collection – Two Space Approach
I data structure
root set
from−space to−space
Bertram Felgenhauer
Real-Time Garbage Collection 11/18
Introduction Garbage Collection Methods Summary
Copying Garbage Collection – Two Space Approach
I live and dead objects
from−space
root set
to−space
Bertram Felgenhauer
Real-Time Garbage Collection 11/18
Introduction Garbage Collection Methods Summary
Copying Garbage Collection – Two Space Approach
I garbage collection: copy first object from root set
root set
from−space to−space
Bertram Felgenhauer
Real-Time Garbage Collection 11/18
Introduction Garbage Collection Methods Summary
Copying Garbage Collection – Two Space Approach
I leave forwarding pointer in from-space
root set
from−space to−space
Bertram Felgenhauer
Real-Time Garbage Collection 11/18
Introduction Garbage Collection Methods Summary
Copying Garbage Collection – Two Space Approach
I continue copying to to-space
to−space
root set
from−space
Bertram Felgenhauer
Real-Time Garbage Collection 11/18
Introduction Garbage Collection Methods Summary
Copying Garbage Collection – Two Space Approach
I continue copying to to-space
root set
from−space to−space
Bertram Felgenhauer
Real-Time Garbage Collection 11/18
Introduction Garbage Collection Methods Summary
Copying Garbage Collection – Two Space Approach
I continue copying to to-space
from−space to−space
root set
Bertram Felgenhauer
Real-Time Garbage Collection 11/18
Introduction Garbage Collection Methods Summary
Copying Garbage Collection – Two Space Approach
I continue copying to to-space
root set
from−space to−space
Bertram Felgenhauer
Real-Time Garbage Collection 11/18
Introduction Garbage Collection Methods Summary
Copying Garbage Collection – Two Space Approach
I follow forwarding pointer
root set
from−space to−space
Bertram Felgenhauer
Real-Time Garbage Collection 11/18
Introduction Garbage Collection Methods Summary
Copying Garbage Collection – Two Space Approach
I to-space only contains garbage now. Swap spaces.
root set
to−space from−space
Bertram Felgenhauer
Real-Time Garbage Collection 11/18
Introduction Garbage Collection Methods Summary
Copying Garbage Collection – Two Space Approach
advantages:I can collect cyclic data structuresI allocation can be implemented by incrementing a pointerI more memory means less time collecting garbageI improves locality of reference
disadvantages:I long pause timesI requires at least 2M memory and a stack for the
garbage collection
Bertram Felgenhauer
Real-Time Garbage Collection 12/18
Introduction Garbage Collection Methods Summary
Copying Garbage Collection – Two Space Approach
advantages:I can collect cyclic data structuresI allocation can be implemented by incrementing a pointerI more memory means less time collecting garbageI improves locality of reference
disadvantages:I long pause timesI requires at least 2M memory and a stack for the
garbage collection
Bertram Felgenhauer
Real-Time Garbage Collection 12/18
Introduction Garbage Collection Methods Summary
Copying Garbage Collection – Two Space Approach
advantages:I can collect cyclic data structuresI allocation can be implemented by incrementing a pointerI more memory means less time collecting garbageI improves locality of reference
disadvantages:I long pause timesI requires at least 2M memory and a stack for the
garbage collection
Bertram Felgenhauer
Real-Time Garbage Collection 12/18
Introduction Garbage Collection Methods Summary
Copying Garbage Collection – Two Space Approach
advantages:I can collect cyclic data structuresI allocation can be implemented by incrementing a pointerI more memory means less time collecting garbageI improves locality of reference
disadvantages:I long pause timesI requires at least 2M memory and a stack for the
garbage collection
Bertram Felgenhauer
Real-Time Garbage Collection 12/18
Introduction Garbage Collection Methods Summary
Copying Garbage Collection – Two Space Approach
advantages:I can collect cyclic data structuresI allocation can be implemented by incrementing a pointerI more memory means less time collecting garbageI improves locality of reference
disadvantages:I long pause timesI requires at least 2M memory and a stack for the
garbage collection
Bertram Felgenhauer
Real-Time Garbage Collection 12/18
Introduction Garbage Collection Methods Summary
Copying Garbage Collection – Two Space Approach
advantages:I can collect cyclic data structuresI allocation can be implemented by incrementing a pointerI more memory means less time collecting garbageI improves locality of reference
disadvantages:I long pause timesI requires at least 2M memory and a stack for the
garbage collection
Bertram Felgenhauer
Real-Time Garbage Collection 12/18
Introduction Garbage Collection Methods Summary
Copying Garbage Collection in Real-Time
I interleave operation of application and garbage collectorI copy one object from from-space to to-space for every
allocated object
I prevent application from seeing pointers toforwarding pointers
I forbid application to create pointers from to-spaceto from-space
I allocate new objects in to-space
Bertram Felgenhauer
Real-Time Garbage Collection 13/18
Introduction Garbage Collection Methods Summary
Copying Garbage Collection in Real-Time
I interleave operation of application and garbage collectorI copy one object from from-space to to-space for every
allocated object
I prevent application from seeing pointers toforwarding pointers
I forbid application to create pointers from to-spaceto from-space
I allocate new objects in to-space
Bertram Felgenhauer
Real-Time Garbage Collection 13/18
Introduction Garbage Collection Methods Summary
Copying Garbage Collection in Real-Time
I interleave operation of application and garbage collectorI copy one object from from-space to to-space for every
allocated object
I prevent application from seeing pointers toforwarding pointers
I forbid application to create pointers from to-spaceto from-space
I allocate new objects in to-space
Bertram Felgenhauer
Real-Time Garbage Collection 13/18
Introduction Garbage Collection Methods Summary
Copying Garbage Collection in Real-Time
I interleave operation of application and garbage collectorI copy one object from from-space to to-space for every
allocated object
I prevent application from seeing pointers toforwarding pointers
I forbid application to create pointers from to-spaceto from-space
I allocate new objects in to-space
Bertram Felgenhauer
Real-Time Garbage Collection 13/18
Introduction Garbage Collection Methods Summary
Copying Garbage Collection in Real-Time
I interleave operation of application and garbage collectorI copy one object from from-space to to-space for every
allocated object
I prevent application from seeing pointers toforwarding pointers
I forbid application to create pointers from to-spaceto from-space
I allocate new objects in to-space
Bertram Felgenhauer
Real-Time Garbage Collection 13/18
Introduction Garbage Collection Methods Summary
Copying Garbage Collection in Real-Time, ctd.
prevent application from seeing pointers to forwarding pointersI idea: have a forwarding pointer in all objects
I always forward all pointers before accessing memorya = a->fwd; /* forward */b = a->left;
Bertram Felgenhauer
Real-Time Garbage Collection 14/18
Introduction Garbage Collection Methods Summary
Copying Garbage Collection in Real-Time, ctd.
prevent application from seeing pointers to forwarding pointersI idea: have a forwarding pointer in all objects
I always forward all pointers before accessing memorya = a->fwd; /* forward */b = a->left;
Bertram Felgenhauer
Real-Time Garbage Collection 14/18
Introduction Garbage Collection Methods Summary
Copying Garbage Collection in Real-Time, ctd.
forbid creating pointers from to-space to from-space:I idea: copy object before creating a pointer to it
a = a->fwd; /* forward */if (in_from_space(a))
a = copy_to_to_space(a);b = b->fwd; /* forward */b->left = a;
Bertram Felgenhauer
Real-Time Garbage Collection 15/18
Introduction Garbage Collection Methods Summary
Copying Garbage Collection in Real-Time, ctd.
forbid creating pointers from to-space to from-space:I idea: copy object before creating a pointer to it
a = a->fwd; /* forward */if (in_from_space(a))
a = copy_to_to_space(a);b = b->fwd; /* forward */b->left = a;
Bertram Felgenhauer
Real-Time Garbage Collection 15/18
Introduction Garbage Collection Methods Summary
Copying Garbage Collection in Real-Time – Summary
I additional assumption: there is a maximum object sizeI requires at most 4M memoryI features fast read access to dataI write access can be slow (but takes bounded time)
Bertram Felgenhauer
Real-Time Garbage Collection 16/18
Introduction Garbage Collection Methods Summary
Copying Garbage Collection in Real-Time – Summary
I additional assumption: there is a maximum object sizeI requires at most 4M memoryI features fast read access to dataI write access can be slow (but takes bounded time)
Bertram Felgenhauer
Real-Time Garbage Collection 16/18
Introduction Garbage Collection Methods Summary
Copying Garbage Collection in Real-Time – Summary
I additional assumption: there is a maximum object sizeI requires at most 4M memoryI features fast read access to dataI write access can be slow (but takes bounded time)
Bertram Felgenhauer
Real-Time Garbage Collection 16/18
Introduction Garbage Collection Methods Summary
Copying Garbage Collection in Real-Time – Summary
I additional assumption: there is a maximum object sizeI requires at most 4M memoryI features fast read access to dataI write access can be slow (but takes bounded time)
Bertram Felgenhauer
Real-Time Garbage Collection 16/18
Introduction Garbage Collection Methods Summary
Other Approaches
I parallel GC – three color marking (Djikstra and others)I aim for good performance and soft real time:
I let collector work on larger chunksI probability of missing a deadline can be reduced
by adding more memory (Bacon and others)
Bertram Felgenhauer
Real-Time Garbage Collection 17/18
Introduction Garbage Collection Methods Summary
Other Approaches
I parallel GC – three color marking (Djikstra and others)I aim for good performance and soft real time:
I let collector work on larger chunksI probability of missing a deadline can be reduced
by adding more memory (Bacon and others)
Bertram Felgenhauer
Real-Time Garbage Collection 17/18
Introduction Garbage Collection Methods Summary
Other Approaches
I parallel GC – three color marking (Djikstra and others)I aim for good performance and soft real time:
I let collector work on larger chunksI probability of missing a deadline can be reduced
by adding more memory (Bacon and others)
Bertram Felgenhauer
Real-Time Garbage Collection 17/18
Introduction Garbage Collection Methods Summary
Other Approaches
I parallel GC – three color marking (Djikstra and others)I aim for good performance and soft real time:
I let collector work on larger chunksI probability of missing a deadline can be reduced
by adding more memory (Bacon and others)
Bertram Felgenhauer
Real-Time Garbage Collection 17/18
Introduction Garbage Collection Methods Summary
SummaryI There is demand for real-time garbage collection.I Real-time garbage collection is feasible.
OutlookI more garbage collection approachesI many small improvementsI target soft real-time to achieve higher performance
Questions?
Bertram Felgenhauer
Real-Time Garbage Collection 18/18
Introduction Garbage Collection Methods Summary
SummaryI There is demand for real-time garbage collection.I Real-time garbage collection is feasible.
OutlookI more garbage collection approachesI many small improvementsI target soft real-time to achieve higher performance
Questions?
Bertram Felgenhauer
Real-Time Garbage Collection 18/18
Introduction Garbage Collection Methods Summary
SummaryI There is demand for real-time garbage collection.I Real-time garbage collection is feasible.
OutlookI more garbage collection approachesI many small improvementsI target soft real-time to achieve higher performance
Questions?
Bertram Felgenhauer
Real-Time Garbage Collection 18/18
Introduction Garbage Collection Methods Summary
SummaryI There is demand for real-time garbage collection.I Real-time garbage collection is feasible.
OutlookI more garbage collection approachesI many small improvementsI target soft real-time to achieve higher performance
Questions?
Bertram Felgenhauer
Real-Time Garbage Collection 18/18
Introduction Garbage Collection Methods Summary
SummaryI There is demand for real-time garbage collection.I Real-time garbage collection is feasible.
OutlookI more garbage collection approachesI many small improvementsI target soft real-time to achieve higher performance
Questions?
Bertram Felgenhauer
Real-Time Garbage Collection 18/18
Introduction Garbage Collection Methods Summary
SummaryI There is demand for real-time garbage collection.I Real-time garbage collection is feasible.
OutlookI more garbage collection approachesI many small improvementsI target soft real-time to achieve higher performance
Questions?
Bertram Felgenhauer
Real-Time Garbage Collection 18/18