Skip to content

Commit a861615

Browse files
committed
Fix for #176.
Don't consider methods in the call string that don't return streams. We need a trace.
1 parent 0e3f954 commit a861615

File tree

4 files changed

+60
-24
lines changed

4 files changed

+60
-24
lines changed

edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/Stream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ protected InstanceKey computeInstanceKey(Collection<InstanceKey> trackedInstance
444444

445445
for (InstanceKey ik : trackedInstances)
446446
if (instanceKeyCorrespondsWithInstantiationInstruction(ik, instruction,
447-
this.getEnclosingMethodReference(), engine.getCallGraph()))
447+
this.getEnclosingMethodReference(), engine))
448448
return ik;
449449
}
450450

edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/safe/InstructionBasedSolver.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,23 @@
2020
import com.ibm.wala.ssa.SSAInvokeInstruction;
2121

2222
import edu.cuny.hunter.streamrefactoring.core.utils.LoggerNames;
23+
import edu.cuny.hunter.streamrefactoring.core.wala.EclipseProjectAnalysisEngine;
2324

2425
public class InstructionBasedSolver extends TrackingUniqueSolver {
2526

2627
private static final Logger LOGGER = Logger.getLogger(LoggerNames.LOGGER_NAME);
2728

2829
private SSAInvokeInstruction instruction;
2930

31+
private EclipseProjectAnalysisEngine<InstanceKey> engine;
32+
3033
public InstructionBasedSolver(CallGraph cg, PointerAnalysis<?> pointerAnalysis, TypeStateProperty property,
3134
TypeStateOptions options, ILiveObjectAnalysis live, BenignOracle ora, TypeStateMetrics metrics,
3235
IReporter reporter, TraceReporter traceReporter, IMergeFunctionFactory mergeFactory,
33-
SSAInvokeInstruction instruction) {
36+
SSAInvokeInstruction instruction, EclipseProjectAnalysisEngine<InstanceKey> engine) {
3437
super(cg, pointerAnalysis, property, options, live, ora, metrics, reporter, traceReporter, mergeFactory);
3538
this.instruction = instruction;
39+
this.engine = engine;
3640
}
3741

3842
@Override
@@ -46,7 +50,7 @@ protected Collection<InstanceKey> computeTrackedInstances() throws PropertiesExc
4650
LOGGER.info("Examining instance: " + instanceKey);
4751
try {
4852
if (Util.instanceKeyCorrespondsWithInstantiationInstruction(instanceKey, this.getInstruction(), null,
49-
this.getCallGraph()))
53+
this.getEngine()))
5054
ret.add(instanceKey);
5155
} catch (NoApplicationCodeExistsInCallStringsException e) {
5256
LOGGER.log(Level.SEVERE, e, () -> "Encountered NoApplicationCodeExistsInCallStringsException.");
@@ -65,4 +69,8 @@ protected Collection<InstanceKey> computeTrackedInstances() throws PropertiesExc
6569
protected SSAInvokeInstruction getInstruction() {
6670
return this.instruction;
6771
}
72+
73+
protected EclipseProjectAnalysisEngine<InstanceKey> getEngine() {
74+
return this.engine;
75+
}
6876
}

edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/safe/TypestateSolverFactory.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,45 +16,49 @@
1616
import com.ibm.wala.escape.ILiveObjectAnalysis;
1717
import com.ibm.wala.ipa.callgraph.AnalysisOptions;
1818
import com.ibm.wala.ipa.callgraph.CallGraph;
19+
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
1920
import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis;
2021
import com.ibm.wala.ssa.SSAInvokeInstruction;
2122
import com.ibm.wala.util.CancelException;
2223

24+
import edu.cuny.hunter.streamrefactoring.core.wala.EclipseProjectAnalysisEngine;
25+
2326
public class TypestateSolverFactory extends com.ibm.safe.typestate.core.TypestateSolverFactory {
2427

2528
protected TypestateSolverFactory() {
2629
}
2730

2831
public static TrackingUniqueSolver getSolver(CallGraph cg, PointerAnalysis<?> pointerAnalysis, HeapGraph<?> hg,
2932
TypeStateProperty dfa, BenignOracle ora, TypeStateOptions options, TypeStateMetrics metrics,
30-
IReporter reporter, TraceReporter traceReporter, SSAInvokeInstruction instruction)
31-
throws PropertiesException, CancelException {
33+
IReporter reporter, TraceReporter traceReporter, SSAInvokeInstruction instruction,
34+
EclipseProjectAnalysisEngine<InstanceKey> engine) throws PropertiesException, CancelException {
3235
return getSolver(options.getTypeStateSolverKind(), cg, pointerAnalysis, hg, dfa, ora, options, metrics,
33-
reporter, traceReporter, instruction);
36+
reporter, traceReporter, instruction, engine);
3437
}
3538

