Reginf pldi3

208 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
208
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Reginf pldi3

  1. 1. Region Inference for an Object-Oriented Language Wei Ngan Chin 1,2 Joint work with Florin Craciun 1 , Shengchao Qin 1,2 , Martin Rinard 3 1 National University of Singapore 2 Singapore-MIT Alliance 3 MIT
  2. 2. Background <ul><li>Basic problem : </li></ul><ul><ul><li>how to recover memory of dead objects? </li></ul></ul><ul><li>Two Approaches </li></ul><ul><ul><li>garbage collection </li></ul></ul><ul><ul><li>explicit memory management </li></ul></ul><ul><li>Our Focus : </li></ul><ul><ul><li>Explicit memory regions with different lifetimes </li></ul></ul>
  3. 3. Current Status <ul><li>Region Inference for a functional language </li></ul><ul><ul><li> -Calculus [Tofte-Talpin POPL94] </li></ul></ul><ul><li>Previous Works on Region Type Checkers : </li></ul><ul><ul><li>Java [DIKU98], </li></ul></ul><ul><ul><li>Real-Time Java : [MIT-PLDI03], </li></ul></ul><ul><ul><li>Cyclone [Cornell-PLDI02]. </li></ul></ul>Our Goal : automatic region inference for object-oriented programs
  4. 4. Two Major Assumptions <ul><li>Lexically-Scoped Regions : </li></ul><ul><ul><li>Stack-like lifetimes </li></ul></ul><ul><ul><li>construct for local region : </li></ul></ul><ul><ul><li>letreg r in e </li></ul></ul>top (younger) bottom (older) r1 r2 r3 r4 <ul><li>No Dangling References : </li></ul><ul><ul><li>Regions of components should have longer lifetimes than its object. </li></ul></ul>
  5. 5. Main Contributions <ul><li>Region Inference for Core-Java </li></ul><ul><li>Constraint-Based Type System. </li></ul><ul><li>Region Polymorphism & Region Subtyping </li></ul><ul><li>Handles Inheritance, Overriding, Downcast </li></ul><ul><li>Implementation </li></ul>
  6. 6. Region-Annotated Core-Java region parameters for polymorphism constraint abstractions class invariant method precondition region constraint s
  7. 7. Inferring for Class Step 4 : Inherit constraint of superclass. Step 1 : Reserve first region for the receiver object ( this ). Step 2 : Keep regions of fields distinct for precision. Step 3 : No dangling property as class invariant.
  8. 8. Inferring for Class Step 1 : Reserve first region for the receiver object ( this ). Step 2 : Keep regions of fields distinct for precision. Step 3 : No dangling requirement as class invariant.
  9. 9. Inferring for Methods Step 3 : Localise regions that do not escape. Step 4 : Fix-point analysis for recursion. method precondition Step 2 : Gather constraints from method body. Step 1 : Region parameters from method signature.
  10. 10. Outline <ul><li>Background </li></ul><ul><li>Key Techniques </li></ul><ul><ul><li>Inferring Class </li></ul></ul><ul><ul><li>Inferring Methods </li></ul></ul><ul><ul><li>Region Subtyping </li></ul></ul><ul><li>Region Inference </li></ul><ul><li>Method Overriding + Downcast </li></ul><ul><li>Experimental Results </li></ul>
  11. 11. (Object) Region Subtyping concept pioneered in Cyclone [PLDI02] an object w of type c <r,..> can be passed to a location v of type c <s,..> provided r º s (e.g. in assignment and parameter/result passing)
  12. 12. Example Without region subtyping, regions of a and b are forced to be equal . With region subtyping, these regions may be distinct .
  13. 13. Problem – Recursive Fields Recursive nodes being forced into the same region Some programs work better with recursive nodes in different regions …
  14. 14. (Field) Region Subtyping SOLUTION : Covariance for Read-Only Fields. Example: read-only mutable
  15. 15. Outline <ul><li>Background </li></ul><ul><li>Key Techniques </li></ul><ul><li>Region Inference </li></ul><ul><li>Method Overriding + Downcast </li></ul><ul><li>Experimental Results </li></ul>
  16. 16. Region Inference <ul><li>Main type inference rules </li></ul><ul><li>Apply inference according to global dependency graph (class,call,override dependencies). </li></ul>
  17. 17. Inference Rule : Sequence Inference is flow-insensitive but can be improved by SSA form
  18. 18. Inference Rule : Expression Block rs : the set of regions that do not escape the block Regions of rs coalesced into a single localised region r
  19. 19. Example – Localised Region
  20. 20. Example – Localised Region localised region r
  21. 21. Example : Recursive Function
  22. 22. Outline <ul><li>Background </li></ul><ul><li>Key Techniques </li></ul><ul><li>Region Inference </li></ul><ul><li>Overriding + Downcast </li></ul><ul><li>Experimental Results </li></ul>
  23. 23. Method Overriding <ul><li>class B h r 1 .. r n i extends A h r 1 .. r m i where C B  </li></ul><ul><li>In class A: Y mn h r’ 1 ,..,r’ p i (X) where M A {  } </li></ul><ul><li>In class B: Y mn h r’ 1 ,..,r’ p i (X) where M B {  } </li></ul><ul><li>Dynamic Dispatch : </li></ul><ul><li>Allows B.mn may be invoked where A.mn is expected </li></ul>Method Override Rule: C B Æ M A ) M B
  24. 24. Override Conflict Resolution <ul><li>Derived constraints C B M A M B may conflict with method override rule. </li></ul>Solution : strengthen C B , M A to C’ B , M’ A Until: C’ B Æ M’ A ) M B
  25. 25. Downcast Safety <ul><li>Compile-time guarantee to downcast safety. </li></ul><ul><li>Problem : regions are lost during upcast that have to be recovered for downcast . </li></ul><ul><li>Our Solution: </li></ul><ul><ul><li>Selectively maintain extra regions that are lost during upcast and may be needed by downcast. </li></ul></ul><ul><ul><li>Use flow analysis </li></ul></ul>
  26. 26. Experiments <ul><li>Prototype was built using Haskell. </li></ul><ul><li>Inference is fast and takes <5s for the Olden benchmark. </li></ul>
  27. 27. Experiments <ul><li>Inference is competitive to hand-annotation (RegJava benchmark) </li></ul><ul><ul><li>similar localised regions </li></ul></ul><ul><ul><li>same space recovery </li></ul></ul><ul><li>Region subtyping gives better space recovery for some examples. </li></ul>
  28. 28. Concluding Remarks <ul><li>Constraint-based region inference system: </li></ul><ul><ul><ul><li>Region subtyping . </li></ul></ul></ul><ul><ul><ul><li>Region polymorphism. </li></ul></ul></ul><ul><ul><ul><li>Polymorphic recursion </li></ul></ul></ul><ul><li>Handles OO features: </li></ul><ul><ul><ul><li>class subtyping </li></ul></ul></ul><ul><ul><ul><li>method overriding </li></ul></ul></ul><ul><ul><ul><li>downcast safety </li></ul></ul></ul><ul><li>Implementation is fast and precise. </li></ul>
  29. 29. Future Work <ul><li>Better Lifetime Precision </li></ul><ul><ul><li>variable liveness analysis </li></ul></ul><ul><ul><li>flow sensitivity via SSA </li></ul></ul><ul><ul><li>treat null as a primitive value </li></ul></ul><ul><li>Memory Efficiency : Sized Regions + Reuse </li></ul><ul><li>Extensions : Genericity + RTSJ </li></ul>
  30. 30. Correctness
  31. 31. Core-Java
  32. 32. Key Principles : Classes <ul><li>Region type : c h r 1 ,…, r n i </li></ul><ul><ul><li>r 1 : (region for current object of this type) </li></ul></ul><ul><ul><li>r 2 ,…,r n (regions for components/fields) </li></ul></ul><ul><ul><li>r k º r 1 , 8 k 2 2..n (no dangling references) </li></ul></ul><ul><li>First region is special. </li></ul><ul><li>Keep regions of components distinct. </li></ul>
  33. 33. No Region Subtyping [Boyapati et al PLDI03] supports class subtyping but not region subtyping
  34. 34. No Region Subtyping [Boyapati et al PLDI03] supports class subtyping but not region subtyping
  35. 35. Key Principles : Methods <ul><li>Region polymorphism from the region types of parameters and output </li></ul><ul><ul><li>t mn h r * i ((t v) * ) where rc e </li></ul></ul><ul><ul><li>r * captures region polymorphism </li></ul></ul><ul><li>Keep region constraints of classes and methods separate. </li></ul>
  36. 36. Example - Reynolds3 With field region subtyping, the List(x,p) object can be allocated in a local region of the recursive call.
  37. 37. Method Overriding <ul><li>class B h r 1 .. r n i extends A h r 1 .. r m i where C B  </li></ul><ul><li>In class A: Y mn h r’ 1 ,..,r’ p i (X) where M A {  } </li></ul><ul><li>In class B: Y mn h r’ 1 ,..,r’ p i (X) where M B {  } </li></ul><ul><li>Function Subtyping Rule: </li></ul><ul><li>Method Override Rule: </li></ul><ul><li>C B Æ M A ) M B </li></ul>argument result selection
  38. 38. Downcast Safety <ul><li>In our framework : </li></ul><ul><ul><li>regions may be lost during upcast </li></ul></ul><ul><ul><ul><li>e.g. Object <r1> o = new Pair <s1,s2,s3> (…) </li></ul></ul></ul><ul><ul><li>lost regions must be recovered during downcast. </li></ul></ul><ul><ul><ul><li>e.g. Pair <a1,a2,a3> p = (Pair) o </li></ul></ul></ul><ul><li>Key technique : maintain extra regions that were lost during upcasting and may be needed! </li></ul><ul><ul><ul><li>e.g. Object <r1 >[r2,r3] p = new Pair <s1,s2,s3> (…) </li></ul></ul></ul><ul><li>Solution : Flow analysis </li></ul>
  39. 39. Region Subtyping concept from [Cyclone PLDI02] allows v=w where location v::c <s,..> can be passed an object w of type c <r,..> provided r  s
  40. 40. Experiments <ul><li>Inference is competitive hand-annotation. </li></ul><ul><li>Prototype is fast (< 5s for upto 1000 lines) </li></ul><ul><li>http://loris-4.ddns.comp.nus.edu.sg/~craciunm </li></ul>
  41. 41. Experiments
  42. 42. Inference of Methods class invariant method precondition
  43. 43. Inferring for Class class invariant to prevent dangling references
  44. 44. List Example <ul><li>Key Principles </li></ul><ul><ul><li>First region is for only object of the class. </li></ul></ul><ul><ul><li>Keep regions of fields distinct for precision. </li></ul></ul>
  45. 45. Inference of Methods <ul><li>Key Principles </li></ul><ul><ul><li>Region polymorphism from parameters/result </li></ul></ul><ul><ul><li>Method precondition is applicable to only those objects that may invoke the method. </li></ul></ul>
  46. 46. Example – Cyclic Structure p1 p2
  47. 47. Inference of Methods method precondition

×