Static ControlFlow Analysis for Reverse Engineering of UML

  • Slides: 20
Download presentation
Static Control-Flow Analysis for Reverse Engineering of UML Sequence Diagrams Atanas (Nasko) Rountev Ohio

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 m 1() m 2()

Example of a UML Sequence Diagram start: X p: A m 1() m 2() m 3() create() opt n: A m 4() PRESTO Research Group - Ohio State University Nasko Rountev PASTE'05 2

UML Sequence Diagrams § § § Popular UML artifacts for modeling of object interactions

UML 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 PRESTO Research Group - Ohio State University § Nasko Rountev PASTE'05 Together Control. Center (Borland) 3

Reverse-Engineering Analyses Dynamic analysis: tracks a set of representative run-time executions § Several research

Reverse-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) § RED tool for Java: PRESTO group at OSU § URL: presto. cse. ohio-state. edu/red PRESTO Research Group - Ohio State Nasko Rountev § Call chain analysis; control-flow University PASTE'05 4 §

Representation of Intraprocedural Flow of Control Given: the methods whose bodies will be used

Representation of Intraprocedural Flow of Control Given: the methods whose bodies will be used to construct the diagram § How should we represent the intraprocedural flow of control inside intra 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 PRESTO Research Group - Ohio State Nasko Rountev § Subsequent diagram transformations § University PASTE'05 5

UML 2. 0 Interaction Fragments § Opt, alt, loop, break; added generalized break PRESTO

UML 2. 0 Interaction Fragments § Opt, alt, loop, break; added generalized break PRESTO Research Group - Ohio State University Nasko Rountev PASTE'05 6

Analysis Stages CFG Phase I: Preprocessing Phase II: Fragment Construction Phase III: Transformations Data

Analysis Stages CFG Phase I: Preprocessing Phase II: Fragment Construction Phase III: Transformations Data Structure for Fragments PRESTO Research Group - Ohio State University Nasko Rountev PASTE'05 7

Phase I: Preprocessing Post-dominance tree § Node n 2 post-dominates n 1 if all

Phase I: Preprocessing Post-dominance tree § Node n 2 post-dominates n 1 if all paths from n 1 to exit go through n 2 § Immediate post-dominator; parent in the tree § Analyze branch nodes § What is the merge point for all branches? § Analyze loops § Nesting relationships PRESTO Research Group - Ohio State Rountev § What is the merge point for. Nasko all loop University PASTE'05 § 8

Post-dominance Tree PRESTO Research Group - Ohio State University Nasko Rountev PASTE'05 9

Post-dominance Tree PRESTO Research Group - Ohio State University Nasko Rountev PASTE'05 9

Branch Nodes and Branch Successors § Branch successor: node where the outgoing paths for

Branch Nodes and Branch Successors § Branch successor: node where the outgoing paths for a branch node merge the branch successo r of 3 is 6 PRESTO Research Group - Ohio State University Nasko Rountev PASTE'05 10

Loops and Loop Successors § § Reducible CFG: contains only natural loops Loop successor:

Loops and Loop Successors § § Reducible CFG: contains only natural loops Loop successor: merge point of all paths exiting the loop success or of L is 12 PRESTO Research Group - Ohio State University Nasko Rountev PASTE'05 11

Branch/Loop Successors Inside Loop L § § Consider only edges inside L Create a

Branch/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 the branch successo r PRESTO Research Group Ohio of- 7 is State 10 University Nasko Rountev PASTE'05 12

Analysis Stages CFG Phase I: Preprocessing Phase II: Fragment Construction Phase III: Transformations Data

Analysis Stages CFG Phase I: Preprocessing Phase II: Fragment Construction Phase III: Transformations Data Structure for Fragments PRESTO Research Group - Ohio State University Nasko Rountev PASTE'05 13

Phase II: Fragment Construction TOP 1: i = -1 Pattern. Entry: get. Chars() 2:

Phase II: Fragment Construction TOP 1: i = -1 Pattern. Entry: get. Chars() 2: s = e. get. Chars() ALT 1 cond: s != null String: char. At(0) T 3 : s != null F Vector: index. Of(e) 4 5: i = patterns. index. Of(e) : e = s. char. At(0) LOOP 1 cond: i>= 0 F 6: i>=0 BREAK 1 T F 7: status. Array[i] !=0 OPT 1 T cond: i<0 breaks_from: LOOP 1 cond: status. Array[i] !=0 Vector: element. At(i) 8 : e 1 = patterns. element. At(i) 9: e 1 != null BREAK 2 cond: e 1 != null breaks_from: LOOP 1 T Merge. Collation: fix. Entry(e 1) F 10 : patterns. remove. Element. At(i) 11 : fix. Entry(e 1) Vector: remove. Element. At(i) 12: exit PRESTO Research Group - Ohio State University Nasko Rountev PASTE'05 14

Various Issues § UML additions § Multi-level break fragments § Multiple method exits Opt-like

Various 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 PRESTO Research Group State Rountev may have to- Ohio produce multiple. Nasko identical § University PASTE'05 15

Average Running Time per Method [milliseconds] PRESTO Research Group - Ohio State University Nasko

Average Running Time per Method [milliseconds] PRESTO Research Group - Ohio State University Nasko Rountev PASTE'05 16

Methods Requiring Return/Throw Fragments PRESTO Research Group - Ohio State University Nasko Rountev PASTE'05

Methods Requiring Return/Throw Fragments PRESTO Research Group - Ohio State University Nasko Rountev PASTE'05 17

Methods Requiring Multi-level Break Fragments PRESTO Research Group - Ohio State University Nasko Rountev

Methods Requiring Multi-level Break Fragments PRESTO Research Group - Ohio State University Nasko Rountev PASTE'05 18

Methods Requiring Node Replication PRESTO Research Group - Ohio State University Nasko Rountev PASTE'05

Methods Requiring Node Replication PRESTO Research Group - Ohio State University Nasko Rountev PASTE'05 19

Summary and Future Work § § General and fast algorithm § Creates detailed and

Summary and Future Work § § General and fast algorithm § Creates detailed and precise representation Subsequent simplifications § Lossless: e. g. merge a fragment with the surrounding fragment [OSUCISRC-3/04 -TR 12] Lossy: e. g. give up on multi-level breaks § Interactive visualization [VISSOFT’ 05] § Collapse and un-collapse fragments; PRESTO Research Group - Ohio State w. r. t. a fragment Nasko Rountev slice the diagram of University PASTE'05 20 § University PASTE'05 20