Docsity

Precise Dynamic Slicing Algorithms, Study notes of Algorithms and Programming

Toggle sidebar
bg1
Precise Dynamic Slicing Algorithms
Xiangyu Zhang Rajiv Gupta
The University of Arizona
Dept. of Computer Science
Tucson, Arizona 85721
Youtao Zhang
The Univ. of Texas at Dallas
Dept. of Computer Science
Richardson, TX 75083
Abstract
Dynamic slicing algorithms can greatly reduce the de-
bugging effort by focusing the attention of the user on a rele-
vant subset of program statements. In this paper we present
the design and evaluation of three precise dynamic slicing
algorithms called the full preprocessing (FP), no prepro-
cessing (NP) and limited preprocessing (LP) algorithms.
The algorithms differ in the relative timing of construct-
ing the dynamic data dependence graph and its traversal
for computing requested dynamic slices. Our experiments
show that the LP algorithm is a fast and practical precise
slicing algorithm. In fact we show that while precise slices
can be orders of magnitude smaller than imprecise dynamic
slices, for small number of slicing requests, the LP algo-
rithm is faster than an imprecise dynamic slicing algorithm
proposed by Agrawal and Horgan.
1. Introduction
The concept of program slicing was first introduced by
Mark Weiser [10]. He introduced program slicing as a de-
bugging aid and gave the first static slicing algorithm. Since
then a great deal of research has been conducted on static
slicing and an excellent survey of many of the proposed
techniques and tools can be found in [8] and [5]. Other
works on slicing have explored the applications of slicing
in greater depth. Some examples of such works include the
use of slicing in debugging sequential and distributed pro-
grams as well as testing sequential programs [2,6].
It is widely recognized that for programs that make ex-
tensive use of pointers, the highly conservative nature of
data dependency analysis leads to highly imprecise and con-
siderably larger slices. For program debugging, where the
objective of slicing is to reduce the debugging effort by fo-
cusing the attention of the user on the relevant subset of pro-
gram statements, conservatively computed large slices are
Supported by a grant from IBM and National Science Foundation
grants CCR-0220334, CCR-0208756, CCR-0105355, and EIA-0080123
to the University of Arizona.
clearly undesirable. Recognizing the need for accurate slic-
ing, Korel and Laski proposed the idea of dynamic slicing
[7]. The data dependences that are exercised during a pro-
gram execution are captured precisely and saved. Dynamic
slices are constructed upon users requests by traversing the
captured dynamic dependence information. An exception
to this approach is various works on forward computation
of dynamic slices [11, 12] which precompute all dynamic
slices prior to users requests. While no experimental data
is reported in [11, 12], the execution times of this approach
can be expected to be high. Therefore in this paper we take
the standard approach of computing onlythe dynamic slices
requested by the user.
It has been shown that precise dynamic slices can be
considerably smaller than static slices [9, 5]. The data in
Table 1 shows the effectiveness of dynamic slicing. For
each of the benchmark programs, we computed 25 distinct
dynamic slices half way through the program’s execution
(@Midpoint) and another 25 at the end of program’s ex-
ecution (@End). The average (AVG), minimum (MIN) and
maximum (MAX) precise dynamic slice sizes that were ob-
served are given in the precise dynamic slices PDS column.
In addition, the number of distinct statements in the pro-
gram (Static) and the number of distinct statements that are
executed (Executed) are also given. For example, program
126.gcc contains 585491 static instructions and, during
the collection of the execution trace, 170135 of these in-
structions were executed at least once. When 25 precise dy-
namic slices were computed, they had average, minimum
and maximum sizes of 6614, 2, and 11860 instructions re-
spectively. As we can see, the PDS values are much smaller
that the Static and Executed values. Thus, dynamic slices
greatly help in focusing the attention of the user to a small
subset of statements during debugging.
While precise dynamic slices can be very useful, it is also
well known that computing them is expensive. Therefore
researchers have proposed imprecise dynamic slicing algo-
rithms that trade-off precision of dynamic slicing with the
costs of computing dynamic slicing. However, while such
algorithms have the potential of reducing the cost of slicing,
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Precise Dynamic Slicing Algorithms and more Study notes Algorithms and Programming in PDF only on Docsity!

Precise Dynamic Slicing Algorithms

Xiangyu Zhang Rajiv Gupta

The University of Arizona

Dept. of Computer Science

Tucson, Arizona 85721

Youtao Zhang

The Univ. of Texas at Dallas

Dept. of Computer Science

Richardson, TX 75083

Abstract

