modular heap analysis of higher order programs

32
Modular Heap Analysis Of Higher Order Programs Ravichandhran Madhavan + * Ganesan Ramalingam * Kapil Vaswani * * Microsoft Research India + EPFL, Switzerland

Upload: aoife

Post on 24-Feb-2016

29 views

Category:

Documents


0 download

DESCRIPTION

Modular Heap Analysis Of Higher Order Programs. Ravichandhran Madhavan + * Ganesan Ramalingam * Kapil Vaswani * * Microsoft Research India + EPFL, Switzerland. Goal 1: Analyze Modularly. Compute succinct summaries for procedures - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Modular Heap Analysis Of Higher Order Programs

Modular Heap Analysis Of Higher Order ProgramsRavichandhran Madhavan + *Ganesan Ramalingam *Kapil Vaswani *

* Microsoft Research India+ EPFL, Switzerland

Page 2: Modular Heap Analysis Of Higher Order Programs

Goal 1: Analyze Modularly

β€’ Compute succinct summaries for procedures

β€’ Summaries: total functions approximating the relational semantics

𝛾 (π‘†π‘’π‘šπ‘šπ‘Žπ‘Ÿ 𝑦 𝑃)

Input State

Output States

[𝑃 ]π‘βŠ‡

Page 3: Modular Heap Analysis Of Higher Order Programs

Goal 2: Track Heap Information

β€’ The summary of a procedure should capture the transformation of the input mutable heap

Goal 3: Analyze HO programs

β€’ Should be able to summarize higher order proceduresβ€’ Input state includes data as well as code

Page 4: Modular Heap Analysis Of Higher Order Programs

Challengeβ€’ Indirect procedure calls esp. Call backsβ€’ Virtual method calls, function pointer calls, lambda expressions

Foo(PTR* p , FP* fp){ *p = (**fp)(0);}

Count() { iter = this.iterator(); i = 0; while(iter.HasNext()) { iter.next(); i++; } }

Page 5: Modular Heap Analysis Of Higher Order Programs

Challengeβ€’ All widely used languages support Higher Order constructs

But how do existing modular analyses

handle them ?

Page 6: Modular Heap Analysis Of Higher Order Programs

A Common Hackβ€’ Estimate the targets of the indirect calls through an

inexpensive analysis E.g.

β€’ CHA, RTI analysis for OO programsβ€’ Light weight pointer analysis …

β€’ Construct a conservative call graph

β€’ Analyze bottom up

Page 7: Modular Heap Analysis Of Higher Order Programs

Limitations of the Hackβ€’ Over-approximated targets

β€’ A call-graph is necessarily context insensitive for HO programs

A

C

B

D

EB’s context

A’s context

Page 8: Modular Heap Analysis Of Higher Order Programs

Limitations of the Hackβ€’ Inability to construct client independent summaries

Foo(FP* fp){ (*fp)(…);}

m1(){ …}

C1(){ Foo(m1);}

m2(){ …}

C2(){ Foo(m2)}

Resolved to m1

Summary:

Page 9: Modular Heap Analysis Of Higher Order Programs

Limitations of the Hack

β€’ Reuse of summaries possible only within an analysisβ€’ Need to analyze libraries together with clientsβ€’ Need to reanalyze libraries for each new client

Doesn’t allow library compositional analysis

Page 10: Modular Heap Analysis Of Higher Order Programs

Our approach

β€’ Use existing techniques for summarizing first-order code segments:

β€’ [Whaley, Salcianu, Rinard, OOPSLA β€˜99, VMCAI ’04]β€’ [Madhavan et al., SAS β€˜11]

β€’ Retain the call backs in the summaries

Page 11: Modular Heap Analysis Of Higher Order Programs

Our approach

β€’ Perform as much simplification as possible without the knowledge of the calling context

β€’ Eliminate fully resolved calls from the summaries

Enables efficient library compositional analysis

