Interprocedural Heap Analysis using Access Graphs and Value Contexts - - PowerPoint PPT Presentation

interprocedural heap analysis using access graphs and
SMART_READER_LITE
LIVE PREVIEW

Interprocedural Heap Analysis using Access Graphs and Value Contexts - - PowerPoint PPT Presentation

Interprocedural Heap Analysis using Access Graphs and Value Contexts with applications to liveness-based garbage collection Rohan Padhye under the guidance of Prof. Uday Khedker Department of Computer Science & Engineering Indian


slide-1
SLIDE 1

Interprocedural Heap Analysis using Access Graphs and Value Contexts

with applications to liveness-based garbage collection Rohan Padhye

under the guidance of

  • Prof. Uday Khedker

Department of Computer Science & Engineering Indian Institute of Technology Bombay

M.Tech Project

slide-2
SLIDE 2

Outline

1

Background and Motivation Heap Reference Analysis Key Issues

2

Heap Alias Analysis Need for Alias Analysis Existing Abstractions Proposed Abstraction: Acccessor Relationship Graph

3

Interprocedural Analysis Existing Frameworks Our Framework: Value Contexts The Role of Call Graphs

4

Access Graphs for Garbage Collection Existing Ideas Novel Technique: Dynamic Heap Pruning

5

Summary & Future Work

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 2 / 32

slide-3
SLIDE 3

Background

Heap Reference Analysis [Khedker, Sanyal & Karkare, 2007] S1: x = root S2: while (x.val > M): S3: x = x.l S4: x = x.r S5: print x.val S6: EXIT x l3 r4 Access graph for x at S2. root x 1 2 4 8 9 5 10 11 3 6 12 13 7 14 15 The binary tree in the heap at S2. Filled nodes are live objects.

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 3 / 32

slide-4
SLIDE 4

Key Issues

Three main issues in performing Heap Reference Analysis:

1 How to perform a precise alias analysis for arbitrary access paths in

the heap?

2 How to implement whole-program heap reference analysis in an

inter-procedural manner?

3 How to use the resulting access graphs to improve garbage

collection?

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 4 / 32

slide-5
SLIDE 5

Outline

1

Background and Motivation Heap Reference Analysis Key Issues

2

Heap Alias Analysis Need for Alias Analysis Existing Abstractions Proposed Abstraction: Acccessor Relationship Graph

3

Interprocedural Analysis Existing Frameworks Our Framework: Value Contexts The Role of Call Graphs

4

Access Graphs for Garbage Collection Existing Ideas Novel Technique: Dynamic Heap Pruning

5

Summary & Future Work

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 5 / 32

slide-6
SLIDE 6

Need for Alias Analysis

S1 S2 S3 x.p = z S4 u = y.p S5 v = u.q S6 use v S7 x and y do not alias at S4. LVIN4 x y p5 q6 LVOUT4 y p5 q6

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 6 / 32

slide-7
SLIDE 7

Need for Alias Analysis

S1 x = y S2 S3 x.p = z S4 u = y.p S5 v = u.q S6 use v S7 x may alias y at S4 LVIN4 x y p5 q6 z q6 LVOUT4 y p5 q6

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 7 / 32

slide-8
SLIDE 8

Need for Alias Analysis

x = y S1 S2 S3 x.p = z S4 u = y.p S5 v = u.q S6 use v S7 x must alias y at S4 LVIN4 x y z q6 LVOUT4 y p5 q6

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 8 / 32

slide-9
SLIDE 9

Need for Alias Analysis

May-alias analysis is required for sound heap liveness analysis. Must-alias analysis is desirable for performing strong updates. In general, alias queries may not be as straightforward as the preceeding examples: w.r = z x p3 q4 r5 In the above program, z is live if w may be aliased to any object accessible by the pattern x(.p)∗.q. The key obervation is here is that we need to determine aliases between live access patterns.

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 9 / 32

slide-10
SLIDE 10

Access Graphs and Access Patterns

S1: w.r = z S2: while (...): S3: x = x.p S4: x = x.q S5: x = x.r S6: use x S7: EXIT Consider liveness at S2. Access Graph x p3 q4 r5 Equivalent Automaton x p q r p q Access Patterns

x/p3 : x.p(.p)∗ x/q4 : x(.p)∗.q x/r5 : x(.p)∗.q.r

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 10 / 32

slide-11
SLIDE 11

Approaches to Heap Alias Analysis

Modelling an unbounded number of objects using a finite abstraction: Muchnick & Jones, 1981: k-limited graph Chase, Wegman & Zadeck, 1990: Merge on allocation sites Sagiv, Reps & Wilhelm, 1996: “Materialization” Sagiv, Reps & Wilhelm, 1999: 3-valued logic

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 11 / 32

slide-12
SLIDE 12

Approaches to Heap Alias Analysis

Modelling an unbounded number of objects using a finite abstraction: Muchnick & Jones, 1981: k-limited graph Chase, Wegman & Zadeck, 1990: Merge on allocation sites Sagiv, Reps & Wilhelm, 1996: “Materialization” Sagiv, Reps & Wilhelm, 1999: 3-valued logic Our approach: Use access patterns from liveness graphs to improve expressibility of points-to graph

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 11 / 32

slide-13
SLIDE 13

Proposed Approach

y = new S0 z = new S1 t = new S2 t.n = x S3 x = t S4 a = x S5 b = a.n S6 a.n = y S7 b.n = z S8 use x.n S9 exit S10

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 12 / 32

slide-14
SLIDE 14

Proposed Approach

y = new S0 z = new S1 t = new S2 t.n = x S3 x = t S4 a = x S5 b = a.n S6 a.n = y S7 b.n = z S8 use x.n S9 exit S10

Actual heap layout after S6

x · · · n n n n a b y z

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 12 / 32

slide-15
SLIDE 15

Proposed Approach

y = new S0 z = new S1 t = new S2 t.n = x S3 x = t S4 a = x S5 b = a.n S6 a.n = y S7 b.n = z S8 use x.n S9 exit S10

Actual heap layout after S6

x · · · n n n n a b y z

P0: Initial Points-to Analysis

PTOUT6 = PTIN7 = PTIN8: x S2 n a b y S0 z S1

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 12 / 32

slide-16
SLIDE 16

Proposed Approach

y = new S0 z = new S1 t = new S2 t.n = x S3 x = t S4 a = x S5 b = a.n S6 a.n = y S7 b.n = z S8 use x.n S9 exit S10

Actual heap layout after S6

x · · · n n n n a b y z

P0: Initial Points-to Analysis

PTOUT6 = PTIN7 = PTIN8: x S2 n a b y S0 z S1

L1: Liveness after P0

LVIN9 = LVOUT7 = LVOUT8: x n9 LVIN7 (considering a

may

= x): a x n9 y , , LVIN8 (considering b

may

= x): b x n9 z , , LVOUT6 = LVIN7 ∪ LVIN8: a b x n9 y , , , z ,

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 12 / 32

slide-17
SLIDE 17

Proposed Approach

y = new S0 z = new S1 t = new S2 t.n = x S3 x = t S4 a = x S5 b = a.n S6 a.n = y S7 b.n = z S8 use x.n S9 exit S10

Actual heap layout after S6

x · · · n n n n a b y z

P0: Initial Points-to Analysis

PTOUT6 = PTIN7 = PTIN8: x S2 n a b y S0 z S1

P1: Points-to Analysis using L1

PTOUT6 = PTIN7 = PTIN8: x S2 S2 S2

x, a x/n9, b −

n n n a b y S0

y

z S1

z

L1: Liveness after P0

