Skip to content

Commit

Permalink
feat(spgroup#31): run only call graph
Browse files Browse the repository at this point in the history
  • Loading branch information
barbosamaatheus committed Aug 11, 2021
1 parent 38b122a commit 29127d4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class InterproceduralOverrideAssignment extends SceneTransformer implemen
private final AbstractMergeConflictDefinition definition;
private final FlowSet<DataFlowAbstraction> left;
private final FlowSet<DataFlowAbstraction> right;
private FlowSet<DataFlowAbstraction> abstraction;

private final Logger logger;

Expand All @@ -38,7 +37,6 @@ public InterproceduralOverrideAssignment(AbstractMergeConflictDefinition definit
this.conflicts = new HashSet<>();
this.left = new ArraySparseSet<>();
this.right = new ArraySparseSet<>();
this.abstraction = new ArraySparseSet<>();
this.traversedMethods = new ArrayList<>();
this.pointsToAnalysis = Scene.v().getPointsToAnalysis();

Expand Down Expand Up @@ -73,19 +71,19 @@ public void configureEntryPoints() {
protected void internalTransform(String s, Map<String, String> map) {

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

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

/*left.forEach(dataFlowAbstraction -> {
/* left.forEach(dataFlowAbstraction -> {
String leftStmt = String.format("%s", "LEFT: " + dataFlowAbstraction.getStmt());
logger.log(Level.INFO, leftStmt);
});
right.forEach(dataFlowAbstraction -> {
String rightStmt = String.format("%s", "RIGHT: " + dataFlowAbstraction.getStmt());
logger.log(Level.INFO, rightStmt);
});*/
}); */
}

/**
Expand All @@ -95,27 +93,26 @@ protected void internalTransform(String s, Map<String, String> map) {
* @param flowChangeTag This parameter identifies whether the unit under analysis is in the flow of any statement already marked.
* Initially it receives the value IN_BETWEEN but changes if the call to the current method (sootMethod) has been marked as SOURCE or SINK.
* The remaining statements of the current method that have no markup will be marked according to the flowChangeTag.
* @return the result of applying the analysis considering the income abstraction (in) and the sootMethod
*/
private FlowSet<DataFlowAbstraction> traverse(FlowSet<DataFlowAbstraction> in, SootMethod sootMethod, Statement.Type flowChangeTag) {
//System.out.println(sootMethod);
if (this.traversedMethods.contains(sootMethod) || sootMethod.isPhantom()) {
return null;
return in;
}

this.traversedMethods.add(sootMethod);

Body body = retrieveActiveBodySafely(sootMethod);

if (body != null) {

body.getUnits().forEach(unit -> {

for (Unit unit : body.getUnits()) {
if (isTagged(flowChangeTag, unit)) {
runAnalysisWithTaggedUnit(in, sootMethod, flowChangeTag, unit);
in = runAnalysisWithTaggedUnit(in, sootMethod, flowChangeTag, unit);
} else {
runAnalysisWithBaseUnit(in, sootMethod, flowChangeTag, unit);
in = runAnalysisWithBaseUnit(in, sootMethod, flowChangeTag, unit);
}
});
}
}

this.traversedMethods.remove(sootMethod);
Expand All @@ -136,8 +133,8 @@ private FlowSet<DataFlowAbstraction> runAnalysisWithTaggedUnit(FlowSet<DataFlowA
}

private FlowSet<DataFlowAbstraction> runAnalysisWithBaseUnit(FlowSet<DataFlowAbstraction> in, SootMethod sootMethod,
Statement.Type flowChangeTag, Unit unit) {
return runAnalysis(in, sootMethod, flowChangeTag, unit, false);
Statement.Type flowChangeTag, Unit unit) {
return runAnalysis(in, sootMethod, flowChangeTag, unit, false);
}

/**
Expand All @@ -163,14 +160,16 @@ private FlowSet<DataFlowAbstraction> runAnalysis(FlowSet<DataFlowAbstraction> in
AssignStmt assignStmt = (AssignStmt) unit;

if (assignStmt.containsInvokeExpr()) {
return executeCallGraph(in.clone(), flowChangeTag, unit);
return executeCallGraph(in, flowChangeTag, unit);
}

if (tagged) {
Statement stmt = getStatementAssociatedWithUnit(sootMethod, unit, flowChangeTag);
// logger.log(Level.INFO, () -> String.format("%s", "stmt: " + stmt.toString()));
separeteAbstraction(in);
gen(in, stmt);
} else {
separeteAbstraction(in);
kill(in, unit);
}

Expand Down Expand Up @@ -198,35 +197,39 @@ In this case, this condition will be executed for the call to the foo() method a
return in;
}

private void separeteAbstraction(FlowSet<DataFlowAbstraction> in) {
in.forEach(item -> {
if (isLefAndRightStatement(item.getStmt())) {
right.add(item);
left.add(item);
} else if (isLeftStatement(item.getStmt())) {
left.add(item);
} else if (isRightStatement(item.getStmt())) {
right.add(item);
}
});
}

private FlowSet<DataFlowAbstraction> executeCallGraph(FlowSet<DataFlowAbstraction> in, Statement.Type flowChangeTag, Unit unit) {
CallGraph callGraph = Scene.v().getCallGraph();
Iterator<Edge> edges = callGraph.edgesOutOf(unit);

List<FlowSet<DataFlowAbstraction>> flowSetList = new ArrayList<FlowSet<DataFlowAbstraction>>();
FlowSet<DataFlowAbstraction> flowSetUnion = new ArraySparseSet<>();
List<FlowSet<DataFlowAbstraction>> flowSetList = new ArrayList<FlowSet<DataFlowAbstraction>>();

while (edges.hasNext()) {
Edge e = edges.next();
Statement stmt = getStatementAssociatedWithUnit(e.getTgt().method(), unit, flowChangeTag);
SootMethod method = e.getTgt().method();
Statement stmt = getStatementAssociatedWithUnit(method, unit, flowChangeTag);

FlowSet<DataFlowAbstraction> traverseResult = traverse(in.clone(), e.getTgt().method(), stmt.getType());
FlowSet<DataFlowAbstraction> traverseResult = traverse(in.clone(), method, stmt.getType());
flowSetList.add(traverseResult);

/* System.out.println("------traverseResult--------");
System.out.println("METHOD: " + e.getTgt().method());
traverseResult.forEach(item -> System.out.println(item.getStmt()));
System.out.println("------traverseResult--------");*/
}

FlowSet<DataFlowAbstraction> flowSetUnion = new ArraySparseSet<>();
flowSetList.forEach(flowSet -> flowSetUnion.union(flowSet));

System.out.println("--------------flowSetUnion--------------");
flowSetUnion.forEach(item -> System.out.println(item.getStmt()));
System.out.println("--------------in--------------");
in.forEach(item -> System.out.println(item.getStmt()));

return flowSetUnion;

}

