IBM Haifa Research Lab © 2008 IBM Corporation Co-Slicing for Program Comprehension and Reuse March 2008 Ran Ettinger Software Asset Management Group In.

Slides:



Advertisements
Similar presentations
Chapter 4 Loops Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved
Advertisements

Simplifications of Context-Free Grammars
3.6 Support Vector Machines
한양대학교 정보보호 및 알고리즘 연구실 이재준 담당교수님 : 박희진 교수님
2. Getting Started Heejin Park College of Information and Communications Hanyang University.
EE384y: Packet Switch Architectures
1 Concurrency: Deadlock and Starvation Chapter 6.
1
1 Vorlesung Informatik 2 Algorithmen und Datenstrukturen (Parallel Algorithms) Robin Pomplun.
Chapter 7 System Models.
Chapter 7 Constructors and Other Tools. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 7-2 Learning Objectives Constructors Definitions.
© 2008 Pearson Addison Wesley. All rights reserved Chapter Seven Costs.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
IBM Haifa Research Lab © 2007 IBM Corporation Program Sliding A Novel Approach for the Automation of Slicing-Based Refactoring June 2007 Ran Ettinger In.
Refactoring via Program Slicing and Sliding Ran Ettinger Programming Tools Group University of Oxford In Panayas Reading Group 2 November, 2006.
IBM Haifa Research Lab © 2007 IBM Corporation Refactoring via Program Slicing and Sliding June 2007 Ran Ettinger Software Asset Management Group In HRL.
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 6 Author: Julia Richards and R. Scott Hawley.
Author: Julia Richards and R. Scott Hawley
Properties Use, share, or modify this drill on mathematic properties. There is too much material for a single class, so you’ll have to select for your.
UNITED NATIONS Shipment Details Report – January 2006.
By John E. Hopcroft, Rajeev Motwani and Jeffrey D. Ullman
David Burdett May 11, 2004 Package Binding for WS CDL.
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 5: Repetition and Loop Statements Problem Solving & Program.
1 RA I Sub-Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Casablanca, Morocco, 20 – 22 December 2005 Status of observing programmes in RA I.
Conversion Problems 3.3.
Properties of Real Numbers CommutativeAssociativeDistributive Identity + × Inverse + ×
1 Click here to End Presentation Software: Installation and Updates Internet Download CD release NACIS Updates.
R O O T S Field-Sensitive Points-to-Analysis Eda GÜNGÖR
Week 2 The Object-Oriented Approach to Requirements
Pole Placement.
Chapter 11: Models of Computation
Turing Machines.
PP Test Review Sections 6-1 to 6-6
Chapter 17 Linked Lists.
Parallel List Ranking Advanced Algorithms & Data Structures Lecture Theme 17 Prof. Dr. Th. Ottmann Summer Semester 2006.
Data Structures Using C++
EU Market Situation for Eggs and Poultry Management Committee 21 June 2012.
EIS Bridge Tool and Staging Tables September 1, 2009 Instructor: Way Poteat Slide: 1.
Chapter 4 Gates and Circuits.
2007 Pearson Education, Inc. All rights reserved C Structures, Unions, Bit Manipulations and Enumerations.
Legacy Systems Older software systems that remain vital to an organisation.
Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation 1.
Direct-Current Circuits
Copyright © 2012, Elsevier Inc. All rights Reserved. 1 Chapter 7 Modeling Structure with Blocks.
1 RA III - Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Buenos Aires, Argentina, 25 – 27 October 2006 Status of observing programmes in RA.
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
1 Human Resources Almanac For the State of Connecticut Executive Branch 12/31/2008 Edition.
1..
CONTROL VISION Set-up. Step 1 Step 2 Step 3 Step 5 Step 4.
Adding Up In Chunks.
While Loop Lesson CS1313 Spring while Loop Outline 1.while Loop Outline 2.while Loop Example #1 3.while Loop Example #2 4.while Loop Example #3.
1 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt Synthetic.
Analyzing Genes and Genomes
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Pointers and Arrays Chapter 12
Essential Cell Biology
PSSA Preparation.
Essential Cell Biology
Mani Srivastava UCLA - EE Department Room: 6731-H Boelter Hall Tel: WWW: Copyright 2003.
Energy Generation in Mitochondria and Chlorplasts
Insertion Sort Introduction to Algorithms Insertion Sort CSE 680 Prof. Roger Crawfis.
Techniques for proving programs with pointers A. Tikhomirov.
User Defined Functions Lesson 1 CS1313 Fall User Defined Functions 1 Outline 1.User Defined Functions 1 Outline 2.Standard Library Not Enough #1.
1 Decidability continued…. 2 Theorem: For a recursively enumerable language it is undecidable to determine whether is finite Proof: We will reduce the.
The Pumping Lemma for CFL’s
IBM Haifa Research Lab © 2008 IBM Corporation Automating Big Refactorings for Componentization and the Move to SOA IBM Programming Languages and Development.
Industrial Project (236504) Advanced programming tools for refactoring Java code in Eclipse Student: Alexander Libov Supervisor: Dr. Ran Ettinger, IBM.
Ran Ettinger, IBM Research – Haifa Beijing, China 16 June 2012
Presentation transcript:

