Program Slicing for Refactoring Advanced SW Tools Seminar Jan 2005Yossi Peery.

Slides:



Advertisements
Similar presentations
Overview Structural Testing Introduction – General Concepts
Advertisements

A Survey of Program Slicing Techniques A Survey of Program Slicing Techniques Sections 3.1,3.6 Swathy Shankar
Program Slicing – Based Techniques
SSA and CPS CS153: Compilers Greg Morrisett. Monadic Form vs CFGs Consider CFG available exp. analysis: statement gen's kill's x:=v 1 p v 2 x:=v 1 p v.
Semantics Static semantics Dynamic semantics attribute grammars
Data-Flow Analysis II CS 671 March 13, CS 671 – Spring Data-Flow Analysis Gather conservative, approximate information about what a program.
Chapter 9 Code optimization Section 0 overview 1.Position of code optimizer 2.Purpose of code optimizer to get better efficiency –Run faster –Take less.
Context-Sensitive Interprocedural Points-to Analysis in the Presence of Function Pointers Presentation by Patrick Kaleem Justin.
Architecture-dependent optimizations Functional units, delay slots and dependency analysis.
Compilation 2011 Static Analysis Johnni Winther Michael I. Schwartzbach Aarhus University.
Data-Flow Analysis Framework Domain – What kind of solution is the analysis looking for? Ex. Variables have not yet been defined – Algorithm assigns a.
CS412/413 Introduction to Compilers Radu Rugina Lecture 37: DU Chains and SSA Form 29 Apr 02.
1 CS 201 Compiler Construction Lecture Interprocedural Data Flow Analysis.
 Program Slicing Long Li. Program Slicing ? It is an important way to help developers and maintainers to understand and analyze the structure.
Program Slicing; Andreas Linder eXtreme Programming lab course 2004.
A survey of techniques for precise program slicing Komondoor V. Raghavan Indian Institute of Science, Bangalore.
Program Slicing Mark Weiser and Precise Dynamic Slicing Algorithms Xiangyu Zhang, Rajiv Gupta & Youtao Zhang Presented by Harini Ramaprasad.
1 Program Slicing Purvi Patel. 2 Contents Introduction What is program slicing? Principle of dependences Variants of program slicing Slicing classifications.
Introduction to Program Slicing Presenter: M. Amin Alipour Software Design Laboratory
Interprocedural Slicing using Dependence Graphs Susan Horwitz, Thomas Reps, and David Binkley University of Wisconsin-Madison.
Recap from last time We were trying to do Common Subexpression Elimination Compute expressions that are available at each program point.
Next Section: Pointer Analysis Outline: –What is pointer analysis –Intraprocedural pointer analysis –Interprocedural pointer analysis (Wilson & Lam) –Unification.
4/25/08Prof. Hilfinger CS164 Lecture 371 Global Optimization Lecture 37 (From notes by R. Bodik & G. Necula)
Previous finals up on the web page use them as practice problems look at them early.
Survey of program slicing techniques
CHAPTER 10 Recursion. 2 Recursive Thinking Recursion is a programming technique in which a method can call itself to solve a problem A recursive definition.
Prof. Bodik CS 164 Lecture 16, Fall Global Optimization Lecture 16.
Impact Analysis of Database Schema Changes Andy Maule, Wolfgang Emmerich and David S. Rosenblum London Software Systems Dept. of Computer Science, University.
1 ECE 453 – CS 447 – SE 465 Software Testing & Quality Assurance Instructor Kostas Kontogiannis.
Katanosh Morovat.   This concept is a formal approach for identifying the rules that encapsulate the structure, constraint, and control of the operation.
Code Optimization, Part III Global Methods Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 412.
Software (Program) Analysis. Automated Static Analysis Static analyzers are software tools for source text processing They parse the program text and.
2006/09/19AOAsia 21 Towards Locating a Functional Concern Based on a Program Slicing Technique Takashi Ishio 1,2, Ryusuke Niitani 2 and Katsuro Inoue 2.
Bug Localization with Machine Learning Techniques Wujie Zheng
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University How to extract.
Generative Programming. Automated Assembly Lines.
Dataflow Analysis Topic today Data flow analysis: Section 3 of Representation and Analysis Paper (Section 3) NOTE we finished through slide 30 on Friday.
Refactoring1 Improving the structure of existing code.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Technology and Science, Osaka University Dependence-Cache.
 Program Slicing : Analysis technique of extracting parts of a given program, relevant to the aspects being analyzed (the slicing criterion). E.g. slicing.
