Effective Soundness-Guided Reflection Analysis Yue Li , Tian Tan and - - PowerPoint PPT Presentation

effective soundness guided reflection analysis
SMART_READER_LITE
LIVE PREVIEW

Effective Soundness-Guided Reflection Analysis Yue Li , Tian Tan and - - PowerPoint PPT Presentation

Effective Soundness-Guided Reflection Analysis Yue Li , Tian Tan and Jingling Xue Complier Research Group @ UNSW, Australia September 10, 2015 SAS 2015 Saint-Malo Static analysis for OO in practice ? Static analysis for OO in practice ? re re


slide-1
SLIDE 1

Effective Soundness-Guided Reflection Analysis

Yue Li, Tian Tan and Jingling Xue

Complier Research Group @ UNSW, Australia September 10, 2015

SAS 2015 Saint-Malo

slide-2
SLIDE 2

Static analysis for OO in practice ?

slide-3
SLIDE 3

Static analysis for OO in practice ?

re re re … reflection !

slide-4
SLIDE 4

Class Person { void setName(String nm) {…}; } Person p = new Person(); p.setName(“John”); … …

slide-5
SLIDE 5

Class Person { void setName(String nm) {…}; } Person p = new Person(); p.setName(“John”); … …

slide-6
SLIDE 6

Class Person { void setName(String nm) {…}; } Person p = new Person(); p.setName(“John”); … …

slide-7
SLIDE 7

Class Person { void setName(String nm) {…}; } Person p = new Person(); p.setName(“John”); … … class method field

slide-8
SLIDE 8

Class Person { void setName(String nm) {…}; } Person p = new Person(); p.setName(“John”); … … class method field

slide-9
SLIDE 9

Class Person { void setName(String nm) {…}; } Person p = new Person(); p.setName(“John”); … … Class c = Class.forName(“Person”); Method m = c.getMethod(“setName”, …); Object p = c.newInstance(); m.invoke(p, “John”); class method field

slide-10
SLIDE 10

Class Person { void setName(String nm) {…}; } Person p = new Person(); p.setName(“John”); … … Class c = Class.forName(“Person”); Method m = c.getMethod(“setName”, …); Object p = c.newInstance(); m.invoke(p, “John”); class method

Compile Time

field

slide-11
SLIDE 11

Class Person { void setName(String nm) {…}; } Person p = new Person(); p.setName(“John”); … … Class c = Class.forName(“Person”); Method m = c.getMethod(“setName”, …); Object p = c.newInstance(); m.invoke(p, “John”); class method

Compile Time

field

slide-12
SLIDE 12

Class Person { void setName(String nm) {…}; } Person p = new Person(); p.setName(“John”); … … Class c = Class.forName(“Person”); Method m = c.getMethod(“setName”, …); Object p = c.newInstance(); m.invoke(p, “John”); class method

Compile Time Runtime

field

slide-13
SLIDE 13

Class c = Class.forName(cName); Method m = c.getMethod(mName, …); A a = new A(); m.invoke(a, …);

B u g D e t e c t i

  • n
slide-14
SLIDE 14

Class c = Class.forName(cName); Method m = c.getMethod(mName, …); A a = new A(); m.invoke(a, …); Method 1 Method 2

B u g D e t e c t i

  • n

Method 3 Bug

slide-15
SLIDE 15

Class c = Class.forName(cName); Method m = c.getMethod(mName, …); A a = new A(); m.invoke(a, …); Method 1 Method 2

B u g D e t e c t i

  • n

Method 3 Bug

Soundness

slide-16
SLIDE 16

Soundness

slide-17
SLIDE 17

ICSE’11 OOPSLA’09 APLAS’05 ECOOP’14

Soundness

slide-18
SLIDE 18

ICSE’11 OOPSLA’09 APLAS’05 ECOOP’14

Soundness Best-Effort

slide-19
SLIDE 19

ICSE’11 OOPSLA’09 APLAS’05 ECOOP’14

Soundness

SAS’15

Best-Effort

slide-20
SLIDE 20

ICSE’11 OOPSLA’09 APLAS’05 ECOOP’14

Soundness

SAS’15

Best-Effort More sound

1

slide-21
SLIDE 21

ICSE’11 OOPSLA’09 APLAS’05 ECOOP’14

Soundness

SAS’15

Best-Effort More sound

1

Unsoundness

slide-22
SLIDE 22

ICSE’11 OOPSLA’09 APLAS’05 ECOOP’14

Soundness

SAS’15

Best-Effort More sound

1

Unsoundness Controllable

2

slide-23
SLIDE 23

