static control-flow analysis for reverse engineering of uml sequence diagrams

20
Static Control-Flow Static Control-Flow Analysis for Reverse Analysis for Reverse Engineering of UML Sequence Engineering of UML Sequence Diagrams Diagrams Atanas (Nasko) Rountev Ohio State University with Olga Volgin and Miriam Reddoch

Upload: connor-stevens

Post on 30-Dec-2015

52 views

Category:

Documents


1 download

DESCRIPTION

Static Control-Flow Analysis for Reverse Engineering of UML Sequence Diagrams. Atanas (Nasko) Rountev Ohio State University with Olga Volgin and Miriam Reddoch. Example of a UML Sequence Diagram. start:X. p:A. m1(). m2(). m3(). create(). n:A. opt. m4(). UML Sequence Diagrams. - PowerPoint PPT Presentation

TRANSCRIPT

Static Control-Flow Analysis for Static Control-Flow Analysis for Reverse Engineering of UML Reverse Engineering of UML

Sequence DiagramsSequence Diagrams

Atanas (Nasko) RountevOhio State University

with Olga Volgin and Miriam Reddoch

PRESTO Research Group - Ohio StPRESTO Research Group - Ohio State Universityate University

Nasko Rountev - PASTE'0Nasko Rountev - PASTE'055

22

Example of a UML Sequence DiagramExample of a UML Sequence Diagram

start:X

m1()

p:A

m2()

n:A

m3()

create()

m4()opt

PRESTO Research Group - Ohio StPRESTO Research Group - Ohio State Universityate University

Nasko Rountev - PASTE'0Nasko Rountev - PASTE'055

33

UML Sequence DiagramsUML Sequence Diagrams

Popular UML artifacts for modeling of object interactions

Design-time sequence diagrams Reverse-engineered sequence

diagrams Based on existing code Iterative development; design recovery for software maintenance; software testing

Implemented in some commercial UML tools Together ControlCenter (Borland) EclipseUML (Omondo)

PRESTO Research Group - Ohio StPRESTO Research Group - Ohio State Universityate University

Nasko Rountev - PASTE'0Nasko Rountev - PASTE'055

44

Reverse-Engineering AnalysesReverse-Engineering Analyses Dynamic analysis: tracks a set of

representative run-time executions Several research tools

Static analysis: examines only the code Commercial tools (deficiencies) Some research work (not comprehensive)

REDRED tool for Java: PRESTOPRESTO group at OSU URL: presto.cse.ohio-state.edu/red Call chain analysis; control-flow analysis; object naming analysis; visualization and navigation; test coverage measurements

PRESTO Research Group - Ohio StPRESTO Research Group - Ohio State Universityate University

Nasko Rountev - PASTE'0Nasko Rountev - PASTE'055

55

Representation of Intraprocedural Flow of Representation of Intraprocedural Flow of ControlControl

Given: the methods whose bodies will be used to construct the diagram

How should we represent the intraintraprocedural flow of control inside these bodies?

Solution: general algorithm for mapping a method’s CFG to UML 2.0 interaction fragments Any reducible exception-free CFG Precise mapping: preserves all call sequences

Subsequent diagram transformations Lossless vs. lossy Visualization and exploration

PRESTO Research Group - Ohio StPRESTO Research Group - Ohio State Universityate University

Nasko Rountev - PASTE'0Nasko Rountev - PASTE'055

66

UML 2.0 Interaction FragmentsUML 2.0 Interaction Fragments Opt, alt, loop, break; added generalized break

sd example

s:String:MergeCollation patterns:Vector

example(e)

LOOP L

BREAK L

e:PatternEntry

ALT

s = getChars()

i=charAt(0)

i=indexOf(e)

OPT e1= elementAt(i)

fixEntry(e1)

removeElementAt(i)

PRESTO Research Group - Ohio StPRESTO Research Group - Ohio State Universityate University

Nasko Rountev - PASTE'0Nasko Rountev - PASTE'055

77

Analysis StagesAnalysis Stages

CFG

Phase I: Preprocessing

Phase II: Fragment Construction

Phase III: Transformations

Data Structure for Fragments

PRESTO Research Group - Ohio StPRESTO Research Group - Ohio State Universityate University

Nasko Rountev - PASTE'0Nasko Rountev - PASTE'055

88

Phase I: PreprocessingPhase I: Preprocessing

Post-dominance tree Node n2 post-dominates n1 if all paths from n1 to exit go through n2

Immediate post-dominator; parent in the tree

Analyze branch nodes What is the merge point for all branches?

Analyze loops Nesting relationships What is the merge point for all loop exits?

PRESTO Research Group - Ohio StPRESTO Research Group - Ohio State Universityate University

Nasko Rountev - PASTE'0Nasko Rountev - PASTE'055

99

12

3

11976

2

81054

1

3: s != null

2: s = e.getChars()

1: i = -1

4: e = s.charAt(0) 5: i = patterns.indexOf(e)

7: statusArray[i] !=0

6: i>=0

8: e1 = patterns.elementAt(i)

11: fixEntry(e1)

9: e1 != null

12: exit

10: patterns.removeElementAt(i)

FT

T

F

T

F

T

F

Post-dominance TreePost-dominance Tree

PRESTO Research Group - Ohio StPRESTO Research Group - Ohio State Universityate University

Nasko Rountev - PASTE'0Nasko Rountev - PASTE'055

1100

3: s != null

2: s = e.getChars()

1: i = -1

4: e = s.charAt(0) 5: i = patterns.indexOf(e)

7: statusArray[i] !=0

6: i>=0

8: e1 = patterns.elementAt(i)

11: fixEntry(e1)

9: e1 != null

12: exit

10: patterns.removeElementAt(i)

FT

T

F

T

F

T

F

12

3