1 Program Slicing Amir Saeidi PhD Student UTRECHT UNIVERSITY.
Compiler Principles Fall Compiler Principles Lecture 0: Local Optimizations Roman Manevich Ben-Gurion University.
Automated Patch Generation Adapted from Tevfik Bultan’s Lecture.
Slicing AspectJ Woven Code Luca Cavallaro Mattia Monga Antonio Castaldo D'Ursi Davide Balzarotti Politecnico di Milano.
Chapter 11: Dynamic Analysis Omar Meqdadi SE 3860 Lecture 11 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
CASE/Re-factoring and program slicing
1 The System Dependence Graph and its use in Program Slicing.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University IWPSE 2003 Program.
Software Engineering Research Group, Graduate School of Engineering Science, Osaka University A Slicing Method for Object-Oriented Programs Using Lightweight.
Industrial Project (236504) Advanced programming tools for refactoring Java code in Eclipse Student: Alexander Libov Supervisor: Dr. Ran Ettinger, IBM.
Program Slicing Techniques CSE 6329 Spring 2013 Parikksit Bhisay
Static Techniques for V&V. Hierarchy of V&V techniques Static Analysis V&V Dynamic Techniques Model Checking Simulation Symbolic Execution Testing Informal.
1 Software Testing & Quality Assurance Lecture 13 Created by: Paulo Alencar Modified by: Frank Xu.
/ PSWLAB Evidence-Based Analysis and Inferring Preconditions for Bug Detection By D. Brand, M. Buss, V. C. Sreedhar published in ICSM 2007.
Onlinedeeneislam.blogspot.com1 Design and Analysis of Algorithms Slide # 1 Download From
Chapter 2 : Graph Coverage (part 2)
Phoenix Based Dynamic Slicing Debugging Tool Eric Cheng Lin Xu Matt Gruskin Ravi Ramaseshan Microsoft Phoenix Intern Team (Summer '06)
Data Flow Analysis Suman Jana
SwE 455 Program Slicing.
Graph Coverage for Design Elements CS 4501 / 6501 Software Testing
Mark Weiser University of Maryland, College Park IEEE CHI, 1981
A Survey of Program Slicing Techniques: Section 4
Program Slicing Baishakhi Ray University of Virginia
University Of Virginia
Chapter 10 Data Flow Testing Slice Testing
Human Complexity of Software
Graph Coverage for Design Elements CS 4501 / 6501 Software Testing
Test Case Test case Describes an input Description and an expected output Description. Test case ID Section 1: Before execution Section 2: After execution.
CSE P 501 – Compilers SSA Hal Perkins Autumn /31/2019
Presentation transcript:

Program Slicing for Refactoring Advanced SW Tools Seminar Jan 2005Yossi Peery

Jan-05Yossi PeeryAdvanced SW Tools Seminar Agenda Slicing Overview Slicing Algorithms Slicing with Inference Rules Refactoring Overview Slice Extraction Refactoring Example NATE – Slicing Based Refactoring Tool

Jan-05Yossi PeeryAdvanced SW Tools Seminar Starter

Jan-05Yossi PeeryAdvanced SW Tools Seminar Program Slicing History Mark Weiser, 1981 Experimented with programmers to show that slices are: “The mental abstraction people make when they are debugging a program” [Weiser] Used Data Flow Equations Ottenstein & Ottenstein – PDG, 1984 Horowitz, Reps & Binkly – SDG, 1990

Jan-05Yossi PeeryAdvanced SW Tools Seminar What is a Slice? All the statements of a program that may affect the values of some variables in a set V at some point of interest p. Slicing Criterion: C = (p, V)

Jan-05Yossi PeeryAdvanced SW Tools Seminar Slice Example A slice for the criterion (10, {product})

Jan-05Yossi PeeryAdvanced SW Tools Seminar What is it good for? Debugging Program Comprehension Reverse Engineering Program Testing Measuring Program Metrics Coverage, Overlap, Clustering Refactoring

Jan-05Yossi PeeryAdvanced SW Tools Seminar Slicing Properties Static Slicing Statically available information only No assumptions made on input Computed slice can never be accurate (minimal slice) Problem is undecidable – reduction to the halting problem Current static methods can only compute approximations Result may not be usefull

Jan-05Yossi PeeryAdvanced SW Tools Seminar Slicing Properties Dynamic Slicing Computed on a given input actual instead of might Useful for applications that provide are input driven (debugging, testing) Criterion: (n=-3, 5, {sign})

Jan-05Yossi PeeryAdvanced SW Tools Seminar Slicing Properties Amorphous & Semantic Slicing Allows any semantic preserving transformations Used for program comprehension and reverse engineering Instead of:We write if (n >= 0) if (n < 0) ;sign := -1 else sign := -1

Jan-05Yossi PeeryAdvanced SW Tools Seminar Slicing Properties Backward Slicing Original Slicing Method Backward Traversal of Program Flow Slicing starts from point p (C = (p, V)) Examines statements that are executed before p (in run-time) Keep statements that affect value of V at p, or execution of p. Not only statements that appear before p

Jan-05Yossi PeeryAdvanced SW Tools Seminar Slicing Properties Forward Slicing Forward Traversal of Program Flow Slicing starts from p (C = (p, V)) Examine all statements that are executed after p Keep statements that are affected by the values of V at p or by the execution of p Shows downstream code that depend on a specific variable or statement Can show the code affected by a modification to a single statement

Jan-05Yossi PeeryAdvanced SW Tools Seminar Slicing Properties Intraprocedural Slicing Computes slice within one procedure Assumes worse case for function calls Interprocedural Slicing Compute slice over an entire program Two ways for crossing procedure boundary Up – going from sliced procedure into calling procedure Down – going from sliced procedure into called procedure Must Be Context Sensitive

Jan-05Yossi PeeryAdvanced SW Tools Seminar Slicing Algorithm CFG – Control Flow Graph Each program statement is a node A directed edge will connect between any 2 nodes that represent statements with a possible control flow between them. Special nodes: Start, Stop Definitions - There is a directed path from I to j - Set of nodes that are influenced by i - all of the variables that are defined (modified) at statement i. - all of the variables that are referenced (used) at statement i.

Jan-05Yossi PeeryAdvanced SW Tools Seminar Slicing Algorithms

Jan-05Yossi PeeryAdvanced SW Tools Seminar Slicing Algorithms Data Flow Equations (Weiser) Iterative Process (Over CFG) Compute consecutive sets of “relevant” variables for each node in the CFG using data dependencies Control dependences are not computed explicitly Variables of control predicates (if, while) are “indirectly relevant” if any one of the statements in their body is relevant Start with slicing criterion: C = (p, V) Continue until a fixed point is reached – last iteration didn’t find new relevant statements

Jan-05Yossi PeeryAdvanced SW Tools Seminar Slicing Algorithms Iteration 0: Iteration k+1:

Jan-05Yossi PeeryAdvanced SW Tools Seminar Slicing Algorithm

Jan-05Yossi PeeryAdvanced SW Tools Seminar Slicing Algorithms Issues with algorithm Output statements are not included in slice Solution: print(x) ≡ out = out + x, out V Interprocedural Slicing Solution proposed by Weiser Can go up or down procedure calls Actual parameters of function call are changed to call parameters (or the opposite) Variables not in scope are removed Is not “context sensitive” – too inaccurate

Jan-05Yossi PeeryAdvanced SW Tools Seminar Slicing Algorithms PDG – Program Dependance Graphs Each node represents a statement (like CFG) Directed Edges represent: Control Dependence (Bold Lines) – between a predicate and the statements it controls Data Dependence (Regular Lines) – between statements modifying a variable and those that may reference it Special “Entry” node is connected to all nodes that are not control dependant

Jan-05Yossi PeeryAdvanced SW Tools Seminar Slicing Algorithms

Jan-05Yossi PeeryAdvanced SW Tools Seminar Slicing Algorithm Slicing with PDG Slicing criterion is less general: C = ( p, Def(p) ∩ Ref(p) ) Graph is computed for a single procedure Slicing becomes a reachability problem A slice consits of all the nodes that have a directed path to the node in the slicing criterion are in the Linear in time, after graph is calculated Issues Method isn’t interprocedural

Jan-05Yossi PeeryAdvanced SW Tools Seminar Slicing Algorithms SDG – System Dependence Graph New nodes: Call Site, Procedure Entry, Actual-in-argument, Actual-out-argument, Formal-in-parameter, Formal-out-parameter New edges: Call Edge – connect “call site” and “procedure entry” Parameter-In Edge – connect “Actual-in” with “Formal-in” Parameter-Out-Edge – connect “Actual-out” with “Formal-out”

Jan-05Yossi PeeryAdvanced SW Tools Seminar Slicing Algorithm

Jan-05Yossi PeeryAdvanced SW Tools Seminar

Jan-05Yossi PeeryAdvanced SW Tools Seminar Slicing Algorithms Context Sensitivity Can not be solved by data flow equations The procedure, included through the procedure will include the call site and consequently Solved by SDG New summary edges (dotted) represent transitive dependences between “actual- in” and “actual-out” nodes. Slice is calculated in 2 passes (instead of 1): 1.Follow all edges except “parameter-out” 2.Follow all edges except “parameter-in”

Jan-05Yossi PeeryAdvanced SW Tools Seminar

Jan-05Yossi PeeryAdvanced SW Tools Seminar Slicing Algorithm SDG - Issues Slicing remains a reachability problem SDG of a program is complex and costly to build (time, space) After computation, many different slices can be found using the same graph Is not efficient for developing code OO concepts and unstructured control flow (jump statements, exceptions) further complicate the graph

Jan-05Yossi PeeryAdvanced SW Tools Seminar Slicing with Inference Rules Concept Use inference rules when traversing backwards the flow of the program to determine relevant statements Rules are applied on a specific configuration of S – Statement or sequence of statements that have been analyized Γ – Current slicing context R – Set of statements that are relevant (so far) Similar in nature to data flow equations method

Jan-05Yossi PeeryAdvanced SW Tools Seminar Slicing with Inference Rules Context: Inference Rule: Initial Configuration: Our Example Final Configuration:

Jan-05Yossi PeeryAdvanced SW Tools Seminar Slicing with Inference Rules Rule Example Inference rules are defined so that, at each step, there is at most one rule that matches the configuration

Jan-05Yossi PeeryAdvanced SW Tools Seminar Slicing with Inference Rules Features Supports interprocedural slicing Context Sensitive Can be extended to support other language features such as: Complex expressions Array access Variable declarations Structured Jumps (break, continue) Object-oriented slicing (scoping, polymorphism) Aliasing

Jan-05Yossi PeeryAdvanced SW Tools Seminar Refactoring Overview Gradually improving design of existing code Source code transformations that, Preserve behavior of original system Manually or Automated Introduced by William Opdyke, 1992 Formally defined the reasonable behavior preservation degree expected from a refactoring tool Formally Disciplined by Martin Fowler 2000 Formal description of a refactoring Catalog of refactoring techniques

Jan-05Yossi PeeryAdvanced SW Tools Seminar Refactoring Overview Over 70 refactoring techniques can be found at: Refactoring categories: Composing Methods, Moving features between Objects, Organizing Data, Making Method Calls Simpler Some refactorings: Rename Method, Extract Method, Move Method, Replace Conditional with Polymorphism

Jan-05Yossi PeeryAdvanced SW Tools Seminar Refactoring Overview

Jan-05Yossi PeeryAdvanced SW Tools Seminar Slice Extraction Refactoring

Jan-05Yossi PeeryAdvanced SW Tools Seminar Slice Extraction Refactoring

Jan-05Yossi PeeryAdvanced SW Tools Seminar Slice Extraction Refactoring Idea introduced by K. Maruyama, 2001 Is not limited to consecutive statements (like extract method) Allows the untangling of a single concern from a complex method Extracted slice can be refactored to New Method New Object New Aspect

Jan-05Yossi PeeryAdvanced SW Tools Seminar Slice Extraction Refactoring Slice Extraction Refactoring Concerns Not all of the statements in the slice can be deleted Deleted statements are determined by re-slicing for variables in statements that were not sliced: Preconditions & Limitations Clean compilation Return statement Global-scoped variables Input/Output statements

Jan-05Yossi PeeryAdvanced SW Tools Seminar Example – original code

Jan-05Yossi PeeryAdvanced SW Tools Seminar Example – Extract as Method

Jan-05Yossi PeeryAdvanced SW Tools Seminar Example – Extract as Object

Jan-05Yossi PeeryAdvanced SW Tools Seminar Example – Extract as Aspect

Jan-05Yossi PeeryAdvanced SW Tools Seminar Example – Extract as Aspect

Jan-05Yossi PeeryAdvanced SW Tools Seminar NATE – Slicing based Refactoring Tool Oxford University – Programming Tools Group cts/nate/nate.html Slicing based refactoring techniques for the Java programming language Currently supports a small subset of Java (March 2004) Extract Slice as Method Refactoring An Eclipse Plug-in

Jan-05Yossi PeeryAdvanced SW Tools Seminar NATE – Slicing based Refactoring Tool How is it used? Programmer selects: slicing criterion Name for new extracted method Tool performs: Compute Slice Check refactoring preconditions If extraction is possible – perform transformation Show original and transformed code in a preview dialog to the user for confirmation User can cancel any operation

Jan-05Yossi PeeryAdvanced SW Tools Seminar Implementation Uses JDT plug-in for access to the AST Slicing is done with inference rules The AST node of a statement is associated with a related inference rule Intensive use of visitor pattern to visit the AST and its related rules Each AST node can be marked as relevant or not NATE – Slicing based Refactoring Tool

Jan-05Yossi PeeryAdvanced SW Tools Seminar

Jan-05Yossi PeeryAdvanced SW Tools Seminar Refernces “Untangling: A Slice Extraction Refactoring - Ran Ettinger and Mathieu Verbaere (March 2004) “Program Slicing for Refactoring” - Mathieu Verbaere (September 2003) “Automated Tools for Refactoring” - Ran Ettinger (June 2003) “Program Slicing” - Mark Weiser (1981)