Dynamic slicing algorithms can greatly reduce the de- bugging effort by focusing the attention of the user on a rele- vant subset of program statements. In this paper we present the design and evaluation of three precise dynamic slicing algorithms called the full preprocessing (FP), no prepro- cessing (NP) and limited preprocessing (LP) algorithms. The algorithms differ in the relative timing of construct- ing the dynamic data dependence graph and its traversal for computing requested dynamic slices. Our experiments show that the LP algorithm is a fast and practical precise slicing algorithm. In fact we show that while precise slices can be orders of magnitude smaller than imprecise dynamic slices, for small number of slicing requests, the LP algo- rithm is faster than an imprecise dynamic slicing algorithm proposed by Agrawal and Horgan.

1. Introduction

The concept of program slicing was first introduced by Mark Weiser [10]. He introduced program slicing as a de- bugging aid and gave the first static slicing algorithm. Since then a great deal of research has been conducted on static slicing and an excellent survey of many of the proposed techniques and tools can be found in [8] and [5]. Other works on slicing have explored the applications of slicing in greater depth. Some examples of such works include the use of slicing in debugging sequential and distributed pro- grams as well as testing sequential programs [2, 6]. It is widely recognized that for programs that make ex- tensive use of pointers, the highly conservative nature of data dependency analysis leads to highly imprecise and con- siderably larger slices. For program debugging, where the objective of slicing is to reduce the debugging effort by fo- cusing the attention of the user on the relevant subset of pro- gram statements, conservatively computed large slices are  Supported by a grant from IBM and National Science Foundation grants CCR-0220334, CCR-0208756, CCR-0105355, and EIA- to the University of Arizona.

clearly undesirable. Recognizing the need for accurate slic- ing, Korel and Laski proposed the idea of dynamic slicing [7]. The data dependences that are exercised during a pro- gram execution are captured precisely and saved. Dynamic slices are constructed upon users requests by traversing the captured dynamic dependence information. An exception to this approach is various works on forward computation of dynamic slices [11, 12] which precompute all dynamic slices prior to users requests. While no experimental data is reported in [11, 12], the execution times of this approach can be expected to be high. Therefore in this paper we take the standard approach of computing only the dynamic slices requested by the user. It has been shown that precise dynamic slices can be considerably smaller than static slices [9, 5]. The data in Table 1 shows the effectiveness of dynamic slicing. For each of the benchmark programs, we computed 25 distinct dynamic slices half way through the program’s execution (@Midpoint) and another 25 at the end of program’s ex- ecution (@End). The average (AVG), minimum (MIN) and maximum (MAX) precise dynamic slice sizes that were ob- served are given in the precise dynamic slices PDS column. In addition, the number of distinct statements in the pro- gram ( Static ) and the number of distinct statements that are executed ( Executed ) are also given. For example, program 126.gcc contains 585491 static instructions and, during the collection of the execution trace, 170135 of these in- structions were executed at least once. When 25 precise dy- namic slices were computed, they had average, minimum and maximum sizes of 6614, 2, and 11860 instructions re- spectively. As we can see, the PDS values are much smaller that the Static and Executed values. Thus, dynamic slices greatly help in focusing the attention of the user to a small subset of statements during debugging. While precise dynamic slices can be very useful, it is also well known that computing them is expensive. Therefore researchers have proposed imprecise dynamic slicing algo- rithms that trade-off precision of dynamic slicing with the costs of computing dynamic slicing. However, while such algorithms have the potential of reducing the cost of slicing,

Table 1. Effectiveness of Dynamic Slicing. Program Static Instructions PDS IDS-II/PDS IDS-I/PDS Executed AVG MIN MAX AVG MIN MAX AVG MIN MAX 126.gcc @ End 585491 170135 6614 2 11860 2.01 1 5188.25 3.82 1.75 13759. 126.gcc @ Midpoint 585491 144504 2325.8 2 7405 2.69 1 1953.25 6.60 1 4804. 099.go @ End 95459 61350 5382 4 8449 1.20 1 946.30 2.27 1 3328. 099.go @ Midpoint 95459 55538 3560 2 6900 1.43 1 1321.83 2.55 1 5353. 134.perl @ End 116182 21451 765 2 2208 3.43 1 96.15 4.26 1 973. 134.perl @ Midpoint 116182 20934 601 2 2208 3.04 1 813.5 4.80 1 953. 130.li @ End 31829 10958 834 2 834 5.96 1 41.9 12.87 1 667. 130.li @ Midpoint 31829 10429 48 2 584 17.33 1 1036.00 53.40 4.35 1339. 008.espresso @ End 74039 27333 350 2 1304 3.90 1 48.57 5.54 1 1273. 008.espresso @ Midpoint 74039 21027 295 2 1114 3.65 1 300.25 9.78 1 1133. Average 4.46 1 1174.6 10.59 1.41 3358.

