screaming fast declarative pointer analysis

101
Screaming Fast Declarative Pointer Analysis http://doop.program-analysis.org Martin Bravenboer and Yannis Smaragdakis University of Massachusetts Amherst University of Oregon NEPLS March 5, 2008

Upload: others

Post on 06-Apr-2022

13 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Screaming Fast Declarative Pointer Analysis

Screaming Fast Declarative Pointer Analysishttp://doop.program-analysis.org

Martin Bravenboer and Yannis Smaragdakis

University of Massachusetts AmherstUniversity of Oregon

NEPLSMarch 5, 2008

Page 2: Screaming Fast Declarative Pointer Analysis

overview 1

what do we do?

fully declarative pointer analysisfast, really fast

how do we do it?

novel, aggressive optimizationexposition of indexes

why do you care?

fastsophisticated, simpledifferent

why is it relevant?

optimizationunderstanding, find bugs

Page 3: Screaming Fast Declarative Pointer Analysis

overview 1

what do we do?

fully declarative pointer analysisfast, really fast

how do we do it?

novel, aggressive optimizationexposition of indexes

why do you care?

fastsophisticated, simpledifferent

why is it relevant?

optimizationunderstanding, find bugs

Page 4: Screaming Fast Declarative Pointer Analysis

overview 1

what do we do?

fully declarative pointer analysisfast, really fast

how do we do it?

novel, aggressive optimizationexposition of indexes

why do you care?

fastsophisticated, simpledifferent

why is it relevant?

optimizationunderstanding, find bugs

Page 5: Screaming Fast Declarative Pointer Analysis

overview 1

what do we do?

fully declarative pointer analysisfast, really fast

how do we do it?

novel, aggressive optimizationexposition of indexes

why do you care?

fastsophisticated, simpledifferent

why is it relevant?

optimizationunderstanding, find bugs

Page 6: Screaming Fast Declarative Pointer Analysis

overview 1

what do we do?

fully declarative pointer analysisfast, really fast

how do we do it?

novel, aggressive optimizationexposition of indexes

why do you care?

fastsophisticated, simpledifferent

why is it relevant?

optimizationunderstanding, find bugs

Page 7: Screaming Fast Declarative Pointer Analysis

program analysis: run faster 2

Page 8: Screaming Fast Declarative Pointer Analysis

program analysis: software understanding 3

Page 9: Screaming Fast Declarative Pointer Analysis

program analysis: find bugs 4

Page 10: Screaming Fast Declarative Pointer Analysis

pointer analysis 5

what objects can a variable point to?

programvoid foo() {a = new A1();b = id(a);

}

void bar() {a = new A2();b = id(a);

}

A id(A a) {return a;

}

Page 11: Screaming Fast Declarative Pointer Analysis

pointer analysis 5

what objects can a variable point to?

programvoid foo() {

� a = new A1();b = id(a);

}

void bar() {

� a = new A2();b = id(a);

}

A id(A a) {return a;

}

points-tofoo.a new A1()bar.a new A2()

id.a new A1(), new A2()foo.b new A1(), new A2()bar.b new A1(), new A2()

Page 12: Screaming Fast Declarative Pointer Analysis

pointer analysis 5

what objects can a variable point to?

programvoid foo() {a = new A1();

� b = id(a);}

void bar() {a = new A2();

� b = id(a);}

� A id(A a) {return a;

}

points-tofoo.a new A1()bar.a new A2()id.a new A1(), new A2()

foo.b new A1(), new A2()bar.b new A1(), new A2()

Page 13: Screaming Fast Declarative Pointer Analysis

pointer analysis 5

what objects can a variable point to?

programvoid foo() {a = new A1();

� b = id(a);}

void bar() {a = new A2();

� b = id(a);}

A id(A a) {

� return a;}

points-tofoo.a new A1()bar.a new A2()id.a new A1(), new A2()foo.b new A1(), new A2()bar.b new A1(), new A2()

Page 14: Screaming Fast Declarative Pointer Analysis

pointer analysis 5

what objects can a variable point to?

programvoid foo() {a = new A1();b = id(a);

}

void bar() {a = new A2();b = id(a);

}

A id(A a) {return a;

}

points-tofoo.a new A1()bar.a new A2()id.a new A1(), new A2()foo.b new A1(), new A2()bar.b new A1(), new A2()

context-sensitive points-tofoo.a new A1()bar.a new A2()id.a (foo) new A1()id.a (bar) new A2()foo.b new A1()bar.b new A2()

Page 15: Screaming Fast Declarative Pointer Analysis

pointer analysis: a complex domain 6

• inclusion-based

• subset-based

• unification-based

• equality-based

• flow-sensitive

• context-sensitive

• k-cfa

• field-based

• field-sensitive

• heap cloning

• context-sensitiveheap abstraction

Page 16: Screaming Fast Declarative Pointer Analysis