ICSE’11 OOPSLA’09 APLAS’05 ECOOP’14

Soundness

SAS’15

Best-Effort More sound

1

Unsoundness Controllable

2

Soundness-Guided

slide-24
SLIDE 24

More sound

1

Controllable

2

slide-25
SLIDE 25

More sound

1

slide-26
SLIDE 26

The Challenging Problem

Class c = Class.forName(cName)

Object v = c1.newInstance( )

i:

unknown

slide-27
SLIDE 27

Class c = Class.forName(cName)

Object v = c1.newInstance( )

i:

unknown

A a = (A) v2

Intra-procedural post-dominant cast operations

Existing Approach

slide-28
SLIDE 28

Class c = Class.forName(cName)

Object v = c1.newInstance( )

i:

unknown

A a = (A) v2

Intra-procedural post-dominant cast operations

cA

Existing Approach

slide-29
SLIDE 29

Class c = Class.forName(cName)

Object v = c1.newInstance( )

i:

unknown

A a = (A) v2

Intra-procedural post-dominant cast operations

  • nly works for this intra-post-dominance pattern

cA

Existing Approach

slide-30
SLIDE 30

Class c = Class.forName(cName)

Object v = c1.newInstance( )

i:

unknown

A a = (A) v2

Intra-procedural post-dominant cast operations

  • nly works for this intra-post-dominance pattern

I g I g n n

  • r

r e e d d

cA

Existing Approach

slide-31
SLIDE 31

Lazy Heap Modeling (LHM)

slide-32
SLIDE 32

A reflectively created object (returned by newInstance()) is usually used in two cases in practice

Lazy Heap Modeling (LHM)

Observation

slide-33
SLIDE 33

Lazy Heap Modeling (LHM)

Observation Intuition The side effect of a newInstance() call can be modeled lazily at these usage points

A reflectively created object (returned by newInstance()) is usually used in two cases in practice

slide-34
SLIDE 34

Lazy Heap Modeling (LHM)

Class c = Class.forName(cName)

Object v = c1.newInstance( )

i:

unknown

slide-35
SLIDE 35

Lazy Heap Modeling (LHM)

Class c = Class.forName(cName)

Object v = c1.newInstance( )

i:

unknown

cu

slide-36
SLIDE 36

Lazy Heap Modeling (LHM)

Class c = Class.forName(cName)

Object v = c1.newInstance( )

i:

unknown

cu

i

  • u
slide-37
SLIDE 37

Lazy Heap Modeling (LHM)

Class c = Class.forName(cName)

Object v = c1.newInstance( )

i:

unknown

cu

i

  • u

Abstract Heap Objects

  • f newInstance()

are created lazily ( at LHM points )

slide-38
SLIDE 38

Lazy Heap Modeling (LHM)

Class c = Class.forName(cName)

Object v = c1.newInstance( )

i:

Case (I)

unknown

cu

i

  • u

Abstract Heap Objects

  • f newInstance()

are created lazily ( at LHM points )

B b = (B) v2 A a = (A) v1

slide-39
SLIDE 39

i

  • B

| B | i | b, v4

i

  • B

| B | i | b

Lazy Heap Modeling (LHM)

Class c = Class.forName(cName)

Object v = c1.newInstance( )

i:

Case (I)

unknown

cu

i

  • u

Abstract Heap Objects

  • f newInstance()

are created lazily ( at LHM points )

i

  • A

A | i | | a |

Type Object Location

|

Pointed by

|

B b = (B) v2 A a = (A) v1

slide-40
SLIDE 40

i

  • B

| B | i | b, v4

i

  • B

| B | i | b

Lazy Heap Modeling (LHM)

Class c = Class.forName(cName)

Object v = c1.newInstance( )

i:

Case (I) Case (II)

unknown

cu

i

  • u

Abstract Heap Objects

  • f newInstance()

are created lazily ( at LHM points )

i

  • A

A | i | | a |

Type Object Location

|

Pointed by

|

B b = (B) v2 A a = (A) v1 m1.invoke(v3, args)

slide-41
SLIDE 41

i

  • B

| B | i | b, v4

i

  • B

| B | i | b

Lazy Heap Modeling (LHM)

Class c = Class.forName(cName)

Object v = c1.newInstance( )

i:

Case (I) Case (II)

unknown

cu

i

  • u

Abstract Heap Objects

  • f newInstance()

are created lazily ( at LHM points )

i

  • A

A | i | | a |

Type Object Location

|

Pointed by

|

Method m = c2.getDeclaredMethod(mName, ...)

B b = (B) v2 A a = (A) v1 m1.invoke(v3, args)

slide-42
SLIDE 42