LVIN9 = LVOUT7 = LVOUT8: x n9 LVIN7 (considering a

may

= x): a x n9 y , , LVIN8 (considering b

may

= x): b x n9 z , , LVOUT6 = LVIN7 ∪ LVIN8: a b x n9 y , , , z ,

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 12 / 32

slide-18
SLIDE 18

Proposed Approach

y = new S0 z = new S1 t = new S2 t.n = x S3 x = t S4 a = x S5 b = a.n S6 a.n = y S7 b.n = z S8 use x.n S9 exit S10

Actual heap layout after S6

x · · · n n n n a b y z

P0: Initial Points-to Analysis

PTOUT6 = PTIN7 = PTIN8: x S2 n a b y S0 z S1

P1: Points-to Analysis using L1

PTOUT6 = PTIN7 = PTIN8: x S2 S2 S2

x, a x/n9, b −

n n n a b y S0

y

z S1

z

L1: Liveness after P0

LVIN9 = LVOUT7 = LVOUT8: x n9 LVIN7 (considering a

may

= x): a x n9 y , , LVIN8 (considering b

may

= x): b x n9 z , , LVOUT6 = LVIN7 ∪ LVIN8: a b x n9 y , , , z ,

L2: Liveness after P1

LVIN9 = LVOUT7 = LVOUT8: x n9 LVIN7 (considering a must = x): x y , LVIN8 (considering b = x): x n9 LVOUT6 = LVIN7 ∪ LVIN8: x n9 y ,

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 12 / 32

slide-19
SLIDE 19

Proposed Approach

y = new S0 z = new S1 t = new S2 t.n = x S3 x = t S4 a = x S5 b = a.n S6 a.n = y S7 b.n = z S8 use x.n S9 exit S10

Actual heap layout after S6

x · · · n n n n a b y z

P0: Initial Points-to Analysis

PTOUT6 = PTIN7 = PTIN8: x S2 n a b y S0 z S1

P1: Points-to Analysis using L1

PTOUT6 = PTIN7 = PTIN8: x S2 S2 S2

x, a x/n9, b −

n n n a b y S0

y

z S1

z

L1: Liveness after P0

LVIN9 = LVOUT7 = LVOUT8: x n9 LVIN7 (considering a

may

= x): a x n9 y , , LVIN8 (considering b

may

= x): b x n9 z , , LVOUT6 = LVIN7 ∪ LVIN8: a b x n9 y , , , z ,

L2: Liveness after P1

LVIN9 = LVOUT7 = LVOUT8: x n9 LVIN7 (considering a must = x): x y , LVIN8 (considering b = x): x n9 LVOUT6 = LVIN7 ∪ LVIN8: x n9 y ,

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 12 / 32

Note

We are not performing “materialization”. P1 does not use P0 and L2 does not use L1. These are new passes from scratch! Li uses Pi−1 for implicit updates. Pi uses Li for expressibility.

slide-20
SLIDE 20

Proposed Approach

Key idea: distinguish between objects accessible by distinct sets of access patterns. Thus, our approach is more precise than naive summarization in that:

1

Unnecessary may-aliases are avoided.

2

Useful must-aliases are discovered.

Inter-dependence of liveness and points-to analysis:

1

Perform naive points-to (summarize on alloc sites).

2

Backward analysis to get huge liveness info (sound but imprecise).

3

Again do points-to, distinguishing on access patterns found above.

4

Another round of backward analysis to get precise liveness info.

5

Fixed point...?

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 13 / 32

slide-21
SLIDE 21

Accessor Relationship Graph

Symbol Definition Cardinality V Variables Proportional to program size M Memory allocation sites Proportional to program size R Field dereference points Proportional to program size A Access graph nodes |V | + |V | × |R| H Heap graph nodes |M| × 2|A|

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 14 / 32

slide-22
SLIDE 22

Accessor Relationship Graph

Symbol Definition Cardinality V Variables Proportional to program size M Memory allocation sites Proportional to program size R Field dereference points Proportional to program size A Access graph nodes |V | + |V | × |R| H Heap graph nodes |M| × 2|A|

Definition

Accessor Relationship Graph is a 3-tuple Ev, Ef , summary, where: Ev ⊆ V × H Ef ⊆ H × F × H summary : H → {true, false}

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 14 / 32

slide-23
SLIDE 23

Lattice Representation

Definition

Ev, Ef , summary ⊒ E ′

v, E ′ f , summary′ if:

Ev ⊆ E ′

v

Ef ⊆ E ′

f

∀k ∈ H : summary(k) ⇒ summary′(k)

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 15 / 32

slide-24
SLIDE 24

Lattice Representation

Definition

Ev, Ef , summary ⊒ E ′

v, E ′ f , summary′ if:

Ev ⊆ E ′

v

Ef ⊆ E ′

f

∀k ∈ H : summary(k) ⇒ summary′(k)

Definition

Ev, Ef , summary ⊓ E ′

v, E ′ f , summary′ = E ′′ v , E ′′ f , summary′′ such that:

E ′′

v = Ev ∪ E ′ v

E ′′

f = Ef ∪ E ′ f

∀k ∈ H : summary′′(k) = summary(k) ∨ summary′(k)

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 15 / 32

slide-25
SLIDE 25

Data Flow Analysis

Normalization: Θ(X, L) = Consistency + Reachability x = x.n S5 n8 n6 n5 x x S1 S1 S1 S1 n n n n

x x/n5 x/n6 x/n8

n8 n6 x x S1 S1 S1 S1 n n n n

x x/n5 x x/n6 x/n8

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 16 / 32

slide-26
SLIDE 26

Data Flow Analysis

Normalization: Θ(X, L) = Consistency + Reachability x = x.n S5 n8 n6 n5 x x S1 S1 S1 S1 n n n n

x x/n5 x/n6 x/n8

n8 n6 x x S1 S1 S1 S1 n n n n

x x/n5 x x/n6 x/n8

Data Flow Equations: PTINb = ⊓

p∈pred(b)Θ(PTOUTp, LVINb)

PTOUTb = Θ(fb(PTINb), LVOUTb)

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 16 / 32

slide-27
SLIDE 27

System Model

ˆ L : S × AP → {true, false} (Results of liveness analysis) ˆ P : S × AP × AP → {true, false} (Results of points-to analysis) HLA : ˆ P → ˆ L (Heap Liveness Analysis) PTA : ˆ L → ˆ P (Heap Points-To Analysis) ˆ L0 = λsλa.false ∀i ≥ 0 : ˆ Pi = PTA(ˆ Li) ∀i ≥ 0 : ˆ Li+1 = HLA(ˆ Pi)

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 17 / 32

slide-28
SLIDE 28

System Model

ˆ L : S × AP → {true, false} (Results of liveness analysis) ˆ P : S × AP × AP → {true, false} (Results of points-to analysis) HLA : ˆ P → ˆ L (Heap Liveness Analysis) PTA : ˆ L → ˆ P (Heap Points-To Analysis) ˆ L0 = λsλa.false ∀i ≥ 0 : ˆ Pi = PTA(ˆ Li) ∀i ≥ 0 : ˆ Li+1 = HLA(ˆ Pi) ˆ Li ⊆ ˆ Lj iff ∀s ∈ S, ∀a ∈ AP : ˆ Li(s, a) ⇒ ˆ Lj(s, a) ˆ Pi ⊆ ˆ Pj iff ∀s ∈ S, ∀a ∈ AP, ∀b ∈ AP : ˆ Pi(s, a, b) ⇒ ˆ Pj(s, a, b)

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 17 / 32

slide-29
SLIDE 29

Precision of Liveness

ˆ L0 ˆ P0 ˆ L1 ˆ P1 ˆ L2 ˆ P2 ˆ L3 ˆ P3 ˆ L4 · · ·

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 18 / 32