algorithms in a 10-page pointer analysis paper 7

Page 17: Screaming Fast Declarative Pointer Analysis

algorithms in a 10-page pointer analysis paper 7

Page 18: Screaming Fast Declarative Pointer Analysis

algorithms in a 10-page pointer analysis paper 7

Page 19: Screaming Fast Declarative Pointer Analysis

algorithms in a 10-page pointer analysis paper 7

Page 20: Screaming Fast Declarative Pointer Analysis

algorithms in a 10-page pointer analysis paper 7

Page 21: Screaming Fast Declarative Pointer Analysis

algorithms in a 10-page pointer analysis paper 7

Page 22: Screaming Fast Declarative Pointer Analysis

algorithms in a 10-page pointer analysis paper 7

Page 23: Screaming Fast Declarative Pointer Analysis

algorithms in a 10-page pointer analysis paper 7

Page 24: Screaming Fast Declarative Pointer Analysis

algorithms in a 10-page pointer analysis paper 7

variation pointsunclear

every variant newalgorithm

correctnessunclear

insights,specifics?

incomparablein precision

incomparablein performance

Page 25: Screaming Fast Declarative Pointer Analysis

program analysis: a domain of mutual recursion 8

var points-to

Page 26: Screaming Fast Declarative Pointer Analysis

program analysis: a domain of mutual recursion 8

var points-to

x = y

Page 27: Screaming Fast Declarative Pointer Analysis

program analysis: a domain of mutual recursion 8

var points-to

x = y

Page 28: Screaming Fast Declarative Pointer Analysis

program analysis: a domain of mutual recursion 8

call graph

var points-to

x = f()

Page 29: Screaming Fast Declarative Pointer Analysis

program analysis: a domain of mutual recursion 8

call graph

var points-to

x = f()

Page 30: Screaming Fast Declarative Pointer Analysis

program analysis: a domain of mutual recursion 8

call graph

var points-to

x = y.f()

Page 31: Screaming Fast Declarative Pointer Analysis

program analysis: a domain of mutual recursion 8

call graph

reachable methods

var points-to

x = new A()

Page 32: Screaming Fast Declarative Pointer Analysis

program analysis: a domain of mutual recursion 8

call graph

reachable methods

var points-to

x = new A()

Page 33: Screaming Fast Declarative Pointer Analysis

program analysis: a domain of mutual recursion 8

call graph

field points-to

reachable methods

var points-to

x.f = y

Page 34: Screaming Fast Declarative Pointer Analysis

program analysis: a domain of mutual recursion 8

call graph

field points-to

reachable methods

var points-to

x.f = y

Page 35: Screaming Fast Declarative Pointer Analysis

program analysis: a domain of mutual recursion 8

call graph

field points-to

reachable methods

var points-to

x = f.y

Page 36: Screaming Fast Declarative Pointer Analysis

program analysis: a domain of mutual recursion 8

call graphexceptions

field points-to

reachable methods

var points-to

throw e

Page 37: Screaming Fast Declarative Pointer Analysis

program analysis: a domain of mutual recursion 8

call graphexceptions

field points-to

reachable methods

var points-to

throw e

Page 38: Screaming Fast Declarative Pointer Analysis

program analysis: a domain of mutual recursion 8

call graphexceptions

field points-to

reachable methods

var points-to

catch(E e)

Page 39: Screaming Fast Declarative Pointer Analysis

program analysis: a domain of mutual recursion 8

call graphexceptions

field points-to

reachable methods

var points-to

g()

Page 40: Screaming Fast Declarative Pointer Analysis

datalog: declarative mutual recursion 9

source

a = new A();b = new B();c = new C();a = b;b = a;c = b;

Page 41: Screaming Fast Declarative Pointer Analysis

datalog: declarative mutual recursion 9

source

a = new A();b = new B();c = new C();a = b;b = a;c = b;

AssignHeapAllocation

a new A()b new B()c new C()

Assign

b aa bb c

Page 42: Screaming Fast Declarative Pointer Analysis

datalog: declarative mutual recursion 9

source

a = new A();b = new B();c = new C();a = b;b = a;c = b;

AssignHeapAllocation

a new A()b new B()c new C()

Assign

b aa bb c

VarPointsTo(?var, ?heap) <-AssignHeapAllocation(?var, ?heap).

VarPointsTo(?to, ?heap) <-Assign(?from, ?to),

VarPointsTo(?from, ?heap).

Page 43: Screaming Fast Declarative Pointer Analysis

datalog: declarative mutual recursion 9

source

a = new A();b = new B();c = new C();a = b;b = a;c = b;

AssignHeapAllocation

a new A()b new B()c new C()

Assign

b aa bb c

VarPointsTo(?var, ?heap) <-AssignHeapAllocation(?var, ?heap).

