Mix Your Contexts Well Opportunities Unleashed by Recent Advances in - - PowerPoint PPT Presentation

mix your contexts well
SMART_READER_LITE
LIVE PREVIEW

Mix Your Contexts Well Opportunities Unleashed by Recent Advances in - - PowerPoint PPT Presentation

Mix Your Contexts Well Opportunities Unleashed by Recent Advances in Scaling Context-Sensitivity Manas Thakur 1 and V. Krishna Nandivada 2 CC 2020 1 IIT Mandi, India 2 IIT Madras, India Feb 23, 2020 * V. Krishna Nandivada Mix Your Contexts


slide-1
SLIDE 1

*

Mix Your Contexts Well

Opportunities Unleashed by Recent Advances in Scaling Context-Sensitivity

Manas Thakur1 and V. Krishna Nandivada2 CC 2020

1IIT Mandi, India 2IIT Madras, India

Feb 23, 2020

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 1 / 20

slide-2
SLIDE 2

*

Context sensitivity

Your response should be sensitive to the context – Anonymous

A popular way to improve the precision of program analysis, specially for OO programs. Compared to context-insensitive analyses:

Usually more precise Usually unscalable

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 2 / 20

slide-3
SLIDE 3

*

Context sensitivity

Your response should be sensitive to the context – Anonymous

A popular way to improve the precision of program analysis, specially for OO programs. Compared to context-insensitive analyses:

Usually more precise Usually unscalable

A method may be analyzed multiple times

Once in each unique context from which it may be called.

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 2 / 20

slide-4
SLIDE 4

*

Many context abstractions

”What is right” depends on the context – Upanisheds

Several popular context abstractions in literature:

  • Call-site sensitivity

[Sharir & Pnueli 1978]

  • Object-sensitivity

[Milanova et al. 2005]

  • Value contexts

[Khedker & Karkare 2008]

  • LSRV contexts

[Thakur & Nandivada 2019]

  • All above with heap cloning

[Nystrom et al. 2004]

The choice of context abstraction plays an important role in determining the precision and scalability of the analysis. Relative advantages in terms of precision/scalability not well established.

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 3 / 20

slide-5
SLIDE 5

*

Call-site sensitivity

  • 1. class A {

2. A f1,f2; 3. void foo(){ 4. A a,b,c,d; ... 5. c.bar(a); 6. d.bar(b); 7. } 8. void bar(A p){ 9. A x = new A(); 10. p.f1.f2 = x; 11. p.fb(); 12. p.fb(); 13. } } // Assume fb doesn’t // access caller’s heap

2 contexts for bar

foo 5 foo 6

4 contexts for fb

foo 5+bar 11 foo 5+bar 12 foo 6+bar 11 foo 6+bar 12

In case of recursion?

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 4 / 20

slide-6
SLIDE 6

*

Value contexts [CC’08]

  • 1. class A {

2. A f1,f2; 3. void foo(){ 4. A a,b,c,d; ... 5. c.bar(a); 6. d.bar(b); 7. } 8. void bar(A p){ 9. A x = new A(); 10. p.f1.f2 = x; 11. p.fb(); 12. p.fb(); 13. } } // Assume fb doesn’t // access caller’s heap

Points-to graph

Oa Oi Ok Oj Oc Ol a c

f1 f1 f1 f1

Ob b

f1 d

Om...

f2 f2

(Line 5)

Oa Oi Ok Oj Oc Ol a c

f1 f1 f1 f1

Ob b

f1 d

O8

f2 f2 f2 f2

Om...

(Line 6)

Value-context

Oa Oi Oj Oc Ol p this

f1 f1 f1 f1 Om...

(Line 5)

Ok

f1

Ob p this

f2 f2

Ol

f1

Om...

(Line 6)

bar: analyzed twice, but fb: only once; generally scales better.

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 5 / 20

slide-7
SLIDE 7

*