slide-30
SLIDE 30

Precision of Liveness

ˆ L0 ˆ P0 ˆ L1 ˆ P1 ˆ L2 ˆ P2 ˆ L3 ˆ P3 ˆ L4 · · ·

Theorem

The results of the second round of heap liveness analysis is the most precise result which is also sound. That is, ∀k > 0 : ˆ L2 ⊆ ˆ Lk.

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 18 / 32

slide-31
SLIDE 31

Precision of Liveness

ˆ L0 ˆ P0 ˆ L1 ˆ P1 ˆ L2 ˆ P2 ˆ L3 ˆ P3 ˆ L4 · · ·

Theorem

The results of the second round of heap liveness analysis is the most precise result which is also sound. That is, ∀k > 0 : ˆ L2 ⊆ ˆ Lk.

Lemma (1)

∀i, j : ˆ Li ⊆ ˆ Lj ⇒ ˆ Pi ⊇ ˆ Pj

Lemma (2)

∀i, j : ˆ Pi ⊆ ˆ Pj ⇒ ˆ Li+1 ⊆ ˆ Lj+1

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 18 / 32

slide-32
SLIDE 32

Precision of Liveness

ˆ L0 ˆ P0 ˆ L1 ˆ P1 ˆ L2 ˆ P2 ˆ L3 ˆ P3 ˆ L4 · · ·

Theorem

The results of the second round of heap liveness analysis is the most precise result which is also sound. That is, ∀k > 0 : ˆ L2 ⊆ ˆ Lk.

Lemma (1)

∀i, j : ˆ Li ⊆ ˆ Lj ⇒ ˆ Pi ⊇ ˆ Pj

Lemma (2)

∀i, j : ˆ Pi ⊆ ˆ Pj ⇒ ˆ Li+1 ⊆ ˆ Lj+1

Proof.

  • 1. ∀k ≥ 0 : ˆ

L0 ⊆ ˆ Lk (By Definition)

  • 2. ∀k ≥ 0 : ˆ

P0 ⊇ ˆ Pk (Lemma 1)

  • 3. ∀k ≥ 0 : ˆ

L1 ⊇ ˆ Lk+1 (Lemma 2)

  • 4. ∀k ≥ 0 : ˆ

P1 ⊆ ˆ Pk+1 (Lemma 1)

  • 5. ∀k ≥ 0 : ˆ

L2 ⊆ ˆ Lk+2 (Lemma 2)

  • 6. ∀k > 0 : ˆ

L2 ⊆ ˆ Lk (Step 3 and 5)

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 18 / 32

slide-33
SLIDE 33

Outline

1

Background and Motivation Heap Reference Analysis Key Issues

2

Heap Alias Analysis Need for Alias Analysis Existing Abstractions Proposed Abstraction: Acccessor Relationship Graph

3

Interprocedural Analysis Existing Frameworks Our Framework: Value Contexts The Role of Call Graphs

4

Access Graphs for Garbage Collection Existing Ideas Novel Technique: Dynamic Heap Pruning

5

Summary & Future Work

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 19 / 32

slide-34
SLIDE 34

Interprocedural Analysis

No existing implementation of inter-procedural heap reference analysis

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 20 / 32

slide-35
SLIDE 35

Interprocedural Analysis

No existing implementation of inter-procedural heap reference analysis Soot has excellent API for data flow analysis - only intraprocedural

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 20 / 32

slide-36
SLIDE 36

Interprocedural Analysis

No existing implementation of inter-procedural heap reference analysis Soot has excellent API for data flow analysis - only intraprocedural IFDS/IDE solver [Bodden, SOAP 2012]

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 20 / 32

slide-37
SLIDE 37

Interprocedural Analysis

No existing implementation of inter-procedural heap reference analysis Soot has excellent API for data flow analysis - only intraprocedural IFDS/IDE solver [Bodden, SOAP 2012]

f ({x, y, z}) = f ({x}) ⊓ f ({y}) ⊓ f ({z})

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 20 / 32

slide-38
SLIDE 38

Interprocedural Analysis

No existing implementation of inter-procedural heap reference analysis Soot has excellent API for data flow analysis - only intraprocedural IFDS/IDE solver [Bodden, SOAP 2012]

f ({x, y, z}) = f ({x}) ⊓ f ({y}) ⊓ f ({z}) Functions on 2D reduced to functions on D

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 20 / 32

slide-39
SLIDE 39

Interprocedural Analysis

No existing implementation of inter-procedural heap reference analysis Soot has excellent API for data flow analysis - only intraprocedural IFDS/IDE solver [Bodden, SOAP 2012]

f ({x, y, z}) = f ({x}) ⊓ f ({y}) ⊓ f ({z}) Functions on 2D reduced to functions on D Modelled as a graph reachability problem

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 20 / 32

slide-40
SLIDE 40

Interprocedural Analysis

No existing implementation of inter-procedural heap reference analysis Soot has excellent API for data flow analysis - only intraprocedural IFDS/IDE solver [Bodden, SOAP 2012]

f ({x, y, z}) = f ({x}) ⊓ f ({y}) ⊓ f ({z}) Functions on 2D reduced to functions on D Modelled as a graph reachability problem Main limitation: Requires distributive flow functions

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 20 / 32

slide-41
SLIDE 41

Interprocedural Analysis

No existing implementation of inter-procedural heap reference analysis Soot has excellent API for data flow analysis - only intraprocedural IFDS/IDE solver [Bodden, SOAP 2012]

f ({x, y, z}) = f ({x}) ⊓ f ({y}) ⊓ f ({z}) Functions on 2D reduced to functions on D Modelled as a graph reachability problem Main limitation: Requires distributive flow functions Not suitable for many types of heap analysis

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 20 / 32

slide-42
SLIDE 42

Interprocedural Analysis

No existing implementation of inter-procedural heap reference analysis Soot has excellent API for data flow analysis - only intraprocedural IFDS/IDE solver [Bodden, SOAP 2012]

f ({x, y, z}) = f ({x}) ⊓ f ({y}) ⊓ f ({z}) Functions on 2D reduced to functions on D Modelled as a graph reachability problem Main limitation: Requires distributive flow functions Not suitable for many types of heap analysis

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 20 / 32

slide-43
SLIDE 43

Interprocedural Analysis

No existing implementation of inter-procedural heap reference analysis Soot has excellent API for data flow analysis - only intraprocedural IFDS/IDE solver [Bodden, SOAP 2012]

f ({x, y, z}) = f ({x}) ⊓ f ({y}) ⊓ f ({z}) Functions on 2D reduced to functions on D Modelled as a graph reachability problem Main limitation: Requires distributive flow functions Not suitable for many types of heap analysis

x = y.n y

  • 1
  • 2

n y

  • 1
  • 2

n x

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 20 / 32

slide-44
SLIDE 44

Interprocedural Analysis

The most general and precise solutions:

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 21 / 32

slide-45
SLIDE 45

Interprocedural Analysis

The most general and precise solutions: Call Strings (maintain an abstract call stack) [Sharir & Pnueli, 1981]

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 21 / 32

slide-46
SLIDE 46

Interprocedural Analysis

The most general and precise solutions: Call Strings (maintain an abstract call stack) [Sharir & Pnueli, 1981] Functional (flow functions for call statements) [Sharir & Pnueli, 1981]

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 21 / 32

slide-47
SLIDE 47

Interprocedural Analysis

The most general and precise solutions: Call Strings (maintain an abstract call stack) [Sharir & Pnueli, 1981] Functional (flow functions for call statements) [Sharir & Pnueli, 1981]

Function composition method Tabulation method

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 21 / 32

slide-48
SLIDE 48

