UniquenessInference for Individual Object Deallocation Sigmund Cherem and Radu Rugina - PowerPoint PPT Presentation

1 / 79
About This Presentation
Title:

UniquenessInference for Individual Object Deallocation Sigmund Cherem and Radu Rugina

Description:

Use of Uniqueness for MM. Dead unique references can be reclaimed with free statements ... Use of Uniqueness for MM. Dead unique references can be reclaimed ... – PowerPoint PPT presentation

Number of Views:62
Avg rating:3.0/5.0
Slides: 80
Provided by: csCor
Category:

less

Transcript and Presenter's Notes

Title: UniquenessInference for Individual Object Deallocation Sigmund Cherem and Radu Rugina


1
Uniqueness-Inference for Individual Object
DeallocationSigmund Cherem and Radu Rugina
  • International Symposium on Memory Management
  • October, 2007

2
What This Talk Is About
  • Reasoning about heap using uniqueness
  • Programmers use invariants to deal with heap
    complexity
  • E.g. uniqueness, encapsulation
  • Compiler can benefit from knowledge of these
    invariants
  • Using uniqueness for compile-time memory
    management
  • Transform Java to Jfree (Java free)
  • Add effective and predictable memory reclamation
  • Guarantee absence of memory errors
  • Support for real-time systems
  • Reduce run-time overhead

VMfree
Compiler
Java Program
Jfree Program
3
Uniqueness Definitions
  • A reference (variable or field) at program point
    p is unique iff it is the only pointer to its
    target
  • A reference is totally unique if it is unique at
    all times
  • Too restrictive Java programs may have unique
    references that are temporarily shared

unique
not unique
all unique
4
Uniqueness Definitions
  • A reference (variable or field) at program point
    p is unique iff it is the only pointer to its
    target
  • A reference is totally unique if it is unique at
    all times
  • Too restrictive Java programs may have unique
    references that are temporarily shared
  • A reference is weakly unique if it is unique at
    least at method boundaries
  • Can model structures like lists and trees

unique
not unique
all unique
5
Use of Uniqueness for MM
  • Dead unique references can be reclaimed with free
    statements

x new List() // x is unique dead
6
Use of Uniqueness for MM
  • Dead unique references can be reclaimed with free
    statements

x new List() free(x) // x is unique dead
7
Use of Uniqueness for MM
  • Dead unique references can be reclaimed with free
    statements

x new List() free(x) // x is unique dead
List Elem head // weakly unique
8
Use of Uniqueness for MM
  • Dead unique references can be reclaimed with free
    statements

x new List() free(x.head) free(x) // x is
unique dead
List Elem head // weakly unique
9
Use of Uniqueness for MM
  • Dead unique references can be reclaimed with free
    statements
  • Unique fields can be reclaimed with destructors

x new List() free(x.head) free(x) // x is
unique dead
List Elem head // weakly unique
10
Use of Uniqueness for MM
  • Dead unique references can be reclaimed with free
    statements
  • Unique fields can be reclaimed with destructors

x new List() x.destroy() free(x) // x is
unique dead
List Elem head // weakly unique void
destroy()
free(head)
11
Use of Uniqueness for MM
  • Dead unique references can be reclaimed with free
    statements
  • Unique fields can be reclaimed with destructors
  • Support for reclaiming recursive structures

x new List() x.destroy() free(x) // x is
unique dead
List Elem head // weakly unique void
destroy()
free(head)
12
Use of Uniqueness for MM
  • Dead unique references can be reclaimed with free
    statements
  • Unique fields can be reclaimed with destructors
  • Support for reclaiming recursive structures

x new List() x.destroy() free(x) // x is
unique dead
Elem Elem next // weakly unique Object
data
List Elem head // weakly unique void
destroy()
free(head)
13
Use of Uniqueness for MM
  • Dead unique references can be reclaimed with free
    statements
  • Unique fields can be reclaimed with destructors
  • Support for reclaiming recursive structures

x new List() x.destroy() free(x) // x is
unique dead
Elem Elem next // weakly unique Object
data void destroy() if (next !
null) next.destroy() free(next)