3639
public static TrackingUniqueSolver getSolver(TypeStateSolverKind kind, CallGraph cg,
3740
PointerAnalysis<?> pointerAnalysis, HeapGraph<?> hg, TypeStateProperty dfa, BenignOracle ora,
3841
TypeStateOptions options, TypeStateMetrics metrics, IReporter reporter, TraceReporter traceReporter,
39-
SSAInvokeInstruction instruction) throws PropertiesException {
42+
SSAInvokeInstruction instruction, EclipseProjectAnalysisEngine<InstanceKey> engine)
43+
throws PropertiesException {
4044
IMergeFunctionFactory mergeFactory = makeMergeFactory(options, kind);
4145
ILiveObjectAnalysis live = getLiveObjectAnalysis(cg, hg, options);
4246
return new InstructionBasedSolver(cg, pointerAnalysis, dfa, options, live, ora, metrics, reporter,
43-
traceReporter, mergeFactory, instruction);
47+
traceReporter, mergeFactory, instruction, engine);
4448
}
4549

46-
public static ISafeSolver getSolver(AnalysisOptions domoOptions, CallGraph cg,
47-
PointerAnalysis<?> pointerAnalysis, HeapGraph<?> hg, TypeStateProperty dfa, BenignOracle ora,
48-
TypeStateOptions options, TypeStateMetrics metrics, IReporter reporter, TraceReporter traceReporter)
50+
public static ISafeSolver getSolver(AnalysisOptions domoOptions, CallGraph cg, PointerAnalysis<?> pointerAnalysis,
51+
HeapGraph<?> hg, TypeStateProperty dfa, BenignOracle ora, TypeStateOptions options,
52+
TypeStateMetrics metrics, IReporter reporter, TraceReporter traceReporter)
4953
throws PropertiesException, CancelException {
5054
IMergeFunctionFactory mergeFactory = makeMergeFactory(options, TypeStateSolverKind.UNIQUE);
5155
ILiveObjectAnalysis live = getLiveObjectAnalysis(cg, hg, options);
52-
return new UniqueSolver(cg, pointerAnalysis, dfa, options, live, ora, metrics, reporter, traceReporter, mergeFactory);
56+
return new UniqueSolver(cg, pointerAnalysis, dfa, options, live, ora, metrics, reporter, traceReporter,
57+
mergeFactory);
5358
}
5459

5560
protected static ILiveObjectAnalysis getLiveObjectAnalysis(CallGraph cg, HeapGraph<?> hg, TypeStateOptions options)
5661
throws PropertiesException {
57-
return options.shouldUseLiveAnalysis()
58-
? TypeStateSolverCreator.computeLiveObjectAnalysis(cg, hg, false) : null;
62+
return options.shouldUseLiveAnalysis() ? TypeStateSolverCreator.computeLiveObjectAnalysis(cg, hg, false) : null;
5963
}
6064
}

edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/safe/Util.java

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.util.logging.Logger;
55

66
import com.ibm.wala.classLoader.CallSiteReference;
7-
import com.ibm.wala.classLoader.IClassLoader;
87
import com.ibm.wala.classLoader.IMethod;
98
import com.ibm.wala.classLoader.NewSiteReference;
109
import com.ibm.wala.ipa.callgraph.CGNode;
@@ -17,10 +16,12 @@
1716
import com.ibm.wala.types.ClassLoaderReference;
1817
import com.ibm.wala.types.MethodReference;
1918
import com.ibm.wala.types.TypeName;
19+
import com.ibm.wala.types.TypeReference;
2020
import com.ibm.wala.util.collections.Pair;
2121
import com.ibm.wala.util.strings.Atom;
2222

2323
import edu.cuny.hunter.streamrefactoring.core.utils.LoggerNames;
24+
import edu.cuny.hunter.streamrefactoring.core.wala.EclipseProjectAnalysisEngine;
2425
import edu.cuny.hunter.streamrefactoring.core.wala.nCFAContextWithReceiversSelector;
2526