Interprocedural Analysis

The most general and precise solutions: Call Strings (maintain an abstract call stack) [Sharir & Pnueli, 1981] Functional (flow functions for call statements) [Sharir & Pnueli, 1981]

Function composition method Tabulation method

Modified call-strings method [Khedker & Karkare, 2008]

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 21 / 32

slide-49
SLIDE 49

Interprocedural Analysis

The most general and precise solutions: Call Strings (maintain an abstract call stack) [Sharir & Pnueli, 1981] Functional (flow functions for call statements) [Sharir & Pnueli, 1981]

Function composition method Tabulation method

Modified call-strings method [Khedker & Karkare, 2008]

Value-based termination of call string construction

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 21 / 32

slide-50
SLIDE 50

Interprocedural Analysis

The most general and precise solutions: Call Strings (maintain an abstract call stack) [Sharir & Pnueli, 1981] Functional (flow functions for call statements) [Sharir & Pnueli, 1981]

Function composition method Tabulation method

Modified call-strings method [Khedker & Karkare, 2008]

Value-based termination of call string construction

Value contexts [Padhye & Khedker, 2013]

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 21 / 32

slide-51
SLIDE 51

Interprocedural Analysis

The most general and precise solutions: Call Strings (maintain an abstract call stack) [Sharir & Pnueli, 1981] Functional (flow functions for call statements) [Sharir & Pnueli, 1981]

Function composition method Tabulation method

Modified call-strings method [Khedker & Karkare, 2008]

Value-based termination of call string construction

Value contexts [Padhye & Khedker, 2013]

Reformulation of tabulation method

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 21 / 32

slide-52
SLIDE 52

Interprocedural Analysis

The most general and precise solutions: Call Strings (maintain an abstract call stack) [Sharir & Pnueli, 1981] Functional (flow functions for call statements) [Sharir & Pnueli, 1981]

Function composition method Tabulation method

Modified call-strings method [Khedker & Karkare, 2008]

Value-based termination of call string construction

Value contexts [Padhye & Khedker, 2013]

Reformulation of tabulation method Suitable for bi-directional interleaved analyses

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 21 / 32

slide-53
SLIDE 53

Interprocedural Analysis

The most general and precise solutions: Call Strings (maintain an abstract call stack) [Sharir & Pnueli, 1981] Functional (flow functions for call statements) [Sharir & Pnueli, 1981]

Function composition method Tabulation method

Modified call-strings method [Khedker & Karkare, 2008]

Value-based termination of call string construction

Value contexts [Padhye & Khedker, 2013]

Reformulation of tabulation method Suitable for bi-directional interleaved analyses Can map arbitrary call string to value context (dynamic optimizations)

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 21 / 32

slide-54
SLIDE 54

Interprocedural Analysis

The most general and precise solutions: Call Strings (maintain an abstract call stack) [Sharir & Pnueli, 1981] Functional (flow functions for call statements) [Sharir & Pnueli, 1981]

Function composition method Tabulation method

Modified call-strings method [Khedker & Karkare, 2008]

Value-based termination of call string construction

Value contexts [Padhye & Khedker, 2013]

Reformulation of tabulation method Suitable for bi-directional interleaved analyses Can map arbitrary call string to value context (dynamic optimizations) Context-sensitive data flow solution (specialization)

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 21 / 32

slide-55
SLIDE 55

Value Contexts

Value contexts:

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 22 / 32

slide-56
SLIDE 56

Value Contexts

Value contexts: X = method, entryValue

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 22 / 32

slide-57
SLIDE 57

Value Contexts

Value contexts: X = method, entryValue exitValue(X)

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 22 / 32

slide-58
SLIDE 58

Value Contexts

Value contexts: X = method, entryValue exitValue(X) Data Flow Analysis is performed using traditional work-list method

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 22 / 32

slide-59
SLIDE 59

Value Contexts

Value contexts: X = method, entryValue exitValue(X) Data Flow Analysis is performed using traditional work-list method Work-list contains context, node pairs

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 22 / 32

slide-60
SLIDE 60

Value Contexts

Value contexts: X = method, entryValue exitValue(X) Data Flow Analysis is performed using traditional work-list method Work-list contains context, node pairs Call-sites: Find value context X = method, entryValue

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 22 / 32

slide-61
SLIDE 61

Value Contexts

Value contexts: X = method, entryValue exitValue(X) Data Flow Analysis is performed using traditional work-list method Work-list contains context, node pairs Call-sites: Find value context X = method, entryValue

Found: Re-use exitValue(X)

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 22 / 32

slide-62
SLIDE 62

Value Contexts

Value contexts: X = method, entryValue exitValue(X) Data Flow Analysis is performed using traditional work-list method Work-list contains context, node pairs Call-sites: Find value context X = method, entryValue

Found: Re-use exitValue(X) Not found: Create new X and add all nodes to work-list

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 22 / 32

slide-63
SLIDE 63

Value Contexts

Value contexts: X = method, entryValue exitValue(X) Data Flow Analysis is performed using traditional work-list method Work-list contains context, node pairs Call-sites: Find value context X = method, entryValue

Found: Re-use exitValue(X) Not found: Create new X and add all nodes to work-list Record transition from this call-site to X

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 22 / 32

slide-64
SLIDE 64

Value Contexts

Value contexts: X = method, entryValue exitValue(X) Data Flow Analysis is performed using traditional work-list method Work-list contains context, node pairs Call-sites: Find value context X = method, entryValue

Found: Re-use exitValue(X) Not found: Create new X and add all nodes to work-list Record transition from this call-site to X

Exit-sites: Set exitValue(X) and add callers to work-list

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 22 / 32

slide-65
SLIDE 65

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6 Context Proc. Entry Exit Value Contexts ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-66
SLIDE 66

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6 Context Proc. Entry Exit X0 main ⊤ ⊤ Value Contexts ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-67
SLIDE 67

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6

X0, ⊤

Context Proc. Entry Exit X0 main ⊤ ⊤ Value Contexts ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-68
SLIDE 68

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6

X0, ⊤ X0, p+

Context Proc. Entry Exit X0 main ⊤ ⊤ Value Contexts ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-69
SLIDE 69

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6

X0, ⊤ X0, p+

Context Proc. Entry Exit X0 main ⊤ ⊤ X1 f a+b− ⊤ Value Contexts ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-70
SLIDE 70

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6

X0, ⊤ X0, p+

Context Proc. Entry Exit X0 main ⊤ ⊤ X1 f a+b− ⊤ Value Contexts X0 X1 c1 Context Transitions ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-71
SLIDE 71

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6

X0, ⊤ X0, p+ X1, a+b−

Context Proc. Entry Exit X0 main ⊤ ⊤ X1 f a+b− ⊤ Value Contexts X0 X1 c1 Context Transitions ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-72
SLIDE 72

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6

X0, ⊤ X0, p+ X1, a+b− X1, a+b−

Context Proc. Entry Exit X0 main ⊤ ⊤ X1 f a+b− ⊤ Value Contexts X0 X1 c1 Context Transitions ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-73
SLIDE 73

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6

X0, ⊤ X0, p+ X1, a+b− X1, a+b−

Context Proc. Entry Exit X0 main ⊤ ⊤ X1 f a+b− ⊤ X2 g u+ ⊤ Value Contexts X0 X1 c1 Context Transitions ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-74
SLIDE 74

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6

X0, ⊤ X0, p+ X1, a+b− X1, a+b−

Context Proc. Entry Exit X0 main ⊤ ⊤ X1 f a+b− ⊤ X2 g u+ ⊤ Value Contexts X0 X1 X2 c1 c2 Context Transitions ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-75
SLIDE 75

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6

