Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main Class Errors when trying to execute slicer #6

Closed
Lms24 opened this issue Aug 12, 2021 · 6 comments
Closed

Main Class Errors when trying to execute slicer #6

Lms24 opened this issue Aug 12, 2021 · 6 comments
Assignees
Labels
question Further information is requested

Comments

@Lms24
Copy link

Lms24 commented Aug 12, 2021

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.

@Lms24 Lms24 changed the title Error when trying to execute slicer Main Class Errors when trying to execute slicer Aug 12, 2021
@Lms24
Copy link
Author

Lms24 commented Aug 12, 2021

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'

@asoifer
Copy link

asoifer commented Aug 12, 2021

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

@Lms24
Copy link
Author

Lms24 commented Aug 12, 2021

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

@asoifer
Copy link

asoifer commented Aug 12, 2021

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

@khaled-e-a khaled-e-a self-assigned this Aug 12, 2021
@khaled-e-a
Copy link
Collaborator

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.

@khaled-e-a khaled-e-a added the question Further information is requested label Aug 12, 2021
@Lms24
Copy link
Author

Lms24 commented Aug 15, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants