Region Inference for an ObjectOriented Language - PowerPoint PPT Presentation

About This Presentation
Title:

Region Inference for an ObjectOriented Language

Description:

Method Overriding Downcast. Experimental Results. No ... Supports OO features : class subtyping, method overriding, and downcast safety. Implementation ... – PowerPoint PPT presentation

Number of Views:34
Avg rating:3.0/5.0
Slides: 37
Provided by: WNC9
Category:

less

Transcript and Presenter's Notes

Title: Region Inference for an ObjectOriented Language


1
Region Inference for an Object-Oriented Language
  • Wei Ngan Chin1,2
  • Joint work with
  • Florin Craciun1, Shengchao Qin1,2, Martin Rinard3
  • 1 National University of Singapore
  • 2 Singapore-MIT Alliance 3 MIT

2
Background
  • Problem
  • objects have different lifetimes
  • garbage collection can be expensive
  • One Solution
  • Use regions with different lifetimes
  • Avoid dangling references.
  • Previous Works Region checkers for Java
    DIKU98, Real-Time Java Boyapati et al
    PLDI03, C Cyclone PLDI02.
  • Our Goal auto. region inference for OO paradigm

3
Assumptions
top (younger)
  • Lexically-Scoped Regions
  • LIFO behaviour
  • construct letreg r in e
  • No-Dangling References
  • Regions of fields must outlive
  • the region of its enclosing object.

bottom (older)
4
Main Contributions
  • Region Inference for Core-Java
  • Constraint-Based Type System.
  • Region Polymorphism Region Subtyping
  • Handles Inheritance, Overriding, Downcast
  • Implementation

5
Core-Java
6
Region-Annotated Core-Java
region types, parameters, constraints, letreg
7
Inferring for Class
8
Key Principles Classes
  • Region type chr1,, rni
  • r1 (region for current object of this type)
  • r2,,rn (regions for components/fields)
  • rk º r1, 8 k 2 2..n (no dangling references)
  • First region is special.
  • Keep regions of components distinct.

9
List Example
10
Key Principles Methods
  • Region polymorphism from the region types of
    parameters and output
  • t mn hri ((t v)) where rc e
  • r captures region polymorphism
  • Keep region constraints of classes and methods
    separate.

11
Inference of Methods
class invariant
method precondition
12
Outline
  • Background
  • Key Principles
  • Region Subtyping
  • Region Inference
  • Method Overriding Downcast
  • Experimental Results

13
No Region Subtyping
Boyapati et al PLDI03 supports class subtyping
but not region subtyping
14
(Object) Region Subtyping
concept from Cyclone PLDI02 A variable
location vclts,..gt can be passed an object of
type cltr,..gt provided r ? s
15
Example
Variables a and b are assigned to tmp. Without
region subtyping, their regions are equal. With
region subtyping, their regions may be distinct.
16
Problem Recursive Fields
Recursive nodes being forced into the same region
17
Example - Reynolds3
Escape Analysis DeutschPOPL97 allows the
List(x,p) object to be build on runtime stack.
This effect is equivalent to local region at each
recursive call.
18
(Field) Region Subtyping
Our Extension Covariance for Read-Only Fields.
19
Outline
  • Background
  • Key Principles
  • Region Subtyping
  • Region Inference
  • Method Overriding Downcast
  • Experimental Results

20
Region Inference
  • Format of type inference rules
  • Flow-insensitive but context sensitive.
  • Modular inference according to dependency graph.

21
Inference Rule for Block
rs the set of regions that do not escape the
block They are coalesced into a single localised
region r
22
Example Localised Region
23
Example Localised Region
24
Example Cyclic Structure
p1
p2
25
Outline
  • Background
  • Key Principles
  • Region Subtyping
  • Region Inference
  • Overriding Downcast
  • Experimental Results

26
Method Overriding
  • class Bhr1 .. rni extends Ahr1 .. rmi where CB ?
  • In class A Y mnhr1,..,rpi (X) where MA
    ?
  • In class B Y mnhr1,..,rpi (X) where MB
    ?
  • Function Subtyping Rule
  • Method Override Rule
  • CB Æ MA ) MB

argument
result
selection
27
Override Conflict Resolution
  • If method override rule do not hold for
  • CB MA MB
  • Can strengthen CB , MA to CB , MA using
  • Until CB Æ MA ) MB

28
Downcast Safety
  • In our framework
  • regions may be lost during upcast
  • e.g. Objectltr1gt o new Pairlts1,s2,s3gt ()
  • lost regions must be recovered during downcast.
  • e.g. Pairltt1,t2,t3gt p (Pair) o
  • Key technique maintain extra regions that were
    supposedly lost during upcasting!
  • e.g. Objectltr1gtr2,r3 p new Pairlts1,s2,s3gt ()
  • Solution Flow analysis

29
Experiments
  • Region annotation needed in 12 of the code.
  • Comparable space reuse for all programs.
  • Inference is as good as hand-annotation.
  • On Olden benchmark, inference takes lt 5s.

30
Concluding Remarks
  • Automatic region inference for CoreJava.
  • Support classes and methods with region
    polymorphism.
  • Supports region subtyping.
  • Supports OO features class subtyping, method
    overriding, and downcast safety.
  • Implementation

31
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

32
Inference Rule for Sequence
Inference rule is flow-insensitive. Improvement
possible via SSA.
33
Correctness
34
Example Fixed-Point Analysis
35
Inference of Methods
36
Experiments
  • Region inference is fast for large programs too.
  • Our prototype was built using Glasgow Haskell
    Compiler.
Write a Comment
User Comments (0)
About PowerShow.com