X0, ⊤ X0, p+ X1, a+b− X1, a+b− X2, u+

Context Proc. Entry Exit X0 main ⊤ ⊤ X1 f a+b− ⊤ X2 g u+ ⊤ Value Contexts X0 X1 X2 c1 c2 Context Transitions ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-76
SLIDE 76

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6

X0, ⊤ X0, p+ X1, a+b− X1, a+b− X2, u+

Context Proc. Entry Exit X0 main ⊤ ⊤ X1 f a+b− ⊤ X2 g u+ ⊤ X3 f a−b+ ⊤ Value Contexts X0 X1 X2 c1 c2 Context Transitions ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-77
SLIDE 77

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6

X0, ⊤ X0, p+ X1, a+b− X1, a+b− X2, u+

Context Proc. Entry Exit X0 main ⊤ ⊤ X1 f a+b− ⊤ X2 g u+ ⊤ X3 f a−b+ ⊤ Value Contexts X0 X1 X2 X3 c1 c2 c3 Context Transitions ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-78
SLIDE 78

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6

X0, ⊤ X0, p+ X1, a+b− X3, a−b+ X1, a+b− X2, u+

Context Proc. Entry Exit X0 main ⊤ ⊤ X1 f a+b− ⊤ X2 g u+ ⊤ X3 f a−b+ ⊤ Value Contexts X0 X1 X2 X3 c1 c2 c3 Context Transitions ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-79
SLIDE 79

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6

X0, ⊤ X0, p+ X1, a+b− X3, a−b+ X1, a+b− X3, a−b+ X2, u+

Context Proc. Entry Exit X0 main ⊤ ⊤ X1 f a+b− ⊤ X2 g u+ ⊤ X3 f a−b+ ⊤ Value Contexts X0 X1 X2 X3 c1 c2 c3 Context Transitions ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-80
SLIDE 80

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6

X0, ⊤ X0, p+ X1, a+b− X3, a−b+ X1, a+b− X3, a−b+ X2, u+

Context Proc. Entry Exit X0 main ⊤ ⊤ X1 f a+b− ⊤ X2 g u+ ⊤ X3 f a−b+ ⊤ Value Contexts X0 X1 X2 X3 c1 c2 c3 c2 Context Transitions ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-81
SLIDE 81

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6

X0, ⊤ X0, p+ X1, a+b− X3, a−b+ X1, a+b− X3, a−b+ X3, a−b+ X2, u+

Context Proc. Entry Exit X0 main ⊤ ⊤ X1 f a+b− ⊤ X2 g u+ ⊤ X3 f a−b+ ⊤ Value Contexts X0 X1 X2 X3 c1 c2 c3 c2 Context Transitions ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-82
SLIDE 82

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6

X0, ⊤ X0, p+ X1, a+b− X3, a−b+ X3, a−b+ X1, a+b− X3, a−b+ X3, a−b+ X2, u+

Context Proc. Entry Exit X0 main ⊤ ⊤ X1 f a+b− ⊤ X2 g u+ ⊤ X3 f a−b+ ⊤ Value Contexts X0 X1 X2 X3 c1 c2 c3 c2 Context Transitions ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-83
SLIDE 83

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6

X0, ⊤ X0, p+ X1, a+b− X3, a−b+ X3, a−b+ X1, a+b− X3, a−b+ X3, a−b+c− X3, a−b+ X2, u+

Context Proc. Entry Exit X0 main ⊤ ⊤ X1 f a+b− ⊤ X2 g u+ ⊤ X3 f a−b+ ⊤ Value Contexts X0 X1 X2 X3 c1 c2 c3 c2 Context Transitions ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-84
SLIDE 84

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6

X0, ⊤ X0, p+ X1, a+b− X3, a−b+ X3, a−b+ X1, a+b− X3, a−b+ X3, a−b+c− X3, a−b+ X3, a−b+c− X2, u+

Context Proc. Entry Exit X0 main ⊤ ⊤ X1 f a+b− ⊤ X2 g u+ ⊤ X3 f a−b+ ⊤ Value Contexts X0 X1 X2 X3 c1 c2 c3 c2 Context Transitions ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-85
SLIDE 85

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6

X0, ⊤ X0, p+ X1, a+b− X3, a−b+ X3, a−b+ X1, a+b− X3, a−b+ X3, a−b+c− X3, a−b+ X3, a−b+c− X2, u+

Context Proc. Entry Exit X0 main ⊤ ⊤ X1 f a+b− ⊤ X2 g u+ ⊤ X3 f a−b+ a−b+c− Value Contexts X0 X1 X2 X3 c1 c2 c3 c2 Context Transitions ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-86
SLIDE 86

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6

X0, ⊤ X0, p+ X1, a+b− X3, a−b+ X3, a−b+ X1, a+b− X3, a−b+ X3, a−b+c− X3, a−b+ X3, a−b+c− X2, u+ X2, u+v−

Context Proc. Entry Exit X0 main ⊤ ⊤ X1 f a+b− ⊤ X2 g u+ ⊤ X3 f a−b+ a−b+c− Value Contexts X0 X1 X2 X3 c1 c2 c3 c2 Context Transitions ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-87
SLIDE 87

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6

X0, ⊤ X0, p+ X1, a+b− X3, a−b+ X3, a−b+ X1, a+b− X3, a−b+ X3, a−b+c− X3, a−b+ X3, a−b+c− X2, u+ X2, u+v−

Context Proc. Entry Exit X0 main ⊤ ⊤ X1 f a+b− ⊤ X2 g u+ u+v− X3 f a−b+ a−b+c− Value Contexts X0 X1 X2 X3 c1 c2 c3 c2 Context Transitions ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-88
SLIDE 88

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6

X0, ⊤ X0, p+ X1, a+b− X3, a−b+ X3, a−b+ X1, a+b− X3, a−b+ X3, a−b+c− X3, a−b+c− X3, a−b+c− X2, u+ X2, u+v−

Context Proc. Entry Exit X0 main ⊤ ⊤ X1 f a+b− ⊤ X2 g u+ u+v− X3 f a−b+ a−b+c− Value Contexts X0 X1 X2 X3 c1 c2 c3 c2 Context Transitions ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-89
SLIDE 89

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6

X0, ⊤ X0, p+ X1, a+b− X3, a−b+ X3, a−b+ X1, a+b− X3, a−b+ X3, a−b+c− X1, a+b−c− X3, a−b+c− X3, a−b+c− X2, u+ X2, u+v−

Context Proc. Entry Exit X0 main ⊤ ⊤ X1 f a+b− ⊤ X2 g u+ u+v− X3 f a−b+ a−b+c− Value Contexts X0 X1 X2 X3 c1 c2 c3 c2 Context Transitions ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-90
SLIDE 90

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6

X0, ⊤ X0, p+ X1, a+b− X3, a−b+ X1, a+b− X3, a−b+ X1, a+b− X3, a−b+ X3, a−b+c− X1, a+b−c− X3, a−b+c− X3, a−b+c− X2, u+ X2, u+v−

Context Proc. Entry Exit X0 main ⊤ ⊤ X1 f a+b− ⊤ X2 g u+ u+v− X3 f a−b+ a−b+c− Value Contexts X0 X1 X2 X3 c1 c2 c3 c2 Context Transitions ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-91
SLIDE 91

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6

X0, ⊤ X0, p+ X1, a+b− X3, a−b+ X1, a+b− X3, a−b+ X1, a+b− X3, a−b+ X1, a+b−c− X3, a−b+c− X1, a+b−c− X3, a−b+c− X3, a−b+c− X2, u+ X2, u+v−