VarPointsTo(?to, ?heap) <-Assign(?from, ?to),

VarPointsTo(?from, ?heap).

VarPointsTo

Page 44: Screaming Fast Declarative Pointer Analysis

datalog: declarative mutual recursion 9

source

a = new A();b = new B();c = new C();a = b;b = a;c = b;

AssignHeapAllocation

a new A()b new B()c new C()

Assign

b aa bb c

�VarPointsTo(?var, ?heap) <-

AssignHeapAllocation(?var, ?heap).

VarPointsTo(?to, ?heap) <-Assign(?from, ?to),

VarPointsTo(?from, ?heap).

VarPointsTo

a new A()b new B()c new C()

Page 45: Screaming Fast Declarative Pointer Analysis

datalog: declarative mutual recursion 9

source

a = new A();b = new B();c = new C();a = b;b = a;c = b;

AssignHeapAllocation

a new A()b new B()c new C()

Assign

b aa bb c

VarPointsTo(?var, ?heap) <-AssignHeapAllocation(?var, ?heap).

VarPointsTo(?to, ?heap) <-Assign(?from, ?to),

VarPointsTo(?from, ?heap).

VarPointsTo

a new A()b new B()c new C()

Page 46: Screaming Fast Declarative Pointer Analysis

datalog: declarative mutual recursion 9

source

a = new A();b = new B();c = new C();a = b;b = a;c = b;

AssignHeapAllocation

a new A()b new B()c new C()

Assign

b aa bb c

VarPointsTo(?var, ?heap) <-AssignHeapAllocation(?var, ?heap).

VarPointsTo(?to, ?heap) <-

� Assign(?from, ?to),

� VarPointsTo(?from, ?heap).

VarPointsTo

a new A()b new B()c new C()

Page 47: Screaming Fast Declarative Pointer Analysis

datalog: declarative mutual recursion 9

source

a = new A();b = new B();c = new C();a = b;b = a;c = b;

AssignHeapAllocation

a new A()b new B()c new C()

Assign

b aa bb c

VarPointsTo(?var, ?heap) <-AssignHeapAllocation(?var, ?heap).

VarPointsTo(?to, ?heap) <-

� Assign(?from, ?to),

� VarPointsTo(?from, ?heap).

VarPointsTo

a new A()b new B()c new C()a new B()

Page 48: Screaming Fast Declarative Pointer Analysis

datalog: declarative mutual recursion 9

source

a = new A();b = new B();c = new C();a = b;b = a;c = b;

AssignHeapAllocation

a new A()b new B()c new C()

Assign

b aa bb c

VarPointsTo(?var, ?heap) <-AssignHeapAllocation(?var, ?heap).

VarPointsTo(?to, ?heap) <-Assign(?from, ?to),

VarPointsTo(?from, ?heap).

VarPointsTo

a new A()b new B()c new C()a new B()b new A()c new B()

Page 49: Screaming Fast Declarative Pointer Analysis

datalog: declarative mutual recursion 9

source

a = new A();b = new B();c = new C();a = b;b = a;c = b;

AssignHeapAllocation

a new A()b new B()c new C()

Assign

b aa bb c

VarPointsTo(?var, ?heap) <-AssignHeapAllocation(?var, ?heap).

VarPointsTo(?to, ?heap) <-Assign(?from, ?to),

VarPointsTo(?from, ?heap).

VarPointsTo

a new A()b new B()c new C()a new B()b new A()c new B()c new A()

Page 50: Screaming Fast Declarative Pointer Analysis

datalog: properties 10

limited logic programming

• sql with recursionprolog without complex terms (constructors)

• guaranteed terminationcaptures PTIME complexity class

purely declarative

• as opposed to prolog- conjunction commutative- clauses commutative

• enables different execution strategies

• enables more aggressive optimization

writing datalog is less programming, more specification

Page 51: Screaming Fast Declarative Pointer Analysis

datalog: naive evaluation 11

datalog

VarPointsTo(?var, ?heap) <-AssignHeapAllocation(?heap, ?var).

VarPointsTo(?to, ?heap) <-Assign(?from, ?to), VarPointsTo(?from, ?heap).

naive evaluation (relational algebra)

VarPointsTo := AssignHeapAllocation

repeat

tmp := πto→var ,heap(VarPointsTo Z from=var Assign)

VarPointsTo := VarPointsTo ∪ tmp

until fixpoint

Page 52: Screaming Fast Declarative Pointer Analysis

datalog: naive evaluation 11

datalog

VarPointsTo(?var, ?heap) <-AssignHeapAllocation(?heap, ?var).

VarPointsTo(?to, ?heap) <-Assign(?from, ?to), VarPointsTo(?from, ?heap).

naive evaluation (relational algebra)

VarPointsTo := AssignHeapAllocation

repeat

tmp := πto→var ,heap(VarPointsTo Z from=var Assign)

VarPointsTo := VarPointsTo ∪ tmp

until fixpoint VarPointsTo(var, heap)Assign(from, to)

Page 53: Screaming Fast Declarative Pointer Analysis

datalog: naive evaluation 11

datalog

VarPointsTo(?var, ?heap) <-AssignHeapAllocation(?heap, ?var).

VarPointsTo(?to, ?heap) <-Assign(?from, ?to), VarPointsTo(?from, ?heap).

naive evaluation (relational algebra)

VarPointsTo := AssignHeapAllocation

repeat

tmp := πto→var ,heap(VarPointsTo Z from=var Assign)

VarPointsTo := VarPointsTo ∪ tmp

until fixpoint VarPointsTo(var, heap)Assign(from, to)

DO loops are so 1950s!

Page 54: Screaming Fast Declarative Pointer Analysis

datalog: semi-naive evaluation 12

VarPointsTo Assign

Page 55: Screaming Fast Declarative Pointer Analysis

datalog: semi-naive evaluation 12

VarPointsTo Assign

Page 56: Screaming Fast Declarative Pointer Analysis

datalog: semi-naive evaluation 12

VarPointsTo Assign

Page 57: Screaming Fast Declarative Pointer Analysis

datalog: semi-naive evaluation 12

VarPointsTo Assign

Page 58: Screaming Fast Declarative Pointer Analysis

datalog: semi-naive evaluation 12

VarPointsTo Assign

Page 59: Screaming Fast Declarative Pointer Analysis

datalog: semi-naive evaluation 13

InstanceFieldPointsTo(?baseheap, ?signature, ?heap) <-StoreInstanceField(?from, ?base, ?signature),VarPointsTo(?base, ?baseheap),VarPointsTo(?from, ?heap).

StoreInstanceField(?from, ?base, ?signature)

?base . ?signature = ?from

InstanceFieldPointsTo(?baseheap, ?signature, ?heap)

field ?signature

of object ?baseheapmay point to object ?heap

∆iInstanceFieldPointsTo(?heap, ?signature, ?baseheap) <-StoreInstanceField(?from, ?signature, ?base),∆i−1VarPointsTo(?base, ?baseheap),VarPointsTo(?from, ?heap).

∆iInstanceFieldPointsTo(?heap, ?signature, ?baseheap) <-StoreInstanceField(?from, ?signature, ?base),VarPointsTo(?base, ?baseheap),

∆i−1VarPointsTo(?from, ?heap).

Page 60: Screaming Fast Declarative Pointer Analysis

datalog: semi-naive evaluation 13

InstanceFieldPointsTo(?baseheap, ?signature, ?heap) <-StoreInstanceField(?from, ?base, ?signature),VarPointsTo(?base, ?baseheap),VarPointsTo(?from, ?heap).

∆iInstanceFieldPointsTo(?heap, ?signature, ?baseheap) <-StoreInstanceField(?from, ?signature, ?base),∆i−1VarPointsTo(?base, ?baseheap),VarPointsTo(?from, ?heap).

∆iInstanceFieldPointsTo(?heap, ?signature, ?baseheap) <-StoreInstanceField(?from, ?signature, ?base),VarPointsTo(?base, ?baseheap),

∆i−1VarPointsTo(?from, ?heap).

Page 61: Screaming Fast Declarative Pointer Analysis

datalog: semi-naive evaluation 13

InstanceFieldPointsTo(?baseheap, ?signature, ?heap) <-StoreInstanceField(?from, ?base, ?signature),VarPointsTo(?base, ?baseheap),VarPointsTo(?from, ?heap).

∆iInstanceFieldPointsTo(?heap, ?signature, ?baseheap) <-StoreInstanceField(?from, ?signature, ?base),∆i−1VarPointsTo(?base, ?baseheap),VarPointsTo(?from, ?heap).

∆iInstanceFieldPointsTo(?heap, ?signature, ?baseheap) <-StoreInstanceField(?from, ?signature, ?base),VarPointsTo(?base, ?baseheap),

∆i−1VarPointsTo(?from, ?heap).

Page 62: Screaming Fast Declarative Pointer Analysis

pointer analysis: implementation approaches 14

context-sensitive pointer analysis implementations

paddle

implemented in java + relational algebra + bdd

wala

implemented in java, conventional constraint-based

bddbddb

implemented in datalog + bdd (+ java)

Page 63: Screaming Fast Declarative Pointer Analysis

pointer analysis: implementation approaches 14

context-sensitive pointer analysis implementations

paddle

implemented in java + relational algebra + bdd

wala

implemented in java, conventional constraint-based

bddbddb

implemented in datalog + bdd (+ java) not a singlefully declarativespecification

Page 64: Screaming Fast Declarative Pointer Analysis

unconventional theses 15

sophisticated pointer analysis fully expressible in datalog

Page 65: Screaming Fast Declarative Pointer Analysis

unconventional theses 15

sophisticated pointer analysis fully expressible in datalog

Lhotak: “[E]ncoding all the details of a complicated program analysisproblem (such as the interrelated analyses [on-the-fly call graph con-struction, handling of Java features]) purely in terms of subset con-straints may be difficult or impossible.”

Page 66: Screaming Fast Declarative Pointer Analysis

unconventional theses 15

sophisticated pointer analysis fully expressible in datalog

explicit representation fits in memory

Page 67: Screaming Fast Declarative Pointer Analysis

unconventional theses 15

sophisticated pointer analysis fully expressible in datalog

explicit representation fits in memory

Naik: “All publicly available implementations of k-object sensitive aliasanalysis ran out of memory on most of our benchmarks for k=1”

Page 68: Screaming Fast Declarative Pointer Analysis

unconventional theses 15

sophisticated pointer analysis fully expressible in datalog

explicit representation fits in memory

Naik: “All publicly available implementations of k-object sensitive aliasanalysis ran out of memory on most of our benchmarks for k=1”

Lhotak: “Efficiently implementing a 1H-object-sensitive analysis with-out BDDs will require new improvements in the data structures and al-gorithms used to implement points-to analyses”

Page 69: Screaming Fast Declarative Pointer Analysis

unconventional theses 15

sophisticated pointer analysis fully expressible in datalog

explicit representation fits in memory

Naik: “All publicly available implementations of k-object sensitive aliasanalysis ran out of memory on most of our benchmarks for k=1”

Lhotak: “Efficiently implementing a 1H-object-sensitive analysis with-out BDDs will require new improvements in the data structures and al-gorithms used to implement points-to analyses”

Whaley: “Owing to the power of the BDD data structure, bddbddb caneven solve analysis problems that were previously intractable”

Page 70: Screaming Fast Declarative Pointer Analysis

unconventional theses 15

sophisticated pointer analysis fully expressible in datalog

explicit representation fits in memory

Naik: “All publicly available implementations of k-object sensitive aliasanalysis ran out of memory on most of our benchmarks for k=1”

Lhotak: “Efficiently implementing a 1H-object-sensitive analysis with-out BDDs will require new improvements in the data structures and al-gorithms used to implement points-to analyses”

Whaley: “Owing to the power of the BDD data structure, bddbddb caneven solve analysis problems that were previously intractable”

Lhotak: “I’ve never managed to get Paddle to run in available memorywith these settings [2-cfa context-heap], at least not on real benchmarkscomplete with the standard library.”

Page 71: Screaming Fast Declarative Pointer Analysis

unconventional theses 15

sophisticated pointer analysis fully expressible in datalog

explicit representation fits in memory

semi-naive evaluation: performance ∼ size of results

Page 72: Screaming Fast Declarative Pointer Analysis

unconventional theses 15

sophisticated pointer analysis fully expressible in datalog

explicit representation fits in memory

semi-naive evaluation: performance ∼ size of results

Whaley: “By using BDDs to represent relations, bddbddb can oper-ate on entire relations at once, instead of iterating over individualtuples.”

Page 73: Screaming Fast Declarative Pointer Analysis

unconventional theses 15

sophisticated pointer analysis fully expressible in datalog

explicit representation fits in memory

semi-naive evaluation: performance ∼ size of results

Page 74: Screaming Fast Declarative Pointer Analysis

unconventional theses 15

sophisticated pointer analysis fully expressible in datalog

explicit representation fits in memory

semi-naive evaluation: performance ∼ size of results

Page 75: Screaming Fast Declarative Pointer Analysis

unconventional theses 15

sophisticated pointer analysis fully expressible in datalog

explicit representation fits in memory

semi-naive evaluation: performance ∼ size of results

Page 76: Screaming Fast Declarative Pointer Analysis

unconventional theses 15

sophisticated pointer analysis fully expressible in datalog

explicit representation fits in memory

semi-naive evaluation: performance ∼ size of results

Page 77: Screaming Fast Declarative Pointer Analysis

unconventional theses 15

sophisticated pointer analysis fully expressible in datalog

explicit representation fits in memory

semi-naive evaluation: performance ∼ size of results

Page 78: Screaming Fast Declarative Pointer Analysis

benchmark: 1-call-site-sensitive+heap 16

0

1000

2000

3000

4000

5000

6000

7000

antlr bloat chart eclipse hsqldb jython luindex lusearch pmd xalan

anal

ysis

tim

e (s

econ

ds)

dooppaddle

Page 79: Screaming Fast Declarative Pointer Analysis

benchmark: 1-call-site-sensitive+heap 16

0

1000

2000

3000

4000

5000

6000

7000

antlr bloat chart eclipse hsqldb jython luindex lusearch pmd xalan

anal

ysis

tim

e (s

econ

ds)

dooppaddle

comparable: demonstratedequivalence of results!

full order of magni-tude faster!

Page 80: Screaming Fast Declarative Pointer Analysis

where is the magic? 17

fully declarative

everything is incremental

efficient architecture for datalog engine

but, not a magic tool!

⇒ novel optimizations targeting recursive logic

yet, relatively easy!

Page 81: Screaming Fast Declarative Pointer Analysis

datalog engine architecture 18

interning

"<java.lang.Thread: void <clinit>()>"→ 32-bit int

tuple compression

call-graph edge: invocation ×method→ 64-bit int

relations are indexes (b-trees)

‘index-organized tables’

efficient representation of sparse relationsalternative datastructures for (partially) dense relations

indexes ‘exposed’ in the language

reverse argument order is indexVarPointsTo(?var, ?heap)

Page 82: Screaming Fast Declarative Pointer Analysis

optimization principles 19

always use index efficiently

• Assign(?from, ?to), ∆VarPointsTo(?from, ?heap)

• Assign(?to, ?from), ∆VarPointsTo(?from, ?heap)

never iterate over full views

• ∆Assign(?to, ?from), VarPointsTo(?from, ?heap)

• ∆Assign(?to, ?from), VarPointsTo(?heap, ?from)

never iterate over big input relations

• StoreInstanceField(?from, ?signature, ?base),VarPointsTo(?baseheap, ?base),

∆VarPointsTo(?heap, ?from)

• we’ll get back to that . . .

Page 83: Screaming Fast Declarative Pointer Analysis

optimization principles 19

always use index efficiently

• Assign(?from, ?to), ∆VarPointsTo(?from, ?heap)

• Assign(?to, ?from), ∆VarPointsTo(?from, ?heap)

never iterate over full views

• ∆Assign(?to, ?from), VarPointsTo(?from, ?heap)

• ∆Assign(?to, ?from), VarPointsTo(?heap, ?from)

never iterate over big input relations

• StoreInstanceField(?from, ?signature, ?base),VarPointsTo(?baseheap, ?base),

∆VarPointsTo(?heap, ?from)

• we’ll get back to that . . .

Page 84: Screaming Fast Declarative Pointer Analysis

optimization principles 19

always use index efficiently

• Assign(?from, ?to), ∆VarPointsTo(?from, ?heap)

• Assign(?to, ?from), ∆VarPointsTo(?from, ?heap)

never iterate over full views

• ∆Assign(?to, ?from), VarPointsTo(?from, ?heap)

• ∆Assign(?to, ?from), VarPointsTo(?heap, ?from)

never iterate over big input relations

• StoreInstanceField(?from, ?signature, ?base),VarPointsTo(?baseheap, ?base),

∆VarPointsTo(?heap, ?from)

• we’ll get back to that . . .

Page 85: Screaming Fast Declarative Pointer Analysis

optimization principles 19

always use index efficiently

• Assign(?from, ?to), ∆VarPointsTo(?from, ?heap)

• Assign(?to, ?from), ∆VarPointsTo(?from, ?heap)

never iterate over full views

• ∆Assign(?to, ?from), VarPointsTo(?from, ?heap)

• ∆Assign(?to, ?from), VarPointsTo(?heap, ?from)

never iterate over big input relations

• StoreInstanceField(?from, ?signature, ?base),VarPointsTo(?baseheap, ?base),

∆VarPointsTo(?heap, ?from)

• we’ll get back to that . . .

• iterate over delta

• access big relations withindex

Page 86: Screaming Fast Declarative Pointer Analysis

optimization: variable ordering 20

unoptimized

VarPointsTo(?to, ?heap) <-Assign(?from, ?to),VarPointsTo(?from, ?heap).

constraintsAssign VarPointsTo

1. ∆Assign 2. VarPointsTo - ?from1. ∆VarPointsTo 2. Assign ?from -

optimized

VarPointsTo(?heap, ?to) <-Assign(?to, ?from),VarPointsTo(?heap, ?from).

Page 87: Screaming Fast Declarative Pointer Analysis

optimization: variable ordering 20

unoptimized

VarPointsTo(?to, ?heap) <-Assign(?from, ?to),VarPointsTo(?from, ?heap).

constraintsAssign VarPointsTo

1. ∆Assign 2. VarPointsTo - ?from1. ∆VarPointsTo 2. Assign ?from -

optimized

VarPointsTo(?heap, ?to) <-Assign(?to, ?from),VarPointsTo(?heap, ?from).

other join orderings notinteresting: prunedimmediately

Page 88: Screaming Fast Declarative Pointer Analysis

optimization: folding 21

InstanceFieldPointsTo(?baseheap, ?signature, ?heap) <-StoreInstanceField(?from, ?base, ?signature),VarPointsTo1(?baseheap, ?base),

VarPointsTo2(?heap, ?from).

