Backward slice generation for a java file

655 views Asked by At

I have a java file and I want to get all the lines that have impact on result of a specific line (Backward Slice Generation). I know the solution but is there any java code to do that?

as an example cosider the following code:

System.out.println("Start")
Random r = new Random();
int i = r.nextInt(10);
int n = 0;
if(i<8)
{
    n = 1;
    System.out.println("In if");
}
int j = n * i;

I need a code that find the following lines when I run it for line 10:

Random r = new Random();
int i = r.nextInt(10);
int n = 0;
if(i<8)
{
    n = 1;
}
int j = n * i;
1

There are 1 answers

0
d-ell On

It seems that there are more academic papers discussing the theoretical approach than there are actual implementations. (Especially in Java)

You could try one of the following options:

Analyzing singlethreaded programs:

Java Slicer from hammacher(@github). As far as I remember, it gives you a java bytecode slice after you have created a trace out of your program.

Also look at IBM Wala Slicer.

Analyzing multithreaded programs:

The problem is that complexity rises especially when analyzing multithreaded programs. I think the only one currently supporting this is the Indus project. They also provide an eclipse plugin, called Kaveri, but you had to use it with Eclipse 3.1.2

However, your code has to be compliant with Java 2(J2SE 1.4.2). see Java Support