Presentation is loading. Please wait.

Presentation is loading. Please wait.

Program Slicing – Based Techniques

Similar presentations


Presentation on theme: "Program Slicing – Based Techniques"— Presentation transcript:

1 Program Slicing – Based Techniques
By Corey Rahberger

2 Overview What is program slicing? History How to extract a slice
Program slicing techniques Applications Program slicing tools Current Problems Future

3 What is program slicing?
The process of computing a slice of a program A slice is a subset of the original program, which contains portions of the program that are related to the slicing criterion used to create the slice The slicing criterion is the point of interest or variable(s) that are being investigated A slice is an executable program whose behavior must be identical to the specified subset of the original program.

4 Program Slicing Example
int i; int sum = 0; int product = 1; for(i = 0; i < N; i++) { sum = sum + 1; product = product * I; } write(sum); write(product); int i; int sum = 0; for(i = 0; i < N; i++) { sum = sum + 1; } write(sum); Original Program Slice on statement “write(sum)”

5 History First introduced by Mark Weiser in 1984 through publication in IEEE Transactions on Software Engineering Original ideas were in his Ph.D. dissertation (1979) from University of Michigan, Ann Arbor Chief scientist at Xerox PARC Switched his focus to ubiquitous computing

6 History Researchers have expanded on Weiser’s original definition into multiple directions Huge amounts of program slicing techniques have been created to encompass all programming paradigms Different surveys have been made to compare the techniques, but the results have been inconclusive Surveys look at different things: applications and advances empirical results predict future techniques and applications are different techniques really the same

7 How to extract a slice First, the dependences must be found between the different statements These dependences can be represented in a data structure called a control flow graph (CFG) A control flow graph shows all the execution paths that a program might take

8 Control Flow Graph read(text); read(n); lines = 1; chars = 1; subtext = “”; c = getChar(text); while ( c != ‘\eof’) if (c == ‘\n’) then lines = lines + 1; chars = chars + 1; else chars = chars + 1; if (n != 0) then subtext = subtext + c; n = n – 1; write(lines); write(chars); write(subtext); In the CFG, each node is represented by a number that corresponds to a line number of the program Lengauer-Tarjan’s algorithm (graph theory)

9 Problem with Control Flow Graph
Does not include data dependences Solution Add data dependencies to the graph

10 Program Dependence Graph
This new data structure is called a program dependence graph (PDG) “A PDG is an oriented graph where the nodes represent statements in the source code [and the] edges represent control and data flow dependencies between statements in such a way that they induce a partial ordering in the nodes, preserving the semantics of the program.” (Silva)

11 Program Dependence Graph
read(text); read(n); lines = 1; chars = 1; subtext = “”; c = getChar(text); while ( c != ‘\eof’) if (c == ‘\n’) then lines = lines + 1; chars = chars + 1; else chars = chars + 1; if (n != 0) then subtext = subtext + c; n = n – 1; write(lines); write(chars); write(subtext); The solid lines represent the control dependencies and the dotted lines represent the data dependencies.

12 Program Dependence Graph
Since both flow and data dependences are now found for the program, the program dependence graph can be used to compute slices of the program according to the slicing criterion Graphs can get quite large and complex System dependence graph

13 Program Slicing Techniques
There are a huge amount of different techniques We will look more closely into the three main techniques Static slicing Dynamic slicing Conditioned slicing Backward slicing

14 Static Slicing Similar to what Weiser originally introduced
The resulting slice will work for all inputs Usually results in a bigger slice Weiser in 1984

15 Static Slicing – Slicing Criterion
(s,v) ‘s’ represents the line number in the program ‘v’ represents the variable(s) that are of interest Example (7, x)

16 Static Slicing Example
read(n); i := 1; sum := 0; product := 1; while i <= n do begin sum := sum + 1; product := product * i; i := i + 1; end; write(sum); write(product); read(n); i := 1; product := 1; while i <= n do begin product := product * i; i := i + 1; end; write(product); Original Program Slice of program w.r.t. criterion (10, product)

17 Static Slicing Uses Debugging Dead code removal Program analysis
Software maintenance Module cohesion analysis Many more

18 Dynamic Slicing Input(s) for the program are used to help determine the slice Removes portions of the program that are not reached for the given input(s) The resulting slice will not work for all executions of the program Resulting slice is usually smaller than static slicing, but takes longer to compute Korel and Laski in 1988

19 Dynamic Slicing – Slicing Criterion
(si, v, {ai, …, an}) ‘s’ represents the line number in the program ‘i’ represents the position in the execution history of statement ‘s’ ‘v’ represents the variable(s) that are of interest ‘{ai, …, an}’ represents the initial values or inputs Example (71, sum, {x = 1}) ‘i’ represents the occurrence number of statement ‘s’ in the execution history

20 Dynamic Slicing Example
read(n); i := 1; while (i <= n) do begin if (i mod 2 = 0) then x := 17; else x := 18; i := i + 1; end; write(x); read(n); i := 1; while (i <= n) do begin if (i mod 2 = 0) then x := 17; else ; i := i + 1; end; write(x); Original Program Slice of program w.r.t. criterion (81, x, {n = 2})

21 Dynamic Slicing Uses Debugging Testing Tuning Compilers

22 Conditioned Slicing Combination of static and dynamic slicing
Provides information about the inputs values, but does not specify them exactly Resulting slice is ranges between static and dynamic in size Formally introduced in 1994 by Canfora and others

23 Conditioned Slicing – Slicing Criterion
(i, F, s, v) ‘i’ represents the input variable(s) ‘F’ represents a logical formula on ‘i’ ‘s’ represents the line number in the program ‘v’ represents the variable(s) that are of interest Example (sales, F, 11, {total}), where F = (sales > 0)

