From 4e5c5f6872ff1b3b73a2abd38929ff5c527c01ba Mon Sep 17 00:00:00 2001 From: Matheus Barbosa Date: Wed, 6 Oct 2021 16:54:08 -0300 Subject: [PATCH] fix(#31): extract soot settings to soot wrapper --- src/main/java/br/unb/cic/analysis/Main.java | 72 ++---------------- .../java/br/unb/cic/analysis/SootWrapper.java | 76 ++++++++++++++++--- 2 files changed, 75 insertions(+), 73 deletions(-) diff --git a/src/main/java/br/unb/cic/analysis/Main.java b/src/main/java/br/unb/cic/analysis/Main.java index c8ca7e1e..f19ee792 100644 --- a/src/main/java/br/unb/cic/analysis/Main.java +++ b/src/main/java/br/unb/cic/analysis/Main.java @@ -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; @@ -239,73 +240,16 @@ private void runInterproceduralOverrideAssignmentAnalysis(String classpath) { InterproceduralOverrideAssignment interproceduralOverrideAssignment = new InterproceduralOverrideAssignment(definition); - List 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 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 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 configurePackages() { - List packages = new ArrayList(); - packages.add("cg"); - packages.add("wjtp"); - return packages; - } - - private List getIncludeList() { - //"java.lang.*" - List stringList = new ArrayList(Arrays.asList("java.util.*")); //java.util.HashMap - return stringList; - } - - private static void enableSparkCallGraph() { - //Enable Spark - HashMap opt = new HashMap(); - //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 diff --git a/src/main/java/br/unb/cic/analysis/SootWrapper.java b/src/main/java/br/unb/cic/analysis/SootWrapper.java index 33414e78..ae646ea3 100644 --- a/src/main/java/br/unb/cic/analysis/SootWrapper.java +++ b/src/main/java/br/unb/cic/analysis/SootWrapper.java @@ -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 @@ -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 getIncludeList() { + //"java.lang.*" + List stringList = new ArrayList(Arrays.asList("java.util.*")); //java.util.HashMap + return stringList; + } + + public static void configureSootOptionsToRunInterproceduralOverrideAssignmentAnalysis(List 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 configurePackagesWithCallGraph() { + List packages = new ArrayList(); + packages.add("cg"); + packages.add("wjtp"); + return packages; + } + + public static void enableSparkCallGraph() { + //Enable Spark + HashMap opt = new HashMap(); + //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 {