Skip to content

Commit 5a1857f

Browse files
committed
extracted the scheduling into a strategy class
1 parent 9e48fb4 commit 5a1857f

File tree

3 files changed

+144
-7
lines changed

3 files changed

+144
-7
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package soot.jimple.infoflow.solver.fastSolver;
2+
3+
import soot.SootMethod;
4+
import soot.jimple.infoflow.solver.fastSolver.IFDSSolver.ScheduleTarget;
5+
import soot.jimple.toolkits.ide.icfg.BiDiInterproceduralCFG;
6+
7+
/**
8+
* Default implementations for scheduling strategies
9+
*
10+
* @author Steven Arzt
11+
*
12+
*/
13+
public class DefaultSchedulingStrategy<N, D extends FastSolverLinkedNode<D, N>, I extends BiDiInterproceduralCFG<N, SootMethod>> {
14+
15+
protected final IFDSSolver<N, D, I> solver;
16+
17+
public final ISchedulingStrategy<N, D> EACH_EDGE_INDIVIDUALLY = new ISchedulingStrategy<N, D>() {
18+
19+
@Override
20+
public void propagateInitialSeeds(D sourceVal, N target, D targetVal, N relatedCallSite,
21+
boolean isUnbalancedReturn) {
22+
solver.propagate(sourceVal, target, targetVal, relatedCallSite, isUnbalancedReturn,
23+
ScheduleTarget.EXECUTOR);
24+
}
25+
26+
@Override
27+
public void propagateNormalFlow(D sourceVal, N target, D targetVal, N relatedCallSite,
28+
boolean isUnbalancedReturn) {
29+
solver.propagate(sourceVal, target, targetVal, relatedCallSite, isUnbalancedReturn,
30+
ScheduleTarget.EXECUTOR);
31+
}
32+
33+
@Override
34+
public void propagateCallFlow(D sourceVal, N target, D targetVal, N relatedCallSite,
35+
boolean isUnbalancedReturn) {
36+
solver.propagate(sourceVal, target, targetVal, relatedCallSite, isUnbalancedReturn,
37+
ScheduleTarget.EXECUTOR);
38+
}
39+
40+
@Override
41+
public void propagateCallToReturnFlow(D sourceVal, N target, D targetVal, N relatedCallSite,
42+
boolean isUnbalancedReturn) {
43+
solver.propagate(sourceVal, target, targetVal, relatedCallSite, isUnbalancedReturn,
44+
ScheduleTarget.EXECUTOR);
45+
}
46+
47+
@Override
48+
public void propagateReturnFlow(D sourceVal, N target, D targetVal, N relatedCallSite,
49+
boolean isUnbalancedReturn) {
50+
solver.propagate(sourceVal, target, targetVal, relatedCallSite, isUnbalancedReturn,
51+
ScheduleTarget.EXECUTOR);
52+
};
53+
54+
};
55+
56+
public final ISchedulingStrategy<N, D> EACH_METHOD_INDIVIDUALLY = new ISchedulingStrategy<N, D>() {
57+
58+
@Override
59+
public void propagateInitialSeeds(D sourceVal, N target, D targetVal, N relatedCallSite,
60+
boolean isUnbalancedReturn) {
61+
solver.propagate(sourceVal, target, targetVal, relatedCallSite, isUnbalancedReturn,
62+
ScheduleTarget.EXECUTOR);
63+
}
64+
65+
@Override
66+
public void propagateNormalFlow(D sourceVal, N target, D targetVal, N relatedCallSite,
67+
boolean isUnbalancedReturn) {
68+
solver.propagate(sourceVal, target, targetVal, relatedCallSite, isUnbalancedReturn, ScheduleTarget.LOCAL);
69+
}
70+
71+
@Override
72+
public void propagateCallFlow(D sourceVal, N target, D targetVal, N relatedCallSite,
73+
boolean isUnbalancedReturn) {
74+
solver.propagate(sourceVal, target, targetVal, relatedCallSite, isUnbalancedReturn,
75+
ScheduleTarget.EXECUTOR);
76+
}
77+
78+
@Override
79+
public void propagateCallToReturnFlow(D sourceVal, N target, D targetVal, N relatedCallSite,
80+
boolean isUnbalancedReturn) {
81+
solver.propagate(sourceVal, target, targetVal, relatedCallSite, isUnbalancedReturn, ScheduleTarget.LOCAL);
82+
}
83+
84+
@Override
85+
public void propagateReturnFlow(D sourceVal, N target, D targetVal, N relatedCallSite,
86+
boolean isUnbalancedReturn) {
87+
solver.propagate(sourceVal, target, targetVal, relatedCallSite, isUnbalancedReturn,
88+
ScheduleTarget.EXECUTOR);
89+
};
90+
91+
};
92+
93+
/**
94+
* Creates a new instance of the {@link DefaultSchedulingStrategy} class
95+
*
96+
* @param solver The solver on which to schedule the edges
97+
*/
98+
public DefaultSchedulingStrategy(IFDSSolver<N, D, I> solver) {
99+
this.solver = solver;
100+
}
101+
102+
}