Context Proc. Entry Exit X0 main ⊤ ⊤ X1 f a+b− ⊤ X2 g u+ u+v− X3 f a−b+ a−b+c− Value Contexts X0 X1 X2 X3 c1 c2 c3 c2 Context Transitions ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-92
SLIDE 92

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6

X0, ⊤ X0, p+ X1, a+b− X3, a−b+ X1, a+b− X3, a−b+ X1, a+b− X3, a−b+ X1, a+b−c− X3, a−b+c− X1, a+b−c− X3, a−b+c− X1, a+b−c− X3, a−b+c− X2, u+ X2, u+v−

Context Proc. Entry Exit X0 main ⊤ ⊤ X1 f a+b− ⊤ X2 g u+ u+v− X3 f a−b+ a−b+c− Value Contexts X0 X1 X2 X3 c1 c2 c3 c2 Context Transitions ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-93
SLIDE 93

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6

X0, ⊤ X0, p+ X1, a+b− X3, a−b+ X1, a+b− X3, a−b+ X1, a+b− X3, a−b+ X1, a+b−c− X3, a−b+c− X1, a+b−c− X3, a−b+c− X1, a+b−c− X3, a−b+c− X2, u+ X2, u+v−

Context Proc. Entry Exit X0 main ⊤ ⊤ X1 f a+b− a+b−c− X2 g u+ u+v− X3 f a−b+ a−b+c− Value Contexts X0 X1 X2 X3 c1 c2 c3 c2 Context Transitions ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-94
SLIDE 94

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6

X0, ⊤ X0, p+ X0, p+q− X1, a+b− X3, a−b+ X1, a+b− X3, a−b+ X1, a+b− X3, a−b+ X1, a+b−c− X3, a−b+c− X1, a+b−c− X3, a−b+c− X1, a+b−c− X3, a−b+c− X2, u+ X2, u+v−

Context Proc. Entry Exit X0 main ⊤ ⊤ X1 f a+b− a+b−c− X2 g u+ u+v− X3 f a−b+ a−b+c− Value Contexts X0 X1 X2 X3 c1 c2 c3 c2 Context Transitions ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-95
SLIDE 95

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6

X0, ⊤ X0, p+ X0, p+q− X1, a+b− X3, a−b+ X1, a+b− X3, a−b+ X1, a+b− X3, a−b+ X1, a+b−c− X3, a−b+c− X1, a+b−c− X3, a−b+c− X1, a+b−c− X3, a−b+c− X2, u+ X2, u+v−

Context Proc. Entry Exit X0 main ⊤ ⊤ X1 f a+b− a+b−c− X2 g u+ u+v− X3 f a−b+ a−b+c− Value Contexts X0 X1 X2 X3 c1 c2 c3 c2 c4 Context Transitions ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-96
SLIDE 96

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6

X0, ⊤ X0, p+ X0, p+q− X0, p+q−r− X1, a+b− X3, a−b+ X1, a+b− X3, a−b+ X1, a+b− X3, a−b+ X1, a+b−c− X3, a−b+c− X1, a+b−c− X3, a−b+c− X1, a+b−c− X3, a−b+c− X2, u+ X2, u+v−

Context Proc. Entry Exit X0 main ⊤ ⊤ X1 f a+b− a+b−c− X2 g u+ u+v− X3 f a−b+ a−b+c− Value Contexts X0 X1 X2 X3 c1 c2 c3 c2 c4 Context Transitions ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-97
SLIDE 97

Example - Sign Analysis

main() p = 5 n1 q = f(p, -3) c1 r = g(-q) c4 exit n6 f(a, b) if (...) n2 c = a * b n3 c = g(10) c2 return c n5 g(u) v = f(-u, u) c3 return v n6

X0, ⊤ X0, p+ X0, p+q− X0, p+q−r− X1, a+b− X3, a−b+ X1, a+b− X3, a−b+ X1, a+b− X3, a−b+ X1, a+b−c− X3, a−b+c− X1, a+b−c− X3, a−b+c− X1, a+b−c− X3, a−b+c− X2, u+ X2, u+v−

Context Proc. Entry Exit X0 main ⊤ p+q−r− X1 f a+b− a+b−c− X2 g u+ u+v− X3 f a−b+ a−b+c− Value Contexts X0 X1 X2 X3 c1 c2 c3 c2 c4 Context Transitions ⊤ − + ⊥ Component Lattice

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 23 / 32

slide-98
SLIDE 98

Implementation Framework

Context<M,N,A> + getMethod(): M + getEntryValue() : A + getExitValue() : A + getValueBefore(N) : A + getValueAfter(N) : A InterProceduralAnalysis<M,N,A> + topValue() : A + boundaryValue(M) : A + copy(A) : A + meet(A,A) : A + normalFlowFunction(Context<M,N,A>, N, A) : A + callEntryFlowFunction(Context<M,N,A>, M, N, A) : A + callExitFlowFunction(Context<M,N,A>, M, N, A) : A + callLocalFlowFunction(Context<M,N,A>, N, A) : A + programRepresentation() : ProgramRepresentation<M,N> + doAnalysis() : void + getContexts() : Map<M,List<Context<M,N,A>>> + getMeetOverPathsSolution() : DataFlowSolution<M,N,A> ForwardInterProceduralAnalysis<M,N,A> + doAnalysis() : void BackwardInterProceduralAnalysis<M,N,A> + doAnalysis() : void ProgramRepresentation<M,N> + getEntryPoints() : List<M> + getControlFlowGraph(M) : DirectedGraph<N> + isCall(N) : boolean + resolveTargets(M, N) : List<M>

https://github.com/rohanpadhye/vasco

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 24 / 32

slide-99
SLIDE 99

The Role of Call Graphs

Context-sensitivity only useful if call graph is precise

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 25 / 32

slide-100
SLIDE 100

The Role of Call Graphs

Context-sensitivity only useful if call graph is precise OOP: Use points-to analysis to resolve virtual calls

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 25 / 32

slide-101
SLIDE 101

The Role of Call Graphs

Context-sensitivity only useful if call graph is precise OOP: Use points-to analysis to resolve virtual calls Imprecise points-to analysis ⇒ “spurious” edges

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 25 / 32

slide-102
SLIDE 102

The Role of Call Graphs

Context-sensitivity only useful if call graph is precise OOP: Use points-to analysis to resolve virtual calls Imprecise points-to analysis ⇒ “spurious” edges SPARK: Thousands of spurious edges even for small programs

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 25 / 32

slide-103
SLIDE 103

The Role of Call Graphs

Context-sensitivity only useful if call graph is precise OOP: Use points-to analysis to resolve virtual calls Imprecise points-to analysis ⇒ “spurious” edges SPARK: Thousands of spurious edges even for small programs

e.g. Over 250 targets for x.hashCode() in HashSet

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 25 / 32

slide-104
SLIDE 104

The Role of Call Graphs

Context-sensitivity only useful if call graph is precise OOP: Use points-to analysis to resolve virtual calls Imprecise points-to analysis ⇒ “spurious” edges SPARK: Thousands of spurious edges even for small programs

e.g. Over 250 targets for x.hashCode() in HashSet

Affects efficiency and precision of interprocedural analysis

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 25 / 32

slide-105
SLIDE 105

The Role of Call Graphs

Context-sensitivity only useful if call graph is precise OOP: Use points-to analysis to resolve virtual calls Imprecise points-to analysis ⇒ “spurious” edges SPARK: Thousands of spurious edges even for small programs

e.g. Over 250 targets for x.hashCode() in HashSet

Affects efficiency and precision of interprocedural analysis Points-to Analysis using Value Contexts

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 25 / 32

slide-106
SLIDE 106

The Role of Call Graphs