i

  • B

| B | i | b, v4

i

  • B

| B | i | b

Lazy Heap Modeling (LHM)

Class c = Class.forName(cName)

Object v = c1.newInstance( )

i:

Case (I) Case (II)

unknown

cu

i

  • u

Abstract Heap Objects

  • f newInstance()

are created lazily ( at LHM points )

i

  • A

A | i | | a |

Type Object Location

|

Pointed by

|

Method m = c2.getDeclaredMethod(mName, ...)

cD

B b = (B) v2 A a = (A) v1 m1.invoke(v3, args)

slide-43
SLIDE 43

i

  • B

| B | i | b, v4

i

  • B

| B | i | b

Lazy Heap Modeling (LHM)

Class c = Class.forName(cName)

Object v = c1.newInstance( )

i:

Case (I) Case (II)

unknown

cu

i

  • u

Abstract Heap Objects

  • f newInstance()

are created lazily ( at LHM points )

i

  • A

A | i | | a |

Type Object Location

|

Pointed by

|

Method m = c2.getDeclaredMethod(mName, ...)

cD

B b = (B) v2 A a = (A) v1 m1.invoke(v3, args) v3.mName(args)

slide-44
SLIDE 44

i

  • B

| B | i | b, v4

i

  • B

| B | i | b

Lazy Heap Modeling (LHM)

Class c = Class.forName(cName)

Object v = c1.newInstance( )

i:

Case (I) Case (II)

unknown

cu

i

  • u

Abstract Heap Objects

  • f newInstance()

are created lazily ( at LHM points )

i

  • A

A | i | | a |

Type Object Location

|

Pointed by

|

Method m = c2.getDeclaredMethod(mName, ...)

cD

i

  • D

D | | i | v3 B b = (B) v2 A a = (A) v1 m1.invoke(v3, args) v3.mName(args)

slide-45
SLIDE 45

i

  • B

B | | i | v3

i

  • B

| B | i | b, v4

i

  • B

| B | i | b

Lazy Heap Modeling (LHM)

Class c = Class.forName(cName)

Object v = c1.newInstance( )

i:

Case (I) Case (II)

unknown

cu

i

  • u

Abstract Heap Objects

  • f newInstance()

are created lazily ( at LHM points )

i

  • A

A | i | | a |

Type Object Location

|

Pointed by

|

Method m = c2.getDeclaredMethod(mName, ...)

cD

?

i

  • D

D | | i | v3 B b = (B) v2 A a = (A) v1 m1.invoke(v3, args) v3.mName(args)

slide-46
SLIDE 46

i

  • B

B | | i | v3

i

  • B

| B | i | b, v4

i

  • B

| B | i | b

Lazy Heap Modeling (LHM)

Class c = Class.forName(cName)

Object v = c1.newInstance( )

i:

Case (I) Case (II)

unknown

cu

i

  • u

Abstract Heap Objects

  • f newInstance()

are created lazily ( at LHM points )

i

  • A

A | i | | a |

Type Object Location

|

Pointed by

|

Method m = c2.getDeclaredMethod(mName, ...)

cD

? X

i

  • D

D | | i | v3 B b = (B) v2 A a = (A) v1 m1.invoke(v3, args) v3.mName(args)

slide-47
SLIDE 47

i

  • B

B | | i | v3

i

  • B

| B | i | b, v4

i

  • B

| B | i | b

Lazy Heap Modeling (LHM)

Class c = Class.forName(cName)

Object v = c1.newInstance( )

i:

Case (I) Case (II)

unknown

cu

i

  • u

Abstract Heap Objects

  • f newInstance()

are created lazily ( at LHM points )

i

  • A

A | i | | a |

Type Object Location

|

Pointed by

|

Method m = c2.getDeclaredMethod(mName, ...)

cD

? X

i

  • B

| B | i | b, v3

i

  • D

D | | i | v3 B b = (B) v2 A a = (A) v1 m1.invoke(v3, args) v3.mName(args)

slide-48
SLIDE 48

i

  • B

B | | i | v3

i

  • B

| B | i | b, v4

i

  • B

| B | i | b

Lazy Heap Modeling (LHM)

Class c = Class.forName(cName)

Object v = c1.newInstance( )

i:

Case (I) Case (II)

unknown

cu

i

  • u

Abstract Heap Objects

  • f newInstance()

are created lazily ( at LHM points )

i

  • A

A | i | | a |

Type Object Location

|

Pointed by

|

Method m = c2.getDeclaredMethod(mName, ...)

cD

? X

i

  • B

| B | i | b, v3

i

  • D

