Subheap-Augmented Garbage Collection
Total Page:16
File Type:pdf, Size:1020Kb
University of Pennsylvania ScholarlyCommons Publicly Accessible Penn Dissertations 2019 Subheap-Augmented Garbage Collection Benjamin Karel University of Pennsylvania Follow this and additional works at: https://repository.upenn.edu/edissertations Part of the Computer Sciences Commons Recommended Citation Karel, Benjamin, "Subheap-Augmented Garbage Collection" (2019). Publicly Accessible Penn Dissertations. 3670. https://repository.upenn.edu/edissertations/3670 This paper is posted at ScholarlyCommons. https://repository.upenn.edu/edissertations/3670 For more information, please contact [email protected]. Subheap-Augmented Garbage Collection Abstract Automated memory management avoids the tedium and danger of manual techniques. However, as no programmer input is required, no widely available interface exists to permit principled control over sometimes unacceptable performance costs. This dissertation explores the idea that performance- oriented languages should give programmers greater control over where and when the garbage collector (GC) expends effort. We describe an interface and implementation to expose heap partitioning and collection decisions without compromising type safety. We show that our interface allows the programmer to encode a form of reference counting using Hayes' notion of key objects. Preliminary experimental data suggests that our proposed mechanism can avoid high overheads suffered by tracing collectors in some scenarios, especially with tight heaps. However, for other applications, the costs of applying subheaps---in human effort and runtime overheads---remain daunting. Degree Type Dissertation Degree Name Doctor of Philosophy (PhD) Graduate Group Computer and Information Science First Advisor Jonathan M. Smith Keywords Garbage Collection, Memory Management, Subheaps Subject Categories Computer Sciences This dissertation is available at ScholarlyCommons: https://repository.upenn.edu/edissertations/3670 SUBHEAP-AUGMENTED GARBAGE COLLECTION Benjamin Karel A DISSERTATION in Computer and Information Science Presented to the Faculties of the University of Pennsylvania in Partial Fulfillment of the Requirements for the Degree of Doctor of Philosophy 2019 Supervisor of Dissertation Jonathan M. Smith, Olga and Alberico Pompa Professor Graduate Group Chairperson Rajeev Alur, Zisman Family Professor Dissertation Committee Steve Zdancewic (Professor of CIS; Committee Chair) Andreas Haeberlen (Associate Professor of CIS) Joe Devietti (Assistant Professor of CIS) Alex Garthwaite (External Member, VMware) ACKNOWLEDGMENTS I am indebted, in ways large and small, to many whose paths have crossed with mine over the years. My advisor, Jonathan Smith, has not only imparted the wisdom of experience in matters academic, but has also demonstrated by example a more exalted life: unfailingly kind to all who deserve it and many who don't, buttressed by a stubborn positivity in which any day that starts with waking up is a good day. Andr´eDeHon has demonstrated admirable patience and tireless dedication as a collaborator and surrogate advisor. My committee|Andreas Haeberlen, Joe Devietti, Steve Zdancewic, and Alex Garthwaite| have provided helpful feedback on my drafts and ideas and have been universally generous with their time. In words and actions alike, Benjamin Pierce has demonstrated the power and importance of precise thought and clear writing. Milo Martin and Stephanie Weirich both provided sage advice (which, to my detriment, I did not fully heed) and constructive feedback in my first years at Penn. Many fellow graduate students have influenced my time at Penn. Perry Metzger encour- aged me both in my transition into the doctoral program and my pursuit of|as he put it|writing the Great American Compiler. Adam Aviv and Katie Gibson welcomed me into Jonathan's group. Michael Greenberg, Beno^ıtMontagu, and C˘at˘alinHrit¸cu provided friendship, support, and guidance over our respective stints on the SAFE project. But the single biggest fixture of my time at Penn has been Nikos Vasilakis. He has been a fine friend and a generous collaborator. It has been an honor and a privilege to witness his skills|in research and in writing|far exceed my own. Last but not least, I owe much to my family. To my parents, for their unwavering support and all the countless things they have done to help me get to where I am. And to my wife Lauren, last on the page but first in my heart, for being the other half of my orange, and remaining so as the years accumulated past my initially planned graduation date. ii ABSTRACT SUBHEAP-AUGMENTED GARBAGE COLLECTION Benjamin Karel Jonathan M. Smith Automated memory management avoids the tedium and danger of manual techniques. However, as no programmer input is required, no widely available interface exists to permit principled control over sometimes unacceptable performance costs. This dissertation explores the idea that performance-oriented languages should give pro- grammers greater control over where and when the garbage collector (GC) expends effort. We describe an interface and implementation to expose heap partitioning and collection decisions without compromising type safety. We show that our interface allows the programmer to encode a form of reference counting using Hayes' notion of key objects. Preliminary experimental data suggests that our proposed mechanism can avoid high overheads suffered by tracing collectors in some scenarios, especially with tight heaps. However, for other applications, the costs of applying subheaps|in human effort and runtime overheads|remain daunting. iii Chapter Contents ACKNOWLEDGMENTS . ii ABSTRACT . iii LIST OF TABLES . vi LIST OF ILLUSTRATIONS . viii CHAPTER 1 : Introduction . 1 1.1 Motivation: Bridging Language Users and Implementors . 2 1.2 The Core Idea Of Subheaps . 3 1.3 Purpose & Contributions . 4 1.4 Roadmap . 5 1.5 Garbage Collection, Briefly . 6 CHAPTER 2 : Subheaps . 10 2.1 Subheap Principles . 10 2.2 Design Constraints . 12 2.3 Subheap API . 13 2.4 Subheap Implementation . 14 2.5 Generational Variants . 29 2.6 Further Considerations . 33 2.7 Refinements of the Subheap API . 38 CHAPTER 3 : Using Subheaps . 43 3.1 \Hello, World" . 43 3.2 Modes of Usage . 46 iv 3.3 Iterative Deployment & Debugging . 48 3.4 Modularity . 50 3.5 \Reference Counting" with Key Objects . 54 CHAPTER 4 : Evaluation . 59 4.1 Experimental Platform . 61 4.2 Conway's Game of Life . 61 4.3 Tree Microbenchmarks . 76 4.4 Software Caches . 83 4.5 Self-Adjusting Computation . 88 CHAPTER 5 : Challenges & Future Work . 100 5.1 Concurrency . 100 5.2 Untrusted Code . 102 5.3 Stack Scanning Costs . 103 5.4 Automation . 104 CHAPTER 6 : Related Work . 106 6.1 Region-Based Memory Management . 108 6.2 Garbage Collection . 115 CHAPTER 7 : Conclusion . 146 APPENDIX . 152 BIBLIOGRAPHY . 155 v LIST OF TABLES TABLE 1 : Effect of varying granularity of subheap collection on Reynolds2 (input 24). 82 TABLE 2 : Comparison Matrix for Various Memory Management Ap- proaches . 108 vi LIST OF ILLUSTRATIONS FIGURE 1 : Per-line state machine for the \used" bit. 20 FIGURE 2 : Subheap write barrier (C++) . 26 FIGURE 3 : Subheap write barrier (x86-64 asm) . 26 FIGURE 4 : A code pattern that defeats static subheap optimization . 29 FIGURE 5 : Foster code for binarytrees . 44 FIGURE 6 : Simplified cache heap structure . 54 FIGURE 7 : Conway's Game of Life microbenchmark in Foster . 62 FIGURE 8 : Correlation of mark/cons ratio and GC time for Conway . 64 FIGURE 9 : Separating a spiky curve into component effects . 65 FIGURE 10 : Impact of subheaps on Conway . 66 FIGURE 11 : Source code listing for subheap-augmented Conway . 67 FIGURE 12 : Detailed impact of generational collection on Conway . 71 FIGURE 13 : Impact on Conway of increasing ambient heap ballast . 73 FIGURE 14 : Impact of ballast on Conway (mark/cons and runtime) . 74 FIGURE 15 : Bounded Mutator Utilization for Conway . 75 FIGURE 16 : Binary-trees results for Java and Foster . 77 FIGURE 17 : binarytrees on G1 . 78 FIGURE 18 : Reynolds2 source code in Foster . 80 FIGURE 19 : Minicache (B=1000, N=700, K=300) results . 83 FIGURE 20 : Comparison of Foster's Immix variants on minicache. 84 FIGURE 21 : End-to-end memcached workload latency . 86 FIGURE 22 : Mark/Cons Ratios for SAC qsort-500 . 90 vii FIGURE 23 : GC runtime for SAC qsort-500 . 91 FIGURE 24 : Program runtime for SAC qsort-500 . 92 FIGURE 25 : Impact of compaction on SAC qsort-500 runtime . 92 FIGURE 26 : Definition of Modref.read . 94 FIGURE 27 : Partial heap structure allocated by Modref.read . 97 FIGURE 28 : Definition of SAC's qsort implementation . 98 FIGURE 29 : Cycle timings for fine-grained subheaps on SAC qsort/500 . 98 FIGURE 30 : Costlier subheap write barrier (asm). 153 viii CHAPTER 1 : Introduction Most computer programs allocate memory as they run, but memory is a finite re- source. Reclaiming unused memory safely and efficiently motivates the study of garbage collection (GC). Functionally correct GC algorithms date to the early years of computer science [McC60, JHM11]. Yet correctness is not enough: effort over subsequent decades has focused on various facets of performance, such as low pause times, high space efficiency, and productive use of available hardware resources. Re- search in garbage collection has produced designs that work well for most programs, but every GC embodies tradeoffs and heuristics that may be ill-suited for certain programs. Thus the goal for GC design is not merely to produce collectors which are efficient on average, but those which perform well for the widest range