Combining Garbage Collection and Safe Manual Memory Management Michael Hicks University of Maryland,...

16
Combining Garbage Collection and Safe Manual Memory Management Michael Hicks University of Maryland, College Park Joint work with Greg Morrisett - Harvard, Dan Grossman - Uwash, and Trevor Jim - AT&T

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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)