Download presentation
Presentation is loading. Please wait.
Published byWesley Johns Modified over 8 years ago
1
Automatic Memory Management Without Run-time Overhead Brian Brooks
2
What's the point? I love my stop-the-world GC... ● The whole point of automatic memory management is that an object lives as long as it needs to, preferably no longer.
3
What's the point? I love my stop-the-world GC... ● The whole point of automatic memory management is that an object lives as long as it needs to, preferably no longer. ● When can we free an object?
4
What's the point? I love my stop-the-world GC... ● The whole point of automatic memory management is that an object lives as long as it needs to, preferably no longer. ● When can we free an object? – When we can guarantee it wont be used again.
5
We will look at... ● Linear type systems ● Region Based Memory Management ● Capability Calculus
6
History of linearity ● Linear logic (Girard) – Propositions must be used exactly once – No duplication or discarding ● Linear types (Wadler) – No duplication: only one pointer to a value – No discarding: use once, then deallocate
7
A Linear Type System
9
Are Linear Types Practical? ● Key point: values may only be used once. So deallocation is safe. ● Not really expressive. ● Could include non-linear types. Must GC.
10
Regions ● All values are stored in regions. ● Heap contains stack of regions. ● LIFO ordering of region lifetimes.
11
Regions ● All values are stored in regions. ● Heap contains stack of regions. ● LIFO ordering of region lifetimes. ● 2 annotations: “Evaluate e1 to some value and store it in region p” “Allocate a new region and bind it to p, evaluate e2, deallocate region.”
12
● Must ensure that: Region Safety
13
● Must ensure that: ● Need to track region accesses while type checking!! Region Safety
14
● Must ensure that: ● Need to track region accesses while type checking!! ● Annotate function type with an effect – Effect: set of regions the function may access Region Safety
15
● Must ensure that: ● Need to track region accesses while type checking!! ● Annotate function type with an effect – Effect: set of regions the function may access Region Safety
16
Regions: What else? ● Region inference – Translation from source to target annotated lang – Eliminate the need for most annotations ● Region polymorphism – Functions can be “parameterized” over regions. – Ex: Can pass a region to a function to store it's return value in.
17
Capabilities ● Key idea: values are still stored in regions, but region allocation / deallocation is explicit. ● Capabilities are similar to effects: – “Under … assumptions, it is legal to execute d, provided the capability C is held. – Capabilities indicate the set of regions that are valid to access (haven't been free'd).
18
Capabilities ● If we allocate a new region p, we update C to include p ● If we deallocate a region p, p must be in C, we then update C to remove p. ● If we try to read some value – The value v : T at p must be in the typing ctxt – AND, C must contain p.
19
Conclusion ● Linear types aren't very expressive. – No aliasing – Values may be used once ● Region Based Memory Management – Safe, simple discipline of automatic memory management. ● Capability Calculus – More expressive: explicit region lifetimes.
20
Questions?
21
References ● Linear types can change the world! Philip Wadler ● Region-Based Memory Management. Tofte & Talpin ● Typed Memory Management. David Walker ● Effect Types and Region-based Memory Management. Ch in AdvTAPL, Pierce.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.