Recent advance: LSRV contexts [CC’19]

  • 1. class A {

2. A f1,f2; 3. void foo(){ 4. A a,b,c,d; ... 5. c.bar(a); 6. d.bar(b); 7. } 8. void bar(A p){ 9. A x = new A(); 10. p.f1.f2 = x; 11. p.fb(); 12. p.fb(); 13. } } // Assume fb doesn’t // access caller’s heap

(Level Summarized Relevant Value Contexts) Line 5:

Oa Oi Oj p

f1 f1 f1

OD p OD

Relevant value-context LSRV context Line 6:

Ob Ok Ol p

f1 f1 f1

OD p OD

Relevant value-context LSRV context Result: bar and fb both analyzed only once!

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 6 / 20

slide-8
SLIDE 8

*

Another popular choice: Object sensitivity

  • 1. class A {

2. A f1,f2; 3. void foo(){ 4. A a,b,c,d; ... 5. c.bar(a); 6. d.bar(b); 7. } 8. void bar(A p){ 9. A x = new A(); 10. p.f1.f2 = x; 11. p.fb(); 12. p.fb(); 13. } }

Points-to graph

Oa Oi Ok Oj Oc Ol a c

f1 f1 f1 f1

Ob b

f1 d

Om...

f2 f2

(Line 5)

Oa Oi Ok Oj Oc Ol a c

f1 f1 f1 f1

Ob b

f1 d

O8

f2 f2 f2 f2

Om...

(Line 6)

Object-sensitivity: 2 contexts for bar: Line 5: Receiver Oc Line 6: Receiver Ol

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 7 / 20

slide-9
SLIDE 9

*

What we know

What I know is limited, what I don’t is unlimited! – Common folklore.

kobj kobjH kcs = valcs = lsrv kcsH call-string based

  • bject-sensitivity based

k-call-site-sensitive, value contexts and LSRV contexts have the same precision [CC’08, CC’19]. Adding heap cloning improves the precision of call-site- as well as

  • bject-sensitivity.

The relative precisions of object-sensitivity and call-site/value-contextx/LSRV-contexts are incomparable.

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 8 / 20

slide-10
SLIDE 10

*

What we know

What I know is limited, what I don’t is unlimited! – Common folklore.

kobj kobjH kcs = valcs = lsrv kcsH call-string based

  • bject-sensitivity based

k-call-site-sensitive, value contexts and LSRV contexts have the same precision [CC’08, CC’19]. Adding heap cloning improves the precision of call-site- as well as

  • bject-sensitivity.

The relative precisions of object-sensitivity and call-site/value-contextx/LSRV-contexts are incomparable. Our Goal: Get the best of both worlds.

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 8 / 20

slide-11
SLIDE 11

*

Adding heap cloning

Heap cloning: Specializes objects (allocation sites) with the context in which they are created.

Object allocated at line l in context c represented as Ol c.

Improves the partitioning efficacy of context-sensitivity. Usually generates more optimization opportunities, but with an increased analysis cost.

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 9 / 20

slide-12
SLIDE 12

*

Surprise #1 with heap cloning: kcsH vs valcsH

Expectations reduce the joy, surprise enhances joy! - Anonymous

1 class D { 2

void m1() {

3

P p = new P();

4

Q q1 = p.m2();

5

Q q2 = p.m2(); }

6

void m2() {

7

return new Q();

8

} /*m2*/

9 } /*class D*/

Recall: valcs ≡precision kcs

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 10 / 20

slide-13
SLIDE 13

*

Surprise #1 with heap cloning: kcsH vs valcsH

Expectations reduce the joy, surprise enhances joy! - Anonymous

1 class D { 2

void m1() {

3

P p = new P();

4

Q q1 = p.m2();

5

Q q2 = p.m2(); }

6

void m2() {

7

return new Q();

8

} /*m2*/

9 } /*class D*/

Recall: valcs ≡precision kcs kcs: m2 is analyzed twice. valcs: m2 is analyzed once. Both report that q1 and q2 are aliases after line 5.

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 10 / 20