they have also been found to greatly increase reported slice sizes thus diminishing their effectiveness. In [3], Atkinson et al. use dynamic points-to data to improve the accuracy of slicing. Unfortunately, their studies indicate that “im- proved precision of points-to data generally did not trans- late into significantly reduced slices”. In [4], Gupta and Soffa proposed hybrid slicing technique which uses limited amounts of control flow information. However, it does not address the imprecision in data dependency computation in presence of pointers. We implemented two imprecise algo- rithms, Algorithm I and Algorithm II , proposed by Agrawal and Horgan [1] and compared the sizes of the imprecise dynamic slices ( IDS-I and IDS-II ) with corresponding pre- cise dynamic slices ( PDS ). The ratios IDS-I/PDS and IDS- II/PDS are given in Table 1. As we can see, imprecise slices can be many times larger than precise dynamic slices. In the worst case, for program gcc, the imprecise dynamic slice IDS-II was over 5188 times larger than the precise dynamic slice. The IDS-I sizes are even larger. Therefore, so far, all attempts to address the cost issue of dynamic slicing have yielded unsatisfactory results. Given the inaccuracy of im- precise slicing algorithms, we conclude that it is worthwhile to spend effort into designing efficient precise dynamic slic- ing algorithms.

We observe that once a program is executed and its exe- cution trace collected, precise dynamic slicing typically in- volves two tasks: [preprocessing] which builds a depen- dence graph by recovering dynamic dependences from the program’s execution trace; and [slicing] which computes slices for given slicing requests by traversing the dynamic dependence graph. We present three precise dynamic slic- ing algorithms that differ in the degree of preprocessing they carry out prior to computing any dynamic slices. The full preprocessing ( FP ) algorithm builds the entire dependence graph before slicing. The no preprocessing ( NP ) does not perform any preprocessing but rather during slicing it uses demand driven analysis for recovering dynamic dependen- cies and caches the recovered dependencies for potential future reuse. Finally the limited preprocessing ( LP ) algo- rithm performs some preprocessing to first augment the ex-

ecution trace with summary information that allows faster traversal of the trace and then during slicing it uses demand driven analysis to recover the dynamic dependences from the compacted execution trace. Our experience with these algorithms shows: The FP algorithm is impractical for real programs be- cause it runs out of memory during the preprocessing phase as the dynamic dependence graphs are extremely large. The NP algorithm does not run out of memory but is slow. The LP algorithm is practical because it never runs out of memory and is also fast. The execution time of the practical LP algorithm com- pares well with that of the imprecise Algorithm II pro- posed by Agrawal and Horgan. The LP algorithm is even faster than Algorithm II if a small number of slices are computed. Also, the latency of computing the first slice using LP is 2.31 to 16.16 times less than the latency for obtaining the first slice by Algorithm II.

Thus, this paper shows that while imprecise dynamic slicing algorithms are too imprecise and therefore not attractive, a carefully designed precise dynamic slicing algorithm such as the LP algorithm is practical as it provides precise dy- namic slices at reasonable space and time costs. The remainder of the paper is organized as follows. In section 2 we present the precise slicing algorithms. In sec- tion 3 we present our experimental studies. Related work is discussed in section 4. Conclusions are given in section 5.

2 Precise Dynamic Slicing

The basic approach to dynamic slicing is to execute the program once and produce an execution trace which is pro- cessed to construct dynamic data dependence graph that in turn is traversed to compute dynamic slices. The execution trace captures the complete runtime in- formation of the program’s execution that can be used by a dynamic slicing algorithm – in other words, there is suf- ficient information in the trace to compute precise dynamic slices. The information that the trace holds is the full control

Note that it is equally easy to compute a dynamic slice at any earlier execution point. For example, let us compute the

slice corresponding to the value of that is used during the

first execution of statement 15. In this case we will follow the data dependence edge from statement 15 to statement 4 that is labeled

; thus giving us the slice that contains statements 4 and 15.

11:x mod 4==

1:bound= 2:b=bound 3:*step= 4:read(x) 5:x< 6:x mod 2==

7:x<b (^) 12:a=

9:a= 10:y=a*x

8:a= 13:y=a*x+

14:z=y+

15:x=x+*step

16:write(z)

T F

F T T (^) F

T F

Function f(int *bound,int *step)v is an int variable call f(&v,&v)

(1,1)

(1,1)

(1,1)(2,2)

(1,1) (2,1)(3,2)

(1,1) (1,1)(2,2)

(1,1)(2,3)

(1,1)(2,1)(3,1)(4,1)

(2,2) (2,1)(3,2)(4,3)

(1,3)

Figure 1. The path taken by the program on input 

         ^ is

. The precise dynamic

slice for use of $ by the only execution of statement

^ is

16,14,13,12,4,15,

.

2.2 No Preprocessing

