Memory Management with Explicit Regions by David Edward Gay Engineering Diploma (Ecole Polytechnique F´ed´erale de Lausanne, Switzerland) 1992 M.S. (University of California, Berkeley) 1997 A dissertation submitted in partial satisfaction of the requirements for the degree of Doctor of Philosophy in Computer Science in the GRADUATE DIVISION of the UNIVERSITY of CALIFORNIA at BERKELEY Committee in charge: Professor Alex Aiken, Chair Professor Susan L. Graham Professor Gregory L. Fenves Fall 2001 The dissertation of David Edward Gay is approved: Chair Date Date Date University of California at Berkeley Fall 2001 Memory Management with Explicit Regions Copyright 2001 by David Edward Gay 1 Abstract Memory Management with Explicit Regions by David Edward Gay Doctor of Philosophy in Computer Science University of California at Berkeley Professor Alex Aiken, Chair Region-based memory management systems structure memory by grouping objects in regions under program control. Memory is reclaimed by deleting regions, freeing all objects stored therein. Our compiler for C with regions, RC, prevents unsafe region deletions by keeping a count of references to each region. RC's regions have advantages over explicit allocation and deallocation (safety) and traditional garbage collection (better control over memory), and its performance is competitive with both|from 6% slower to 55% faster on a collection of realistic benchmarks. Experience with these benchmarks suggests that modifying many existing programs to use regions is not difficult. An important innovation in RC is the use of type annotations that make the structure of a program's regions more explicit. These annotations also help reduce the overhead of reference counting from a maximum of 25% to a maximum of 12.6% on our benchmarks. We generalise these annotations in a region type system whose main novelty is the use of existentially quantified abstract regions to represent pointers to objects whose region is partially or totally unknown. A distribution of RC is available at http://www.cs.berkeley.edu/~dgay/rc. Professor Alex Aiken Dissertation Committee Chair i Contents List of Figures iv List of Tables vi 1 Introduction 1 1.1 Contributions . 2 1.1.1 Language Design . 2 1.1.2 Types . 3 1.1.3 Implementation Techniques . 4 1.1.4 Detailed Performance Study . 4 1.2 Comparison to Other Memory-Management Styles . 5 1.2.1 Explicit Deallocation . 5 1.2.2 Tracing Garbage Collection . 6 1.2.3 Reference-counted Garbage Collection . 8 1.3 Dissertation Outline . 8 2 Related Work 10 2.1 Regions . 10 2.1.1 Static Safety . 10 2.1.2 Dynamic Safety . 12 2.1.3 No Safety . 14 2.2 Other Styles of Memory-Management . 15 2.3 Safe C Dialects . 15 2.3.1 Language Changes . 16 2.3.2 Conservative Garbage Collection . 16 2.3.3 Instrumentation . 17 2.3.4 Interpretation . 17 3 Language Design 19 3.1 C@ . 19 3.2 RC . 22 3.2.1 C@ Lessons . 23 3.2.2 Assumptions . 25 3.2.3 Region Library . 25 ii 3.2.4 Type Qualifiers . 30 3.2.5 Restrictions . 32 3.2.6 Linking to Existing Object Code . 36 3.2.7 Fallback to C . 36 3.2.8 Debugging Support . 37 3.2.9 Examples . 37 3.3 Titanium . 41 3.3.1 Parallelism in Titanium . 42 3.3.2 Shared and Private Regions . 43 3.3.3 Region-Based Allocation in Titanium . 44 3.3.4 Titanium Example . 45 3.4 RC Extensions . 47 3.4.1 Alternative semantics for deleteregion . 47 3.4.2 Further Type Annotations in RC . 48 3.4.3 Expressing Locality . 50 4 Implementation Techniques 52 4.1 Compiling to C . 52 4.2 Region Library . 53 4.2.1 Regions . 53 4.2.2 Allocators . 55 4.2.3 Page Allocator . 56 4.2.4 Page Map . 58 4.3 Reference Counting . 59 4.3.1 Deleting Regions . 61 4.3.2 Reference Counting for Local Variables . 61 4.3.3 Local Variable Reference Counts in C@ . 62 4.3.4 Local Variable Reference Counts in RC . 64 4.3.5 Alternate Reference Counting Implementations . 67 4.3.6 Variations on Standard Reference Counting . 68 4.3.7 Reference Counts Between Pairs of Regions . 69 4.4 Parallelism . 72 4.4.1 Parallel Region Implementation . 73 4.4.2 Creating and Deleting Regions . 74 4.5 Real-Time Regions . 76 5 rlang 78 5.1 rlang Types . 78 5.2 Region Type Checking in rlang . 80 5.3 Semantics . 84 5.4 Soundness . 88 5.5 Soundness Proof . 90 5.6 Translating RC to rlang . 99 5.7 Alternate Translations of RC to rlang . 101 5.7.1 Extensions to RC . 102 iii 5.7.2 Runtime Checks . 102 5.7.3 Annotation Inference . 103 6 Results 105 6.1 Benchmarks . 105 6.2 Region Structure . 106 6.3 Changes to Benchmarks . 109 6.4 Allocators and Test Environment . 112 6.5 Benchmark Behaviour . 112 6.6 Memory Usage . 115 6.7 Performance . 117 6.7.1 Performance vs Other Allocation Techniques . 117 6.7.2 Performance of Alternative Reference-counting Implementations . 119 6.7.3 Reference-counting Overhead . 120 6.8 Qualifiers . 121 6.9 Local Variables . 126 6.10 Other Overheads . 128 6.11 Atomic Swaps . 128 6.12 Summary . 129 7 Conclusion 131 7.1 Strengths and Weaknesses of Regions . 132 7.2 Extensions . 133 Bibliography 135 A Standard C Library Compatibility 142 iv List of Figures 1.1 An example of region-based allocation. 2 3.1 C@ Region API . 20 3.2 List copy using regions in C@. 21 3.3 An example of region-based allocation. 25 3.4 Region API . 26 3.5 An example of region-based allocation in Titanium. 42 3.6 A larger Titanium example . 46 4.1 Region structure . 54 4.2 Allocator structure . 55 4.3 Block header structure . 57 4.4 Reference counting and annotation checking . 60 4.5 Region scan during deleteregion(r). 62 4.6 Reference counting including same-region references. 68 4.7 Reference counting excluding parent pointers . 69 4.8 Reference counting for reference counts between pairs of regions . 71 4.9 Reference counting in a parallel language . ..
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages154 Page
-
File Size-