Skip to content

Commit

Permalink
fix(spgroup#31): extract soot settings to soot wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
barbosamaatheus committed Oct 6, 2021
1 parent bdcd506 commit 4e5c5f6
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 73 deletions.
72 changes: 8 additions & 64 deletions src/main/java/br/unb/cic/analysis/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
import br.unb.cic.diffclass.DiffClass;
import org.apache.commons.cli.*;
import scala.collection.JavaConverters;
import soot.*;
import soot.jimple.spark.SparkTransformer;
import soot.jimple.toolkits.callgraph.CHATransformer;
import soot.Body;
import soot.BodyTransformer;
import soot.PackManager;
import soot.Transform;

import java.io.File;
import java.io.FileWriter;
Expand Down Expand Up @@ -239,73 +240,16 @@ private void runInterproceduralOverrideAssignmentAnalysis(String classpath) {
InterproceduralOverrideAssignment interproceduralOverrideAssignment =
new InterproceduralOverrideAssignment(definition);

List<String> testClasses = Collections.singletonList(classpath);
PackManager.v().getPack("wjtp").add(new Transform("wjtp.analysis", interproceduralOverrideAssignment));

configureSootOptions(testClasses);
configurePhaseOption();

// Scene.v().addBasicClass("java.util.ArrayList",BODIES);
Scene.v().loadNecessaryClasses();

//enableCHACallGraph();
enableSparkCallGraph();
List<String> classes = Collections.singletonList(classpath);
SootWrapper.configureSootOptionsToRunInterproceduralOverrideAssignmentAnalysis(classes);

interproceduralOverrideAssignment.configureEntryPoints();

configurePackages().forEach(p -> PackManager.v().getPack(p).apply());
PackManager.v().getPack("wjtp").add(new Transform("wjtp.analysis", interproceduralOverrideAssignment));
SootWrapper.configurePackagesWithCallGraph().forEach(p -> PackManager.v().getPack(p).apply());

conflicts.addAll(interproceduralOverrideAssignment.getConflicts().stream().map(c -> c.toString()).collect(Collectors.toList()));
}
private static void enableCHACallGraph() {
CHATransformer.v().transform();
}

private void configureSootOptions(List<String> classpath) {
soot.options.Options.v().set_no_bodies_for_excluded(true);
soot.options.Options.v().set_allow_phantom_refs(true);
soot.options.Options.v().set_output_format(soot.options.Options.output_format_jimple);
soot.options.Options.v().set_whole_program(true);
soot.options.Options.v().set_process_dir(classpath);
soot.options.Options.v().set_full_resolver(true);
soot.options.Options.v().set_keep_line_number(true);
soot.options.Options.v().set_prepend_classpath(false);
soot.options.Options.v().set_include(getIncludeList());
}

private void configurePhaseOption() {
//Options.v().setPhaseOption("cg.spark", "on");
//Options.v().setPhaseOption("cg.spark", "verbose:true");
soot.options.Options.v().setPhaseOption("cg.spark", "enabled:true");
soot.options.Options.v().setPhaseOption("jb", "use-original-names:true");
}

private List<String> configurePackages() {
List<String> packages = new ArrayList<String>();
packages.add("cg");
packages.add("wjtp");
return packages;
}

private List<String> getIncludeList() {
//"java.lang.*"
List<String> stringList = new ArrayList<String>(Arrays.asList("java.util.*")); //java.util.HashMap
return stringList;
}

private static void enableSparkCallGraph() {
//Enable Spark
HashMap<String, String> opt = new HashMap<String, String>();
//opt.put("propagator","worklist");
//opt.put("simple-edges-bidirectional","false");
opt.put("on-fly-cg", "true");
//opt.put("set-impl","double");
//opt.put("double-set-old","hybrid");
//opt.put("double-set-new","hybrid");
//opt.put("pre_jimplify", "true");
SparkTransformer.v().transform("", opt);
soot.options.Options.v().setPhaseOption("cg.spark", "enable:true");
}

/*
* After discussing this algorithm with the researchers at
Expand Down
76 changes: 67 additions & 9 deletions src/main/java/br/unb/cic/analysis/SootWrapper.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package br.unb.cic.analysis;

import soot.PhaseOptions;
import soot.Scene;
import soot.jimple.spark.SparkTransformer;
import soot.jimple.toolkits.callgraph.CHATransformer;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
* A fluent API for executing the soot framework
Expand All @@ -22,14 +29,65 @@ public static Builder builder() {
}

public void execute() {
soot.Main.main(new String[] {"-w" // whole program mode
, "-allow-phantom-refs" // allow phantom types
, "-f", "J" // Jimple format
, "-keep-line-number" // keep line numbers
, "-p", "jb", "optimize:false" // disable the optimizer
, "-p", "jb", "use-original-names:true" // enable original names
, "-cp", classPath // soot class path
, classes}); // set of classes
soot.Main.main(new String[]{"-w" // whole program mode
, "-allow-phantom-refs" // allow phantom types
, "-f", "J" // Jimple format
, "-keep-line-number" // keep line numbers
, "-p", "jb", "optimize:false" // disable the optimizer
, "-p", "jb", "use-original-names:true" // enable original names
, "-cp", classPath // soot class path
, classes}); // set of classes
}

private static List<String> getIncludeList() {
//"java.lang.*"
List<String> stringList = new ArrayList<String>(Arrays.asList("java.util.*")); //java.util.HashMap
return stringList;
}

public static void configureSootOptionsToRunInterproceduralOverrideAssignmentAnalysis(List<String> classpath) {
soot.options.Options.v().set_no_bodies_for_excluded(true);
soot.options.Options.v().set_allow_phantom_refs(true);
soot.options.Options.v().set_output_format(soot.options.Options.output_format_jimple);
soot.options.Options.v().set_whole_program(true);
soot.options.Options.v().set_process_dir(classpath);
soot.options.Options.v().set_full_resolver(true);
soot.options.Options.v().set_keep_line_number(true);
soot.options.Options.v().set_prepend_classpath(false);
soot.options.Options.v().set_include(getIncludeList());
//Options.v().setPhaseOption("cg.spark", "on");
//Options.v().setPhaseOption("cg.spark", "verbose:true");
soot.options.Options.v().setPhaseOption("cg.spark", "enabled:true");
soot.options.Options.v().setPhaseOption("jb", "use-original-names:true");

Scene.v().loadNecessaryClasses();

enableSparkCallGraph();
}

public static List<String> configurePackagesWithCallGraph() {
List<String> packages = new ArrayList<String>();
packages.add("cg");
packages.add("wjtp");
return packages;
}

public static void enableSparkCallGraph() {
//Enable Spark
HashMap<String, String> opt = new HashMap<String, String>();
//opt.put("propagator","worklist");
//opt.put("simple-edges-bidirectional","false");
opt.put("on-fly-cg", "true");
//opt.put("set-impl","double");
//opt.put("double-set-old","hybrid");
//opt.put("double-set-new","hybrid");
//opt.put("pre_jimplify", "true");
SparkTransformer.v().transform("", opt);
soot.options.Options.v().setPhaseOption("cg.spark", "enable:true");
}

public static void enableCHACallGraph() {
CHATransformer.v().transform();
}

public static class Builder {
Expand Down

0 comments on commit 4e5c5f6

Please sign in to comment.