Store VarPointsTo1 VarPointsTo2

1. ∆VarPointsTo12. StoreInstanceField3. VarPointsTo2

?base - ?from

1. ∆VarPointsTo22. StoreInstanceField3. VarPointsTo1

?from ?base -

Page 89: Screaming Fast Declarative Pointer Analysis

optimization: folding 21

InstanceFieldPointsTo(?baseheap, ?signature, ?heap) <-StoreInstanceField(?from, ?base, ?signature),VarPointsTo1(?baseheap, ?base),

VarPointsTo2(?heap, ?from).

Store VarPointsTo1 VarPointsTo2

1. ∆VarPointsTo12. StoreInstanceField3. VarPointsTo2

?base - ?from

1. ∆VarPointsTo22. StoreInstanceField3. VarPointsTo1

?from ?base -

conflicting constraints!there is no efficient in-dex.

Page 90: Screaming Fast Declarative Pointer Analysis

optimization: folding 21

InstanceFieldPointsTo(?baseheap, ?signature, ?heap) <-StoreInstanceField(?from, ?base, ?signature),VarPointsTo1(?baseheap, ?base),

VarPointsTo2(?heap, ?from).

fold StoreInstanceField and VarPointsTo1 to create an index:

InstanceFieldPointsTo(?heap, ?signature, ?baseheap) <-StoreHeapInstanceField(?baseheap, ?signature, ?from),VarPointsTo(?heap, ?from).

StoreHeapInstanceField(?baseheap, ?signature, ?from) <-StoreInstanceField(?from, ?signature, ?base),

VarPointsTo(?baseheap, ?base).

we have just introduced a materialized view!

Page 91: Screaming Fast Declarative Pointer Analysis

precise exception analysis 22

method invocations: propagated exceptions

ThrowPointsTo(?heap, ?callerMethod) <-CallGraphEdge(?invocation, ?tomethod),ThrowPointsTo(?heap, ?tomethod),HeapAllocation:Type[?heap] = ?heaptype,not exists ExceptionHandler[?heaptype, ?invocation],Instruction:Method[?invocation] = ?callerMethod.

method invocations: caught exceptions

VarPointsTo(?heap, ?param) <-CallGraphEdge(?invocation, ?tomethod),ThrowPointsTo(?heap, ?tomethod),HeapAllocation:Type[?heap] = ?heaptype,ExceptionHandler[?heaptype, ?invocation] = ?handler,ExceptionHandler:FormalParam[?handler] = ?param.

Page 92: Screaming Fast Declarative Pointer Analysis

precise exception analysis 22

method invocations: propagated exceptions

�ThrowPointsTo(?heap, ?callerMethod) <-CallGraphEdge(?invocation, ?tomethod),ThrowPointsTo(?heap, ?tomethod),HeapAllocation:Type[?heap] = ?heaptype,not exists ExceptionHandler[?heaptype, ?invocation],Instruction:Method[?invocation] = ?callerMethod.

method invocations: caught exceptions

VarPointsTo(?heap, ?param) <-CallGraphEdge(?invocation, ?tomethod),ThrowPointsTo(?heap, ?tomethod),HeapAllocation:Type[?heap] = ?heaptype,ExceptionHandler[?heaptype, ?invocation] = ?handler,ExceptionHandler:FormalParam[?handler] = ?param.

Page 93: Screaming Fast Declarative Pointer Analysis

precise exception analysis 22

method invocations: propagated exceptions

ThrowPointsTo(?heap, ?callerMethod) <-

� CallGraphEdge(?invocation, ?tomethod),ThrowPointsTo(?heap, ?tomethod),HeapAllocation:Type[?heap] = ?heaptype,not exists ExceptionHandler[?heaptype, ?invocation],Instruction:Method[?invocation] = ?callerMethod.

method invocations: caught exceptions

VarPointsTo(?heap, ?param) <-CallGraphEdge(?invocation, ?tomethod),ThrowPointsTo(?heap, ?tomethod),HeapAllocation:Type[?heap] = ?heaptype,ExceptionHandler[?heaptype, ?invocation] = ?handler,ExceptionHandler:FormalParam[?handler] = ?param.

Page 94: Screaming Fast Declarative Pointer Analysis

precise exception analysis 22

method invocations: propagated exceptions

ThrowPointsTo(?heap, ?callerMethod) <-CallGraphEdge(?invocation, ?tomethod),

� ThrowPointsTo(?heap, ?tomethod),HeapAllocation:Type[?heap] = ?heaptype,not exists ExceptionHandler[?heaptype, ?invocation],Instruction:Method[?invocation] = ?callerMethod.

method invocations: caught exceptions

VarPointsTo(?heap, ?param) <-CallGraphEdge(?invocation, ?tomethod),ThrowPointsTo(?heap, ?tomethod),HeapAllocation:Type[?heap] = ?heaptype,ExceptionHandler[?heaptype, ?invocation] = ?handler,ExceptionHandler:FormalParam[?handler] = ?param.