11976

2

81054

1

Branch Nodes and Branch SuccessorsBranch Nodes and Branch Successors Branch successor: node where the

outgoing paths for a branch node merge

the branch

successorof 3 is 6

PRESTO Research Group - Ohio StPRESTO Research Group - Ohio State Universityate University

Nasko Rountev - PASTE'0Nasko Rountev - PASTE'055

1111

Loops and Loop SuccessorsLoops and Loop Successors

the loop successorof L is 12

3: s != null

2: s = e.getChars()

1: i = -1

4: e = s.charAt(0) 5: i = patterns.indexOf(e)

7: statusArray[i] !=0

6: i>=0

8: e1 = patterns.elementAt(i)

11: fixEntry(e1)

9: e1 != null

12: exit

10: patterns.removeElementAt(i)

FT

T

F

T

F

T

F

12

3

11976

2

81054

1

Reducible CFG: contains only natural loops Loop successor: merge point of all paths exiting

the loop

PRESTO Research Group - Ohio StPRESTO Research Group - Ohio State Universityate University

Nasko Rountev - PASTE'0Nasko Rountev - PASTE'055

1122

Branch/Loop Successors Inside Loop LBranch/Loop Successors Inside Loop L Consider only edges inside L Create a post-dominance tree

for L and use it for: branch successors for nodes in L loop successors for

loops nested in L

3: s != null

2: s = e.getChars()

1: i = -1

4: e = s.charAt(0) 5: i = patterns.indexOf(e)

7: statusArray[i] !=0

6: i>=0

8: e1 = patterns.elementAt(i)

11: fixEntry(e1)

9: e1 != null

12: exit

10: patterns.removeElementAt(i)

FT

T

F

T

F

T

F9

6

8

10

7

the branch

successorof 7 is 10

PRESTO Research Group - Ohio StPRESTO Research Group - Ohio State Universityate University

Nasko Rountev - PASTE'0Nasko Rountev - PASTE'055

1133

Analysis StagesAnalysis Stages

CFG

Phase I: Preprocessing

Phase II: Fragment Construction

Phase III: Transformations

Data Structure for Fragments

PRESTO Research Group - Ohio StPRESTO Research Group - Ohio State Universityate University

Nasko Rountev - PASTE'0Nasko Rountev - PASTE'055

1144

3 : s != null

2: s = e.getChars()

1: i = -1

4 : e = s.charAt(0) 5: i = patterns.indexOf(e)

7: statusArray[i] !=0

6: i>=0

8 : e1 = patterns.elementAt(i)

11 : fixEntry(e1)

9: e1 != null

12: exit

10: patterns.removeElementAt(i)

FT

T

F

T

F

T

F

PatternEntry:getChars()

TOP

OPT

ALT

cond: statusArray[i] !=0

cond: s != null

Vector:elementAt(i)

String:charAt(0)

Vector:indexOf(e)

LOOP

cond: e1 != nullBREAK

MergeCollation:fixEntry(e1)

breaks_from: LOOP1

1

1

1

2

1

BREAK 1breaks_from: LOOPcond: i<0

cond: i>= 0

Vector:removeElementAt(i)

Phase II: Fragment ConstructionPhase II: Fragment Construction

PRESTO Research Group - Ohio StPRESTO Research Group - Ohio State Universityate University

Nasko Rountev - PASTE'0Nasko Rountev - PASTE'055

1155

Various IssuesVarious Issues

UML additions Multi-level break fragments Multiple method exits

Opt-like fragments: return fragments Algorithm uses info about control dependencies

Exceptions (Java) “throw e”: similar to method exit - throw fragment

Ignore catches and implicit exceptions Node replication: the same CFG node may

have to produce multiple identical diagram elements e.g. due to short-circuit evaluation

PRESTO Research Group - Ohio StPRESTO Research Group - Ohio State Universityate University

Nasko Rountev - PASTE'0Nasko Rountev - PASTE'055

1166

Average Running Time per Method Average Running Time per Method [milliseconds][milliseconds]

0

5

10

15

20

25

30

35

40

45

50

PRESTO Research Group - Ohio StPRESTO Research Group - Ohio State Universityate University

Nasko Rountev - PASTE'0Nasko Rountev - PASTE'055

1177

Methods Requiring Return/Throw FragmentsMethods Requiring Return/Throw Fragments

0%

10%

20%

30%

40%

50%

60%

70%

80%

90%

100%

PRESTO Research Group - Ohio StPRESTO Research Group - Ohio State Universityate University

Nasko Rountev - PASTE'0Nasko Rountev - PASTE'055

1188

Methods Requiring Multi-level Break Methods Requiring Multi-level Break FragmentsFragments

0%

2%

4%

6%

8%

10%

12%

14%

16%

18%

PRESTO Research Group - Ohio StPRESTO Research Group - Ohio State Universityate University

Nasko Rountev - PASTE'0Nasko Rountev - PASTE'055

1199

Methods Requiring Node ReplicationMethods Requiring Node Replication

0%

5%

10%

15%

20%

25%

30%

35%

40%

45%

PRESTO Research Group - Ohio StPRESTO Research Group - Ohio State Universityate University

Nasko Rountev - PASTE'0Nasko Rountev - PASTE'055

2200

Summary and Future WorkSummary and Future Work General and fast algorithm

Creates detailed and precise representation

Subsequent simplifications Lossless: e.g. merge a fragment with the surrounding fragment [OSU-CISRC-[OSU-CISRC-3/04-TR12]3/04-TR12]

Lossy: e.g. give up on multi-level breaks Interactive visualization [VISSOFT’05][VISSOFT’05]

Collapse and un-collapse fragments; slice the diagram w.r.t. a fragment of interest

Re-implement in Eclipse and make public, together with the other analyses in REDRED