slide-14
SLIDE 14

*

Surprise #1 with heap cloning: kcsH vs valcsH

Expectations reduce the joy, surprise enhances joy! - Anonymous

1 class D { 2

void m1() {

3

P p = new P();

4

Q q1 = p.m2();

5

Q q2 = p.m2(); }

6

void m2() {

7

return new Q();

8

} /*m2*/

9 } /*class D*/

Recall: valcs ≡precision kcs kcs: m2 is analyzed twice. valcs: m2 is analyzed once. Both report that q1 and q2 are aliases after line 5. With heap-cloning:

kcs: q1 and q2 are not aliases. valcs: q1 and q2 are aliases.

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 10 / 20

slide-15
SLIDE 15

*

Surprise #1 with heap cloning: kcsH vs valcsH

Expectations reduce the joy, surprise enhances joy! - Anonymous

1 class D { 2

void m1() {

3

P p = new P();

4

Q q1 = p.m2();

5

Q q2 = p.m2(); }

6

void m2() {

7

return new Q();

8

} /*m2*/

9 } /*class D*/

Recall: valcs ≡precision kcs kcs: m2 is analyzed twice. valcs: m2 is analyzed once. Both report that q1 and q2 are aliases after line 5. With heap-cloning:

kcs: q1 and q2 are not aliases. valcs: q1 and q2 are aliases.

valcsH ≤precision kcsH

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 10 / 20

slide-16
SLIDE 16

*

Surprise #2 with heap cloning: lsrvH vs valcsH

I love surprises as long as I like the outcome! - Anonymous

Recall: lsrv ≡precision valcs lsrvH ≤precision valcsH∗

∗Reasoning in the paper.

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 11 / 20

slide-17
SLIDE 17

*

Surprise #2 with heap cloning: lsrvH vs valcsH

I love surprises as long as I like the outcome! - Anonymous

Recall: lsrv ≡precision valcs lsrvH ≤precision valcsH∗ ≤precision kcsH

∗Reasoning in the paper.

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 11 / 20

slide-18
SLIDE 18

*

Surprise #2 with heap cloning: lsrvH vs valcsH

I love surprises as long as I like the outcome! - Anonymous

Recall: lsrv ≡precision valcs lsrvH ≤precision valcsH∗ ≤precision kcsH Moreover: Recall: lsrv ≡precision kobj lsrvH ≡precision kobjH∗ (incomparable).

∗Reasoning in the paper.

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 11 / 20

slide-19
SLIDE 19

*

Our idea: Mix the contexts

An insight has little value till it leads to a workable idea – Anonymous

Insight: Heap cloning alters the precision relations quite a bit. Existing context abstractions miss cases covered by each other Some approaches (e.g., LSRV variants) scale very well. Q: Why not use the abstractions together? Idea: Merge abstractions c1 and c2 to get c1•2 such that c1•2 covers the

  • ptimization opportunities covered by both c1 and c2.

In the resultant version, a method is analyzed if any of c1 or c2 is different from the previous contexts.

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 12 / 20

slide-20
SLIDE 20

*

Choosing the right mix

You can make a great fashion statement by doing the right mix and match – Anonymous

More different the abstractions are, better may be the precision of the mix. = ⇒ Choose one approach each from call-site- and object-sensitive approaches. The combined approach needs to be scalable. = ⇒ Choose lsrvH from the call-site- group and kobjH from the

  • bject-sensitive group.

Obtained mix: lsrvkobjH

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 13 / 20

slide-21
SLIDE 21

*

Choosing the right mix

You can make a great fashion statement by doing the right mix and match – Anonymous

More different the abstractions are, better may be the precision of the mix. = ⇒ Choose one approach each from call-site- and object-sensitive approaches. The combined approach needs to be scalable. = ⇒ Choose lsrvH from the call-site- group and kobjH from the

  • bject-sensitive group.

Obtained mix: lsrvkobjH; Implemented in the Soot framework.

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 13 / 20