private boolean isTagged(Statement.Type flowChangeTag, Unit unit) {
Expand Down Expand Up @@ -295,7 +298,8 @@ private void addConflict(Statement left, Statement right) {

private void kill(FlowSet<DataFlowAbstraction> in, Unit unit) {
unit.getDefBoxes().forEach(valueBox -> removeAll(valueBox, in));
//unit.getDefBoxes().forEach(valueBox -> removeAll(valueBox, right));
unit.getDefBoxes().forEach(valueBox -> removeAll(valueBox, left));
unit.getDefBoxes().forEach(valueBox -> removeAll(valueBox, right));
}

private void removeAll(ValueBox valueBox, FlowSet<DataFlowAbstraction> rightOrLeftList) {
Expand Down Expand Up @@ -340,7 +344,8 @@ private String getArrayRefName(ArrayRef arrayRef) {
}

private Statement getStatementAssociatedWithUnit(SootMethod sootMethod, Unit u, Statement.Type flowChangeTag) {
if (isLeftAndRightUnit(u) || isInLeftAndRightStatementFlow(flowChangeTag)) {
if (isLeftAndRightUnit(u) || isInLeftAndRightStatementFlow(flowChangeTag) || isBothUnitOrBothStatementFlow(u,
flowChangeTag)) {
return createStatement(sootMethod, u, Statement.Type.BOTH);
} else if (isLeftUnit(u)) {
return findLeftStatement(u);
Expand All @@ -354,6 +359,15 @@ private Statement getStatementAssociatedWithUnit(SootMethod sootMethod, Unit u,
return createStatement(sootMethod, u, Statement.Type.IN_BETWEEN);
}

private boolean isBothUnitOrBothStatementFlow(Unit u, Statement.Type flowChangeTag) {
if (isRightUnit(u) && isInLeftStatementFlow(flowChangeTag)) {
return true;
} else if (isLeftUnit(u) && isInRightStatementFlow(flowChangeTag)) {
return true;
}
return false;
}

private boolean isLeftUnit(Unit u) {
return definition.getSourceStatements().stream().map(Statement::getUnit).collect(Collectors.toList()).contains(u);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import br.unc.cic.analysis.test.DefinitionFactory;
import br.unc.cic.analysis.test.MarkingClass;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import soot.G;
import soot.PackManager;
Expand Down Expand Up @@ -53,20 +52,21 @@ private List<String> configurePackages() {
}

private List<String> getIncludeList() {
List<String> stringList = new ArrayList<String>(Arrays.asList("java.lang.*", "java.util.*")); //java.util.HashMap
// "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("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"); //
// 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);
}

Expand Down Expand Up @@ -144,15 +144,14 @@ public void containsInvokeExp() {
Assert.assertEquals(1, analysis.getConflicts().size());
}

@Ignore
@Test
public void chainedMethodCallsConflict() {
String sampleClassPath = "br.unb.cic.analysis.samples.ioa.ChainedMethodCallsConflictSample";
AbstractMergeConflictDefinition definition = DefinitionFactory
.definition(sampleClassPath, new int[]{13}, new int[]{12});
InterproceduralOverrideAssignment analysis = new InterproceduralOverrideAssignment(definition);
configureTest(analysis);
Assert.assertEquals(550, analysis.getConflicts().size());
Assert.assertEquals(854, analysis.getConflicts().size());
}

@Test
Expand Down Expand Up @@ -248,26 +247,24 @@ public void localVariablesWithParameterNotConflict() {
Assert.assertEquals(0, analysis.getConflicts().size());
}

@Ignore
@Test
public void additionToArrayConflict() {
String sampleClassPath = "br.unb.cic.analysis.samples.ioa.AdditionToArrayConflictSample";
AbstractMergeConflictDefinition definition = DefinitionFactory
.definition(sampleClassPath, new int[]{11}, new int[]{12});
InterproceduralOverrideAssignment analysis = new InterproceduralOverrideAssignment(definition);
configureTest(analysis);
Assert.assertEquals(57, analysis.getConflicts().size());
Assert.assertEquals(58, analysis.getConflicts().size());
}

@Ignore
@Test
public void hashmapConflict() {
String sampleClassPath = "br.unb.cic.analysis.samples.ioa.HashmapConflictSample";
AbstractMergeConflictDefinition definition = DefinitionFactory
.definition(sampleClassPath, new int[]{11}, new int[]{12});
InterproceduralOverrideAssignment analysis = new InterproceduralOverrideAssignment(definition);
configureTest(analysis);
Assert.assertEquals(511, analysis.getConflicts().size());
Assert.assertEquals(510, analysis.getConflicts().size());
}


Expand Down

0 comments on commit 29127d4

Please sign in to comment.