D | | i | v3 B b = (B) v2 A a = (A) v1 m1.invoke(v3, args) v3.mName(args)

I g I g n n

  • r

r e e d d I g I g n n

  • r

r e e d d I g I g n n

  • r

r e e d d

slide-49
SLIDE 49

Inference System of Solar

  • = newInstance() çè m.invoke(o,…), f.get(o), f.set(o, …)

Collective Inference

slide-50
SLIDE 50

More sound

1

slide-51
SLIDE 51

Controllable

2

slide-52
SLIDE 52

Controllable

2 If the information in a program is not enough to help infer the reflective targets, the soundness criteria is not satisfied

slide-53
SLIDE 53

Lazy Heap Modeling (LHM)

Class c = Class.forName(cName)

Object v = c1.newInstance( )

i:

Case (I) Case (II)

unknown

cu

i

  • u

Abstract Heap Objects

  • f newInstance()

are created lazily ( at LHM points )

i

  • A

A | i | | a |

Type Object Location

|

Pointed by

|

Method m = c2.getDeclaredMethod(mName, ...)

cD

i

  • D

D | | i | v3 B b = (B) v2 A a = (A) v1 m1.invoke(v3, args) v3.mName(args)

i

  • B

| B | i | b, v3

slide-54
SLIDE 54

Lazy Heap Modeling (LHM)

Class c = Class.forName(cName)

Object v = c1.newInstance( )

i:

Case (I) Case (II)

unknown

cu

i

  • u

Abstract Heap Objects

  • f newInstance()

are created lazily ( at LHM points )

i

  • A

A | i | | a |

Type Object Location

|

Pointed by

|

Method m = c2.getDeclaredMethod(mName, ...)

cD

i

  • D

D | | i | v3 B b = (B) v2 A a = (A) v1 m1.invoke(v3, args) v3.mName(args)

i

  • B

| B | i | b, v3

?

slide-55
SLIDE 55

Lazy Heap Modeling (LHM)

Class c = Class.forName(cName)

Object v = c1.newInstance( )

i:

Case (I) Case (II)

unknown

cu

i

  • u

Abstract Heap Objects

  • f newInstance()

are created lazily ( at LHM points )

i

  • A

A | i | | a |

Type Object Location

|

Pointed by

|

Method m = c2.getDeclaredMethod(mName, ...)

cD

i

  • D

D | | i | v3 B b = (B) v2 A a = (A) v1 m1.invoke(v3, args) v3.mName(args)

i

  • B

| B | i | b, v3

?

X

slide-56
SLIDE 56

Lazy Heap Modeling (LHM)

Class c = Class.forName(cName)

Object v = c1.newInstance( )

i:

Case (I) Case (II)

unknown

cu

i

  • u

Abstract Heap Objects

  • f newInstance()

are created lazily ( at LHM points )

i

  • A

A | i | | a |

Type Object Location

|

Pointed by

|

Method m = c2.getDeclaredMethod(mName, ...)

cD

i

  • D

D | | i | v3 B b = (B) v2 A a = (A) v1 m1.invoke(v3, args) v3.mName(args)

i

  • B

| B | i | b, v3

?

X

U U n n s

  • s
  • u

u n n d d

slide-57
SLIDE 57

Lazy Heap Modeling (LHM)

Class c = Class.forName(cName)

Object v = c1.newInstance( )

i:

Case (I) Case (II)

unknown

cu

i

  • u

Abstract Heap Objects

  • f newInstance()

are created lazily ( at LHM points )

i

  • A

A | i | | a |

Type Object Location

|

Pointed by

|

Method m = c2.getDeclaredMethod(mName, ...)

cD

i

  • D

D | | i | v3 B b = (B) v2 A a = (A) v1 m1.invoke(v3, args) v3.mName(args)

i

  • B

| B | i | b, v3

?

X

U U n n s

  • s
  • u

u n n d d To To be annotated

slide-58
SLIDE 58

Controllable

2 If the information in a program is not enough to help infer the reflective targets, the soundness criteria is not satisfied The number of the reflective targets resolved or inferred

slide-59
SLIDE 59

More sound

1

Controllable

2

slide-60
SLIDE 60
slide-61
SLIDE 61

Evaluation

VS

slide-62
SLIDE 62

Evaluation

VS Large real-world Java benchmarks and applications Large and reflection-rich Java library: JDK 1.6

slide-63
SLIDE 63

Recall

More sound

1 Recall: measured by the number of true reflective targets discovered at reflective call sites that are dynamically executed under certain inputs

slide-64
SLIDE 64

Recall

More sound