Context-sensitivity only useful if call graph is precise OOP: Use points-to analysis to resolve virtual calls Imprecise points-to analysis ⇒ “spurious” edges SPARK: Thousands of spurious edges even for small programs

e.g. Over 250 targets for x.hashCode() in HashSet

Affects efficiency and precision of interprocedural analysis Points-to Analysis using Value Contexts

Flow and context-sensitive points-to analysis (FCPA)

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 25 / 32

slide-107
SLIDE 107

The Role of Call Graphs

Context-sensitivity only useful if call graph is precise OOP: Use points-to analysis to resolve virtual calls Imprecise points-to analysis ⇒ “spurious” edges SPARK: Thousands of spurious edges even for small programs

e.g. Over 250 targets for x.hashCode() in HashSet

Affects efficiency and precision of interprocedural analysis Points-to Analysis using Value Contexts

Flow and context-sensitive points-to analysis (FCPA) Context-sensitive call graph constructed on-the-fly

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 25 / 32

slide-108
SLIDE 108

Results of Points-To Analysis

Tested on 7 benchmarks from SPEC JVM98 and DaCapo 2006

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 26 / 32

slide-109
SLIDE 109

Results of Points-To Analysis

Tested on 7 benchmarks from SPEC JVM98 and DaCapo 2006 Time to analyze: 1.15 sec (compress) to 697.4 sec (antlr)

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 26 / 32

slide-110
SLIDE 110

Results of Points-To Analysis

Tested on 7 benchmarks from SPEC JVM98 and DaCapo 2006 Time to analyze: 1.15 sec (compress) to 697.4 sec (antlr) Average contexts per method: 4.24 (mpegaudio) to 25.04 (jess)

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 26 / 32

slide-111
SLIDE 111

Results of Points-To Analysis

Tested on 7 benchmarks from SPEC JVM98 and DaCapo 2006 Time to analyze: 1.15 sec (compress) to 697.4 sec (antlr) Average contexts per method: 4.24 (mpegaudio) to 25.04 (jess) Number of interprocedural paths in resulting call graph (for k = 10):

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 26 / 32

slide-112
SLIDE 112

Results of Points-To Analysis

Tested on 7 benchmarks from SPEC JVM98 and DaCapo 2006 Time to analyze: 1.15 sec (compress) to 697.4 sec (antlr) Average contexts per method: 4.24 (mpegaudio) to 25.04 (jess) Number of interprocedural paths in resulting call graph (for k = 10):

Over 96% less paths in FCPA over SPARK for 3 benchmarks

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 26 / 32

slide-113
SLIDE 113

Results of Points-To Analysis

Tested on 7 benchmarks from SPEC JVM98 and DaCapo 2006 Time to analyze: 1.15 sec (compress) to 697.4 sec (antlr) Average contexts per method: 4.24 (mpegaudio) to 25.04 (jess) Number of interprocedural paths in resulting call graph (for k = 10):

Over 96% less paths in FCPA over SPARK for 3 benchmarks 62-92% less paths in FCPA over SPARK for remaining benchmarks

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 26 / 32

slide-114
SLIDE 114

Outline

1

Background and Motivation Heap Reference Analysis Key Issues

2

Heap Alias Analysis Need for Alias Analysis Existing Abstractions Proposed Abstraction: Acccessor Relationship Graph

3

Interprocedural Analysis Existing Frameworks Our Framework: Value Contexts The Role of Call Graphs

4

Access Graphs for Garbage Collection Existing Ideas Novel Technique: Dynamic Heap Pruning

5

Summary & Future Work

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 27 / 32

slide-115
SLIDE 115

Access Graphs for Garbage Collection

How to use access graphs for improving garbage collection?

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 28 / 32

slide-116
SLIDE 116

Access Graphs for Garbage Collection

How to use access graphs for improving garbage collection?

1 Assign null to dead access paths. Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 28 / 32

slide-117
SLIDE 117

Access Graphs for Garbage Collection

How to use access graphs for improving garbage collection?

1 Assign null to dead access paths.

Requires availability and anticipability analysis to prevent exceptions.

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 28 / 32

slide-118
SLIDE 118

Access Graphs for Garbage Collection

How to use access graphs for improving garbage collection?

1 Assign null to dead access paths.

Requires availability and anticipability analysis to prevent exceptions. Cannot nullify access paths that are not provably safe to dereference.

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 28 / 32

slide-119
SLIDE 119

Access Graphs for Garbage Collection

How to use access graphs for improving garbage collection?

1 Assign null to dead access paths.

Requires availability and anticipability analysis to prevent exceptions. Cannot nullify access paths that are not provably safe to dereference. The safety analyses themselves depend on alias information.

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 28 / 32

slide-120
SLIDE 120

Access Graphs for Garbage Collection

How to use access graphs for improving garbage collection?

1 Assign null to dead access paths.

Requires availability and anticipability analysis to prevent exceptions. Cannot nullify access paths that are not provably safe to dereference. The safety analyses themselves depend on alias information. Increase in code size and possible performance penalty.

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 28 / 32

slide-121
SLIDE 121

Access Graphs for Garbage Collection

How to use access graphs for improving garbage collection?

1 Assign null to dead access paths.

Requires availability and anticipability analysis to prevent exceptions. Cannot nullify access paths that are not provably safe to dereference. The safety analyses themselves depend on alias information. Increase in code size and possible performance penalty. Redundant nullification of same reference from aliased access paths.

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 28 / 32

slide-122
SLIDE 122

Access Graphs for Garbage Collection

How to use access graphs for improving garbage collection?

1 Assign null to dead access paths.

Requires availability and anticipability analysis to prevent exceptions. Cannot nullify access paths that are not provably safe to dereference. The safety analyses themselves depend on alias information. Increase in code size and possible performance penalty. Redundant nullification of same reference from aliased access paths.

2 Augment garbage collector to traverse access graphs. Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 28 / 32

slide-123
SLIDE 123

Access Graphs for Garbage Collection

How to use access graphs for improving garbage collection?

1 Assign null to dead access paths.

Requires availability and anticipability analysis to prevent exceptions. Cannot nullify access paths that are not provably safe to dereference. The safety analyses themselves depend on alias information. Increase in code size and possible performance penalty. Redundant nullification of same reference from aliased access paths.

2 Augment garbage collector to traverse access graphs.

No need of safety analysis.

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 28 / 32

slide-124
SLIDE 124

Access Graphs for Garbage Collection

How to use access graphs for improving garbage collection?

1 Assign null to dead access paths.

Requires availability and anticipability analysis to prevent exceptions. Cannot nullify access paths that are not provably safe to dereference. The safety analyses themselves depend on alias information. Increase in code size and possible performance penalty. Redundant nullification of same reference from aliased access paths.

2 Augment garbage collector to traverse access graphs.

No need of safety analysis. Perfect alias information available at run-time.

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 28 / 32

slide-125
SLIDE 125

Access Graphs for Garbage Collection

How to use access graphs for improving garbage collection?

1 Assign null to dead access paths.

Requires availability and anticipability analysis to prevent exceptions. Cannot nullify access paths that are not provably safe to dereference. The safety analyses themselves depend on alias information. Increase in code size and possible performance penalty. Redundant nullification of same reference from aliased access paths.

2 Augment garbage collector to traverse access graphs.

No need of safety analysis. Perfect alias information available at run-time. Difficult to map named variables and fields to run-time offsets.

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 28 / 32

slide-126
SLIDE 126

Access Graphs for Garbage Collection

How to use access graphs for improving garbage collection?

1 Assign null to dead access paths.

Requires availability and anticipability analysis to prevent exceptions. Cannot nullify access paths that are not provably safe to dereference. The safety analyses themselves depend on alias information. Increase in code size and possible performance penalty. Redundant nullification of same reference from aliased access paths.