List Elem head // weakly unique void
destroy() if (head ! null)
head.destroy() free(head)
14
System Design
Java Program
Uniqueness Inference
Transformation
Jfree Program
Method Summaries
15
System Design
Java Program
Uniqueness Inference
Libraries
Compute Lightweight Summaries (CC 07)
Transformation
Jfree Program
Method Summaries
16
System Design
Java Program
Uniqueness Inference
Transformation
Jfree Program
Method Summaries
17
System Design
Local Must-alias Dataflow Analysis
Java Program
Local Abstraction
Constraints
Global Constraint System
Global Abstraction
Transformation
Jfree Program
Method Summaries
18
System Design
Only Intra-procedural
Local Must-alias Dataflow Analysis
Java Program
Local Abstraction
Constraints
Global Constraint System
Whole-program but lightweight
Global Abstraction
Transformation
Jfree Program
Method Summaries
19
Local Must-alias Dataflow Analysis
20
Local Must-alias Dataflow Analysis
  • Goal answer questions
  • Where are fields and variables unique, and where
    not?
  • Is a field or parameter shared at method
    boundaries?
  • Is the uniqueness of two references correlated?
  • Strategy
  • Track objects manipulated (shape analysis)
  • Must-aliases per program point
  • Keep it intra-procedural (modularity)
  • Initialization assume all external references
    are unique
  • Method calls use summaries to model effects of
    method calls

21
Analysis Example
List void add(Object p) Elem e new
Elem() e.data p e.next
this.head this.head e
  • Explore state of objects assuming all fields and
    parameters are unique at method entry
  • Track objects allocated
  • Track external objects potentially read in the
    method

22
p
add(Object p) Elem e new Elem()
e.data p e.next this.head this.head
e // locals are dead
head
e
23
p
add(Object p) Elem e new Elem()
e.data p e.next this.head this.head
e // locals are dead
head
e
e
24
p
add(Object p) Elem e new Elem()
e.data p e.next this.head this.head
e // locals are dead
head
e
e
e
25
p
add(Object p) Elem e new Elem()
e.data p e.next this.head this.head
e // locals are dead
head
e
e
e
e
this
head
26
p
add(Object p) Elem e new Elem()
e.data p e.next this.head this.head
e // locals are dead
head
e
e
e
e
this
head
head
27
p
add(Object p) Elem e new Elem()
e.data p e.next this.head this.head
e // locals are dead
head
head
28
p
add(Object p) Elem e new Elem()
e.data p e.next this.head this.head
e // locals are dead
head
head
29
p
add(Object p) Elem e new Elem()
e.data p e.next this.head this.head
e // locals are dead
head
head
30
p
add(Object p) Elem e new Elem()
e.data p e.next this.head this.head
e // locals are dead
head
o ? this
this
head
31
p
add(Object p) Elem e new Elem()
e.data p e.next this.head this.head
e // locals are dead
head
o ? this
this
e
next
this
head
32
p
add(Object p) Elem e new Elem()
e.data p e.next this.head this.head
e // locals are dead
head
o ? this
this
e
next
this
e
head
33
p
add(Object p) Elem e new Elem()
e.data p e.next this.head this.head
e // locals are dead
head
o ? this
this
e
next
this
e
next
head
34
p
add(Object p) Elem e new Elem()
e.data p e.next this.head this.head
e // locals are dead
head
o ? this
this
e
next
this
o ? this
e
next
head
35
p
add(Object p) Elem e new Elem()
e.data p e.next this.head this.head
e // locals are dead
head
o ? this
this
e
next
this
o ? this
e
o ? this
next
head
36
p
add(Object p) Elem e new Elem()
e.data p e.next this.head this.head
e // locals are dead
head
o ? this
this
e
next
this
o ? this
e
o ? this
next
head
head
37
p
add(Object p) Elem e new Elem()
e.data p e.next this.head this.head
e // locals are dead
head
next
head
head
38
p
add(Object p) Elem e new Elem()
e.data p e.next this.head this.head
e // locals are dead
head
p
next
head
head
39
p
add(Object p) Elem e new Elem()
e.data p e.next this.head this.head
e // locals are dead
head
p
p
data
next
head
head
40
p
add(Object p) Elem e new Elem()
e.data p e.next this.head this.head
e // locals are dead
head
p
p
data
p
p
next
head
head
41
p
add(Object p) Elem e new Elem()
e.data p e.next this.head this.head
e // locals are dead
head
p
p
data
p
p
data
next
head
head
42
p
head
  • Local Analysis Results

