Skip to content

Commit

Permalink
feat(spgroup#31): add deep limit
Browse files Browse the repository at this point in the history
  • Loading branch information
barbosamaatheus committed Nov 11, 2021
1 parent afd223b commit a2b7355
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/main/java/br/unb/cic/analysis/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ private void runInterproceduralOverrideAssignmentAnalysis(String classpath) {
interproceduralOverrideAssignment.configureEntryPoints();

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

conflicts.addAll(interproceduralOverrideAssignment.getConflicts().stream().map(c -> c.toString()).collect(Collectors.toList()));
}
Expand Down
28 changes: 18 additions & 10 deletions src/main/java/br/unb/cic/analysis/SootWrapper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package br.unb.cic.analysis;

import soot.PackManager;
import soot.Scene;
import soot.jimple.spark.SparkTransformer;
import soot.jimple.toolkits.callgraph.CHATransformer;
Expand Down Expand Up @@ -40,7 +41,7 @@ public void execute() {
}

private static List<String> getIncludeList() {
//"java.lang.*"
//"java.lang.*, java.util.*"
List<String> stringList = new ArrayList<String>(Arrays.asList("java.util.*")); //java.util.HashMap
return stringList;
}
Expand All @@ -63,16 +64,10 @@ public static void configureSootOptionsToRunInterproceduralOverrideAssignmentAna
Scene.v().loadNecessaryClasses();

enableSparkCallGraph();
//enableCHACallGraph();
}

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

public static void enableSparkCallGraph() {
private static void enableSparkCallGraph() {
//Enable Spark
HashMap<String, String> opt = new HashMap<String, String>();
//opt.put("propagator","worklist");
Expand All @@ -86,10 +81,23 @@ public static void enableSparkCallGraph() {
soot.options.Options.v().setPhaseOption("cg.spark", "enable:true");
}

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

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

public static void applyPackages() {
configurePackagesWithCallGraph().forEach(p -> {
PackManager.v().getPack(p).apply();
});
}

public static class Builder {
private String classPath;
private String classes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,20 @@ public Set<Conflict> getConflicts() {
return conflicts;
}

public void configureEntryPoints() {
definition.loadSourceStatements();
definition.loadSinkStatements();

List<SootMethod> entryPoints = new ArrayList<>();
definition.getSourceStatements().forEach(s -> {
if (!entryPoints.contains(s.getSootMethod())) {
entryPoints.add(s.getSootMethod());
}
});
Scene.v().setEntryPoints(entryPoints);
}

@Override
protected void internalTransform(String s, Map<String, String> map) {
long tempoInicial = System.currentTimeMillis();

List<SootMethod> methods = Scene.v().getEntryPoints();
methods.forEach(sootMethod -> traverse(new ArraySparseSet<>(), sootMethod, Statement.Type.IN_BETWEEN));

Set<Conflict> conflictsFilter = filterConflicts(getConflicts());
conflictsFilter.forEach(conflict -> logger.log(Level.INFO, conflict.toStringAbstract()));

//logger.log(Level.INFO, () -> String.format("%s", "CONFLICTS: " + conflictsFilter));
logger.log(Level.INFO, () -> String.format("%s", "CONFLICTS: " + conflictsFilter));

long tempoFinal = System.currentTimeMillis();
System.out.println("Tempo de execução de: " + ((tempoFinal - tempoInicial) / 1000d) + "s");

/* left.forEach(dataFlowAbstraction -> {
String leftStmt = String.format("%s", "LEFT: " + dataFlowAbstraction.getStmt());
Expand All @@ -92,18 +83,49 @@ protected void internalTransform(String s, Map<String, String> map) {
}); */
}

public void configureEntryPoints() {
List<SootMethod> entryPoints = new ArrayList<>();

definition.loadSourceStatements();
definition.loadSinkStatements();

SootMethod sm = getTraversedMethod();

if (sm != null) {
entryPoints.add(sm);
} else {
definition.getSourceStatements().forEach(s -> {
if (!entryPoints.contains(s.getSootMethod())) {
entryPoints.add(s.getSootMethod());
}
});
}
Scene.v().setEntryPoints(entryPoints);
}

private SootMethod getTraversedMethod() {
try {
SootClass sootClass = definition.getSourceStatements().get(0).getSootClass();
return sootClass.getMethodByName("callRealisticRun");
} catch (RuntimeException e) {
return null;
}
}

private Set<Conflict> filterConflicts(Set<Conflict> conflictsResults) {
Set<Conflict> conflictsFilter = new HashSet<>();
conflictsResults.forEach(conflict -> {
for (Conflict conflict : conflictsResults) {
if (conflictsFilter.isEmpty()) {
conflictsFilter.add(conflict);
}
conflictsFilter.forEach(filter -> {
}
for (Conflict conflict : conflictsResults) {
for (Conflict filter : conflictsFilter) {
if ((!conflict.getSourceTraversedLine().get(0).equals(filter.getSourceTraversedLine().get(0))) && (!conflict.getSinkTraversedLine().get(0).equals(filter.getSinkTraversedLine().get(0)))) {
conflictsFilter.add(conflict);
}
});
});
}
}
return conflictsFilter;
}

Expand All @@ -118,11 +140,12 @@ private Set<Conflict> filterConflicts(Set<Conflict> conflictsResults) {
*/
private FlowSet<DataFlowAbstraction> traverse(FlowSet<DataFlowAbstraction> in, SootMethod sootMethod,
Statement.Type flowChangeTag) {
//System.out.println(sootMethod);
if (this.traversedMethods.contains(sootMethod) || sootMethod.isPhantom()) {

if (this.traversedMethods.contains(sootMethod) || this.traversedMethods.size() > 10 || sootMethod.isPhantom()) {
return in;
}

System.out.println(sootMethod + " - " + this.traversedMethods.size());
this.traversedMethods.add(sootMethod);

Body body = definition.retrieveActiveBodySafely(sootMethod);
Expand All @@ -146,7 +169,6 @@ private FlowSet<DataFlowAbstraction> traverse(FlowSet<DataFlowAbstraction> in, S
return in;
}


private FlowSet<DataFlowAbstraction> runAnalysisWithTaggedUnit(FlowSet<DataFlowAbstraction> in, SootMethod sootMethod,
Statement.Type flowChangeTag, Unit unit) {
return runAnalysis(in, sootMethod, flowChangeTag, unit, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private void configureTest(InterproceduralOverrideAssignment analysis) {
analysis.configureEntryPoints();

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

try {
exportResults(analysis.getConflicts());
Expand Down Expand Up @@ -69,7 +69,7 @@ private void exportResults(Set<Conflict> conflicts) throws Exception {
public void StringArraySample() {
String sampleClassPath = "br.unb.cic.analysis.samples.ioa.StringArraySample";
AbstractMergeConflictDefinition definition = DefinitionFactory
.definition(sampleClassPath, new int[]{11}, new int[]{22});
.definition(sampleClassPath, new int[]{14}, new int[]{25});
InterproceduralOverrideAssignment analysis = new InterproceduralOverrideAssignment(definition);
configureTest(analysis);
Assert.assertEquals(1, analysis.getConflicts().size());
Expand Down

0 comments on commit a2b7355

Please sign in to comment.