The FP algorithm first carries out all the preprocessing and then begins slicing. For large programs with long exe- cution runs it is possible that the dynamic dependence graph requires too much space to store and too much time to build. In fact our experiments show that too often we run out of memory since the graphs are too large. For this reason we propose another precise algorithm that does not perform any preprocessing. We refer to this algorithm as the no prepro- cessing (NP) algorithm. In order to avoid a priori preprocessing we employ de- mand driven analysis of the trace to recover dynamic de- pendences. When a slice computation begins we traverse the trace backwards to recover the dynamic dependences required for the slice computation. For example, if we need

the dynamic slice for the value of some variable % at the end

of the program, we traverse the trace backwards till the def-

inition of % is found and include the defining statement in

the dynamic slice. If % is defined in terms of value of an-

other variable & , we resume the traversal of the trace start-

ing from the point where traversal had stopped upon finding

the definition of % and so on. Note that since definitions we

are interested will always appear earlier than the uses, we never need to traverse the same part of the trace twice dur- ing a single slice computation. In essence this algorithm performs partial preprocessing for extracting dynamic dependences relevant to a slicing re- quest as part of the slice computation. It is possible that two different slicing requests involve common dynamic depen- dences. In such a situation, the demand driven algorithm will recover the common dependences from the trace dur- ing both slice computations. To avoid this repetitive work we can cache the recovered dependences. Therefore at any given point in time, all dependences that have been com- puted so far can be found in the cache. Therefore when a dependence is required during a slice computation, the cache is first checked to see if the dependence is already known. If the dependence is cached we can directly access it; otherwise we must recover it from the trace. Thus, at the cost of maintaining a cache, we can avoid repeated recovery of same dependences from the execution trace. We will refer to the two versions of this demand driven algorithm, that is, without caching and with caching, as no preprocessing without caching (NPwoC) and no prepro- cessing with caching (NPwC) algorithms. As an illustration of this algorithm let us reconsider the example of Figure 1. When the NP algorithm is used, ini- tially the flow graph does not contain any dynamic data de-

pendence edges. Now let us say the slice for at the only

execution of statement 16 is computed. This will cause a single backward traversal of the trace through which the data dependence edges

, and

are extracted. When caching is used, in addition to obtaining the slice, these edges are added to the program flow graph. Now if the slice for the

use of in the 3rd instance of statement 14 is computed, all

dependences required are already present in the graph and thus the trace in not reexamined. On the other hand, if the

slice for the use of by the 2nd instance of statement 10 is

requested, the trace is traversed again to extract additional dynamic data dependences.

2.3 Limited Preprocessing

While the NP algorithm described above addresses the space problem of the FP algorithm, this comes at the cost of increased time for slice computations. The time required to traverse a long execution trace is a significant part of the cost of slicing. While the FP algorithm traverses the trace only once for all slicing requests, the NP algorithm often traverses the same part of the trace multiple times, each

Table 2. Benchmark Characteristics Program Lines of Num. of Code Size Instructions Executed Trace Size (Bytes) C Code Funcs (Bytes) (1) (2) (3) (1) (2) (3) 126.gcc 207483 2001 283070464 103156356 112037569 104650291 500000391 500000757 500000215 099.go 29629 372 27512832 117503888 120467852 62271885 500000788 500000747 250000022 134.perl 27044 277 87438967 32729474 55416461 111023934 132807387 250000192 500000438 130.li 7741 357 7964444 122017736 21590453 109323294 581574086 99999705 500000365 008.espresso 14850 361 22432108 1142979 37512537 20203629 4665571 124988145 79512147

time recovering different relevant dependences for a differ- ent slicing request.

In light of the above discussion we can say that NP al- gorithm does too little preprocessing leading to high slic- ing costs while FP algorithm does too much preprocessing leading to space problems. For example, during our exper- iments we found that a run of FP over a trace of around one hundred million instructions for 126.gcc is expected to generate a graph of size five gigabytes. Therefore next we propose an algorithm that strikes a balance between pre- processing and slicing costs. In this precise algorithm we first carry out limited preprocessing of the execution trace aimed at augmenting the trace with summary information that allows faster traversal of the augmented trace. Then we use demand driven analysis to compute the slice using this augmented trace. We refer to this algorithm as the limited preprocessing (LP) algorithm.

This algorithm speeds up trace traversal as follows: the trace is divided into trace blocks such that each trace block is of a fixed size. At the end of each trace block we store a summary of all downward exposed definitions of variable names and memory addresses. During the backward traver- sal for slicing, when looking for a definition of a variable or a memory address, we first look for its presence in the summary of downward exposed definitions. If a definition is found, we traverse the trace block to locate the definition; otherwise using the size information we skip right away to the start of the trace block.