data
next
head
head
43
p
head
  • Local Analysis Results
  • Local Abstraction

data
next
head
head
44
p
head
  • Local Analysis Results
  • Local Abstraction

p
e
p
e
data
o ? this
this
e
p
e
next
this
o ? this
p
e
this
e
head
o ? this
data
next
head
head
45
p
head
  • Local Analysis Results
  • Local Abstraction
  • Method Boundaries Constraints
  • Sharing (0)
  • Correlation (2)

data
next
head
head
46
p
head
  • Local Analysis Results
  • Local Abstraction
  • Method Boundaries Constraints
  • Sharing (0)
  • Correlation (2)

head
p
next
data
If head is shared at entry of method Then next is
also shared
If p is shared, so is data
data
next
head
head
47
Global Constraint System
  • Enforce references are truly unique at method
    boundaries
  • Graph representation
  • Nodes parameters, fields, and S (special shared
    node)
  • Edges if source is shared, target is shared
  • Examples
  • f is shared by method exit
  • Actual parameter ai is not dead (formal pi is
    shared)
  • next unique at exit, assuming head was unique
  • Constraint resolution simple graph reachability
  • A reference is weakly unique if it is not
    reachable from S

S
f
S
pi
head
next
48
Collected Results
  • Local Abstraction
  • Set of object states per program point p
  • May depend on the uniqueness of a field or
    parameter
  • Global Abstraction
  • Set of weakly unique parameters and fields
  • These results are sufficient to answer uniqueness
    queries
  • Example Is x unique at p?
  • Yes when all object states at p containing x
  • have no aliases (local abstraction)
  • only depend on weakly unique references (global
    abstraction)

49
Transformation
50
Transformation
  • Add frees on unique references that become dead
  • After statement
  • On control flow edge

51
Transformation
  • Add frees on unique references that become dead
  • After statement
  • On control flow edge

x new List() if () x.hashCode() // x
is unique dead foo() // x is unique
dead x null
52
Transformation
  • Add frees on unique references that become dead
  • After statement
  • On control flow edge

if
x new List() if () x.hashCode() // x
is unique dead foo() // x is unique
dead x null
x.hashcode()
foo()
x null
53
Transformation
  • Add frees on unique references that become dead
  • After statement
  • On control flow edge

if
x new List() if () x.hashCode()
free(x)// x is unique dead foo() // x is
unique dead x null
x.hashcode()
free(x)
foo()
x null
54
Transformation
  • Add frees on unique references that become dead
  • After statement
  • On control flow edge

if
x new List() if () x.hashCode()
free(x)// x is unique dead
foo() free(x) ??? // x is unique dead x
null
x.hashcode()
free(x)
foo()
free(x)
x null
55
Transformation
  • Add frees on unique references that become dead
  • After statement
  • On control flow edge

if
x new List() if () x.hashCode()
free(x)// x is unique dead foo() else
free(x)// x is unique dead x null
x.hashcode()
free(x)
free(x)
foo()
x null
56
Transformation
  • Add frees on unique references that become dead
  • After statement
  • On control flow edge

57
Transformation
  • Add frees on unique references that become dead
  • After statement
  • On control flow edge
  • Add destructors for weakly unique fields
  • Add calls to destructors
  • Warning destructor calls are not always safe
  • Safe only when fields inductively touched by
    destructors are truly unique (at the point of the
    call)

58
Transformation
  • Add frees on unique references that become dead
  • After statement
  • On control flow edge
  • Add destructors for weakly unique fields
  • Add calls to destructors
  • Warning destructor calls are not always safe
  • Safe only when fields inductively touched by
    destructors are truly unique (at the point of the
    call)
  • Extend methods with uniqueness argument to
    support context-sensitive transformation
    (conditional uniqueness)