IBM Haifa Research Lab © 2008 IBM Corporation Co-Slicing for Program Comprehension and Reuse March 2008 Ran Ettinger Software Asset Management Group In Advanced SW Tools Seminar, TAU

IBM Haifa Research Lab © 2008 IBM Corporation 2 Agenda Introduction to Program Slicing –Debugging aid, program comprehension tool, and much more –PAINLESS demo Co-Slicing for Reuse: Program Sliding –A provably-correct code-motion untangling transformation of slice extraction Co-Slicing for Program Comprehension –Problem of large slices –Novel solution: Interactive program exploration with the slice-inclusion relation and co-slicing A Co-Slicing Algorithm Back to Sliding Related Work –CodeSurfers single-step slice browsing, thin slicing, Dijkstras projections, and method-extraction algorithms Further Challenges

IBM Haifa Research Lab © 2008 IBM Corporation 3 Introduction to Program Slicing Slicing is the study of meaningful subprograms –When debugging unfamiliar programs programmers use program pieces called slices which are sets of statements related by their flow of data. The statements in a slice are not necessarily textually contiguous, but may be scattered through a program [Mark Weiser, CACM82 ] –Given a program and a variable (at a point) of interest, a slice of the program on that variable is a subprogram that preserves the original behavior, with respect to that variable –Demo 1: Slicing HLASM code (Program Analysis INfrastructure for Legacy Enterprise Software Systems project [PAINLESS] at IBM HRL) A wide variety of potential applications –Debugging, program comprehension, testing, refactoring, componentization, parallelization, and more