Since the summary information contains only downward exposed definitions, the number of checks performed to lo- cate the definition being sought is smaller when the sum- mary information is used in contrast with using the trace itself. Thus, if the block is skipped, the net effect is fewer comparisons between the address of the variable whose def- inition is being sought and addresses defined within the trace block. On the other hand, if the block is not skipped, more comparisons are needed because both the summary information and the trace block are examined till the def- inition is located. Note that the cost of comparisons, and the size of the summary information, can also be reduced by representing the summary information using bit vectors. Moreover, since the dynamic slices are quite small in com- parison to the trace size, it is expected that many of the tra- versed trace blocks will not contribute to the dynamic slice

and would therefore be skipped after examination of the summary information. Thus, fewer address comparisons will be performed in practice, and even more importantly, the I/O cost during trace traversal will be greatly reduced.

3 Experimental Evaluation

3.1 Implementation

For our experimentation we used the Trimaran system that takes a C program as its input and produces a lower level intermediate representation (IR) which is actually the machine code for an EPIC style architecture. This interme- diate representation is used as the basis for slicing by our implementations of the algorithms. In other words, when slicing is performed, we compute the slices in terms of a set of statements from this IR. Our implementation supports computation of both data slices as well as full slices that are based both upon data and control dependences. However, when computing slices for C programs, the key source of imprecision is the presence of pointers. Therefore in our experiments we focus primarily upon computation of dy- namic data slices. In the low level IR the usage of registers and presence of memory references has been made explicit by the introduc- tion of load and store instructions. An interpreter for the IR is available which is used to execute instrumented versions of the IR for obtaining execution traces consisting of both the control flow trace and memory trace. In our implemen- tation we read the execution trace in blocks and buffer it to reduce the I/O cost. Some of the programs we use make use of longjmps which makes it difficult to keep track of the calling environment when simulating the call stack. We handle this problem by instrumenting the program to ex- plicitly indicate changes in calling environment as part of the trace. This additional information in the trace is used during traversal of the trace. To achieve a fair comparison among the various dynamic slicing algorithms, we have taken great care in implement- ing them. The dynamic slicing algorithms that are imple- mented share code whenever possible and use the same ba- sic libraries.

(^00 1 2 3 4 5 6 7 8) 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26Slices

5000

10000

15000

20000

25000

30000

35000

Cumulative exec time (sec)

126.gcc @ End −−(1)

Algo. II FP *** OoM NPwoC NPwC LP

(^00 1 2 3 4 5 6 7 8) 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26Slices

5000

10000

15000

20000

25000

30000

35000

Cumulative exec time (sec)

126.gcc @ End −−(2)

Algo. II FP *** OoM NPwoC NPwC(didn’t run) LP

(^00 1 2 3 4 5 6 7 8) 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26Slices

5000

10000

15000

20000

25000

30000

35000

40000

45000

Cumulative exec time (sec)

126.gcc @ End −−(3)

Algo. II FP *** OoM NPwoC NPwC(didn’t run) LP

(^00 1 2 3 4 5 6 7 8) 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26Slices

5000

10000

15000

20000

25000

30000

Cumulative exec time (sec)

099.go @ End −−(1) Algo. II FP *** OoM NPwoC NPwC LP

(^00 1 2 3 4 5 6 7 8) 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26Slices

5000

10000

15000

20000

25000

Cumulative exec time (sec)

099.go @ End −−(2) Algo. II FP *** OoM NPwoC NPwC(didn’t run) LP

(^00 1 2 3 4 5 6 7 8) 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26Slices

1000

2000

3000

4000

5000

6000

7000

8000

9000

10000

11000

Cumulative exec time (sec)

099.go @ End −−(3)

Algo. II FP NPwoC NPwC(didn’t run) LP

(^00 1 2 3 4 5 6 7 8) 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26Slices

1000

2000

3000

4000

Cumulative exec time (sec)

134.perl @ End −−(1) Algo. II FP *** OoM NPwoC NPwC LP

(^00 1 2 3 4 5 6 7 8) 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26Slices

100

200

300

400

500

600

700

800

900

1000

Cumulative exec time (sec)

134.perl @ End −−(2)

Algo. II FP *** OoM NPwoC NPwC(didn’t run) LP

(^00 1 2 3 4 5 6 7 8) 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26Slices 100200

300400

500600

700800

(^1000900) 11001200

13001400

15001600

17001800

19002000

21002200

23002400

Cumulative exec time (sec)

134.perl @ End −−(3)

Algo. II FP *** OoM NPwoC NPwC(didn’t run) LP

(^00 1 2 3 4 5 6 7 8) 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26Slices

1000

2000

3000

4000

5000

6000

7000

8000

9000

10000

11000

Cumulative exec time (sec)

130.li @ End −−(1) Algo. II FP *** OoM NPwoC NPwC LP

(^00 1 2 3 4 5 6 7 8) 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26Slices

1000

2000

3000

4000

5000

Cumulative exec time (sec)

130.li @ End −−(2)

Algo. II FP NPwoC NPwC(didn’t run) LP

(^00 1 2 3 4 5 6 7 8) 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26Slices

