dynamic object flow analysis (phd defense)

102
Dynamic Object Flow Analysis PhD defense Adrian Lienhard Advisor: Oscar Nierstrasz

Upload: lienhard

Post on 25-May-2015

855 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Dynamic Object Flow Analysis (PhD Defense)

DynamicObject Flow Analysis

PhD defense

Adrian Lienhard

Advisor: Oscar Nierstrasz

Page 2: Dynamic Object Flow Analysis (PhD Defense)

2

Page 3: Dynamic Object Flow Analysis (PhD Defense)

3

Page 4: Dynamic Object Flow Analysis (PhD Defense)

4

Page 5: Dynamic Object Flow Analysis (PhD Defense)

5

Page 6: Dynamic Object Flow Analysis (PhD Defense)

6

Page 7: Dynamic Object Flow Analysis (PhD Defense)

a2a1

image:Image copy:Image

:File

image := Image newFor: file. // creates a1copy := image duplicate. // creates a2

name = 'cat.jpg'

7

Page 8: Dynamic Object Flow Analysis (PhD Defense)

a2a1

image:Image copy:Image

:File

image := Image newFor: file. // creates a1copy := image duplicate. // creates a2

copy delete // file.name := nil

name = nil

8

Page 9: Dynamic Object Flow Analysis (PhD Defense)

a2a1

image:Image copy:Image

:File

image := Image newFor: file. // creates a1copy := image duplicate. // creates a2

copy delete // file.name := nil

image display// file.name asUrl NullPointerException

name = nil

9

Page 10: Dynamic Object Flow Analysis (PhD Defense)

a2a1

image:Image copy:Image

:File

image := Image newFor: file. // creates a1copy := image duplicate. // creates a2

copy delete // file.name := nil

image display// file.name asUrl NullPointerException

name = nil

10

Object aliasing is a problem because it introduces hidden dependencies.

Page 11: Dynamic Object Flow Analysis (PhD Defense)

11

Dynamic Control Flow Analysis

Page 12: Dynamic Object Flow Analysis (PhD Defense)

upload

delete

12

Dynamic Control Flow Analysis

Page 13: Dynamic Object Flow Analysis (PhD Defense)

Feature "Upload" Feature "Duplicate" Feature "Delete"

upload

delete