Page 95: Screaming Fast Declarative Pointer Analysis

precise exception analysis 22

method invocations: propagated exceptions

ThrowPointsTo(?heap, ?callerMethod) <-CallGraphEdge(?invocation, ?tomethod),ThrowPointsTo(?heap, ?tomethod),

� HeapAllocation:Type[?heap] = ?heaptype,not exists ExceptionHandler[?heaptype, ?invocation],Instruction:Method[?invocation] = ?callerMethod.

method invocations: caught exceptions

VarPointsTo(?heap, ?param) <-CallGraphEdge(?invocation, ?tomethod),ThrowPointsTo(?heap, ?tomethod),HeapAllocation:Type[?heap] = ?heaptype,ExceptionHandler[?heaptype, ?invocation] = ?handler,ExceptionHandler:FormalParam[?handler] = ?param.

Page 96: Screaming Fast Declarative Pointer Analysis

precise exception analysis 22

method invocations: propagated exceptions

ThrowPointsTo(?heap, ?callerMethod) <-CallGraphEdge(?invocation, ?tomethod),ThrowPointsTo(?heap, ?tomethod),HeapAllocation:Type[?heap] = ?heaptype,

� not exists ExceptionHandler[?heaptype, ?invocation],Instruction:Method[?invocation] = ?callerMethod.

method invocations: caught exceptions

VarPointsTo(?heap, ?param) <-CallGraphEdge(?invocation, ?tomethod),ThrowPointsTo(?heap, ?tomethod),HeapAllocation:Type[?heap] = ?heaptype,ExceptionHandler[?heaptype, ?invocation] = ?handler,ExceptionHandler:FormalParam[?handler] = ?param.

Page 97: Screaming Fast Declarative Pointer Analysis

precise exception analysis 22

method invocations: propagated exceptions

ThrowPointsTo(?heap, ?callerMethod) <-CallGraphEdge(?invocation, ?tomethod),ThrowPointsTo(?heap, ?tomethod),HeapAllocation:Type[?heap] = ?heaptype,not exists ExceptionHandler[?heaptype, ?invocation],

� Instruction:Method[?invocation] = ?callerMethod.

method invocations: caught exceptions

VarPointsTo(?heap, ?param) <-CallGraphEdge(?invocation, ?tomethod),ThrowPointsTo(?heap, ?tomethod),HeapAllocation:Type[?heap] = ?heaptype,ExceptionHandler[?heaptype, ?invocation] = ?handler,ExceptionHandler:FormalParam[?handler] = ?param.

Page 98: Screaming Fast Declarative Pointer Analysis

precise exception analysis 22

method invocations: propagated exceptions

ThrowPointsTo(?heap, ?callerMethod) <-CallGraphEdge(?invocation, ?tomethod),ThrowPointsTo(?heap, ?tomethod),HeapAllocation:Type[?heap] = ?heaptype,not exists ExceptionHandler[?heaptype, ?invocation],Instruction:Method[?invocation] = ?callerMethod.

method invocations: caught exceptions

VarPointsTo(?heap, ?param) <-CallGraphEdge(?invocation, ?tomethod),ThrowPointsTo(?heap, ?tomethod),HeapAllocation:Type[?heap] = ?heaptype,

� ExceptionHandler[?heaptype, ?invocation] = ?handler,ExceptionHandler:FormalParam[?handler] = ?param.

Page 99: Screaming Fast Declarative Pointer Analysis

precise exception analysis 22

method invocations: propagated exceptions

ThrowPointsTo(?heap, ?callerMethod) <-CallGraphEdge(?invocation, ?tomethod),ThrowPointsTo(?heap, ?tomethod),HeapAllocation:Type[?heap] = ?heaptype,not exists ExceptionHandler[?heaptype, ?invocation],Instruction:Method[?invocation] = ?callerMethod.

method invocations: caught exceptions

VarPointsTo(?heap, ?param) <-CallGraphEdge(?invocation, ?tomethod),ThrowPointsTo(?heap, ?tomethod),HeapAllocation:Type[?heap] = ?heaptype,ExceptionHandler[?heaptype, ?invocation] = ?handler,

� ExceptionHandler:FormalParam[?handler] = ?param.

Page 100: Screaming Fast Declarative Pointer Analysis

declarative program analysis is paying off 23

declarativeness

precise exception analysissophisticated reflection analysisjava references, finalization, threading, etc.

high-level optimization

hand-optimization not difficultpotential automation

automatic incrementalization

naive evaluation would be horrible

automatic memory management

out-of-core analyses

automatic parallelization

very promising for program analysis

Page 101: Screaming Fast Declarative Pointer Analysis

questions? 24

http://doop.program-analysis.org