The Mechanized Verification of Garbage Collector Implementations
Total Page:16
File Type:pdf, Size:1020Kb
Abstract The Mechanized Verification of Garbage Collector Implementations Andrew Evan McCreight 2008 Languages such as Java, C], Standard ML, and Haskell use automated memory man- agement to simplify development and improve reliability by eliminating the need for programmers to manually free unused objects. The cost of this improved program- mer experience is that the implementation of the language becomes more complex, requiring a garbage collector. Garbage collectors are becoming increasingly sophis- ticated to adapt them to high-performance, concurrent and real-time applications, making internal collector invariants and the interface with user programs (mutators in garbage collector parlance) subtle and difficult to implement correctly. My thesis is that treating the garbage collected heap as an abstract data type allows the specification and verification of flexible and expressive garbage collector- mutator interfaces, and that the mechanized verification of garbage collector im- plementations using Hoare-style logic is both practical and effective. The mutator- garbage collector interface I describe in this paper is expressive enough to be used with verified mutators, while being abstract enough that a single interface can be used with both stop-the-world and incremental collectors. It is also powerful enough to be used with collectors that require read or write barriers. In this dissertation, I describe my framework for the mechanized verification of garbage collector implementations. I discuss the formal setting, and my approach to garbage collector interfaces. I also describe the specification and verification of the Cheney and Baker copying collectors. The Baker collector is an incremental collector 2 that requires a read barrier. Finally, I discuss some practical tools I developed for program verification using separation logic in the Coq proof assistant. The Mechanized Verification of Garbage Collector Implementations A Dissertation Presented to the Faculty of the Graduate School of Yale University in Candidacy for the Degree of Doctor of Philosophy by Andrew Evan McCreight Dissertation Director: Zhong Shao December 2008 Copyright c 2008 by Andrew Evan McCreight All rights reserved. ii Contents Acknowledgments xiii 1 Introduction 1 2 Formal Setting 5 2.1 Introduction . .5 2.2 The machine . .6 2.2.1 Syntax . .6 2.2.2 Dynamic semantics . .9 2.3 SCAP . 10 2.3.1 Instruction sequence typing rules . 11 2.3.2 Top level typing rules . 14 2.3.3 Soundness . 16 2.4 Weak SCAP . 16 2.5 Separation logic . 20 2.5.1 Predicates . 21 2.5.2 Basic properties . 23 2.5.3 Machine properties . 24 2.6 Implementation . 24 2.7 Specification style . 27 iii 2.8 Example . 30 2.8.1 Verification . 32 2.9 Conclusion . 39 3 Abstract Data Types for Hoare Logic 40 3.1 Introduction . 40 3.2 Basic abstract data types . 42 3.3 Indexed abstract data types . 43 3.3.1 Example . 44 3.3.2 Depth-indexed stack ADT . 46 3.3.3 List-indexed ADT . 47 3.4 Functor-based implementation of ADTs . 48 3.5 ADTs for deep embeddings . 52 3.5.1 Example specification . 55 3.6 Related work and conclusion . 55 4 The Garbage Collector Interface 59 4.1 Introduction . 59 4.2 Garbage collection as ADT . 61 4.3 The abstract state . 64 4.3.1 Representation predicate . 65 4.3.2 Minor interface parameters . 66 4.3.3 Properties of the representation predicate . 67 4.4 Operation specifications . 71 4.4.1 GC step . 71 4.4.2 Read specification . 74 4.4.3 Write specification . 76 iv 4.4.4 Allocator specification . 77 4.5 Top level components . 79 4.6 Collector coercions . 80 4.7 Conclusion . 81 5 Representation Predicates 83 5.1 Introduction . 83 5.2 Mark-sweep collector . 85 5.3 Copying collector . 88 5.4 Incremental copying collector . 92 5.5 Conclusion . 99 6 Cheney Collector Verification 100 6.1 Introduction . 100 6.2 Generic predicates and definitions . 105 6.3 Field scanning . 110 6.3.1 Implementation . 111 6.3.2 Specification . 114 6.3.3 Verification . 121 6.4 The loop . 123 6.4.1 Implementation . 123 6.4.2 Specification . 124 6.4.3 Verification . 128 6.5 The collector . 130 6.5.1 Implementation . 130 6.5.2 Specification . 132 6.5.3 Verification . 137 v 6.6 The allocator . 143 6.6.1 Implementation . 145 6.6.2 Specification . 145 6.6.3 Verification . 146 6.7 Reading and writing . 150 6.7.1 Implementation . 151 6.7.2 Specification . 152 6.7.3 Verification . 152 6.8 Putting it together . 153 6.9 Conclusion . 154 7 Baker Collector Verification 156 7.1 Introduction . 156 7.2 Field scanning . 160 7.3 The loop . 161 7.3.1 Implementation . 161 7.3.2 Specification . 163 7.3.3 Verification . 168 7.4 Allocator . 175 7.4.1 Implementation . 177 7.4.2 Specification . 177 7.4.3 Allocator verification . 183 7.4.4 Restore root verification . 193 7.4.5 Specification weakening . 193 7.5 Read barrier . 195 7.5.1 Implementation . 195 vi 7.5.2 Specification . 197 7.5.3 Verification . 198 7.6 Write barrier . 202 7.6.1 Verification . 203 7.7 Putting it all together . 203 7.8 Conclusion . 204 8 Tools and Tactics 206 8.1 Introduction . 206 8.2 Machine semantics . 207 8.2.1 Command step simplifications . 207 8.2.2 State update simplifications . 209 8.3 Finite sets . 210 8.4 Separation logic . 212 8.4.1 Simplification . 212 8.4.2 Matching . 213 8.4.3 Reordering . 214 8.4.4 Reassociation . 215 8.4.5 Reordering and reassociation . 217 8.5 Related work . 218 8.6 Conclusion . ..