Your SlideShare is downloading. ×
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Reginf pldi3
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Reginf pldi3

91

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
91
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

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

×