2 Augment garbage collector to traverse access graphs.

No need of safety analysis. Perfect alias information available at run-time. Difficult to map named variables and fields to run-time offsets. Optimizations after HRA (static or JIT) invalidate access graphs.

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 28 / 32

slide-127
SLIDE 127

Access Graphs for Garbage Collection

How to use access graphs for improving garbage collection?

1 Assign null to dead access paths.

Requires availability and anticipability analysis to prevent exceptions. Cannot nullify access paths that are not provably safe to dereference. The safety analyses themselves depend on alias information. Increase in code size and possible performance penalty. Redundant nullification of same reference from aliased access paths.

2 Augment garbage collector to traverse access graphs.

No need of safety analysis. Perfect alias information available at run-time. Difficult to map named variables and fields to run-time offsets. Optimizations after HRA (static or JIT) invalidate access graphs.

3 Dynamic heap pruning - a hybrid approach. Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 28 / 32

slide-128
SLIDE 128

Dynamic Heap Pruning

Manipulate the heap using a debugger!

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 29 / 32

slide-129
SLIDE 129

Dynamic Heap Pruning

Manipulate the heap using a debugger!

1 Pause a running program when pruning has to be performed. Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 29 / 32

slide-130
SLIDE 130

Dynamic Heap Pruning

Manipulate the heap using a debugger!

1 Pause a running program when pruning has to be performed. 2 For each frame on the call stack do: Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 29 / 32

slide-131
SLIDE 131

Dynamic Heap Pruning

Manipulate the heap using a debugger!

1 Pause a running program when pruning has to be performed. 2 For each frame on the call stack do: 1

Find the paused program point P using return address of next frame (or PC for top-of-stack).

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 29 / 32

slide-132
SLIDE 132

Dynamic Heap Pruning

Manipulate the heap using a debugger!

1 Pause a running program when pruning has to be performed. 2 For each frame on the call stack do: 1

Find the paused program point P using return address of next frame (or PC for top-of-stack).

2

Construct the call string σ using the sequence of return addresses from the bottom-of-stack.

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 29 / 32

slide-133
SLIDE 133

Dynamic Heap Pruning

Manipulate the heap using a debugger!

1 Pause a running program when pruning has to be performed. 2 For each frame on the call stack do: 1

Find the paused program point P using return address of next frame (or PC for top-of-stack).

2

Construct the call string σ using the sequence of return addresses from the bottom-of-stack.

3

Determine the value context X by traversing σ in the context transition graph.

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 29 / 32

slide-134
SLIDE 134

Dynamic Heap Pruning

Manipulate the heap using a debugger!

1 Pause a running program when pruning has to be performed. 2 For each frame on the call stack do: 1

Find the paused program point P using return address of next frame (or PC for top-of-stack).

2

Construct the call string σ using the sequence of return addresses from the bottom-of-stack.

3

Determine the value context X by traversing σ in the context transition graph.

4

Retrieve the access graphs for point P in context X.

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 29 / 32

slide-135
SLIDE 135

Dynamic Heap Pruning

Manipulate the heap using a debugger!

1 Pause a running program when pruning has to be performed. 2 For each frame on the call stack do: 1

Find the paused program point P using return address of next frame (or PC for top-of-stack).

2

Construct the call string σ using the sequence of return addresses from the bottom-of-stack.

3

Determine the value context X by traversing σ in the context transition graph.

4

Retrieve the access graphs for point P in context X.

5

Traverse the access graphs from the root variables (stack locals) and label heap objects with the set of accessor nodes that reach them.

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 29 / 32

slide-136
SLIDE 136

Dynamic Heap Pruning

Manipulate the heap using a debugger!

1 Pause a running program when pruning has to be performed. 2 For each frame on the call stack do: 1

Find the paused program point P using return address of next frame (or PC for top-of-stack).

2

Construct the call string σ using the sequence of return addresses from the bottom-of-stack.

3

Determine the value context X by traversing σ in the context transition graph.

4

Retrieve the access graphs for point P in context X.

5

Traverse the access graphs from the root variables (stack locals) and label heap objects with the set of accessor nodes that reach them.

3 For each labelled object in the heap do: Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 29 / 32

slide-137
SLIDE 137

Dynamic Heap Pruning

Manipulate the heap using a debugger!

1 Pause a running program when pruning has to be performed. 2 For each frame on the call stack do: 1

Find the paused program point P using return address of next frame (or PC for top-of-stack).

2

Construct the call string σ using the sequence of return addresses from the bottom-of-stack.

3

Determine the value context X by traversing σ in the context transition graph.

4

Retrieve the access graphs for point P in context X.

5

Traverse the access graphs from the root variables (stack locals) and label heap objects with the set of accessor nodes that reach them.

3 For each labelled object in the heap do: 1

Find the set of live fields by looking at the edges out of every accessor that reaches it.

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 29 / 32

slide-138
SLIDE 138

Dynamic Heap Pruning

Manipulate the heap using a debugger!

1 Pause a running program when pruning has to be performed. 2 For each frame on the call stack do: 1

Find the paused program point P using return address of next frame (or PC for top-of-stack).

2

Construct the call string σ using the sequence of return addresses from the bottom-of-stack.

3

Determine the value context X by traversing σ in the context transition graph.

4

Retrieve the access graphs for point P in context X.

5

Traverse the access graphs from the root variables (stack locals) and label heap objects with the set of accessor nodes that reach them.

3 For each labelled object in the heap do: 1

Find the set of live fields by looking at the edges out of every accessor that reaches it.

2

Set the value of all other fields (which are dead) to null.

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 29 / 32

slide-139
SLIDE 139

Dynamic Heap Pruning

Manipulate the heap using a debugger!

1 Pause a running program when pruning has to be performed. 2 For each frame on the call stack do: 1

Find the paused program point P using return address of next frame (or PC for top-of-stack).

2

Construct the call string σ using the sequence of return addresses from the bottom-of-stack.

3

Determine the value context X by traversing σ in the context transition graph.

4

Retrieve the access graphs for point P in context X.

5

Traverse the access graphs from the root variables (stack locals) and label heap objects with the set of accessor nodes that reach them.

3 For each labelled object in the heap do: 1

Find the set of live fields by looking at the edges out of every accessor that reaches it.

2

Set the value of all other fields (which are dead) to null.

4 Resume the program. Let garbage collection run as normal. Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 29 / 32

slide-140
SLIDE 140

Outline

1

Background and Motivation Heap Reference Analysis Key Issues

2

Heap Alias Analysis Need for Alias Analysis Existing Abstractions Proposed Abstraction: Acccessor Relationship Graph

3

Interprocedural Analysis Existing Frameworks Our Framework: Value Contexts The Role of Call Graphs

4

Access Graphs for Garbage Collection Existing Ideas Novel Technique: Dynamic Heap Pruning

5

Summary & Future Work

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 30 / 32

slide-141
SLIDE 141

Summary

The following were the main contributions of this project:

1 A liveness-driven heap abstraction for precise alias analysis. 2 A generic access graph library implemented in Java. 3 A generic inter-procedural data flow analysis framework implemented

in Java.

4 A flow- and context-sensitive points-to analysis implemented in Soot

that constructs precise call graphs.

5 A technique for performing dynamic heap pruning implemented using

the Java Debug Interface (JDI).

Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 31 / 32

slide-142
SLIDE 142

Future Work

1 Implementation of an inter-procedural liveness-driven heap points-to

analysis.

2 Performance analysis of dynamic heap pruning on real benchmarks. 3 Shape analysis using accessor relationship graphs. Rohan Padhye (IIT Bombay) Interprocedural Heap Analysis MTP 32 / 32