soot-infoflow/src/soot/jimple/infoflow/solver/fastSolver/IFDSSolver.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ public enum ScheduleTarget {
141141
private int maxCalleesPerCallSite = 75;
142142
private int maxAbstractionPathLength = 100;
143143

144+
protected ISchedulingStrategy<N, D> schedulingStrategy = new DefaultSchedulingStrategy<N, D, I>(
145+
this).EACH_EDGE_INDIVIDUALLY;
146+
144147
/**
145148
* Creates a solver for the given problem, which caches flow functions and edge
146149
* functions. The solver must then be started by calling {@link #solve()}.
@@ -212,7 +215,7 @@ protected void submitInitialSeeds() {
212215
for (Entry<N, Set<D>> seed : initialSeeds.entrySet()) {
213216
N startPoint = seed.getKey();
214217
for (D val : seed.getValue())
215-
propagate(zeroValue, startPoint, val, null, false, ScheduleTarget.EXECUTOR);
218+
schedulingStrategy.propagateInitialSeeds(zeroValue, startPoint, val, null, false);
216219
addFunction(new PathEdge<N, D>(zeroValue, startPoint, zeroValue));
217220
}
218221
}
@@ -327,7 +330,7 @@ public void accept(SootMethod sCalledProcN) {
327330
// for each callee's start point(s)
328331
for (N sP : startPointsOf) {
329332
// create initial self-loop
330-
propagate(d3, sP, d3, n, false, ScheduleTarget.EXECUTOR); // line 15
333+
schedulingStrategy.propagateCallFlow(d3, sP, d3, n, false); // line 15
331334
}
332335

333336
// register the fact that <sp,d3> has an incoming edge from
@@ -355,7 +358,7 @@ public void accept(SootMethod sCalledProcN) {
355358
if (memoryManager != null)
356359
d3 = memoryManager.handleGeneratedMemoryObject(d2, d3);
357360
if (d3 != null)
358-
propagate(d1, returnSiteN, d3, n, false, ScheduleTarget.EXECUTOR);
361+
schedulingStrategy.propagateCallToReturnFlow(d1, returnSiteN, d3, n, false);
359362
}
360363
}
361364
}
@@ -419,7 +422,7 @@ protected void applyEndSummaryOnCall(final D d1, final N n, final D d2, Collecti
419422
d5p = d2;
420423
break;
421424
}
422-
propagate(d1, retSiteN, d5p, n, false, ScheduleTarget.EXECUTOR);
425+
schedulingStrategy.propagateReturnFlow(d1, retSiteN, d5p, n, false);
423426
}
424427
}
425428
}
@@ -521,7 +524,7 @@ protected void processExit(PathEdge<N, D> edge) {
521524
d5p = predVal;
522525
break;
523526
}
524-
propagate(d4, retSiteC, d5p, c, false, ScheduleTarget.EXECUTOR);
527+
schedulingStrategy.propagateReturnFlow(d4, retSiteC, d5p, c, false);
525528
}
526529
}
527530
}
@@ -546,7 +549,7 @@ protected void processExit(PathEdge<N, D> edge) {
546549
if (memoryManager != null)
547550
d5 = memoryManager.handleGeneratedMemoryObject(d2, d5);
548551
if (d5 != null)
549-
propagate(zeroValue, retSiteC, d5, c, true, ScheduleTarget.EXECUTOR);
552+
schedulingStrategy.propagateReturnFlow(zeroValue, retSiteC, d5, c, true);
550553
}
551554
}
552555
}
@@ -603,7 +606,7 @@ private void processNormalFlow(PathEdge<N, D> edge) {
603606
if (memoryManager != null && d2 != d3)
604607
d3 = memoryManager.handleGeneratedMemoryObject(d2, d3);
605608
if (d3 != null)
606-
propagate(d1, m, d3, null, false, ScheduleTarget.LOCAL);
609+
schedulingStrategy.propagateNormalFlow(d1, m, d3, null, false);
607610
}
608611
}
609612
}
@@ -888,4 +891,13 @@ public void setMaxAbstractionPathLength(int maxAbstractionPathLength) {
888891
this.maxAbstractionPathLength = maxAbstractionPathLength;
889892
}
890893

894+
/**
895+
* Sets the strategy for scheduling edges
896+
*
897+
* @param strategy The strategy for scheduling edges
898+
*/
899+
public void setSchedulingStrategy(ISchedulingStrategy<N, D> strategy) {
900+
this.schedulingStrategy = strategy;
901+
}
902+
891903
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package soot.jimple.infoflow.solver.fastSolver;
2+
3+
/**
4+
* Common interface for all edge scheduling strategies in the solver
5+
*
6+
* @author Steven Arzt
7+
*
8+
*/
9+
public interface ISchedulingStrategy<N, D extends FastSolverLinkedNode<D, N>> {
10+
11+
public void propagateInitialSeeds(D sourceVal, N target, D targetVal, N relatedCallSite,
12+
boolean isUnbalancedReturn);
13+
14+
public void propagateNormalFlow(D sourceVal, N target, D targetVal, N relatedCallSite, boolean isUnbalancedReturn);
15+
16+
public void propagateCallFlow(D sourceVal, N target, D targetVal, N relatedCallSite, boolean isUnbalancedReturn);
17+
18+
public void propagateCallToReturnFlow(D sourceVal, N target, D targetVal, N relatedCallSite,
19+
boolean isUnbalancedReturn);
20+
21+
public void propagateReturnFlow(D sourceVal, N target, D targetVal, N relatedCallSite, boolean isUnbalancedReturn);
22+
23+
}

0 commit comments

Comments
 (0)