1000

2000

3000

4000

5000

Cumulative exec time (sec)

130.li @ End −−(3) Algo. II FP *** OoM NPwoC NPwC(didn’t run) LP

(^00 1 2 3 4 5 6 7 8) 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26Slices

10

20

30

40

50

60

70

80

90

100

110

120

Cumulative exec time (sec)

008.espresso @ End −−(1) Algo. II FP NPwoC NPwC LP

(^00 1 2 3 4 5 6 7 8) 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26Slices

1000

2000

3000

4000

Cumulative exec time (sec)

008.espresso @ End −−(2)

Algo. II FP NPwoC NPwC(didn’t run) LP

(^00 1 2 3 4 5 6 7 8) 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26Slices 100200

300400

500600

700800

(^1000900) 11001200

13001400

15001600

17001800

19002000

21002200

Cumulative exec time (sec)

008.espresso @ End −−(3)

Algo. II FP NPwoC NPwC(didn’t run) LP

Figure 2. Execution Times.

than NPwoC. Since the impact of caching was minimal for the first input, we did not run the NPwC version on the other two inputs. When we look at the results of using LP algorithm we find that the limited preprocessing indeed pays off. The LP cumulative execution time rises much more slowly than the NPwoC and NPwC curves. Since limited preprocessing re- quires only a single forward traversal of the trace, its prepro- cessing cost is small in comparison to the savings it provides during slice computations. The execution times of the LP algorithm are 1.13 to 3.43 times less than the NP algorithm for the first input set (see Table 5). This is not surprising when one considers the percentage of trace blocks that are skipped by the LP algorithm (see Table 6). Each trace block consisted of the trace of 200 basic blocks. Varying the trace block size makes little difference as the percentage of trace blocks skipped is quite large.

Table 5. Cumulative times: NP vs LP.

Program 

(1) (2) (3) 126.gcc @ End 1.43 1.833 1. 099.go @ End 1.13 1.31 2. 134.perl @ End 3.19 1.25 1. 130.li @ End 1.95 1.25 1. 008.espresso @ End 2.67 3.43 2. Average 2.07 1.81 1.

Table 6. Trace Blocks Skipped by LP. Program % Blocks Skipped (1) (2) (3) 126.gcc @ End 90.43 97.63 89. 099.go @ End 57.52 65.38 91. 134.perl @ End 92.42 98.99 98. 130.li @ End 99.02 99.51 99. 008.espresso @ End 96.6 97.15 98. Average 87.20 91.73 95.

3.4 LP vs. Imprecise Algorithm II

In this section we compare the performance of our best precise dynamic slicing algorithm, the LP algorithm, with Agrawal and Horgan’s Algorithm II. We do not include data for Algorithm I because as shown by the data presented in Table 1, Algorithm I is extremely imprecise even in com- parison to Algorithm II. Before describing the results it is important to under- stand the differences between the LP algorithm and Algo- rithm II. Both algorithms do not run out of memory and hence solve the problem of large graph sizes. The LP algo- rithm solves this problem by demand-driven construction of relevant part of the precise dynamic dependence graph. Al- gorithm II solves the same problem by constructing an im- precise dynamic dependence graph where the instances of statements among which dependences exist are not remem- bered. This approximation greatly reduces the size of the

graph which is constructed in a single pass over the trace. Thus all the preprocessing is carried out once in the be- ginning and then slices can be computed very quickly by traversing this graph. A question that may arise is whether the performance of Algorithm II can be further improved by applying the demand-driven approach and limited preprocessing used by the LP algorithm. Since the approximate dynamic depen- dence graph constructed by Algorithm II is already small, there is no point in building it in a demand-driven fashion. Moreover, given the approach taken by Algorithm II , the demand-driven construction of the approximate dynamic dependence graph will only further slow down Algorithm II. This is because Algorithm II constructs the complete ap- proximate dynamic dependence graph in a single pass over the trace. If demand-driven approach is used, to extract sub- set of dependences from the trace, the entire trace may have to be traversed for extracting these dependences. Thus, re- peated passes over the trace would have to be carried out to extract different subsets of dependences which will fur- ther slow down Algorithm II. On the other hand, the LP algorithm has to build the precise dependence graph in a demand-driven fashion because the complete graph is too large. Furthermore, since Algorithm II traverses the trace only once, there is no point in augmenting the trace with summary information because such augmentation would also require a complete traversal of the trace.

