Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 27

Program Slicing

Daekyoon Kim Michael Fong

Problems
The size and complexity of a software today gets harder to understand, maintain and test - You might have had questions like.. If I change this statement, what pieces of the program are going to be affected? Where are the values that flow into this statement coming from? My code is bloated. How can I limit the functionality to only what I need?

Problems (Contd)
Studies of software maintainers have shown that approximately 50% of their time is spent in the process of understanding the code that they are to maintain
- Jussi Koskinen, Asst Prof, University of Jyvskyl, Finland-

Our Goals
Debug your thousands lines of code easily by reducing the complexity of the program Write a robust program before testing your code Save your regression testing time by limiting the tests to only those that exercise the changed code

Approach

Break your code into smaller pieces

Approach

How?

Ill slice you into smaller pieces


Using This?

Dont even think about this way!!!

Program Slicing
What is it?
- A well-known program analysis and transformation
technique that uses program statement dependence information to identify parts of a program that influence or are influenced by an initial set of program points of interest which is called the slice criteria

- Introduced by Mark Weiser in his Ph.D. thesis (1979)

Program Slicing (contd)


indirectly relevant

Slice

Slicing Criterion

Source program

Resulting slice

slicing criterion is provided by the user

Program Slicing (contd)


Program slicing describes a mechanism which allows the automatic generation of a slice All Statements affecting or affected by the variables mentioned in the slicing criterion becomes a part of the slice Variables V at statements S can be affected by statements because:
Statements define whether S is executed at all (Control Dependence) Statements define a variable that is used by S (Data Dependence)

Program Slicing (contd)


A slice s(V, S) is derived from a program P by deleting statements from P The slice must be syntactically correct in terms of the programming language used in P The values for variables V received from the slice at statements S have to be the same as the values for V at statements S in program P

Variants of Program Slicing


Many different variants of program slicing exist
1. Static Slicing

2. Backward Slicing 3. Forward Slicing


4. 5. 6. Dynamic Slicing Conditional Slicing Chopping

Also Many Different tools, however


Most program slicing tools are written for C but there are also some for C++ and Java Most of these have problems with dynamic binding, inheritance, polymorphism and performance

Variants of Program Slicing (Contd)


Static Slicing
Slices derived from the source code for all possible input values No assumptions about input values May lead to relatively big slices Contains all Statements that may affect a variable for every possible execution

Dynamic Slicing
Uses information derived from a particular execution of a program Execution is monitored and slices are computed with respect to program history Relatively small slices Contains all statements that actually affect the value of a variable

Conditional Slicing
Acts as bridge between the two extremes of static and dynamic slicing

Backward Slicing
Contains the statements of the program P which may have some effect in the slicing criterion S(V, n)

Forward Slicing
Contains all those statements of P which are affected by S(V, n)

Backward Slice Example


public class SimpleExample { static int add(int a, int b){ return(a+b); } public static void main(final String[] arg){ int i = 1; int sum = 0; while (i < 11) { sum = add(sum, i); i = add(i, 1); } System.out.println("sum = " + sum); System.out.println("i = " + i); } Slicing } Criterion

Forward Slice Example


public class SimpleExample { static int add(int a, int b){ return(a+b); } Slicing public static void main(final String[] arg){ Criterion int i = 1; int sum = 0; while (i < 11) { sum = add(sum, i); i = add(i, 1); } System.out.println("sum = " + sum); System.out.println("i = " + i); } }

Why is It Useful?
Program slicing is useful in many different states of the software development lifecycle
Debugging:
Slicing visualizes control and data dependencies It highlights statements influencing the slice

Testing:
Tests may be decomposed and test-work gets faster and more efficient

Software quality assurance


Safety critical code can be isolated and functions can be implemented redundant and in functional diversity manner

Software measurement, Maintenance,.

Dependences
Various notions of Dependences
Data dependence Control dependence Synchronization dependence
The usual stuff Dependences related to threading & locking

Data Dependence
public class BoundedBuffer { protected int numSlots = 0; protected Object[] buffer = null; protected int putIn = 0; protected int takeOut = 0; protected int count = 0; public BoundedBuffer(int numSlots) { if (numSlots <= 0) { throw new IllegalArgumentException(); } this.numSlots = numSlots; buffer = new Object[numSlots]; } }

Data Dependence Definition of variable V at statement S1 reaches a use of V at statement S2

these statements depend on the data value assigned to parameter numSlots

Data Dependence
public class BoundedBuffer { protected int numSlots = 0; protected Object[] buffer = null; protected int putIn = 0; protected int takeOut = 0; protected int count = 0; public BoundedBuffer(int numSlots) { if (numSlots <= 0) { throw new IllegalArgumentException(); } this.numSlots = numSlots; buffer = new Object[numSlots]; } .... }

Data Dependence Definition of variable V at statement S1 reaches a use of V at statement S2

these statements depend on the data value assigned to parameter numSlots

Control Dependence
public class BoundedBuffer { protected int numSlots = 0; protected Object[] buffer = null; protected int putIn = 0; protected int takeOut = 0; protected int count = 0; public BoundedBuffer(int numSlots) { if (numSlots <= 0) { throw new IllegalArgumentException(); } this.numSlots = numSlots; buffer = new Object[numSlots]; } .... }

Control Dependence A conditional statement controls whether or not the current statement is executed

this statement depends on the conditional which controls whether it is reached or bypassed by throwing an exception

Tool Overview Indus / Kaveri


Indus provides a rich collection of program analyses and transformations for Java programs(full java)
Platform for static analyses such as points-to analysis, escape analysis and dependence analyses. Transformations such as program slicing and program specialization via partial evaluation

Kaveri provides a featureful Eclipse-based UI front-end for Indus integrated with Eclipse Java development environment
Configuring, invoking and visualizing results of Indus slicing Scripting framework for flexible querying of underlying analysis APIs

Indus / Kaveri Architecture


Slicer Input

Slice Calculation

Java Representation Dependence Calculation

Supporting Analysis

Output Construction

Eclipse-based Front-end
Visualization of Slice

Eclipse-based Front-end

Inspection of underlying Jimple

Eclipse-based Front-end

Navigation of dependences

Conclusions
Program slicing comes from the ability to assist in tedious and error prone tasks such as program debugging, testing, parallelization, integration, software safety, understanding, and software maintenance. A robust program slicer that can be applied to real Java is a sophisticated analysis and transformation framework with many applications. Applying Indus slicing for Java Application
is easy (completely automatic no user intervention) is inexpensive (compared to model checking costs) is effective and orthogonal to other reduction strategies (typical reduction factors range from 2x 5x)

Indus can be downloaded and immediately applied in the context of Java verification efforts

Demo

You might also like