Page 12: Modular Heap Analysis Of Higher Order Programs

Illustration1

7

2

4

3

5

6

*fp(a,b)𝑆24

𝑆13𝑆12

𝑆56

𝑆67𝑆47

Page 13: Modular Heap Analysis Of Higher Order Programs

Illustration1

7

2

4

3

5

6

*fp(a,b)𝑆24

𝑆13𝑆12

𝑆56

𝑆67𝑆47

Page 14: Modular Heap Analysis Of Higher Order Programs

Illustration

3

5

6

*fp(a,b)

𝑆13

𝑆56

𝑆67

7

1

𝜏17

Page 15: Modular Heap Analysis Of Higher Order Programs

Illustration

3

5

*fp(a,b)

7

1

𝜏17

𝜏57

𝜏13

Page 16: Modular Heap Analysis Of Higher Order Programs

Exploiting Local Context

3

5

*fp(a,b)

7

1

𝜏17

𝜏57=(𝜏 𝑙 ,𝜏 β€²)

𝜏13

3

5

*fp(a,b)

7

1

𝜏17

𝜏 β€²

𝜏13

𝜏 π‘™βˆ˜πœ13

Frame Rule

Page 17: Modular Heap Analysis Of Higher Order Programs

Exploiting Local Context

3

5

*fp(a,b)

7

1

𝜏17

𝜏57=(𝜏 𝑙 ,𝜏 β€²)

𝜏13

3

5

*fp(a,b)

7

1

𝜏 β€²

𝜏13Frame Rule

Page 18: Modular Heap Analysis Of Higher Order Programs

Flow Insensitive Abstraction

3

5

*fp(a,b)

7

1

𝜏

𝜏

𝜏

𝜏

3

5

*fp(a,b)

7

1

𝜏57

𝜏13

𝜏17𝜏=𝜏13βŠ”πœ17βŠ”πœ57

Page 19: Modular Heap Analysis Of Higher Order Programs

Flow Insensitive Abstraction

(𝜏 , \{𝑐1 ,… ,π‘π‘˜ \})

HO summary = First order summary +

set of call backs

𝑐1β€¦π‘π‘˜

2

3

4

1

𝜏

𝜏

𝜏

𝜏

Page 20: Modular Heap Analysis Of Higher Order Programs

Composition Operation

(𝜏1 ,πœ”1)𝑆1;𝑆2 ;…;𝑆𝑛 𝑐1β€¦π‘π‘˜

2

3

4

1

𝜏1

𝜏1

𝜏1

𝜏1

(𝜏2 ,πœ”2)𝑆𝑛+ 1;…;π‘†π‘š 𝑑1…𝑑 𝑗6

7

8

5

𝜏2

𝜏2

𝜏2

𝜏2

ID

Page 21: Modular Heap Analysis Of Higher Order Programs

Composition Operation

(𝜏1 ,πœ”1)𝑆1;𝑆2 ;…;𝑆𝑛

(𝜏2 ,πœ”2)𝑆𝑛+ 1;…;π‘†π‘š

𝑐1β€¦π‘π‘˜

2

3

4

1

𝜏1

𝜏1

𝜏1

𝜏1

𝑑1…𝑑 𝑗6

7

8

5

𝜏2

𝜏2

𝜏2

𝜏2

ID𝜏2∘𝜏1

Page 22: Modular Heap Analysis Of Higher Order Programs

Composition Operation

β€’ where , is the composed abstract state

β€’ When the first order summaries (and hence composition) are isotonic:

(𝜏2 ,πœ”2 )∘ (𝜏1 ,πœ”1 )=(𝜏2∘𝜏1 ,πœ”1βˆͺπœ”2)

Page 23: Modular Heap Analysis Of Higher Order Programs

Handling Direct Callsβ€’ Handle direct calls via summary composition

(πœπ‘’ ,πœ”π‘’)

(πœπ‘Ÿ ,πœ”π‘Ÿ)