24 Conditioned Slicing Example
read(text); read(n); lines = 1; chars = 1; subtext = “”; c = getChar(text); while ( c != ‘\eof’) if (c == ‘\n’) then lines = lines + 1; chars = chars + 1; else chars = chars + 1; if (n != 0) then subtext = subtext + c; n = n – 1; write(lines); write(chars); write(subtext); (1) read(text); (2) read(n); (5) subtext = “”; (6) c = getChar(text); (7) while ( c != ‘\eof’) (8) if (c == ‘\n’) then (12) if (n != 0) then (13) subtext = subtext + c; (14) n = n – 1; (15) c = getChar(text); (18) write(subtext); Original Program Slice of program w.r.t. criterion ((text, n), F, 18, {subtext}), where F = (∀ c ∈ text, c != ‘\n’ . n > 0)

25 Conditioned Slicing Uses
Debugging Software reuse Ripple effect analysis Understanding legacy code Program comprehension

26 Applications All the different techniques have made program slicing a useful tool in all areas of programming Examples Debugging Cohesion measurement Comprehension Maintenance and reengineering Testing Debugging - program slicing can help narrow down the search for the error(s) Cohesion measurement - program slicing can help to make sure that a program is following good object-oriented programming Comprehension - program slicing can help in the maintenance by splitting it into understandable pieces Maintenance and reengineering - program slicing can help separate sections of code to be modified Testing - program slicing can simplify the section of the program to be tested and can increase the speed of the testing

27 Program Slicing Tools Sprite Unravel CodeSurfer Open source
National Institute of Standards and Technology CodeSurfer University of Wisconsin Slicing Tool GrammaTech Sprite – favors performance, uses Steensgaard’s almost linear points-to analysis, and also performs context insensitivity slices Unravel – prototype, ANSI C source code, last information from 1998 CodeSurfer – Andersen’s cubic time pointer analysis and uses summary edges to provide infinite context sensitivity

28 CodeSurfer University of Wisconsin Slicing Tool CodeSurfer 1.0
Developed Susan Horwitz, Thomas Reps and others CodeSurfer 1.0 Released in June 1999 Derived from Wisconsin’s Slicing Tool

29 CodeSurfer Language Platforms Cost C/C++ Windows Linux Solaris
Basic – (Locked) $795 (Floating) $1495 Suite – (Locked) $3995 (Floating) $5995

30 NASA’s evaluation of CodeSurfer
Johnson Space Center Safety and Mission Assurance Directorate, Flight Equipment Division Reviewed the efficiency of CodeSurfer compared to doing it manually Compared results from two projects Space Integrated Global Positioning System/Inertial Navigation System (SIGI) Health Management System Defibrillator (Defib) Power and Data Interface Module (PDIM) Johnson Space Center – usually deals with projects 1,000 to 50,000 LOC

31 NASA’s evaluation of CodeSurfer
COMBINED SIGI AND PDIM INSPECTION DATA Metric Manual Code inspection With CodeSurfer Inspection Time (hr) 17 12.25 Lines of Code (LOC) 10650 Inspection Rate (LOC/hr) 626 869 Total Defects Found Using Method 8 18 Defects Found per Hour 0.47 1.47 Unique Defects Found Using Method 2 12

32 NASA’s evaluation of CodeSurfer
Drawbacks from CodeSurfer Must be compiled using on a compiler provided with the tool Training is required, which is expensive Must use it regularly to remain knowledgeable on using CodeSurfer

33 Current Problems Resources need to compute slices
It can take a while to compute slices Usability of program slicing tools Computing a slice from a PDG of N nodes is O(N) Cost of building a slice is O(N2)

34 Future Rate at which slices can be computed Usability
Integration into mainstream development tools

35 Conclusion Program slicing techniques have been and are still constantly improving Can be used in all the different programming paradigms As soon as the usability has been increased, program slicing should become a well known and useful tool

36 Questions?

37 References Binkley, D., & Harman, M. (2004). A Survey of Empirical Results on Program Slicing. Advanced Computing, 62, Retrieved October 27, 2012, from Harman, M., & Hierons, R. (2001). An Overview of Program Slicing. Software Focus, 2(3), Retrieved October 27, 2012, from Sasirekha, N., Robert, A. E., & Hemalatha, M. (2011, July). Program Slicing Techniques and Its Applications. International Journal of Software Engineering & Applications, 2(3), Retrieved October 21, 2012, from Silva, J. (2012, June). A Vocabulary of Program Slicing-Based Techniques. ACM Computing Surveys, 44(3), 12:1-12:41. Retrieved September 12, 2012, from Tip, F. (1995). A Survey of Program Slicing Techniques. Java Programming Language, 3, Retrieved October 27, 2012, from Weiser, M. (1984, July). Program Slicing. IEEE Transactions of Software Engineering, 10(4), Retrieved October 21, 2012, from

38 References (cont.) Lyle, Jim. "The Unravel Project." The Unravel Program Slicing Tool. National Institute of Standards and Technology, 37 Mar Web. 10 Dec Brown, Aaron. "CodeSurfer: It Slices, It Chops, But Doesn't Make Julienne Fries." GrammaTech, n.d. Web. 10 Dec United States. Johnson Space Center Safety and Mission Assurance Directorate. Flight Equipment Division. Can CodeSurfer Increase Code Inspection Efficiency? By Mark Markovich and Dan Freund. N.p., n.d. Web. 10 Dec   "Wisconsin Program-Slicing Project." N.p., n.d. Web. 10 Dec "CodeSurfer." GrammaTech. N.p., Web. 12 Dec


Download ppt "Program Slicing – Based Techniques"

Similar presentations


Ads by Google