1 / 34

An Effect System Combining Alias and Liveness for Explicit Memory Reuse

An Effect System Combining Alias and Liveness for Explicit Memory Reuse. Oukseh Lee ROPAS / KAIST December 17, 2001. Garbage Collection. Safe and efficient. Inefficient for frequent temporary heap allocations. fun incr l = case l of [] => [] | h::t => (h+1)::(incr t).

mea
Download Presentation

An Effect System Combining Alias and Liveness for Explicit Memory Reuse

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. An Effect System Combining Alias and Liveness for Explicit Memory Reuse Oukseh Lee ROPAS / KAIST December 17, 2001

  2. Garbage Collection • Safe and efficient. • Inefficient for frequent temporary heap allocations. fun incr l = case l of [] => [] | h::t => (h+1)::(incr t)

  3. Memory Reuse (or Recycle) • Operationally, destructive update. • Cheap to evaluate. fun incr l = case l of [] => [] | h::t => (h+1)::(incr t) at l

  4. Final Goal Find an algorithm that inserts “safe and effective” memory recycle commands into ML programs.

  5. Goal Find a memory type system to guarantee the memory safety for ML with explicit memory recycle.

  6. Memory Safety x = 1::[] y = 2::[] at x case x of … x = 1::[] y = 2::[] at x z = 3::[] at x We cannot recycle heap cells that will be used later (or recycled again). Conceptually, recycle = free + malloc.

  7. Language

  8. Steps How to abstract the heap? • How to check the memory safety?

  9. How to Abstract the Heap? • Symbolic locations. • Names for sets of addresses. • Two-level abstract domains. • Concrete. • Collapsed. • Kinds of cells.

  10. Symbolic Locations • Names for sets of addresses. • Allocations / recycles may introduce a new location.

  11. Symbolic Locations for Functions • Locations of arguments and locations newly allocated in the function are bound. • A function call is a substitution for bound locations.

  12. Two-Level Abstract Types • Analyze the heap as concrete as possible. • Need an abstraction for possibly infinite heap structure. • Two-level abstractions: • Concrete: as concrete as the heap cells are. • Collapsed: ignoring the heap structure.

  13. Concrete Type C D Leaf Leaf E B Node Leaf A Node

  14. Two-Level Abstract Types Abstraction: concrete -> collapsed. • When we join two different heap structures. • Reconstruction: collapsed -> concrete. • When we need the structure. If … then [] else [1,2] case x of h::t => …

  15. Collapsing the Structure! C D Leaf Leaf E B Node Leaf A Node

  16. Cell-Kinds • Diving a list into the spine and elements seems to be effective. • Kinds of cells are its generalization. • Abstract data values: its constructor. • Tuples: its type.

  17. Leaf Leaf Node Leaf Node Classifying by Cell-Kinds C D E B A

  18. Two-Level Abstract Types • Abstraction: concrete -> collapsed. • When we join two different heap structures. Reconstruction: collapsed -> concrete. • When we need the heap structure. If … then [] else [1,2] case x of h::t => …

  19. Leaf Leaf Node Leaf Node How to Reconstruct? C D E B A

  20. A,B A,B Leaf Leaf C,D,E C,D,E Node Node Node Naïve Reconstruction A,B

  21. Leaf Leaf Node Node Node Accurate Reconstruction G H I J F

  22. A,B A,B Leaf Leaf C,D,E C,D,E Node Node Node Then, Restore Locations A,B

  23. Leaf Leaf Leaf Leaf Node Node Node Node Node Sharing Flags • If locations are shared, we do not use accurate reconstruction. • Sharing flag for each set of locations. C D G H I J B A F

  24. Steps • How to abstract the heap? How to check the memory safety?

  25. Liveness Analysis • Collect used and recycled locations. • Used: by “case x of …,” or “1::[].” • Recycled: by “at x.”

  26. Liveness Analysis We cannot recycle locations that will be used later (or recycled again) !

  27. Function Calls Induce Aliases • Between formal parameters. • Between formal and actual parameters. let val z = [1,2,3] fun f (x, y) = e in f (z, z) end

  28. Robust Against Aliases let val z = [1,2,3] fun f (x, y) = … at x … case y … in f (z, z) end let val z = [1,2,3] fun f (x, y) = … case y … at x … in f (z, z) end If A and B may be aliased and A is recycled, then B must not be used (nor recycled).

  29. Conclusion • We presents an effect system for checking every memory reuse is safe. • Preliminary experiment encourages us. • GC overhead: 0-51.6% (in OCaml). • sieve runs 28.1% faster with reuse. • Need to be proved. • Need to devise an inference algorithm. • Need to be extended to other language constructs.

  30. Leaf Leaf Node Node Sharing Flags • We can accurately reconstruct only non-shared collapsed-type. C D B A

  31. Leaf Leaf Leaf Node Node Node Sharing Flags • We can accurately reconstruct only non-shared collapsed-type. C D C,D B A,B A

  32. Leaf Leaf Leaf Leaf Node Node Node Node Node Sharing Flags • We can accurately reconstruct only non-shared collapsed-type. C D G H I J B A F

  33. Leaf Leaf Leaf Node Node Node Sharing Flags • We can accurately reconstruct only non-shared collapsed-type. C D w {C,D} B {A,B} A

  34. Leaf Leaf Leaf Leaf Node Node Node Node Node Sharing Flags • We can accurately reconstruct only non-shared collapsed-type. C D G H w w {C,D} {C,D} B A F

More Related