ΒΏ

Call backs in the callee are inlined in the caller

Page 24: Modular Heap Analysis Of Higher Order Programs

Indirect call Resolution

(𝜏 , \{𝑐1 \})

3

5

7

1

𝜏 𝜏

𝜏

𝑐1 B (πœπ‘ , \{𝑐2 \})

(𝜏 βˆ˜πœπ‘ )βˆ—βˆ˜πœ

(𝜏2 , \{𝑐1 ,𝑐2 \})

𝜏

A

Page 25: Modular Heap Analysis Of Higher Order Programs

Indirect Call Resolution

A

(𝜏 , \{𝑐1 \})

calls B

B

(𝜏4❑ , \{𝑐1 ,𝑐2 ,𝑐3 \})(𝜏2❑ , \{𝑐1 ,𝑐2 \})

calls C

C

(𝜏3❑ , \{𝑐1 ,𝑐2 ,𝑐3 \})

calls B calls A

(πœπ‘ , \{𝑐2 \})

(πœπ‘ , \{𝑐3 \})

Page 26: Modular Heap Analysis Of Higher Order Programs

Indirect Call Resolution

A

(𝜏 π‘–βˆ’ 1❑ ,πœ” π‘–βˆ’1)

…

BC

(πœπ‘ , \{𝑐2 \})

(πœπ‘ , \{𝑐3 \})

(𝜏 𝑖❑ ,πœ”π‘–)…..

Fixed point

Page 27: Modular Heap Analysis Of Higher Order Programs

Eliminating resolved calls

(a) is Non escaping.Unreachable from

indirect calls and prestate

𝑝2

(b) and are unreachable from prestate and other call backs

𝑓𝑝1*fp1

…

Resolved calls

Foo

*fp2

𝑓𝑝2 …

𝑝1Bar

Page 28: Modular Heap Analysis Of Higher Order Programs

Experimental Evaluation

β€’ Applied to Purity/Side-effects Analysis for C# libraries

β€’ Every method is classified as:

β€’ Pure – No side-effects β€’ Conditionally Pure – Purity depends on the calling contextβ€’ Impure – Has side-effectsβ€’ Impure and Incomplete – Has side-effects and can have more

depending on the calling context

Page 29: Modular Heap Analysis Of Higher Order Programs

Experimental ResultsBenchmark LOC Pure C-Pure Impure I-Impure Time

DocX 10K ~ 1 min

FB APIs 2.2% 32%

Data Disp. 57%

Test APIs

Json Libs

Quickgraph

Refactory libs 30% 8%

Utility Libs 32% 8%

PDF libs 28.4%

GPS libs 250K ~ 2 hrs

10 – 20%

15 – 30%

20 – 30%

2 – 27 min

Page 30: Modular Heap Analysis Of Higher Order Programs

Analysis StatisticsBenchmark Unresolved

CallsNon Escaping Abs. Objects

DocX

FB APIs 9%

Data Disp.

Test APIs

Json Libs 7.3

Quickgraph

Refactory libs

Utility Libs

PDF libs 37%

GPS libs 5.9

2 – 4

10 – 33 %

Page 31: Modular Heap Analysis Of Higher Order Programs

Comparison with CHA CG based Bottom up Analysis

Benchmark Time # of SCCs Avg. Scc size

DocX 12x 0 NA

FB APIs 11x 3x 1.5x

Data Disp. 6x 6x

Test APIs 6x 2x 1.25x

Json Libs 2x 6x

Quickgraph 11x 33x

Refactory libs 1.4x 5.6x

Utility Libs 30x 4x 12x

PDF libs 2x 3.5x 1.5x

Page 32: Modular Heap Analysis Of Higher Order Programs

Conclusion

β€’ A principled approach

β€’ Formalized as an Abstract Interpretation

β€’ A generic theory agnostic to the underlying compositional heap analysis

β€’ Goto www.rise4fun.com/seal for a hands-on experience