Document not found! Please try again

Interprocedural Slicing of Generic Programs

4 downloads 13589 Views 351KB Size Report
parameters passed in the procedure are known at the time of procedure call only. 2009 International Conference on Signal Processing Systems.
2009 International Conference on Signal Processing Systems

Interprocedural Slicing of Generic Programs Soubhagya Sankar Barpanda, Baikuntha Narayan Biswal, Sasmita Rani Behera, Mitrabinda Ray Durga Prasad Mohapatra Department of Computer Science & Engineering, NIT Rourkela, India {soubhagyab, baikuntha, mitrabindar-cs801, sasmitar-cs104, durga}@nitrkl.ac.in

(SDG). They also developed a two pass algorithm to calculate the slices which were more precise. Harman and Hierons [13] have given notes on condition slicing and amorphous slicing. Amorphous slices [12] are constructed using any program transformation which simplifies the program and which preserves the effect of the program with respect to the slicing criterion. Condition slicing [13] is used to bridge the gap between static slicing and dynamic slicing. Here the slice is conditioned by knowledge about the condition in which the program is to be executed. Researchers have extended the language features represented by SDG in order to calculate the slices of object-oriented programs. Zhao [8] has also developed multithreaded dependence graph (MDG) for concurrent Java programs. Lallchandani and Mall [7] have also developed an object oriented concurrent program dependence graph (OOCPDG) as an intermediate representation for slicing of concurrent object-oriented programs. However, no existing technique addresses the problem of slicing inter-procedural programs which are generic in nature. Genericity is the parametric polymorphism [1] where the data types of the parameters passed in the procedure are known at the time of procedure call only. To the best of our knowledge so far, there is no research paper that discusses about slicing of generic programs.

Abstract— This paper proposes a novel static slicing technique for object-oriented programs which are generic in nature. Many algorithms have been proposed so far for objectoriented programs. There are also few algorithms which describe slicing of inter-procedural object-oriented programs. But till date there is no algorithm proposed so far for slicing of object-oriented programs which are generic in nature. In this paper we describe an algorithm for slicing of inter-procedural generic program written in C++. But this technique can be applied to any programs which are generic in nature and written in any other languages like Ada, Eiffel, and J2SE etc. Keywords- program slicing; generic programming; program dependence graph; generic system dependence graph; two pass algorithm.

I. INTRODUCTION In 1979, Weiser [14] introduced the concept of “program slicing” for the purpose of debugging of programs. Program slicing is a decomposition technique that extracts the useful program statements relevant to a particular computation. The slicing criterion introduced by Weiser was a pair (n, v), containing a program point n that represents the statement number and a set of variables v. A slice of a program P with respect to a slicing criterion (n, v) is the set of all statements of the program P that might affect the slicing criterion for every possible input to the program. Weiser defined a program slice S as a reduced, executable program obtained from the program P by removing statements such that the remaining part replicates part of the behavior of P. This traditional slicing technique introduced by Weiser is now-a-days called static backward slicing, because we have to compute the slice irrespective of any particular input and backward as we have to consider the flow of control backward while constructing the slice. Depending on the type, slice can be backward or forward. If we take into consideration the run time environment, it can be static slice or dynamic slice. Weiser’s algorithm [14, 15] uses dataflow analysis to compute the slices of programs. Later Ottenstein and Ottenstein [9] developed a graph called program dependence graph (PDG) to track the control flow in a program. Applying two pass algorithm to the graph, they could compute the slices of a program. Horwitz, Reps and Binkley [16] also used the PDG to calculate the slices of a program. But while calculating the slices of inter-procedural programs, they extended the concept of PDG and the modified graph was then called system dependence graph 978-0-7695-3654-5/09 $25.00 © 2009 IEEE DOI 10.1109/ICSPS.2009.165

II. BACKGROUND Generic programming [5] is one of the important feature which has been added to the object- oriented programming languages like C++. Recently J2SE 5.0 [1] version of java has the required feature to support generic programming. Object-oriented programming languages provide basic features such as encapsulation, data binding, inheritance, polymorphism, message-passing etc. So, while slicing object-oriented programs, we have to pay special attention because of the above said object-oriented features. In this paper, we will discuss about slicing of interprocedural programs, written in C++. Generic programming is an approach where generic types are used as parameters in methods so that they work for suitable data types and data structures. Genericity is a feature that helps us to detect type mismatch during compile time which is known as compile time type safety. Genericity represents parametric polymorphism where the data types of the parameters passed in the procedure are known at the time of procedure call only.

570

Authorized licensed use limited to: NATIONAL INSTITUTE OF TECHNOLOGY ROURKELA. Downloaded on July 19, 2009 at 23:57 from IEEE Xplore. Restrictions apply.

III. PROGRAM DEPENDENCE GRAPH