2627
public class Util {
@@ -64,11 +65,11 @@ public class Util {
6465
* Iff application code was not found while processing call strings.
6566
*/
6667
public static boolean instanceKeyCorrespondsWithInstantiationInstruction(InstanceKey instanceKey,
67-
SSAInvokeInstruction instruction, MethodReference instructionEnclosingMethod, CallGraph callGraph)
68-
throws NoApplicationCodeExistsInCallStringsException {
68+
SSAInvokeInstruction instruction, MethodReference instructionEnclosingMethod,
69+
EclipseProjectAnalysisEngine<InstanceKey> engine) throws NoApplicationCodeExistsInCallStringsException {
6970
// Creation sites for the instance with the given key in the given call
7071
// graph.
71-
Iterator<Pair<CGNode, NewSiteReference>> creationSites = instanceKey.getCreationSites(callGraph);
72+
Iterator<Pair<CGNode, NewSiteReference>> creationSites = instanceKey.getCreationSites(engine.getCallGraph());
7273

7374
CallSiteReference instructionCallSite = instruction.getCallSite();
7475
LOGGER.fine("instruction call site is: " + instructionCallSite);
@@ -77,6 +78,9 @@ public static boolean instanceKeyCorrespondsWithInstantiationInstruction(Instanc
7778
// indicate that N is too small.
7879
boolean applicationCodeInCallString = false;
7980

81+
// true iff all non-application code in the call strings return streams.
82+
boolean allNonApplicationCodeReturnsStreams = true;
83+
8084
// for each creation site.
8185
while (creationSites.hasNext()) {
8286
Pair<CGNode, NewSiteReference> pair = creationSites.next();
@@ -102,21 +106,40 @@ public static boolean instanceKeyCorrespondsWithInstantiationInstruction(Instanc
102106
IMethod method = methods[i];
103107
LOGGER.fine("Method at " + i + " is: " + method);
104108

109+
ClassLoaderReference callSiteReferenceClassLoaderReference = callSiteReference.getDeclaredTarget()
110+
.getDeclaringClass().getClassLoader();
111+
ClassLoaderReference methodClassLoader = method.getReference().getDeclaringClass().getClassLoader();
112+
105113
// if we haven't encountered application code in the call string yet.
106114
if (!applicationCodeInCallString) {
107115
// get the class loaders.
108-
ClassLoaderReference callSiteReferenceClassLoader = callSiteReference.getDeclaredTarget()
109-
.getDeclaringClass().getClassLoader();
110-
IClassLoader methodClassLoader = method.getDeclaringClass().getClassLoader();
111116

112117
// if either the call site reference class loader or the (enclosing) method
113118
// class loader is of type Application.
114-
if (callSiteReferenceClassLoader.equals(ClassLoaderReference.Application)
119+
if (callSiteReferenceClassLoaderReference.equals(ClassLoaderReference.Application)
115120
|| methodClassLoader.equals(ClassLoaderReference.Application))
116121
// then, we've seen application code.
117122
applicationCodeInCallString = true;
118123
}
119124

125+
// if all non-application code in the call strings return streams.
126+
if (allNonApplicationCodeReturnsStreams) {
127+
// find out if this one does as well.
128+
if (!callSiteReferenceClassLoaderReference.equals(ClassLoaderReference.Application)) {
129+
IMethod target = engine.getClassHierarchy()
130+
.resolveMethod(callSiteReference.getDeclaredTarget());
131+
TypeReference type = edu.cuny.hunter.streamrefactoring.core.analysis.Util
132+
.getEvaluationType(target);
133+
134+
boolean implementsBaseStream = edu.cuny.hunter.streamrefactoring.core.analysis.Util
135+
.implementsBaseStream(type, engine.getClassHierarchy());
136+
137+
if (!implementsBaseStream)
138+
// we found one that doesn't.
139+
allNonApplicationCodeReturnsStreams = false;
140+
}
141+
}
142+
120143
// if the call site reference equals the call site corresponding
121144
// to the creation instruction.
122145
if (callSiteReference.equals(instructionCallSite)
@@ -130,8 +153,9 @@ public static boolean instanceKeyCorrespondsWithInstantiationInstruction(Instanc
130153
LOGGER.fine("No match found. Instance key: " + instanceKey + " does not correspond with instruction: "
131154
+ instruction + ".");
132155

133-
// if we did not encounter application code in the call strings.
134-
if (!applicationCodeInCallString)
156+
// if we did not encounter application code in the call strings and if all
157+
// of the non-application code all return streams.
158+
if (!applicationCodeInCallString && allNonApplicationCodeReturnsStreams)
135159
throw new NoApplicationCodeExistsInCallStringsException(
136160
"Could not find application code in call string while processing instance key: " + instanceKey
137161
+ " and instruction: " + instruction + ". This may indicate that the current value of N ("

0 commit comments

Comments
 (0)