1 Only Solar achieves total recall : all the true reflective targets found in recall are resolved by Solar. Recall: measured by the number of true reflective targets discovered at reflective call sites that are dynamically executed under certain inputs

slide-65
SLIDE 65

The benefit of achieving higher recall: more true call graph edges discovered

slide-66
SLIDE 66

The benefit of achieving higher recall: more true call graph edges discovered The figure shows the more true call graph edges found in recall by Solar than Elf (Solar - Elf) and by Elf than Doop (Elf - Doop) The true call graph edges are computed by instrumentation at runtime

slide-67
SLIDE 67

Precision

More sound

1 Insight: Soundness ßà precision. Solar achieves higher recall (more sound), indicates worse precision ?

slide-68
SLIDE 68

Precision

More sound

1 Insight: Soundness ßà precision. Solar achieves higher recall (more sound), indicates worse precision ? No! Solar maintains nearly the same precision as Doop and Elf (2 popular clients).

slide-69
SLIDE 69

Precision

Devir Call: the percentage of the virtual calls whose targets can be disambiguated Safe Case: the percentage of the casts that can be statically shown to be safe

slide-70
SLIDE 70

Controllable

2

slide-71
SLIDE 71

In 10 evaluated programs, 7 can be analyzed scalably and soundly by Solar with full automation.

Controllable

2

slide-72
SLIDE 72

In 10 evaluated programs, 7 can be analyzed scalably and soundly by Solar with full automation. For the remaining 3 programs, Probe is scalable and reports 13 unsound calls and 1 imprecise call.

Controllable

2

slide-73
SLIDE 73

In 10 evaluated programs, 7 can be analyzed scalably and soundly by Solar with full automation.

Controllable

2 After manual check, all the identified 14 unsound/imprecise calls are the true ones. For the remaining 3 programs, Probe is scalable and reports 13 unsound calls and 1 imprecise call.

slide-74
SLIDE 74

In 10 evaluated programs, 7 can be analyzed scalably and soundly by Solar with full automation.

Controllable

2 After manual check, all the identified 14 unsound/imprecise calls are the true ones. Probe also reports 7 corresponding annotation points for these 14 unsound/imprecise calls For the remaining 3 programs, Probe is scalable and reports 13 unsound calls and 1 imprecise call.

slide-75
SLIDE 75

In 10 evaluated programs, 7 can be analyzed scalably and soundly by Solar with full automation.

Controllable

2 After manual check, all the identified 14 unsound/imprecise calls are the true ones. Probe also reports 7 corresponding annotation points for these 14 unsound/imprecise calls After the 7 light-weight annotations, Solar can analyze these 3 programs scalably and soundly For the remaining 3 programs, Probe is scalable and reports 13 unsound calls and 1 imprecise call.

slide-76
SLIDE 76

Performance More sound

1

Controllable

2

slide-77
SLIDE 77

Potential Impact

More sound

1

Reflection Analysis

Hundreds of Papers & Tools ¡

slide-78
SLIDE 78

Potential Impact

More sound

1

Reflection Analysis

Hundreds of Papers & Tools ¡

slide-79
SLIDE 79

Potential Impact

More sound

1

Reflection Analysis

Hundreds of Papers & Tools ¡

Nothing needs to change

slide-80
SLIDE 80

Potential Impact

More sound

1

Reflection Analysis

Hundreds of Papers & Tools ¡

Nothing needs to change More bugs, etc.

slide-81
SLIDE 81

Ø A static bug verification tool reports no bugs.

4 reflective calls are identified unsoundly analyzed by Solar

Potential Impact

More sound

1 Hundreds of Papers & Tools ¡

Reflection Analysis

Nothing needs to change More bugs, etc.

Controllable

2

slide-82
SLIDE 82

Ø A static bug detection tool reports 10 bugs. Ø A static bug verification tool reports no bugs.

All reflective calls are reported soundly analyzed by Solar 4 reflective calls are identified unsoundly analyzed by Solar

Potential Impact

More sound

1 Hundreds of Papers & Tools ¡

Reflection Analysis

Nothing needs to change More bugs, etc.

Controllable

2

slide-83
SLIDE 83

h#p://www.cse.unsw.edu.au/~corg/solar ¡

slide-84
SLIDE 84

Static analysis for OO in practice ?

slide-85
SLIDE 85

Static analysis for OO in practice ?

Reflection

slide-86
SLIDE 86

Thank You

September 10, 2015

Yue Li

CORG @ UNSW, Australia

slide-87
SLIDE 87

Controllable

2

Light-weight Annotations More sound

1 The number of annotations required for improving the soundness of unsoundly resolved reflective calls. Others: 338 vs Solar: 7