slide-22
SLIDE 22

*

Evaluation results (Devirtualization)

I evaluate, therefore I am. – System designer’s mantra #polyCalls

2 4 6 8 a v r

  • r

a b a t i k e c l i p s e l u i n d e x l u s e a r c h m

  • l

d y n m

  • n

t e c a r l

  • p

m d r a y t r a c e r s u n fl

  • w

G e

  • M

e a n

lsrv lsrvH 1objH lsrv1objH

lsrvkobjH resolves the least number of calls as polymorphic.

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 14 / 20

slide-23
SLIDE 23

*

Evaluation results (Devirtualization)

I evaluate, therefore I am. – System designer’s mantra #polyCalls

2 4 6 8 a v r

  • r

a b a t i k e c l i p s e l u i n d e x l u s e a r c h m

  • l

d y n m

  • n

t e c a r l

  • p

m d r a y t r a c e r s u n fl

  • w

G e

  • M

e a n

lsrv lsrvH 1objH lsrv1objH

lsrvkobjH resolves the least number of calls as polymorphic. lsrvkobjH leads to the least number of call-graph edges.

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 14 / 20

slide-24
SLIDE 24

*

Evaluation results (Time taken)

I evaluate, therefore I am. – System designer’s mantra

Benchmark time % increase lsrv (s) lsrvh avrora 55 24.5 batik 946 167.3 eclipse 988 224.0 luindex 46 38.5 lusearch 57 44.6 moldyn 53 85.3 montecarlo 53 58.3 pmd 108 44.8 raytracer 53 62.1 sunflow 684 40.8 GeoMean 130 62.3 lsrvkobjH scales well for all the benchmarks (and improves precision as shown in the previous slides).

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 15 / 20

slide-25
SLIDE 25

*

Evaluation results (Time taken)

I evaluate, therefore I am. – System designer’s mantra

Benchmark time % increase lsrv (s) lsrvh 1objh lsrv1objh avrora 55 24.5 646.2 26.5 batik 946 167.3 709.8 129.2 eclipse 988 224.0

  • 225.9

luindex 46 38.5 653.9 23.3 lusearch 57 44.6 672.1 61.4 moldyn 53 85.3 448.5 83.6 montecarlo 53 58.3 474.3 67.2 pmd 108 44.8 587.3 2263.2 raytracer 53 62.1 452.6 68.7 sunflow 684 40.8 1097.1 53.2 GeoMean 130 62.3

  • 93.6

lsrvkobjH scales well for all the benchmarks (and improves precision as shown in the previous slides).

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 15 / 20

slide-26
SLIDE 26

*

Updated world view

By the time you update your working space, it becomes outdated – Anonymous

kobj kobjH kcs = valcs = lsrv kcsH call-string based

  • bject-sensitivity based

valcsH lsrvkobjH lsrvH

Newer variants find proper placement. Effects of heap cloning incorporated. lsrvkobjH connects the previously unconnected approaches!

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 16 / 20

slide-27
SLIDE 27

*

In the paper

World is unlimited: talk → paper → matrix! – Anonymous

Insights on reducing the overheads of object-sensitivity. 3-stage efficient computation of lsrvkobjH contexts. Theoretical and practical precisions of existing and recent approaches. Correctness and termination discussions. Study of the memory consumption of the various approaches.

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 17 / 20

slide-28
SLIDE 28

*

Representative related work

Learn from those who have trodden the path before. – Explorer Anonymous

Explaining abstractions: Kanvar and Khedker (CS’16) survey heap abstractions and assert their importance towards precision and scalability. Smaragdakis et al. (POPL’11) clarify the definition of

  • bject-sensitivity and propose type-sensitivity as a close sibling.

Combining analyses/abstractions: Codish et al. (TOPLAS’95) perform multiple program analyses together over a combined domain. Kastrinis et al. (PLDI’13) propose hybrid context-sensitivity, but conclude that combining call-site- and object-sensitivity is impractical.

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 18 / 20

