specialized reference counting garbage collection using data structure annotations
DESCRIPTION
Specialized Reference Counting Garbage Collection using Data Structure Annotations. By Eric Watkins and Dzin Avots for CS 343 Spring 2002. Motivation. Improve use of ref counting for C++ Problem: cycles can’t be freed automatically, expensive to determine what is unreachable - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Specialized Reference Counting Garbage Collection using Data Structure Annotations](https://reader035.vdocuments.mx/reader035/viewer/2022062808/5681530e550346895dc133f2/html5/thumbnails/1.jpg)
Specialized Reference Counting Garbage Collection using Data
Structure AnnotationsBy Eric Watkins and Dzin Avots
for CS 343 Spring 2002
![Page 2: Specialized Reference Counting Garbage Collection using Data Structure Annotations](https://reader035.vdocuments.mx/reader035/viewer/2022062808/5681530e550346895dc133f2/html5/thumbnails/2.jpg)
Motivation
• Improve use of ref counting for C++
• Problem: cycles can’t be freed automatically, expensive to determine what is unreachable
• Solution: Use user specified data structure annotations to improve performance
![Page 3: Specialized Reference Counting Garbage Collection using Data Structure Annotations](https://reader035.vdocuments.mx/reader035/viewer/2022062808/5681530e550346895dc133f2/html5/thumbnails/3.jpg)
Goals & Techniques
• Avoid unnecessary mark & sweeps– Acyclic Data Structure Optimizations
• Avoid some memory leaks– Reference Removal Invariant Model
![Page 4: Specialized Reference Counting Garbage Collection using Data Structure Annotations](https://reader035.vdocuments.mx/reader035/viewer/2022062808/5681530e550346895dc133f2/html5/thumbnails/4.jpg)
Reference Counting using Smart Pointers
![Page 5: Specialized Reference Counting Garbage Collection using Data Structure Annotations](https://reader035.vdocuments.mx/reader035/viewer/2022062808/5681530e550346895dc133f2/html5/thumbnails/5.jpg)
Garbage Example #1
• Doubly Linked List
• Everything is strongly connected
• Nothing can be freed until all external refs are gone
• How can we recognize this data structure?ext ptr ext ptr
![Page 6: Specialized Reference Counting Garbage Collection using Data Structure Annotations](https://reader035.vdocuments.mx/reader035/viewer/2022062808/5681530e550346895dc133f2/html5/thumbnails/6.jpg)
Abstract Description of Data Structures
• The compiler can’t differentiate these two even though they will obviously be connected in different ways.
• ADDS can tell us how to customize smart pointer usage for certain data structures
![Page 7: Specialized Reference Counting Garbage Collection using Data Structure Annotations](https://reader035.vdocuments.mx/reader035/viewer/2022062808/5681530e550346895dc133f2/html5/thumbnails/7.jpg)
Doubly Linked List ADDS
![Page 8: Specialized Reference Counting Garbage Collection using Data Structure Annotations](https://reader035.vdocuments.mx/reader035/viewer/2022062808/5681530e550346895dc133f2/html5/thumbnails/8.jpg)
Binary Tree w/ Parents ADDS
![Page 9: Specialized Reference Counting Garbage Collection using Data Structure Annotations](https://reader035.vdocuments.mx/reader035/viewer/2022062808/5681530e550346895dc133f2/html5/thumbnails/9.jpg)
ADDS spec
• Dimensions (1-d, 2-d, etc.)
• Directionality (forward and backward)
• Uniqueness of forward references (DAGs vs. lists)
• Cyclicity
![Page 10: Specialized Reference Counting Garbage Collection using Data Structure Annotations](https://reader035.vdocuments.mx/reader035/viewer/2022062808/5681530e550346895dc133f2/html5/thumbnails/10.jpg)
Linked List Optimization
• The entire dimension is strongly connected, forwards and backwards
• Summarize with single ref counter for all external references to dimension
![Page 11: Specialized Reference Counting Garbage Collection using Data Structure Annotations](https://reader035.vdocuments.mx/reader035/viewer/2022062808/5681530e550346895dc133f2/html5/thumbnails/11.jpg)
Dimensional Independence
• Dimensions X and Y are dependent if one traversal along X and another traversal along Y may lead to a common node by different paths
![Page 12: Specialized Reference Counting Garbage Collection using Data Structure Annotations](https://reader035.vdocuments.mx/reader035/viewer/2022062808/5681530e550346895dc133f2/html5/thumbnails/12.jpg)
Other ADDS issues
• What about describing relations between different acyclic data structures?
• Could avoid marking & sweeping this structure
etc.
![Page 13: Specialized Reference Counting Garbage Collection using Data Structure Annotations](https://reader035.vdocuments.mx/reader035/viewer/2022062808/5681530e550346895dc133f2/html5/thumbnails/13.jpg)
Primary & Secondary Pointers
• Primary pointers – if these point to an object, then object is still in use
• Secondary pointers – point to object, but don’t affect use status
• Memory leak – Primary pointers are all removed, but a secondary pointer remains
![Page 14: Specialized Reference Counting Garbage Collection using Data Structure Annotations](https://reader035.vdocuments.mx/reader035/viewer/2022062808/5681530e550346895dc133f2/html5/thumbnails/14.jpg)
Garbage Example #2
Bug
BugManager Grid
Bug
Secondary refs Primary refs
• Programs can contain complicated, interconnected relationships between objects
![Page 15: Specialized Reference Counting Garbage Collection using Data Structure Annotations](https://reader035.vdocuments.mx/reader035/viewer/2022062808/5681530e550346895dc133f2/html5/thumbnails/15.jpg)
Garbage Example #2
Bug
BugManager Grid
Bug
Secondary refs Primary ref
• If the user forgets to remove the secondary reference, the Bug won’t be deleted.
![Page 16: Specialized Reference Counting Garbage Collection using Data Structure Annotations](https://reader035.vdocuments.mx/reader035/viewer/2022062808/5681530e550346895dc133f2/html5/thumbnails/16.jpg)
Primary & Secondary Pointers
• User specifies primary & secondary pointers in ADDS specification
• Primary & Secondary pointer invariant can be expressed as instrumentation predicate in 3-valued logic
• Generate shape analysis to detect leak condition
![Page 17: Specialized Reference Counting Garbage Collection using Data Structure Annotations](https://reader035.vdocuments.mx/reader035/viewer/2022062808/5681530e550346895dc133f2/html5/thumbnails/17.jpg)
Plan of Action
• Investigate use of ADDS specs to improve refcount performance
• Generate interprocedural shape analysis from primary & secondary edge specs
• Look into other improvements from user specifications
![Page 18: Specialized Reference Counting Garbage Collection using Data Structure Annotations](https://reader035.vdocuments.mx/reader035/viewer/2022062808/5681530e550346895dc133f2/html5/thumbnails/18.jpg)
Related Work
• ADDS work: L. Hendren and J. Hummel, Abstractions for Recursive Pointer Data Structures: Improving the Analysis and Transformation of Imperative Programs
• Shape Analysis: M. Sagiv, T. Reps and R. Wilhelm, Parametric Shape Analysis via 3-Valued Logic