Slice sizes. The data presented in the introduction already showed that precise dynamic slices are much smaller than the imprecise dynamic slices computed using Algorithm II. In Table 7 similar data for the two additional inputs is given. As we can see, the same observation holds across these ad- ditional inputs. We have already compared the slice sizes of LP and Al- gorithm II. However, since the results of such comparisons are dependent upon the variables for which slicing is per- formed, we also developed a novel slice independent ap- proach for comparing the algorithms by simply comparing the dynamic dependence graphs constructed by them and measuring the imprecision in these dependence graphs that is introduced by Algorithm II. This method is motivated by the fact that the imprecision in dynamic dependence graph constructed by Algorithm II is the root cause of resulting imprecision in the dynamic slices computed by this algo- rithm. The number of dynamic dependences recovered by the precise algorithm is exact. However, when the impre- cise algorithm is used, the imprecision is introduced in the dynamic dependence graph in form of false dependences. Therefore if we compute the equivalent number of dynamic dependences for the imprecise algorithm they will be higher than those for the precise algorithm. The greater the number

Table 9. Preprocessing + Slicing Times: Algo. II vs. LP for Input (1).

Program Algorithm II LP 126.gcc @ End 33014.1 + 11.46 727.82+17556. 126.gcc @ Midpoint 9271.64+ 5.24 347.61+4371. 099.go @ End 12671.8 + 5.37 893.92+24766. 099.go @ Midpoint 6039.56 +3.21 455.17+8582. 134.perl @ End 631.32 + 0.76 190.18+996. 134.perl @ Midpoint 407.83+0.32 94.16+543. 130.li @ End 2725.32 + 3.43 858.08+4493. 130.li @ Midpoint 1747.38+1.89 464.71+2736. 008.espresso @ End 25.15 + 0.11 7.83+33. 008.espresso @ Midpoint 15.39+0.03 3.74+25.

carry out preprocessing. On the other hand, for espresso @ End we can compute around 10 slices using LP algo- rithm in the same amount of time as it takes Algorithm II to carry out preprocessing. We also compared the performance of LP and Algorithm II for the first input trace at execution midpoint (i.e., @ Midpoint). The results are presented in Figure 3. As we can see, at this earlier point in program executions similar observations hold.

4 Related Work

Agrawal and Horgan proposed two imprecise and two precise dynamic slicing algorithms in [1]. We have already compared the performance of our algorithms with the im- precise algorithms in detail. The first precise algorithm they propose, Algorithm III , is quite similar to our FP algo- rithm. The difference is in the dynamic dependence graph representation. While FP labels dependence edges with in- stances, Agrawal and Horgan construct multiple instances of nodes and edges. In practice, we found our representa- tion to be more compact. To reduce the size of the dependence graph, Agrawal and Horgan also proposed another precise algorithm which is Algorithm IV in their paper. Algorithm IV is based upon the idea of forward computation of dynamic slices where slices for all variables can be maintained at all times, and when a statement is executed, the new slice of the vari- able just defined can be computed from the slices of the variables whose values are used in the definition. Algo- rithm IV maintains the current dynamic slices in terms of the dynamic dependence graph. A new node is added to the dynamic dependence graph only if following the execu- tion of a statement the dynamic slice of the defined variable changes. Thus, the size of the graph is bounded by the num- ber of different dynamic slices. As shown in [8], a program of size can have

different dynamic slices. Essentially Algorithm IV precomputes all of the dynamic slices. While this idea results in space savings, the precom- putation time of Algorithm IV can be reasonably assumed to be much higher than the preprocessing time in FP , in

(^00 1 2 3 4 5 6 7 8) 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26Slices

1000

2000

3000

4000

5000

6000

7000

8000

9000

10000

Cumulative exec time (sec)

126.gcc @ Mid −−(1)

Algo. II FP *** OoM NPwoC NPwC(didn’t run) LP

(^00 1 2 3 4 5 6 7 8) 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26Slices

1000

2000

3000

4000

5000

6000

7000

8000

9000

10000

11000

12000

Cumulative exec time (sec)

099.go @ Mid −−(1) Algo. II FP *** OoM NPwoC NPwC(didn’t run) LP

(^00 1 2 3 4 5 6 7 8) 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26Slices

100

200

300

400

500

600

700

800

900

1000

1100

1200

Cumulative exec time (sec)

134.perl @ Mid −−(1) Algo. II FP NPwoC NPwC(didn’t run) LP

(^00 1 2 3 4 5 6 7 8) 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26Slices

1000

2000

3000

4000

5000

6000

7000

8000

9000

10000

Cumulative exec time (sec)

130.li @ Mid −−(1)

Algo. II FP NPwoC NPwC(didn’t run) LP

(^00 1 2 3 4 5 6 7 8) 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26Slices

10

20

30

40

50

60

70

80

Cumulative exec time (sec)

008.espresso @ Mid −−(1) Algo. II FP NPwoC NPwC(didn’t run) LP

Figure 3. Execution Times @Midpoint.