slide-29
SLIDE 29

*

Conclusion and Future Work

Conclusion = What we could do. Future work = What we could not. –Anonymous

Clarified: relative precision of existing and recent context abstractions. Demonstrated: heap cloning leads to surprising precision relations. Introduced: novel idea of mixing abstractions to improve precision. Showed: mixing offers the best precision-scalability trade-off

gives benefits of both call-site- and object-sensitive approaches.

Future Work: Generalize mixing to multiple context abstractions and use it for different analyses.

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 19 / 20

slide-30
SLIDE 30

*

Questions?

Expected answers are not guaranteed. Clarified: relative precision of existing and recent context abstractions. Demonstrated: heap cloning leads to surprising precision relations. Introduced: novel idea of mixing abstractions to improve precision. Showed: mixing offers the best precision-scalability trade-off gives benefits over both call-site- and object-sensitive approaches.

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 20 / 20

slide-31
SLIDE 31

Backup

slide-32
SLIDE 32

*

Incomparability of the two broad variants

1 class D { 2

...

3

void foo() {

4

B x = new B();

5

Y y = new Y();

6

Z z = new Z();

7

x.m3(y);

8

x.m3(z);

9

}

10

B m3(B p) {

11

p.f = p;

12

}

13 }

O5 y O6 z f f f f O5 y O6 z f f

kobj kcs/valcs/lsrv y.f and z.f are aliases in kobj (imprecise), but not in kcs/valcs/lsrv (precise).

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 1 / 4

slide-33
SLIDE 33

*

Incomparability of the two broad variants (Cont.)

1 class D { 2

...

3

void bar() {

4

B r = new B();

5

B s = new B();

6

B t = * ? r : s;

7

t.m4();

8

}

9

B m4() {

10

this.f = this;

11

}

12 }

O4 r O5 s f f O4 r O5 s f f f f

kobj kcs/valcs/lsrv r.f and s.f are aliases in kcs/valcs/lsrv (imprecise) but not in kobj (precise).

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 2 / 4

slide-34
SLIDE 34

*

Surprise #2 with heap cloning: lsrvH vs valcsH

1 class W { 2

X f;

3

W() { f = new X(); }

4

void setG(Y y) {

5

f.g = y; }

6

Y getG() {

7

return f.g; } }

8 class X { Y g; } 9 class Y { 10

void m() {...} }

11 class Z extends Y { 12

void m() {...} }

13

class D {

14

void bar() {

15

W w1 = new W();

16

Y y1 = new Y();

17

w1.setG(y1);

18

W w2 = new W();

19

Z z1 = new Z();

20

w2.setG(z1);

21

Y p = w1.getG();

22

p.m();

23

Y q = w2.getG();

24

q.m(); } }

valcsH re-analyzes W’s constructor and resolves the calls to m as monomorphic (unlike lsrvH).

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 3 / 4

slide-35
SLIDE 35

*

Surprise #3 with heap cloning: lsrvH vs kobjH

1 class W { 2

X f;

3

W() { f = new X(); }

4

void setG(Y y) {

5

f.g = y; }

6

Y getG() {

7

return f.g; } }

8 class X { Y g; } 9 class Y { 10

void m() {...} }

11 class Z extends Y { 12

void m() {...} }

13

class D {

14

void bar() {

15

W w1 = new W();

16

Y y1 = new Y();

17

w1.setG(y1);

18

W w2 = new W();

19

Z z1 = new Z();

20

w2.setG(z1);

21

Y p = w1.getG();

22

p.m();

23

Y q = w2.getG();

24

q.m(); } }

In lsrvH, W’s constructor is not re-analyzed at line 18, w1.f and w2.f point to O3, w1.f.g and w2.f.g both point to {O16, O19}, and both the calls to m are polymorphic. Not so in kobjH.

  • V. Krishna Nandivada

Mix Your Contexts Well Feb 23 2020 4 / 4