resess / Slicer4J

Slicer4J is an accurate, low-overhead dynamic slicer for Java programs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Main Class Errors when trying to execute slicer

Lms24 opened this issue · comments

Hello,

first off, thank you very(!) much for your contribution. I am a student at Graz University of Technology and I am currently working on my Master's thesis which deals with test suite reduction. For my approach I need to compute dynamic slices of Java programs and thus I was very happy when I found out that this tool was published just weeks before I started with my project. I'll make sure to cite your publication and give proper credit to you in my thesis!

Unfortunately though, as of now, I cannot seem to get the slicer working. Some words on my environment: I use Archlinux and I tried everything with JDK 11 and 16 but there's no difference in behaviour.

I tried to follow the Readme to produce a dynamic slice of the SliceMe program. For that I conducted the following steps:

  1. mvn -Dmaven.test.skip=true clean install for both, the core and the Slicer4J repo
  2. cd'd to benchmarks/SliceMe and performed a mvn clean install there to get the target/sliceme-1.0.0.jar.

Then I first tried to run the provided python script for Slicer4J:

python3 ../../scripts/slicer4j.py -j target/sliceme-1.0.0.jar -o sliceme_slice/ -b SliceMe:9 -m "SliceMe"

which provided the following output:

Instrumenting the JAR
Instrumented jar is at: /home/lukas/workspace/master-jsr/slicer/slicer4j/benchmarks/SliceMe/sliceme_slice/sliceme-1.0.0_i.jar
Running the instrumented JAR
Running instrumented JAR
------------------------------------
Error: Main Class SliceMe could not be found or loaded
Caused by: java.lang.ClassNotFoundException: SliceMe
------------------------------------
Slicing from line SliceMe:9
Traceback (most recent call last):
  File "/home/lukas/workspace/master-jsr/slicer/slicer4j/benchmarks/SliceMe/../../scripts/slicer4j.py", line 181, in <module>
    main()
  File "/home/lukas/workspace/master-jsr/slicer/slicer4j/benchmarks/SliceMe/../../scripts/slicer4j.py", line 67, in main
    log_file, slice_graph = dynamic_slice(jar_file=jar_file, out_dir=out_dir, backward_criterion=backward_criterion,
  File "/home/lukas/workspace/master-jsr/slicer/slicer4j/benchmarks/SliceMe/../../scripts/slicer4j.py", line 128, in dynamic_slice
    line = sc.split(", ")[0]
UnboundLocalError: local variable 'sc' referenced before assignment

I also tried to run the Slicer4J jar directly as described in the Readme (with the -h option just to verify if the program actually works):

java -cp "../../Slicer4J/target/slicer4j-jar-with-dependencies.jar:Slicer4J/target/lib/*" ca.ubc.ece.resess.slicer.dynamic.slicer4j.Slicer -h

which yielded the following error message:

Error: Main class ca.ubc.ece.resess.slicer.dynamic.slicer4j.Slicer cannot be initialized
Caused by java.lang.NoClassDefFoundError: soot/Type

Please note that I translated parts of the error message from German to English so they might not be a 100% equal to the actual english output.

It could very well be an error on my end but I can run every other Java program correctly on my system.

Anyway, I'd be glad if you could help me. Thanks a lot again.

A further try of executing the benchmarks with python3 run_benchmarks.py yielded the following output:

====================
Benchmark: javaslicer-bench1-intra-procedural
********************
Original exec time (s): 0.08215594291687012
********************
Running Slicer4J
Instrumentation time (s): 0.5224616527557373
Error: Main class Bench could not be found or loaded
Caused by: java.lang.ClassNotFoundException: Bench
Execution time (s): 0.06292152404785156
Traceback (most recent call last):
  File "/home/lukas/workspace/master-jsr/slicer/slicer4j/benchmarks/run_benchmarks.py", line 178, in <module>
    run_slicer4j(project, jar_name, project_arg, "", "", "")
  File "/home/lukas/workspace/master-jsr/slicer/slicer4j/benchmarks/run_benchmarks.py", line 132, in run_slicer4j
    line = sc.split(", ")[0]
AttributeError: 'NoneType' object has no attribute 'split'

Hi, I think that you are trying to run the slicer on Windows.
The script was made for running on Linux, so you have to change ":" by ";" in Java commands.
On the other hand you have to replace the cat and grep invocations for reading log information.

Fortunately, I did this. So I'm attaching another script, for windows,
Regards.

slicer4j.zip

Hi, thanks for the advice. I only tried running the slicer on Linux (ArchLinux), though.

Right, I thought you were on Windows because I had the same error before.

Hi Lukas, thank you for considering using Slicer4J in your work!

java -cp "../../Slicer4J/target/slicer4j-jar-with-dependencies.jar:Slicer4J/target/lib/*" ca.ubc.ece.resess.slicer.dynamic.slicer4j.Slicer -h

For this command, the JVM cannot find the soot.Type class because the class path is not written properly. It should be like this if you are running from SliceMe folder:

java -cp "../../Slicer4J/target/slicer4j-jar-with-dependencies.jar:../../Slicer4J/target/lib/*" ca.ubc.ece.resess.slicer.dynamic.slicer4j.Slicer -h

or this if you run from the main Slicer4J directory

java -cp "Slicer4J/target/slicer4j-jar-with-dependencies.jar:Slicer4J/target/lib/*" ca.ubc.ece.resess.slicer.dynamic.slicer4j.Slicer -h

As for the script not working, I suspect the instrumentation didn't work for some reason, it could be related to the location of installation of DynamicSlicingCore, as the script refers to that location to fetch the classes to be injected in the instrumented JAR. The DynamicSlicingCore should be installed in the parent directory of Slicer4J:

| - DynamicSlicingCore 
|      |----- core
|      |----- DynamicSlicingLoggingClasses
| - Slicer4J
|     |-----Slicer4J
|     |-----scripts
. . .

Please let me know if that's your directory structure and the script is still not working.

Hello Khaled,

thank you for your reply. I finally managed to execute the SLicer4J by using the python script. Also, runBenchmarks.py works now (except for the 3 projects that are actually not in the repo but I assume rather some sort of symlink to the project).

It seems like my mistake was to rename the top level directories DymanicSlicingCore and Slicer4J. Pulling the newest changes, restoring the folder structure as described in your post and rebuilding everything fixed the issues.

Thank you for your hints. I'll be sure to cite you correctly if I'm able to integrate this tool into my project.