Combining Garbage Collection and Safe Manual Memory Management Michael Hicks University of Maryland,...
-
Upload
maximillian-boyd -
Category
Documents
-
view
212 -
download
0
Transcript of Combining Garbage Collection and Safe Manual Memory Management Michael Hicks University of Maryland,...
![Page 1: Combining Garbage Collection and Safe Manual Memory Management Michael Hicks University of Maryland, College Park Joint work with Greg Morrisett - Harvard,](https://reader035.fdocuments.in/reader035/viewer/2022072006/56649f525503460f94c7598f/html5/thumbnails/1.jpg)
Combining Garbage Collection and Safe Manual Memory
Management
Michael HicksUniversity of Maryland, College Park
Joint work with
Greg Morrisett - Harvard,
Dan Grossman - Uwash, and
Trevor Jim - AT&T
![Page 2: Combining Garbage Collection and Safe Manual Memory Management Michael Hicks University of Maryland, College Park Joint work with Greg Morrisett - Harvard,](https://reader035.fdocuments.in/reader035/viewer/2022072006/56649f525503460f94c7598f/html5/thumbnails/2.jpg)
Cyclone
• Derived from C, having similar goals– Exposes low-level data representations,
provides fine-grained operations
• But memory safe– Restrictions to C (e.g., (int *)1 not allowed)– Additions and types to regain flexibility
![Page 3: Combining Garbage Collection and Safe Manual Memory Management Michael Hicks University of Maryland, College Park Joint work with Greg Morrisett - Harvard,](https://reader035.fdocuments.in/reader035/viewer/2022072006/56649f525503460f94c7598f/html5/thumbnails/3.jpg)
Goal: Programmer Control
• Many reasonable MM choices– Garbage collection– Stack allocation
– malloc/free– Reference counting
• Linux, COM
– Arenas (individual allocation, bulk free)• Apache, LCC
• Depends on the application
![Page 4: Combining Garbage Collection and Safe Manual Memory Management Michael Hicks University of Maryland, College Park Joint work with Greg Morrisett - Harvard,](https://reader035.fdocuments.in/reader035/viewer/2022072006/56649f525503460f94c7598f/html5/thumbnails/4.jpg)
Unifying Theme: Region types
• Conceptually divide memory into regions– Different kinds of regions (e.g., not just bulk-free)
• Associate every pointer with a region
• Prevent dereferencing pointers into dead regions
int *`r x; // x points into region `r *x = 3; // deref allowed if `r is live
(inference often obviates annotations `r)
![Page 5: Combining Garbage Collection and Safe Manual Memory Management Michael Hicks University of Maryland, College Park Joint work with Greg Morrisett - Harvard,](https://reader035.fdocuments.in/reader035/viewer/2022072006/56649f525503460f94c7598f/html5/thumbnails/5.jpg)
Regions Summary (PLDI 02)
Region Variety
Allocation
(objects)
Deallocation
(what) (when)
Aliasing
(objects)
Stack static whole region
exit of scope
free
Lexical dynamic
Heap single objects
GC
![Page 6: Combining Garbage Collection and Safe Manual Memory Management Michael Hicks University of Maryland, College Park Joint work with Greg Morrisett - Harvard,](https://reader035.fdocuments.in/reader035/viewer/2022072006/56649f525503460f94c7598f/html5/thumbnails/6.jpg)
Regions Summary (now)
Region Variety
Allocation
(objects)
Deallocation
(what) (when)
Aliasing
(objects)
Stack static whole region
exit of scope
free
Lexical dynamic
Dynamic manual
Heap single objects
GC
Unique manual
restricted
Refcounted
![Page 7: Combining Garbage Collection and Safe Manual Memory Management Michael Hicks University of Maryland, College Park Joint work with Greg Morrisett - Harvard,](https://reader035.fdocuments.in/reader035/viewer/2022072006/56649f525503460f94c7598f/html5/thumbnails/7.jpg)
Enabled by Linearity (Affinity)
• Pointers whose state is carefully tracked• To simplify programming:
– Polymorphism– Temporary aliasing– Atomic swap (e.g., destructive reads)
• Main ideas close to Walker & Watkins• Key contribution: extension and integration
into realistic low-level language
![Page 8: Combining Garbage Collection and Safe Manual Memory Management Michael Hicks University of Maryland, College Park Joint work with Greg Morrisett - Harvard,](https://reader035.fdocuments.in/reader035/viewer/2022072006/56649f525503460f94c7598f/html5/thumbnails/8.jpg)
Programming Experience
• Optimize for memory use– Important for embedded systems, OSs
• Optimize for speed– Servers, OSs, etc.
• Applications– Event-based webserver (only unique pointers)– MediaNet: Streaming data overlay network
• All six region varieties; packet data is unique or reference-counted
![Page 9: Combining Garbage Collection and Safe Manual Memory Management Michael Hicks University of Maryland, College Park Joint work with Greg Morrisett - Harvard,](https://reader035.fdocuments.in/reader035/viewer/2022072006/56649f525503460f94c7598f/html5/thumbnails/9.jpg)
Memory Usage: webserver
![Page 10: Combining Garbage Collection and Safe Manual Memory Management Michael Hicks University of Maryland, College Park Joint work with Greg Morrisett - Harvard,](https://reader035.fdocuments.in/reader035/viewer/2022072006/56649f525503460f94c7598f/html5/thumbnails/10.jpg)
MediaNet: gc (4 KB packets)
![Page 11: Combining Garbage Collection and Safe Manual Memory Management Michael Hicks University of Maryland, College Park Joint work with Greg Morrisett - Harvard,](https://reader035.fdocuments.in/reader035/viewer/2022072006/56649f525503460f94c7598f/html5/thumbnails/11.jpg)
MediaNet: gc+free (4 KB packets)
![Page 12: Combining Garbage Collection and Safe Manual Memory Management Michael Hicks University of Maryland, College Park Joint work with Greg Morrisett - Harvard,](https://reader035.fdocuments.in/reader035/viewer/2022072006/56649f525503460f94c7598f/html5/thumbnails/12.jpg)
MediaNet: throughput
![Page 13: Combining Garbage Collection and Safe Manual Memory Management Michael Hicks University of Maryland, College Park Joint work with Greg Morrisett - Harvard,](https://reader035.fdocuments.in/reader035/viewer/2022072006/56649f525503460f94c7598f/html5/thumbnails/13.jpg)
Future Work
• Further generalization– Type-safe Reaps (Berger et al.)
• More programming experience• Better inference (e.g. for alias)• Formal model• …
![Page 14: Combining Garbage Collection and Safe Manual Memory Management Michael Hicks University of Maryland, College Park Joint work with Greg Morrisett - Harvard,](https://reader035.fdocuments.in/reader035/viewer/2022072006/56649f525503460f94c7598f/html5/thumbnails/14.jpg)
Conclusions
• High degree of control, safely:
• Sound mechanisms for programmer-controlled memory management– Region-based vs. object-based deallocation– Manual vs. automatic reclamation
• Region-annotated pointers within a simple framework– Lexical regions as unifying theme (alias,open)– Region polymorphism, for code reuse
![Page 15: Combining Garbage Collection and Safe Manual Memory Management Michael Hicks University of Maryland, College Park Joint work with Greg Morrisett - Harvard,](https://reader035.fdocuments.in/reader035/viewer/2022072006/56649f525503460f94c7598f/html5/thumbnails/15.jpg)
More Information
• Cyclone homepage– http://www.cs.cornell.edu/projects/cyclone/
• Has papers and free distribution– Read about it, write some code!
![Page 16: Combining Garbage Collection and Safe Manual Memory Management Michael Hicks University of Maryland, College Park Joint work with Greg Morrisett - Harvard,](https://reader035.fdocuments.in/reader035/viewer/2022072006/56649f525503460f94c7598f/html5/thumbnails/16.jpg)
Related Work (incomplete)
• Regions– ML-Kit (foundation for Cyclone’s type system)– RC– Reaps– Walker/Watkins
• Uniqueness– Wadler, Walker/Watkins, Clean– Alias types, Calculus of Capabilities, Vault– Destructive reads (e.g., Boyland)