IBM Haifa Research Lab © 2008 IBM Corporation 4 Co-Slicing for Reuse: Program Sliding Extract the computation of profit i = 0; while (i > sale[i++]; if (shouldProcess) { i = 0; totalSale = 0; while (i < days) { totalSale = totalSale+sale[i]; i = i+1; } profit = 0.9*totalSale-cost; } Example source: Lakhotia and Deprez [IST98] if (shouldProcess) { i = 0; totalPay = 0; while (i < days) { totalPay = totalPay+0.1*sale[i]; if (sale[i]>1000) totalPay = totalPay+50; i = i+1; } pay = totalPay/days+100; } if (shouldProcess) { i = 0; totalPay = 0; while (i < days) { totalPay = totalPay+0.1*sale[i]; if (sale[i]>1000) totalPay = totalPay+50; i = i+1; } pay = totalPay/days+100; } i = 0; while (i > sale[i++]; if (shouldProcess) { i = 0; totalSale = 0; while (i < days) { totalSale = totalSale+sale[i]; i = i+1; } profit = 0.9*totalSale-cost; } The extracted slice The complement (no unnecessary duplication of the loop for reading sales; hence, no need to reject!)

IBM Haifa Research Lab © 2008 IBM Corporation 5 Co-Slicing for Reuse: Program Sliding A provably-correct code-motion untangling transformation of slice extraction –My doctoral thesis Refactoring via Program Slicing and Sliding [Ett] –Automated slice extraction Combines statement reordering with code duplication –A sequential composition of a slice with its complement (i.e. co-slice) –Adding some compensatory code, for correctness Enables automation of advanced refactorings –Split/Merge Loops –Separate Query from Modifier Command/Query separation –Arbitrary Method Extraction Advanced versions of Extract Method Sliding thesis [Ett] and Raghavan Komondoors thesis [Kom] –Replace Temp with Query By slice extraction Demo 2: Nate, an Eclipse plugin, prototype slice-extraction refactoring for a small subset of Java, developed by Mathieu Verbaere and myself at Oxford, 2003/2004, supported by an Eclipse Innovation Grant by IBM

IBM Haifa Research Lab © 2008 IBM Corporation 6 Co-Slicing for Program Comprehension: Problem of Large Slices Slices (especially from the end) tend to grow too large to be effective Why is the typical end-slice so large? –The slice must produce correct values It hence includes all statements that may contribute to the value of any used variable, at any point in the slice (i.e., it follows all data-flow dependences) Demo 3: indirect (i.e. base register) data dependence –The slice must be executable It hence includes all statements with conditions and jumps, if those control whether to execute (or not) any other statement in the slice Demo 4: following control dependences

IBM Haifa Research Lab © 2008 IBM Corporation 7 Problem of Large Slices: End-Slice of Variable pay pay totalPay i sale cin

IBM Haifa Research Lab © 2008 IBM Corporation 8 Novel Solution: A Slice-Inclusion Relation and Co-Slicing Interactive program exploration Guided by a slice-inclusion diagram –First introduced by Gallagher and Lyle [ToSE91] For software maintenance, supporting a process of change, avoiding the need for regression testing The diagram is a directed graph, representing a given program (or subprogram) S, and including: –A node for each (defined) variable x Stands for the slice of S on x, from the end –A directed edge from x to y whenever The slice of x is fully included in that of y, and There is no other variable z whose slice both includes the slice of x and is included in the slice of y

IBM Haifa Research Lab © 2008 IBM Corporation 9 Example: Slice-Inclusion Diagram i = 0; while (i > sale[i++]; if (shouldProcess) { i = 0; totalSale = 0; totalPay = 0; while (i < days) { totalSale = totalSale+sale[i]; totalPay = totalPay+0.1*sale[i]; if (sale[i]>1000) totalPay = totalPay+50; i = i+1; } pay = totalPay/days+100; profit = 0.9*totalSale-cost; } profitpay totalPay totalSale i sale cin

IBM Haifa Research Lab © 2008 IBM Corporation 10 Interactive Program Exploration: An On-Demand Approach profit totalSale i sale cin

IBM Haifa Research Lab © 2008 IBM Corporation 11 On-Demand Exploration profit totalSale i sale cin

IBM Haifa Research Lab © 2008 IBM Corporation 12 On-Demand Exploration profit totalSale i sale cin

IBM Haifa Research Lab © 2008 IBM Corporation 13 On-Demand Exploration profit totalSale i sale cin

IBM Haifa Research Lab © 2008 IBM Corporation 14 On-Demand Exploration: Back to End-Slice of profit …the problem of large slices is not yet solved profit totalSale i sale cin

IBM Haifa Research Lab © 2008 IBM Corporation 15 Interactive Program Exploration with Slices and Co-Slices: A Bottom-Up Approach

IBM Haifa Research Lab © 2008 IBM Corporation 16 Bottom-Up Exploration with Slices and Co-Slices i

IBM Haifa Research Lab © 2008 IBM Corporation 17 Bottom-Up Exploration with Slices and Co-Slices i sale cin

IBM Haifa Research Lab © 2008 IBM Corporation 18 Bottom-Up Exploration with Slices and Co-Slices totalPay i sale cin

IBM Haifa Research Lab © 2008 IBM Corporation 19 Bottom-Up Exploration with Slices and Co-Slices totalPay totalSale i sale cin

IBM Haifa Research Lab © 2008 IBM Corporation 20 Bottom-Up Exploration with Slices and Co-Slices pay totalPay totalSale i sale cin

IBM Haifa Research Lab © 2008 IBM Corporation 21 Bottom-Up Exploration with Slices and Co-Slices profitpay totalPay totalSale i sale cin

IBM Haifa Research Lab © 2008 IBM Corporation 22 Whats in a Co-Slice then? Is it the complementary set of statements? [too small!] profitpay totalPay totalSale i sale cin

IBM Haifa Research Lab © 2008 IBM Corporation 23 Whats in a Co-Slice then? Is it the union of slices of all remaining variables? [too large!] profitpay totalPay totalSale i sale cin

IBM Haifa Research Lab © 2008 IBM Corporation 24 Whats in a Co-Slice then? Assume results of selected variables are available and reuse them profitpay totalPay totalSale i sale cin

IBM Haifa Research Lab © 2008 IBM Corporation 25 Illustration of a Co-Slicing algorithm (1): Assume results of selected variables are available and reuse them i = 0; while (i > sale[i++]; if (shouldProcess) { i = 0; totalSale = 0; totalPay = 0; while (i < days) { totalSale = totalSale+fSale[i]; totalPay = totalPay+0.1*fSale[i]; if (fSale[i]>1000) totalPay = totalPay+50; i = i+1; } pay = fTotalPay/days+100; profit = 0.9*fTotalSale-cost; } profitpay totalPay totalSale i sale cin

IBM Haifa Research Lab © 2008 IBM Corporation 26 Illustration of a Co-Slicing algorithm (2): Slice now… and get a smaller slice profitpay totalPay totalSale i sale cin

IBM Haifa Research Lab © 2008 IBM Corporation 27 Illustration of a Co-Slicing algorithm (3): Undo the variable renaming… wherever possible profitpay totalPay totalSale i sale cin

IBM Haifa Research Lab © 2008 IBM Corporation 28 Back to Sliding: Separate non-maximal from maximal i = 0; while (i > sale[i++]; if (shouldProcess) { i = 0; totalSale = 0; totalPay = 0; while (i < days) { totalSale = totalSale+sale[i]; totalPay = totalPay+0.1*sale[i]; if (sale[i]>1000) totalPay = totalPay+50; i = i+1; } if (shouldProcess) { pay = totalPay/days+100; profit = 0.9*totalSale-cost; } totalPay totalSale i sale cin

IBM Haifa Research Lab © 2008 IBM Corporation 29 Another Sliding Example: Separate profit and all included variables i = 0; while (i > sale[i++]; if (shouldProcess) { i = 0; totalSale = 0; while (i < days) { totalSale = totalSale+sale[i]; i = i+1; } profit = 0.9*totalSale-cost; } if (shouldProcess) { i = 0; totalPay = 0; while (i < days) { totalPay = totalPay+0.1*sale[i]; if (sale[i]>1000) totalPay = totalPay+50; i = i+1; } pay = totalPay/days+100; } profit totalSale i sale cin

IBM Haifa Research Lab © 2008 IBM Corporation 30 The Promise of Sliding Mainly good for: –Enhancing reusability of tangled (non-contiguous) existing code –Refactoring (e.g. Replace Temp with Query) –Componentization –Parallelization Particularly strong in: –Correctness, i.e. behavior preservation –Maximizing reuse (of extracted computations results, in the complement) –Minimizing code duplication, i.e. yielding a small complement –Minimizing the necessary compensation, i.e. less backup variables –Improving applicability, i.e. less reasons to reject a request

IBM Haifa Research Lab © 2008 IBM Corporation 31 Related Work: Enhance Reuse by Method Extraction Slice extraction –Tucking by Lakhotia and Deprez [IST98] Complement is union of slices from all non-extracted points No data flow from slice to complement –Block-based slicing by Maruyama [SSR01] A rudimentary approach (no proof of correctness) –Untangling: A Slice Extraction Refactoring [AOSD04] Arbitrary method extraction: Extract any selection of (not- necessarily contiguous) code –Tucking [IST98] –Procedure extraction by Komondoor and Horwitz [POPL00,IWPC03,Kom] Allows data flow from extracted code to the complement Inspired invention of co-slices However, does not support duplication of assignments –Hence, no untangling of loops; instead, may extract more code than actually selected

IBM Haifa Research Lab © 2008 IBM Corporation 32 Related Work: Program Comprehension Thin slicing (by Sridharan, Fink and Bodik [PLDI07]) –Focus on direct (value, not pointer) data dependences –Ignore control dependences –Ignore data dependences carrying pointers (base and index registers, in the context of HLASM) –A thin slice can be expanded with other thin slices Yielding the full traditional slice, in the limit CodeSurfers slice browsing [CodeSurfer] –One step at a time, jumping forward or backward in a slice, following data or control dependences Dijkstras projections (in his Smoothsort article [SoCP82]) –Explaining an algorithm stepwise, one variable/projection at a time

IBM Haifa Research Lab © 2008 IBM Corporation 33 Some Further Challenges Implement the co-slicing and sliding algorithms –Extend to real languages Collect empirical results on length and usefulness of co-slices Extend the slice-inclusion diagram to slices from internal program points Apply sliding to more refactorings (e.g. Separate Query from Modifier [Fow], arbitrary method extraction) Apply the sliding-related refactorings in bigger reengineering challenges (e.g. Convert Procedural Design to Objects [Fow], componentization, conversion to SOA) Sliding beyond refactoring (e.g. in optimizing compilers, code obfuscation)

IBM Haifa Research Lab © 2008 IBM Corporation 34 Thanks!

IBM Haifa Research Lab © 2008 IBM Corporation 35 References [CACM82] Programmers use slices when debugging, M. Weiser, 1982 [SoCP82] Smoothsort, an Alternative for Sorting In Situ, E. W. Dijkstra, 1982 [ToSE91] Using Program Slicing in Software Maintenance, Gallagher and Lyle, 1991 [IST98] Restructuring programs by tucking statements into functions, A. Lakhotia and J.-C. Deprez, 1998 [FOW] Refactoring: Improving the Design of Existing Code, M. Fowler, 2000 [POPL00] Semantics-preserving procedure extraction, R. Komondoor and S. Horwitz, 2000 [SSR01] Automated method-extraction refactoring by using block-based slicing, K. Maruyama, 2001 [IWPC03] Effective automatic procedure extraction, R. Komondoor and S. Horwitz, 2003 [Kom] Automated Duplicated-Code Detection and Procedure Extraction, R. Komondoor, PhD thesis, University of Wisconsin-Madison, 2003 [AOSD04] Untangling: a slice extraction refactoring, R. Ettinger and M. Verbaere, 2004 [Ett] Refactoring via Program Slicing and Sliding, R. Ettinger, DPhil thesis, 2006 – [PLDI07] Thin Slicing, M. Sridharan, S. J. Fink, R. Bodik, 2007 [CodeSurfer] CodeSurfer from GrammaTech – [PAINLESS] The Program Analysis INfrastructure for Legacy Enterprise Software Systems project –

IBM Haifa Research Lab © 2008 IBM Corporation 36 Backup

IBM Haifa Research Lab © 2008 IBM Corporation 37 A Definition of (Slices and) Co-Slices Definition of a slice: – Let S be a given statement and let V be a set of variables of interest. – A statement S is a slice of S on V, if for any input on which S terminates, S will terminate too, and with the same result held in all program variables V. In a similar manner, the novel concept of a co-slice can be defined as follows: – Let S be a given statement and let V be a set of variables of NO interest. That is, the final value of each variable in V, and the code for computing it, in S, can be removed -- if not contributing to any other result. – A statement S is a co-slice of S on V, if for any input on which S terminates, S will terminate too, and with the same result held in all program variables outside V. – Moreover, suppose the result of V is available for reuse through the corresponding set of fresh variables fV. A co-slice S on V with fV is free to use the final value of variables in V through the corresponding elements of fV (or even directly from V, if only such final value references are present in S).

IBM Haifa Research Lab © 2008 IBM Corporation 38 A Co-Slicing Algorithm: Rationale The goal of the algorithm is to maximize reuse of the available final values before slicing for the complementary set of variables However, a simplistic approach of substituting all uses of co-sliced variables will not do –Some of the uses make reference to intermediate (i.e. non-final) values –The final-value references must be identified and substituted, ahead of slicing Finally, after slicing, some substitutions may be undone

IBM Haifa Research Lab © 2008 IBM Corporation 39 Final-Use Substitution A final use of a variable x is a reference to x in a program point p, in which x is guaranteed to hold its final value –That is, no path from p to the exit, in terms of control flow, includes a definition of x –Or, equivalently, an assertion of the form assert x == fx, where fx is a fresh variable, can be correctly propagated backwards (against the flow of control) from the exit to the program point p A definition of final-use substitution: – Given a program statement S, a set of variables X, and a corresponding set of fresh variables fX, the final-use substitution of X with fX, on statement S, yields a new statement S by replacing all final-use references of each member of X with a reference to the corresponding member of fX

IBM Haifa Research Lab © 2008 IBM Corporation 40 A Co-Slicing Algorithm Given a statement S, a set of variables of no-interest V, and a corresponding set of final values fV, compute the co-slice of S on V with fV as follows: 1.Reuse fV wherever possible a.Let S be S with final-use substitution of V by fV 2.Slice for all remaining variables a.Determine the complementary set of variables, coV, as all possibly-modified variables in S that are not in V b.Let S be the slice of S on coV 3.Undo the earlier substitutions wherever possible a.Let V1 be the set of all variables in V that are not referenced (i.e. neither used nor defined) in S b.Let fV1 be the subset of fV corresponding to the subset V1 of V c.Let S be the statement S after normal substitution of all variables fV1 with the corresponding program variables V1 4.Return S as the co-slice of S on V with fV