which the direct dependences are merely added as edge la- bels but no slices are computed. Given the fact that LP is faster than FP , it is going to perform even better in compari- son to Algorithm IV. Furthermore, the dynamic dependence graph produced by Algorithm IV can be used only to com- pute dynamic slices for the last definitions of variables. All the algorithms we have developed can be used to compute dynamic slices corresponding to any executed definition of any variable at any program point. In other words, in or- der to produce a compacted graph, Algorithm IV sacrifices some of the functionality of Algorithm III. In [11] another algorithm for forward computation of dy- namic slices was introduced which precomputes and stores all dynamic slices on disk and later accesses to them in re- sponse to users requests. This algorithm saves sufficient information so that dynamic slices at any execution point can be obtained. Like Algorithm IV , it will also take a long time to respond to user’s first request due to the long prepro- cessing time. Some applications of dynamic slicing, such as debugging, may involve only a small number of slicing re- quests. Thus, the large amount of preprocessing performed is not desirable. Our demand driven approach represents a much better choice for such situations. Korel and Yalamanchili [12] introduced another forward method which computes executable dynamic slices. Their method is based on the notion of removable blocks. A dy- namic slice is constructed from the original program by deleting removable blocks. During program execution on each exit from a block, the algorithm determines whether the executed block should be included in a dynamic slice or not. It is reported in [8] that executable dynamic slices produced may be inaccurate in the presence of loops. Finally no experimental data is presented to evaluate the forward computation of dynamic slices in any of the above works [1, 11, 12]. In this paper we have shown that it is important to consider practical design tradeoffs when de- veloping a precise backward slicing algorithm. Any similar issues that may exist in the design of algorithms that per- form forward computation of dynamic slices have yet to be studied by anyone.

5 Conclusions

In this paper we have shown that a careful design of a dynamic slicing can greatly improve its practicality. We de- signed and studied three different precise dynamic slicing algorithms: FP , NP , and LP. We made the use of demand driven analysis (with and without caching) and trace aug- mentation (with trace block summaries) to achieve practical implementations of precise dynamic slicing. We demon- strated that the precise LP algorithm which first performs limited preprocessing to augment the trace and then uses demand driven analysis performs the best. In comparison to

the imprecise Algorithm II it runs faster when a small num- ber of slices are computed. Also, the latency of computing the first slice using LP is 2.31 to 16.16 times less than the latency for obtaining the first slice by Algorithm II. In conclusion this paper shows that while imprecise dy- namic slicing algorithms are too imprecise and therefore not an attractive option, a carefully designed precise dynamic slicing algorithm such as the LP algorithm is practical as it provides precise dynamic slices at reasonable space and time costs.

References

[1] H. Agrawal and J. Horgan, “Dynamic Program Slicing,” ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI), pages 246-256, 1990. [2] H. Agrawal, R. DeMillo, and E. Spafford, “Debugging with Dynamic Slicing and Backtracking,” Software Practice and Ex- perience (SP&E), Vol. 23, No. 6, pages 589-616, 1993. [3] D.C. Atkinson, M. Mock, C. Chambers, and S.J. Eggers, “Pro- gram Slicing Using Dynamic Points-to Data,” ACM SIGSOFT 10th Symposium on the Foundations of Software Engineering (FSE), November 2002. [4] R. Gupta and M.L. Soffa, “Hybrid Slicing: An Approach for Refining Static Slices using Dynamic Information,” ACM SIG- SOFT 3rd Symposium on the Foundations of Software Engi- neering (FSE), pages 29-40, October 1995. [5] T. Hoffner, “Evaluation and Comparison of Program Slicing Tools.” Technical Report , Dept. of Computer and Information Science, Linkoping University, Sweden, 1995. [6] M. Kamkar, “Interprocedural Dynamic Slicing with Applica- tions to Debugging and Testing,” PhD Thesis , Linkoping Uni- versity, 1993. [7] B. Korel and J. Laski, “Dynamic Program Slicing,” Informa- tion Processing Letters (IPL), Vol. 29, No. 3, pages 155-163,

[8] F. Tip, “A Survey of Program Slicing Techniques,” Journal of Programming Languages (JPL), Vol. 3, No. 3, pages 121-189, September 1995. [9] G. Venkatesh, “Experimental Results from Dynamic Slicing of C Programs,” ACM Transactions on Programming Lan- guages and Systems (TOPLAS), Vol. 17, No. 2, pages 197-216,

[10] M. Weiser, “Program Slicing,” IEEE Transactions on Soft- ware Engineering (TSE), Vol. SE-10, No. 4, pages 352-357,

[11] A. Beszedes, T. Gergely, Z.M. Szabo, J. Csirik, and T. Gy- imothy, “Dynamic Slicing Method for Maintenance of Large C Programs,” 5th European Conference on Software Mainte- nance and Reengineering (CSMR), March 2001. [12] B. Korel and S. Yalamanchili. “Forward computation of dy- namic program slices,” International Symposium on Software Testing and Analysis (ISSTA), August 1994