59
Conditional Uniqueness
Id lookup (String s) Id v get(s) if (v
null) v new Id(s) put(s,
v) return v
60
Conditional Uniqueness
lookup(example1)
String u new String(example2) lookup(u)
Id lookup (String s) Id v get(s) if (v
null) v new Id(s) put(s,
v) return v
61
Conditional Uniqueness
lookup(example1)
String u new String(example2) lookup(u)
free(u) ???
Id lookup (String s) Id v get(s) if (v
null) v new Id(s) put(s,
v) return v
62
Conditional Uniqueness
lookup(example1)
String u new String(example2) lookup(u)
Id lookup (String s) Id v get(s) if (v
null) v new Id(s) put(s,
v) else free(s) ??? return v
63
Conditional Uniqueness
lookup(example1, false)
String u new String(example2) lookup(u,
true)
Id lookup (String s, boolean s_is_unique) Id
v get(s) if (v null) v new
Id(s) put(s, v) else if
(s_is_unique) free(s) return v
64
Experimental Evaluation
65
Settings and Compiling Statistics
  • Implementation Infrastructure
  • Jfree-UI Compiler System
  • Soot infrastructure 2.2.2 Vallee-Rai et al. 99
  • JfreeVM Runtime System
  • JikesRVM 2.3.5 Alpern et al. 99
  • MMTk Blackburn et al. 04
  • Programs Analyzed
  • SPECjvm98 (exclude mpegaudio) 2630 methods
  • Analysis time (average per program) 7 sec
  • Weakly unique fields (all) 22
  • Libraries (java.lang, java.util, java.io) 5426
    methods
  • Analysis time (total) 30 sec
  • Weakly unique fields (all) 8

66
Memory Freed
of total allocated memory
67
Memory Freed
of total allocated memory
68
Memory Freed
of total allocated memory
69
Memory Freed
of total allocated memory
70
Memory Freed
of total allocated memory
71
Memory Freed
of total allocated memory
72
Runtime Savings
5
Free MS MS
4
3
Time normalized w.r.t time of No MM
2
1.5
Geometric Mean in SPECjvm98
1.25
1
1
2
3
4
5
1.16
1.33
1.66
Memory Size normalized w.r.t. MS min heap
73
Comparison to Previous Work
Java Bytecode
JFree SA ISMM06
Java Bytecode Free
VM Free
74
Comparison to Previous Work
Java Bytecode
JFree SA ISMM06
660 s
Total analysis time (SPEC)
Java Bytecode Free
VM Free
75
Comparison to Previous Work
Java Bytecode
JFree SA ISMM06
660 s
Total analysis time (SPEC)
Java Bytecode Free
Average memory savings
54
VM Free
76
Comparison to Previous Work
Java Bytecode
JFree SA ISMM06
JFree UI (this talk)
660 s
Total analysis time (SPEC)
Java Bytecode Free
Average memory savings
54
VM Free
77
Comparison to Previous Work
Java Bytecode
JFree SA ISMM06
JFree UI (this talk)
660 s
45 s
Total analysis time (SPEC)
Java Bytecode Free
Average memory savings
61
54
VM Free
78
Related Work
  • Compile-Time Memory Management
  • Stack Allocation and Region-based MM
  • Blanchet OOPLSA99, Choi et al. OOPSLA99, Whaley
    and Rinard OOPSLA99, Bogda and Hoelzle
    OOPSLA99, Gay/Steensgard CC00
  • Tofte and Talpin POPL94, AFL PLDI95,
  • Cherem and Rugina ISMM04, Chin et al. PLDI04
  • Individual Object Deallocation
  • Cherem and Rugina ISMM06, Guyer et al. PLDI06,
    Shaham et al. SAS03
  • Shape Analysis
  • Sagiv et al. POPL99, Hackett and Rugina POPL05
  • Linear Types and Unique references
  • Language support Wadler 90, Minsky ECOOP96,
    Hicks et al. ISMM04 (Cyclone), Boyland SPE01,
    Adrich et al. OOPSLA02 (AliasJava)
  • Inference Cherem and Rugina CC07, Ma and Foster
    OOPSLA07, Adrich et al. OOSPLA02

79
Conclusions
  • Uniqueness Inference Algorithm
  • Exploits modular design of programmers
    invariants
  • It allows temporary sharing (both stack and heap)
  • Applications to program understanding and to MM
  • Uniqueness based MM transformation
  • Supports reclamation of recursive structures via
    destructors
  • Experimental evaluation
  • Analysis is modular and fast (10x improvement)
  • 22 of application fields are unique
  • 60 of memory can be reclaimed statically
  • Transformed programs can run 31 faster for small
    heaps
Write a Comment
User Comments (0)
About PowerShow.com