13[Salah and Mancoridis ICSM'04]

Dynamic Control Flow Analysis

Page 14: Dynamic Object Flow Analysis (PhD Defense)

Feature "Upload" Feature "Duplicate" Feature "Delete"

upload

delete?

14

Dynamic Control Flow Analysis

Page 15: Dynamic Object Flow Analysis (PhD Defense)

a2a1

image:Image copy:Image

:File

name = 'cat.jpg'

15

Dynamic Data Analysis

Page 16: Dynamic Object Flow Analysis (PhD Defense)

16

[De Pauw, Sevitsky ECOOP’99]

Reference Patterns

Dynamic Data Analysis

[Hill, Noble, Potter JVLC’02]

Ownership Trees

Page 17: Dynamic Object Flow Analysis (PhD Defense)

a2

a1

image:Image copy:Image

:File

name = 'cat.jpg'

17

Dynamic Data Analysis

Page 18: Dynamic Object Flow Analysis (PhD Defense)

a2

a1

image:Image copy:Image

:File

name = 'cat.jpg'

?

18

Dynamic Data Analysis

Page 19: Dynamic Object Flow Analysis (PhD Defense)

Dynamic Analysis

control flow data data flow

!! ?

method

execution

reference

structure

reference

transfer

19

Page 20: Dynamic Object Flow Analysis (PhD Defense)

Dynamic Analysis

control flow data data flow

!! ?

method

execution

reference

structure

reference

transfer

20

Page 21: Dynamic Object Flow Analysis (PhD Defense)

Thesis

Object references must be captured and modeled explicitly.

21

Page 22: Dynamic Object Flow Analysis (PhD Defense)

a2a1

image:Image copy:Image

:File

Runtime

Object Flow

Metamodel

22

Page 23: Dynamic Object Flow Analysis (PhD Defense)

a2a1

image:Image copy:Image

:File

Object

Runtime

Object Flow

Metamodel

23

Page 24: Dynamic Object Flow Analysis (PhD Defense)

1

a2a1

image:Image copy:Image

:File

Alias Objectvalue

*

Runtime

Object Flow

Metamodel

24

Page 25: Dynamic Object Flow Analysis (PhD Defense)

1

a2a1

image:Image copy:Image

:File

Alias Objectvalue

*

origin

*0..1

Runtime

Object Flow

Metamodel

25

Page 26: Dynamic Object Flow Analysis (PhD Defense)

* 1Alias Object

value

*

origin

*0..1

Runtime

Object Flow

Metamodel

26

Page 27: Dynamic Object Flow Analysis (PhD Defense)

0..1

caller

*Activation

1Alias Object

value

*

origin

*0..1

Runtime

Object Flow

Metamodel

27

Page 28: Dynamic Object Flow Analysis (PhD Defense)

context

0..1

caller

*1

*

Activation

1Alias Object

value

*

origin

*0..1

Runtime

Object Flow

Metamodel

28

Page 29: Dynamic Object Flow Analysis (PhD Defense)

upload

delete

context

0..1

caller

*1

*

Activation

duplicate

1Alias Object

value

*

origin

*0..1

Runtime

Object Flow

Metamodel

29

Page 30: Dynamic Object Flow Analysis (PhD Defense)

30

Object Flow

Page 31: Dynamic Object Flow Analysis (PhD Defense)

Object Tracking

Visualizing

Object Flows

Feature

Dependencies

Test

Blueprints Runtim

e M

onito

ring

in th

e V

MAlias Objectorigin

Activation

Metamodel

31

Page 32: Dynamic Object Flow Analysis (PhD Defense)

Object Tracking

Visualizing

Object Flows

Feature

Dependencies

Test

Blueprints Runtim

e M

onito

ring

in th

e V

MAlias Objectorigin

Activation

Metamodel

32

Page 33: Dynamic Object Flow Analysis (PhD Defense)

Object Tracking

Visualizing

Object Flows

Feature

Dependencies

Test

Blueprints Runtim

e M

onito

ring

in th

e V

MAlias Objectorigin

Activation

Metamodel

33

Page 34: Dynamic Object Flow Analysis (PhD Defense)

Object Tracking

Visualizing

Object Flows

Feature

Dependencies

Test

Blueprints Runtim

e M

onito

ring

in th

e V

MAlias Objectorigin

Activation

Metamodel

34

Page 35: Dynamic Object Flow Analysis (PhD Defense)

Object Tracking

Visualizing

Object Flows

Feature

Dependencies

Test

Blueprints Runtim

e M

onito

ring

in th

e V

MAlias Objectorigin

Activation

Metamodel

35

Page 36: Dynamic Object Flow Analysis (PhD Defense)

Object Tracking

Visualizing

Object Flows

Feature

Dependencies

Test

Blueprints Runtim

e M

onito

ring

in th

e V

MAlias Objectorigin

Activation

Metamodel

36

Page 37: Dynamic Object Flow Analysis (PhD Defense)

Alias Objectvalue

1*

*0..1

Activation

context1

*

Detecting flows between classes

origin

37

Page 38: Dynamic Object Flow Analysis (PhD Defense)

Alias Objectvalue

1*

*0..1

Activation

context

Method

1

*

1

*

Detecting flows between classes

origin

38

Page 39: Dynamic Object Flow Analysis (PhD Defense)

Alias Objectvalue

1*

*0..1

Activation

context

Method

Class

1

*

1

*

1

*

Detecting flows between classes

origin

Class A

Class B

Class C

39

Page 40: Dynamic Object Flow Analysis (PhD Defense)

Class B

Class A

value

1*

*0..1

context1

*

1

*

1

*

Detecting flows between classes

originAlias

Activation

Method

Class

Object

Class C

40

Page 41: Dynamic Object Flow Analysis (PhD Defense)

41

Inter-unit Flow View

Page 42: Dynamic Object Flow Analysis (PhD Defense)

42

Chronological propagation

Page 43: Dynamic Object Flow Analysis (PhD Defense)

42

Chronological propagation

Page 44: Dynamic Object Flow Analysis (PhD Defense)

42

Chronological propagation

Page 45: Dynamic Object Flow Analysis (PhD Defense)

43

Parser (4)

Spanning flows

Page 46: Dynamic Object Flow Analysis (PhD Defense)

44

Spanning flows

IRBuilder

Page 47: Dynamic Object Flow Analysis (PhD Defense)

Object Tracking

Visualizing

Object Flows

Feature

Dependencies

Test

Blueprints Runtim

e M

onito

ring

in th

e V

MAlias Objectorigin

Activation

Metamodel

45

[Lienhard etal.

COMLAN'09]

Page 48: Dynamic Object Flow Analysis (PhD Defense)

Object Tracking

Visualizing

Object Flows

Feature

Dependencies

Test

Blueprints Runtim

e M

onito

ring

in th

e V

MAlias Objectorigin

Activation

Metamodel

46

Page 49: Dynamic Object Flow Analysis (PhD Defense)

Feature "Upload" Feature "Duplicate" Feature "Delete"

[Salah and Mancoridis ICSM'04]

47

Page 50: Dynamic Object Flow Analysis (PhD Defense)

Feature "Upload" Feature "Duplicate" Feature "Delete"

a1

image:

:File

48

Page 51: Dynamic Object Flow Analysis (PhD Defense)

Feature "Upload" Feature "Duplicate" Feature "Delete"

a1

image:

:File

a2a1

image: copy:

:File

49

Page 52: Dynamic Object Flow Analysis (PhD Defense)

Feature "Upload" Feature "Duplicate" Feature "Delete"

a1

image:

:File

a2a1

image: copy:

:File

a2

a1

image: copy:

:File

50

Page 53: Dynamic Object Flow Analysis (PhD Defense)

Feature "Upload" Feature "Duplicate" Feature "Delete"

Alias Objectvalue

1*

origin*0..1

Activation

context

0..1

*

1

*

Feature1*

51

Page 54: Dynamic Object Flow Analysis (PhD Defense)

Feature "Upload" Feature "Duplicate" Feature "Delete"

Alias Objectvalue

1*

origin

*0..1

Activation

context

0..1

*

1

*

Feature1*

upload

delete

duplicate

52

Page 55: Dynamic Object Flow Analysis (PhD Defense)

53

IRC client dependencies

Disconnect

New Console

Receive Message

Send Message

Join Channel

MOTD

Connect

Setup

Open

0 5 10 15 20 25 30 35

Our approach Salah et al.

Page 56: Dynamic Object Flow Analysis (PhD Defense)

Open

Connect

Join Channel

Send Message

Object Dependency Graph

of feature Receive Message

54

Page 57: Dynamic Object Flow Analysis (PhD Defense)

Open

Connect

Join Channel

Send Message

Object Dependency Graph

of feature Receive Message

55

Page 58: Dynamic Object Flow Analysis (PhD Defense)

Open

Connect

Join Channel

Send Message

Object Dependency Graph

of feature Receive Message

56

Page 59: Dynamic Object Flow Analysis (PhD Defense)

Open

Connect

Join Channel

Send Message

Object Dependency Graph

of feature Receive Message

57

Page 60: Dynamic Object Flow Analysis (PhD Defense)

Object Tracking

Visualizing

Object Flows

Feature

Dependencies

Test

Blueprints Runtim

e M

onito

ring

in th

e V

MAlias Objectorigin

Activation

Metamodel

58

Lienhard etal.

ICPC'07

Page 61: Dynamic Object Flow Analysis (PhD Defense)

Object Tracking

Visualizing

Object Flows

Feature

Dependencies

Test

Blueprints Runtim

e M

onito

ring

in th

e V

MAlias Objectorigin

Activation

Metamodel

59

Page 62: Dynamic Object Flow Analysis (PhD Defense)

60

Writing a Unit Test

1. Setup

2. Invoke

3. Assert

Page 63: Dynamic Object Flow Analysis (PhD Defense)

duplicate

61

Page 64: Dynamic Object Flow Analysis (PhD Defense)

:Image (target)

:File

:Image (return)

existingnew

References

Objects

:Image existing:Image new

Test Blueprint

duplicate

62

Page 65: Dynamic Object Flow Analysis (PhD Defense)

:Image (target)

:File

:Image (return)

existingnew

References

1 file := File named: 'cat.jpg'.2 image := Image new.3 image file: file.

Objects

:Image existing:Image new

Test Blueprint

duplicate

63

Page 66: Dynamic Object Flow Analysis (PhD Defense)

:Image (target)

:File

:Image (return)

existingnew

References

1 file := File named: 'cat.jpg'.2 image := Image new.3 image file: file.

4 copy := image duplicate.

Objects

:Image existing:Image new

Test Blueprint

duplicate

64

Page 67: Dynamic Object Flow Analysis (PhD Defense)

:Image (target)

:File

:Image (return)

existingnew

References

1 file := File named: 'cat.jpg'.2 image := Image new.3 image file: file.

4 copy := image duplicate.

5 self assert: copy class = Image.6 self assert: copy file == file

Objects

:Image existing:Image new

Test Blueprint

duplicate

65

Page 68: Dynamic Object Flow Analysis (PhD Defense)

Alias Objectvalue

1*

*0..1

Activation

context

0..1

*

target parameters

*1

duplicate

origin

caller

66

Page 69: Dynamic Object Flow Analysis (PhD Defense)

67

InstanceScope>>newMethodScope

IRBuilder>>add: FunctionScope>>lookupVar:

NonClosureScopeFixer>>acceptVarNode:

Program instrumentation

Execution of existing tests

Analysis (Section 6)

object flow +execution trace data

coverage data

Example program execution

Execution Trace Test Blueprint

12

34

Page 70: Dynamic Object Flow Analysis (PhD Defense)

Execution Trace Test Blueprint

68

Page 71: Dynamic Object Flow Analysis (PhD Defense)

Execution Trace Test Blueprint

69

Initial Study ILet a developer use the tool:

12 tests in 2h

Page 72: Dynamic Object Flow Analysis (PhD Defense)

Execution Trace Test Blueprint

70

Initial Study IIRewrote assertions of 14 existing tests:

72 identical, 12 missed, 5 additional

Page 73: Dynamic Object Flow Analysis (PhD Defense)

Object Tracking

Visualizing

Object Flows

Feature

Dependencies

Test

Blueprints Runtim

e M

onito

ring

in th

e V

MAlias Objectorigin

Activation

Metamodel

71

Lienhard etal.

CSMR'08

Page 74: Dynamic Object Flow Analysis (PhD Defense)

Object Tracking

Visualizing

Object Flows

Feature

Dependencies

Test

Blueprints Runtim

e M

onito

ring

in th

e V

MAlias Objectorigin

Activation

Metamodel

72

Page 75: Dynamic Object Flow Analysis (PhD Defense)

Object Tracking

Visualizing

Object Flows

Feature

Dependencies

Test

Blueprints Runtim

e M

onito

ring

in th

e V

MAlias Objectorigin

Activation

Metamodel

73

Page 76: Dynamic Object Flow Analysis (PhD Defense)

74

Page 77: Dynamic Object Flow Analysis (PhD Defense)

75

Specification of object flow tracking by extending language semantics

Page 78: Dynamic Object Flow Analysis (PhD Defense)

f := new File

...

return f

Computer

(formal semantics)Source Code

Dynamic

Analysis Data

Example execution

76

Page 79: Dynamic Object Flow Analysis (PhD Defense)

allocationf := new File

...

return f

Computer

(formal semantics)Source Code

Dynamic

Analysis Data

Example execution

77

Page 80: Dynamic Object Flow Analysis (PhD Defense)

allocation

field-write

f := new File

...

return f

Computer

(formal semantics)Source Code

Dynamic

Analysis Data

Example execution

78

Page 81: Dynamic Object Flow Analysis (PhD Defense)

allocation

return

field-write

f := new File

...

return f

Computer

(formal semantics)Source Code

Dynamic

Analysis Data

Example execution

79

Page 82: Dynamic Object Flow Analysis (PhD Defense)

Object Tracking

Visualizing

Object Flows

Feature

Dependencies

Test

Blueprints Runtim

e M

onito

ring

in th

e V

MAlias Objectorigin

Activation

Metamodel

80

Page 83: Dynamic Object Flow Analysis (PhD Defense)

Object Tracking

Visualizing

Object Flows

Feature

Dependencies

Test

Blueprints Runtim

e M

onito

ring

in th

e V

MAlias Objectorigin

Activation

Metamodel

81

Page 84: Dynamic Object Flow Analysis (PhD Defense)

Problem of conventional debuggers

In 50% of the cases the execution stack contains

essentially no information about the bug's cause.

[Liblit etal. PLDI'05]

82

Page 85: Dynamic Object Flow Analysis (PhD Defense)

Back-in-time debugging

Challenges

1. amount of data

2. execution overhead

83

Page 86: Dynamic Object Flow Analysis (PhD Defense)

84

Approaches

Omniscient Debugger

Trace-oriented debugger (full)

Trace-oriented debugger (partial)

complete historyoverhead 100x

loss of old historyoverhead 100x

loss of selected historyoverhead 10x

Page 87: Dynamic Object Flow Analysis (PhD Defense)

85

Approaches

Omniscient Debugger

Trace-oriented debugger (full)

Trace-oriented debugger (partial)

complete historyloss of old history loss of history

overhead 100x overhead 100xoverhead 10x

Our approachlow overhead

relevant history

Page 88: Dynamic Object Flow Analysis (PhD Defense)

86

Delete history when it gets irrelevant

History of origins of objectsPrevious field values of objectsCall stacks in which above appear

Page 89: Dynamic Object Flow Analysis (PhD Defense)

Before deletion

87

Page 90: Dynamic Object Flow Analysis (PhD Defense)

After deletion

Before deletion

88

Page 91: Dynamic Object Flow Analysis (PhD Defense)

89

header

field_1

field_2

....

field_n

header

value

context

origin

predecessor

...

header

...

header

field_1

field_2

....

field_n

header

...

regular objects

pointer

alias

Object Flow VM

Typical model Object Flow VM

Page 92: Dynamic Object Flow Analysis (PhD Defense)

Capturing historical object state

image height: 17

t3

image := Image new

t1 t2image height: 42

90

Page 93: Dynamic Object Flow Analysis (PhD Defense)

image: @t1 nilheight

Capturing historical object state

image height: 17

t3

image := Image new

t1 t2image height: 42

91

Page 94: Dynamic Object Flow Analysis (PhD Defense)

image: @t2

@t1

17

nil

predecessor

height

Capturing historical object state

image height: 17

t3

image := Image new

t1 t2image height: 42

92

Page 95: Dynamic Object Flow Analysis (PhD Defense)

image:

@t2

@t3

@t1

17

42

nil

predecessor

predecessor

height

Capturing historical object state

image height: 17

t3

image := Image new

t1 t2image height: 42

93

Page 96: Dynamic Object Flow Analysis (PhD Defense)

image:

@t2

@t3

@t1

17

42

nil

predecessor

predecessor

height

Capturing historical object state

image height: 17

t3

image := Image new

t1 t2image height: 42

Alias Objectorigin

predecessor

0..1 0..1

fields

* 1

94

Page 97: Dynamic Object Flow Analysis (PhD Defense)

95

Evaluation memory usage (1)

0

5e+08

1e+09

1.5e+09

2e+09

2.5e+09

0 200 400 600 800 1000 0

2e+06

4e+06

6e+06

8e+06

1e+07

#classes

Number of aliases allocated (left Y-axis)Number of aliases in memory (right Y-axis)Number of objects in memory (right Y-axis)

Page 98: Dynamic Object Flow Analysis (PhD Defense)

96

Evaluation memory usage (2)

0

1e+06

2e+06

3e+06

4e+06

5e+06

6e+06

7e+06

0 2 4 6 8 10 12 14 16 18 0

10

20

30

40

50

%

#samples

Number of aliases allocatedNumber of aliases in memoryNumber of objects in memory

Ratio between aliases in memory and allocated

Page 99: Dynamic Object Flow Analysis (PhD Defense)

97

Evaluation memory usage (3)

0

1e+06

2e+06

3e+06

4e+06

5e+06

6e+06

7e+06

8e+06

9e+06

1e+07

5 10 15 20 25

#requests

Number of aliases allocatedNumber of aliases in memoryNumber of objects in memory

Page 100: Dynamic Object Flow Analysis (PhD Defense)

98

Evaluation run-time overhead

Overhead GC

Recording off 1.15 1.6%

Recording on 3.84 27.6%

Largest overhead: 6.9

Page 101: Dynamic Object Flow Analysis (PhD Defense)

Object Tracking

Visualizing

Object Flows

Feature

Dependencies

Test

Blueprints Runtim

e M

onito

ring

in th

e V

MAlias Objectorigin

Activation

Metamodel

99

Lienhard etal.

ECOOP'08

Page 102: Dynamic Object Flow Analysis (PhD Defense)

Object Tracking

Visualizing

Object Flows

Feature

Dependencies

Test

Blueprints Runtim

e M

onito

ring

in th

e V

MAlias Objectorigin

Activation

Metamodel