the formal_in, formal_out vertices. The job of the generic edge is that it passes necessary information to the function call about the data type of the parameter passed. In the below example program, we have a function call depending on the if statement or else statement. In the if part we have passed integer parameters and in the else part we have passed floating point parameters. Depending on the function call appropriate parameters will be passed in the function add ( ). So the generic formal parameters “a1” and “b1” will either be integer or float.

Ottenstein and Ottenstein [6, 9] proposed that the PDG can best describe the flow of control in a program, and hence can be an ideal representation for constructing program slices. Horwitz used PDG for slicing of intraprocedural programs, which a modified version of the previous one was proposed by Ottenstein and Ottenstein. The graph was a directed multi-graph. So the graph had more than one edge between two vertices, also the edges could be different kinds. The edges might be control dependence or flow dependence. Hence, this modified version of PDG proposed by Horwitz was more useful for slicing of intra-procedural programs. However, the real world programs don’t consist of just single procedure. There may be a calling procedure and a procedure call inside that procedure. So slicing of inter-procedural programs requires special attention, because there are issues like parameter passing, procedure call. We are also required to associate the formal parameters with the actual parameters. To address this problem, Horwitz [16, 17] proposed a modified graph called System Dependence Graph (SDG). Actually, a SDG is a collection of procedure dependence graphs, one for every individual procedure. A procedure dependence graph represents a procedure in which statements of the procedure are shown by vertices. In a SDG, there are different kinds of edges are used. They can be classified as control dependence edges, data dependence edges, parameter edges, summary edges etc. In the next section, we will explain the use of different edges. Hence by using SDG, we can model an inter-procedural program perfectly. Horwitz also proposed a two passes algorithm to compute precise slices of inter-procedural programs. In this paper, we are going to discuss about slicing of generic programs. We also propose a new graph called Generic System Dependence Graph (GSDG) which is described in the next section.

V. SLICING OF GENERIC PROGRAMS WITH GSDG We will compute the slices of the example program given in the previous discussion by solving the graph reachability problem on the GSDG. Horwitz, Reps, and Binkley have also proposed a two passes algorithm (popularly known as HRB algorithm) to compute slices of inter-procedural programs. The first pass of the interprocedural slicing algorithm traverses backward along all edges except parameter-out edges and mark all vertices reached during the traversal. The second pass traverses backward from all vertices marked during the first pass along all edges except call and parameter-in vertices and marks those reached vertices. The slice is the union of the vertices marked during the pass one and pass two traversal. We have extended our own algorithm by applying the two pass algorithm as described below. However, we have incorporated node marking techniques [4] to compute the slices with respect to the slicing criterion (11, e) in the GSDG in Fig. 1. A node marking algorithm for computing slices: Input: - A GSDG of the corresponding program Output: - A GSDG with some of its nodes marked representing the slices. Algorithm: - Before execution of the program unmark all the nodes of the GSDG. 1. Pass-1: i. Traverse backward on the GSDG i.e. from target to source. Traverse along data flow edges, control flow edges, call edges, summary edges, generic-in edges and parameter-in edges. ii. During the traversal mark those nodes which are reached. 2. Pass-2: i. Traverse backward from target to source through data flow edges, control flow edges, summary edges, generic-out edges and parameter-out edges; but not through parameter-in edges, generic-in edges and the edges traversed in pass-1. ii. Mark all those nodes reached in pass-2. 3. The slices of the program are the union of the vertices marked during pass-1 and pass-2 of the algorithm. The shadowed vertices represent the slices of the generic program for the slicing criterion (11, e).

IV. INTRODUCTION TO GENERIC DEPENDENCE SYSTEM GRAPH (GSDG) The proposed Generic System Dependence Graph (GSDG) is used to model generic inter-procedural programs. It is very similar to the system dependence graph (SDG) proposed by Larson and Harrold [10] for modeling a sequential object-oriented programs. More details about SDG can be found in Horwitz, Reps, and Binkley [16, 17]. In Fig. 1, we have written a simple and sequential generic C++ program by creating a template procedure. The corresponding GSDG is shown for that program. The GSDG is an arc-specified graph which consists of a number of generic procedure dependence graphs each representing a generic method. The generic edges are used to associate the actual parameters in the procedure call with the generic formal parameters in the called procedure. The GSDG is unique in the sense that it has a special edge named generic edge in addition to the parameter binding edges. The generic edges connect the actual_in, actual_out vertices to

571

Authorized licensed use limited to: NATIONAL INSTITUTE OF TECHNOLOGY ROURKELA. Downloaded on July 19, 2009 at 23:57 from IEEE Xplore. Restrictions apply.

#include #include 1. main( ) { int a, b, c; 2. int d=5; 3. float e=0.5; 4. a=1; 5. b=10; 6. c=26; 7. if (c= =25) 8. while((a!=d) && (a0)) 11. add(e,2.5); 12. cout

Suggest Documents