This commit is contained in:
Julian Dolby 2017-05-08 08:45:02 -04:00
commit ba743ef19c
41 changed files with 140 additions and 91 deletions

1
.gitignore vendored
View File

@ -42,3 +42,4 @@ com.ibm.wala.dalvik.test/data/sample.cup
com.ibm.wala.dalvik.test/parser.java
com.ibm.wala.dalvik.test/report
com.ibm.wala.dalvik.test/sym.java
results

View File

@ -2,3 +2,4 @@ source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
javacProjectSettings = true

View File

@ -2,3 +2,4 @@ source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
javacProjectSettings = true

View File

@ -47,7 +47,7 @@ public class AstJavaModRef<T extends InstanceKey> extends AstModRef<T> {
}
@Override
protected RefVisitor makeRefVisitor(CGNode n, Collection<PointerKey> result, PointerAnalysis<T> pa, ExtendedHeapModel h) {
protected RefVisitor<T, ? extends ExtendedHeapModel> makeRefVisitor(CGNode n, Collection<PointerKey> result, PointerAnalysis<T> pa, ExtendedHeapModel h) {
return new AstJavaRefVisitor<>(n, result, pa, h);
}
@ -73,7 +73,7 @@ public class AstJavaModRef<T extends InstanceKey> extends AstModRef<T> {
}
@Override
protected ModVisitor makeModVisitor(CGNode n, Collection<PointerKey> result, PointerAnalysis<T> pa, ExtendedHeapModel h, boolean ignoreAllocHeapDefs) {
protected ModVisitor<T, ? extends ExtendedHeapModel> makeModVisitor(CGNode n, Collection<PointerKey> result, PointerAnalysis<T> pa, ExtendedHeapModel h, boolean ignoreAllocHeapDefs) {
return new AstJavaModVisitor<>(n, result, h, pa);
}

View File

@ -4,4 +4,5 @@ bin.includes = META-INF/,\
.,\
lib/htmlparser-1.4.jar
jars.extra.classpath = lib/htmlparser-1.4.jar
javacProjectSettings = true

View File

@ -2,3 +2,4 @@ source.. = src/,\
testdata/
bin.includes = META-INF/,\
.
javacProjectSettings = true

View File

@ -3,3 +3,4 @@ source.. = src/,\
bin.includes = META-INF/,\
.,\
lib/json-20160212.jar
javacProjectSettings = true

View File

@ -3,3 +3,4 @@ output.. = bin/,\
/com.ibm.wala.cast.js.test.data/examples-src/
bin.includes = META-INF/,\
.
javacProjectSettings = true

View File

@ -4,3 +4,4 @@ bin.includes = META-INF/,\
.,\
lib/rhino-1.7.6.jar
jars.extra.classpath = lib/rhino-1.7.6.jar
javacProjectSettings = true

View File

@ -2,3 +2,4 @@ source.. = harness-src
output.. = bin/
bin.includes = META-INF/,\
.
javacProjectSettings = true

View File

@ -4,3 +4,4 @@ bin.includes = .,\
lib/jericho-html-3.2.jar
source.. = source/,\
dat/
javacProjectSettings = true

View File

@ -99,7 +99,7 @@ public class JavaScriptModRef<T extends InstanceKey> extends AstModRef<T> {
}
@Override
protected RefVisitor makeRefVisitor(CGNode n, Collection<PointerKey> result, PointerAnalysis<T> pa, ExtendedHeapModel h) {
protected RefVisitor<T, ? extends ExtendedHeapModel> makeRefVisitor(CGNode n, Collection<PointerKey> result, PointerAnalysis<T> pa, ExtendedHeapModel h) {
return new JavaScriptRefVisitor<>(n, result, pa, h);
}
@ -168,7 +168,7 @@ public class JavaScriptModRef<T extends InstanceKey> extends AstModRef<T> {
}
@Override
protected ModVisitor makeModVisitor(CGNode n, Collection<PointerKey> result, PointerAnalysis<T> pa, ExtendedHeapModel h, boolean ignoreAllocHeapDefs) {
protected ModVisitor<T, ? extends ExtendedHeapModel> makeModVisitor(CGNode n, Collection<PointerKey> result, PointerAnalysis<T> pa, ExtendedHeapModel h, boolean ignoreAllocHeapDefs) {
return new JavaScriptModVisitor<>(n, result, h, pa);
}
}

View File

@ -2,3 +2,4 @@ source.. = harness-src
output.. = bin/
bin.includes = META-INF/,\
.
javacProjectSettings = true

View File

@ -3,3 +3,4 @@ output.. = bin/
bin.includes = META-INF/,\
lib/commons-io-2.4.jar,\
.
javacProjectSettings = true

View File

@ -90,7 +90,7 @@ public class AstModRef<T extends InstanceKey> extends ModRef<T> {
}
@Override
protected RefVisitor makeRefVisitor(CGNode n, Collection<PointerKey> result, PointerAnalysis<T> pa, ExtendedHeapModel h) {
protected RefVisitor<T, ? extends ExtendedHeapModel> makeRefVisitor(CGNode n, Collection<PointerKey> result, PointerAnalysis<T> pa, ExtendedHeapModel h) {
return new AstRefVisitor<>(n, result, pa, (AstHeapModel)h);
}
@ -150,7 +150,7 @@ public class AstModRef<T extends InstanceKey> extends ModRef<T> {
}
@Override
protected ModVisitor makeModVisitor(CGNode n, Collection<PointerKey> result, PointerAnalysis<T> pa, ExtendedHeapModel h, boolean ignoreAllocHeapDefs) {
protected ModVisitor<T, ? extends ExtendedHeapModel> makeModVisitor(CGNode n, Collection<PointerKey> result, PointerAnalysis<T> pa, ExtendedHeapModel h, boolean ignoreAllocHeapDefs) {
return new AstModVisitor<>(n, result, (AstHeapModel)h, pa);
}

View File

@ -5,3 +5,4 @@ bin.includes = META-INF/,\
.,\
plugin.xml,\
plugin.properties
javacProjectSettings = true

View File

@ -137,7 +137,7 @@ public class SlicerTest {
// compute a data slice
final PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis();
Collection<Statement> computeBackwardSlice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis,
InstanceKey.class, DataDependenceOptions.FULL, ControlDependenceOptions.NONE);
DataDependenceOptions.FULL, ControlDependenceOptions.NONE);
Collection<Statement> slice = computeBackwardSlice;
dumpSlice(slice);
@ -168,7 +168,7 @@ public class SlicerTest {
// compute a data slice
final PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis();
Collection<Statement> computeBackwardSlice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis,
InstanceKey.class, DataDependenceOptions.FULL, ControlDependenceOptions.NONE);
DataDependenceOptions.FULL, ControlDependenceOptions.NONE);
Collection<Statement> slice = computeBackwardSlice;
dumpSlice(slice);
@ -192,7 +192,7 @@ public class SlicerTest {
System.err.println("Statement: " + s);
// compute a data slice
final PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis();
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, InstanceKey.class, DataDependenceOptions.FULL,
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, DataDependenceOptions.FULL,
ControlDependenceOptions.NONE);
dumpSlice(slice);
Assert.assertEquals(slice.toString(), 1, countAllocations(slice));
@ -216,7 +216,7 @@ public class SlicerTest {
System.err.println("Statement: " + s);
// compute a data slice
final PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis();
Collection<Statement> slice = Slicer.computeForwardSlice(s, cg, pointerAnalysis, InstanceKey.class, DataDependenceOptions.FULL,
Collection<Statement> slice = Slicer.computeForwardSlice(s, cg, pointerAnalysis, DataDependenceOptions.FULL,
ControlDependenceOptions.NONE);
dumpSlice(slice);
Assert.assertEquals(slice.toString(), 4, slice.size());
@ -240,7 +240,7 @@ public class SlicerTest {
System.err.println("Statement: " + s);
// compute a data slice
final PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis();
Collection<Statement> slice = Slicer.computeForwardSlice(s, cg, pointerAnalysis, InstanceKey.class,
Collection<Statement> slice = Slicer.computeForwardSlice(s, cg, pointerAnalysis,
DataDependenceOptions.FULL, ControlDependenceOptions.NONE);
dumpSlice(slice);
Assert.assertEquals(slice.toString(), 7, slice.size());
@ -270,7 +270,7 @@ public class SlicerTest {
System.err.println("Statement: " + s);
// compute a data slice
final PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis();
Collection<Statement> slice = Slicer.computeForwardSlice(s, cg, pointerAnalysis, InstanceKey.class,
Collection<Statement> slice = Slicer.computeForwardSlice(s, cg, pointerAnalysis,
DataDependenceOptions.FULL, ControlDependenceOptions.NONE);
dumpSlice(slice);
}
@ -299,12 +299,12 @@ public class SlicerTest {
System.err.println("Statement: " + s);
// compute a backward slice, with data dependence and no exceptional control dependence
final PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis();
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, InstanceKey.class, DataDependenceOptions.FULL,
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, DataDependenceOptions.FULL,
ControlDependenceOptions.NO_EXCEPTIONAL_EDGES);
dumpSlice(slice);
Assert.assertEquals(4, countInvokes(slice));
// should only get 4 statements total when ignoring control dependences completely
slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, InstanceKey.class, DataDependenceOptions.FULL,
slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, DataDependenceOptions.FULL,
ControlDependenceOptions.NONE);
Assert.assertEquals(slice.toString(), 4, slice.size());
}
@ -326,7 +326,7 @@ public class SlicerTest {
System.err.println("Statement: " + s);
// compute a backward slice, with data dependence and no exceptional control dependence
final PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis();
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, InstanceKey.class, DataDependenceOptions.FULL,
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, DataDependenceOptions.FULL,
ControlDependenceOptions.NO_EXCEPTIONAL_EDGES);
//dumpSlice(slice);
Assert.assertEquals(/*slice.toString(), */5, countApplicationNormals(slice));
@ -350,7 +350,7 @@ public class SlicerTest {
System.err.println("Statement: " + s);
// compute a data slice
final PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis();
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, InstanceKey.class, DataDependenceOptions.NONE,
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, DataDependenceOptions.NONE,
ControlDependenceOptions.FULL);
dumpSlice(slice);
Assert.assertEquals(slice.toString(), 2, countConditionals(slice));
@ -374,7 +374,7 @@ public class SlicerTest {
System.err.println("Statement: " + s);
// compute a data slice
final PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis();
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, InstanceKey.class, DataDependenceOptions.NONE,
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, DataDependenceOptions.NONE,
ControlDependenceOptions.FULL);
dumpSlice(slice);
Assert.assertEquals(slice.toString(), 1, countConditionals(slice));
@ -398,7 +398,7 @@ public class SlicerTest {
System.err.println("Statement: " + s);
// compute a data slice
final PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis();
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, InstanceKey.class, DataDependenceOptions.NONE,
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, DataDependenceOptions.NONE,
ControlDependenceOptions.FULL);
dumpSlice(slice);
Assert.assertEquals(slice.toString(), 0, countConditionals(slice));
@ -423,13 +423,13 @@ public class SlicerTest {
// compute a no-data slice
final PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis();
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, InstanceKey.class, DataDependenceOptions.NONE,
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, DataDependenceOptions.NONE,
ControlDependenceOptions.FULL);
dumpSlice(slice);
Assert.assertEquals(0, countConditionals(slice));
// compute a full slice
slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, InstanceKey.class,
slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis,
DataDependenceOptions.FULL, ControlDependenceOptions.FULL);
dumpSlice(slice);
Assert.assertEquals(slice.toString(), 1, countConditionals(slice));
@ -454,7 +454,7 @@ public class SlicerTest {
// compute a no-data slice
final PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis();
Collection<Statement> slice = Slicer.computeForwardSlice(s, cg, pointerAnalysis, InstanceKey.class,
Collection<Statement> slice = Slicer.computeForwardSlice(s, cg, pointerAnalysis,
DataDependenceOptions.NONE, ControlDependenceOptions.NO_EXCEPTIONAL_EDGES);
dumpSlice(slice);
Assert.assertTrue(slice.toString(), slice.size() > 1);
@ -479,7 +479,7 @@ public class SlicerTest {
// compute a no-data slice
final PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis();
Collection<Statement> slice = Slicer.computeForwardSlice(s, cg, pointerAnalysis, InstanceKey.class,
Collection<Statement> slice = Slicer.computeForwardSlice(s, cg, pointerAnalysis,
DataDependenceOptions.NONE, ControlDependenceOptions.NO_EXCEPTIONAL_EDGES);
dumpSlice(slice);
Assert.assertEquals(slice.toString(), 2, countInvokes(slice));
@ -503,7 +503,7 @@ public class SlicerTest {
System.err.println("Statement: " + s);
// compute a data slice
final PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis();
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, InstanceKey.class, DataDependenceOptions.FULL,
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, DataDependenceOptions.FULL,
ControlDependenceOptions.NONE);
dumpSlice(slice);
Assert.assertEquals(slice.toString(), 1, countAllocations(slice));
@ -527,7 +527,7 @@ public class SlicerTest {
System.err.println("Statement: " + s);
// compute a data slice
final PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis();
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, InstanceKey.class, DataDependenceOptions.FULL,
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, DataDependenceOptions.FULL,
ControlDependenceOptions.NONE);
dumpSlice(slice);
Assert.assertEquals(slice.toString(), 2, countAllocations(slice));
@ -552,7 +552,7 @@ public class SlicerTest {
System.err.println("Statement: " + s);
// compute a data slice
final PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis();
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, InstanceKey.class, DataDependenceOptions.FULL,
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, DataDependenceOptions.FULL,
ControlDependenceOptions.NONE);
dumpSlice(slice);
Assert.assertEquals(slice.toString(), 2, countAllocations(slice));
@ -579,7 +579,7 @@ public class SlicerTest {
// compute normal data slice
// compute a data slice
final PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis();
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, InstanceKey.class, DataDependenceOptions.FULL,
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, DataDependenceOptions.FULL,
ControlDependenceOptions.NONE);
dumpSlice(slice);
Assert.assertEquals(3, countAllocations(slice));
@ -587,7 +587,7 @@ public class SlicerTest {
// compute thin slice .. ignore base pointers
Collection<Statement> computeBackwardSlice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis,
InstanceKey.class, DataDependenceOptions.NO_BASE_PTRS, ControlDependenceOptions.NONE);
DataDependenceOptions.NO_BASE_PTRS, ControlDependenceOptions.NONE);
slice = computeBackwardSlice;
dumpSlice(slice);
Assert.assertEquals(slice.toString(), 2, countAllocations(slice));
@ -612,7 +612,7 @@ public class SlicerTest {
System.err.println("Statement: " + s);
// compute a data slice
final PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis();
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, InstanceKey.class, DataDependenceOptions.FULL,
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, DataDependenceOptions.FULL,
ControlDependenceOptions.NONE);
dumpSlice(slice);
Assert.assertEquals(slice.toString(), 1, countAllocations(slice));
@ -638,7 +638,7 @@ public class SlicerTest {
System.err.println("Statement: " + s);
// compute a data slice
final PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis();
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, InstanceKey.class, DataDependenceOptions.FULL,
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, DataDependenceOptions.FULL,
ControlDependenceOptions.NONE);
dumpSlice(slice);
Assert.assertEquals(slice.toString(), 2, countAllocations(slice));
@ -663,7 +663,7 @@ public class SlicerTest {
// compute a data slice
final PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis();
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, InstanceKey.class, DataDependenceOptions.FULL,
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, DataDependenceOptions.FULL,
ControlDependenceOptions.NONE);
dumpSlice(slice);
Assert.assertEquals(slice.toString(), 3, countAllocations(slice));
@ -691,7 +691,7 @@ public class SlicerTest {
// compute full slice
final PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis();
Collection<Statement> slice = Slicer.computeBackwardSlice(s, pcg, pointerAnalysis, InstanceKey.class,
Collection<Statement> slice = Slicer.computeBackwardSlice(s, pcg, pointerAnalysis,
DataDependenceOptions.FULL, ControlDependenceOptions.FULL);
dumpSlice(slice);
Assert.assertEquals(slice.toString(), 0, countAllocations(slice));
@ -733,7 +733,7 @@ public class SlicerTest {
System.err.println("Statement: " + s);
final PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis();
Collection<Statement> slice = Slicer.computeBackwardSlice(s, pcg, pointerAnalysis, InstanceKey.class,
Collection<Statement> slice = Slicer.computeBackwardSlice(s, pcg, pointerAnalysis,
DataDependenceOptions.FULL, ControlDependenceOptions.NONE);
dumpSlice(slice);
Assert.assertEquals(slice.toString(), 1, countAllocations(slice));
@ -757,7 +757,7 @@ public class SlicerTest {
System.err.println("Statement: " + s);
// compute a data slice
final PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis();
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, InstanceKey.class, DataDependenceOptions.FULL,
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, DataDependenceOptions.FULL,
ControlDependenceOptions.NONE);
dumpSlice(slice);
Assert.assertEquals(slice.toString(), 1, countApplicationAllocations(slice));
@ -824,7 +824,7 @@ public class SlicerTest {
System.err.println("Statement: " + s);
final PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis();
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, InstanceKey.class, DataDependenceOptions.FULL,
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, DataDependenceOptions.FULL,
ControlDependenceOptions.NO_EXCEPTIONAL_EDGES);
dumpSlice(slice);
}

View File

@ -170,13 +170,13 @@ public class PDFSlice {
Collection<Statement> slice = null;
if (goBackward) {
final PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis();
slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, InstanceKey.class, dOptions, cOptions);
slice = Slicer.computeBackwardSlice(s, cg, pointerAnalysis, dOptions, cOptions);
} else {
// for forward slices ... we actually slice from the return value of
// calls.
s = getReturnStatementForCall(s);
final PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis();
slice = Slicer.computeForwardSlice(s, cg, pointerAnalysis, InstanceKey.class, dOptions, cOptions);
slice = Slicer.computeForwardSlice(s, cg, pointerAnalysis, dOptions, cOptions);
}
SlicerTest.dumpSlice(slice);

View File

@ -8,3 +8,4 @@ output.. = bin/
source.. = dat/,\
src/,\
lib/
javacProjectSettings = true

View File

@ -271,10 +271,6 @@ public abstract class AbstractAnalysisEngine<I extends InstanceKey> implements A
return heapGraph;
}
public SDG<I> getSDG(Class<I> instanceKeyClass, DataDependenceOptions data, ControlDependenceOptions ctrl) {
return new SDG<I>(getCallGraph(), getPointerAnalysis(), data, ctrl);
}
public SDG<I> getSDG(DataDependenceOptions data, ControlDependenceOptions ctrl) {
return new SDG<I>(getCallGraph(), getPointerAnalysis(), data, ctrl);
}

View File

@ -52,11 +52,11 @@ public class PABasedMemoryAccessMap implements MemoryAccessMap {
private final Map<PointerKey, Set<Statement>> invRef;
public PABasedMemoryAccessMap(CallGraph cg, PointerAnalysis<InstanceKey> pa) {
this(cg, pa, new SDG<InstanceKey>(cg, pa, InstanceKey.class, DataDependenceOptions.NO_BASE_NO_HEAP_NO_EXCEPTIONS, ControlDependenceOptions.NONE));
this(cg, pa, new SDG<InstanceKey>(cg, pa, DataDependenceOptions.NO_BASE_NO_HEAP_NO_EXCEPTIONS, ControlDependenceOptions.NONE));
}
public PABasedMemoryAccessMap(CallGraph cg, PointerAnalysis<InstanceKey> pa, SDG<InstanceKey> sdg) {
this(cg, pa, CISlicer.scanForMod(sdg, pa, true, ModRef.make(InstanceKey.class)), CISlicer.scanForRef(sdg, pa));
this(cg, pa, CISlicer.scanForMod(sdg, pa, true, ModRef.make()), CISlicer.scanForRef(sdg, pa));
}
public PABasedMemoryAccessMap(CallGraph cg, PointerAnalysis<InstanceKey> pa, Map<Statement, Set<PointerKey>> mod,

View File

@ -54,9 +54,16 @@ public class CHACallGraph extends BasicCallGraph<CHAContextInterpreter> {
private final IClassHierarchy cha;
private final AnalysisOptions options;
private final IAnalysisCacheView cache;
/**
* if set to true, do not include call graph edges in classes outside
* the application class loader. This means callbacks from library
* to application will be ignored.
*/
private final boolean applicationOnly;
private boolean isInitialized = false;
private class CHANode extends NodeImpl {
protected CHANode(IMethod method, Context C) {
@ -65,20 +72,17 @@ public class CHACallGraph extends BasicCallGraph<CHAContextInterpreter> {
@Override
public IR getIR() {
assert false;
return null;
return cache.getIR(method);
}
@Override
public DefUse getDU() {
assert false;
return null;
return cache.getDefUse(cache.getIR(method));
}
@Override
public Iterator<NewSiteReference> iterateNewSites() {
assert false;
return null;
return getInterpreter(this).iterateNewSites(this);
}
@Override
@ -100,13 +104,18 @@ public class CHACallGraph extends BasicCallGraph<CHAContextInterpreter> {
public boolean addTarget(CallSiteReference reference, CGNode target) {
return false;
}
}
public CHACallGraph(IClassHierarchy cha) {
this(cha, false);
}
public CHACallGraph(IClassHierarchy cha, boolean applicationOnly) {
this.cha = cha;
this.options = new AnalysisOptions();
this.cache = new AnalysisCacheImpl();
this.applicationOnly = applicationOnly;
setInterpreter(new ContextInsensitiveCHAContextInterpreter());
}
@ -123,7 +132,7 @@ public class CHACallGraph extends BasicCallGraph<CHAContextInterpreter> {
closure();
isInitialized = true;
}
@Override
public IClassHierarchy getClassHierarchy() {
return cha;
@ -141,7 +150,7 @@ public class CHACallGraph extends BasicCallGraph<CHAContextInterpreter> {
}
}
}
@Override
public Set<CGNode> getPossibleTargets(CGNode node, CallSiteReference site) {
return Iterator2Collection.toSet(
@ -150,7 +159,7 @@ public class CHACallGraph extends BasicCallGraph<CHAContextInterpreter> {
getPossibleTargets(site),
new Predicate<IMethod>() {
@Override public boolean test(IMethod o) {
return !o.isAbstract();
return isRelevantMethod(o);
}
}
),
@ -164,7 +173,7 @@ public class CHACallGraph extends BasicCallGraph<CHAContextInterpreter> {
return null;
}
}
}));
}));
}
@Override
@ -174,7 +183,7 @@ public class CHACallGraph extends BasicCallGraph<CHAContextInterpreter> {
@Override
public Iterator<CallSiteReference> getPossibleSites(final CGNode src, final CGNode target) {
return
return
new FilterIterator<CallSiteReference>(getInterpreter(src).iterateCallSites(src),
new Predicate<CallSiteReference>() {
@Override public boolean test(CallSiteReference o) {
@ -182,10 +191,10 @@ public class CHACallGraph extends BasicCallGraph<CHAContextInterpreter> {
}
});
}
private class CHARootNode extends CHANode {
private final Set<CallSiteReference> calls = HashSetFactory.make();
protected CHARootNode(IMethod method, Context C) {
super(method, C);
}
@ -200,7 +209,7 @@ public class CHACallGraph extends BasicCallGraph<CHAContextInterpreter> {
return calls.add(reference);
}
}
@Override
protected CGNode makeFakeRootNode() throws CancelException {
return new CHARootNode(new FakeRootMethod(cha, options, cache), Everywhere.EVERYWHERE);
@ -210,23 +219,23 @@ public class CHACallGraph extends BasicCallGraph<CHAContextInterpreter> {
protected CGNode makeFakeWorldClinitNode() throws CancelException {
return new CHARootNode(new FakeWorldClinitMethod(cha, options, cache), Everywhere.EVERYWHERE);
}
private int clinitPC = 0;
@Override
@SuppressWarnings("deprecation")
public CGNode findOrCreateNode(IMethod method, Context C) throws CancelException {
assert C.equals(Everywhere.EVERYWHERE);
assert !method.isAbstract();
CGNode n = getNode(method, C);
if (n == null) {
assert !isInitialized;
n = makeNewNode(method, C);
IMethod clinit = method.getDeclaringClass().getClassInitializer();
if (clinit != null && getNode(clinit, Everywhere.EVERYWHERE) == null) {
CGNode cln = makeNewNode(clinit, Everywhere.EVERYWHERE);
CGNode cln = makeNewNode(clinit, Everywhere.EVERYWHERE);
CGNode clinits = getFakeWorldClinitNode();
clinits.addTarget(CallSiteReference.make(clinitPC++, clinit.getReference(), IInvokeInstruction.Dispatch.STATIC), cln);
}
@ -235,7 +244,7 @@ public class CHACallGraph extends BasicCallGraph<CHAContextInterpreter> {
}
private Stack<CGNode> newNodes = new Stack<CGNode>();
private void closure() throws CancelException {
while (! newNodes.isEmpty()) {
CGNode n = newNodes.pop();
@ -243,7 +252,7 @@ public class CHACallGraph extends BasicCallGraph<CHAContextInterpreter> {
Iterator<IMethod> methods = getPossibleTargets(sites.next());
while (methods.hasNext()) {
IMethod target = methods.next();
if (!target.isAbstract()) {
if (isRelevantMethod(target)) {
CGNode callee = getNode(target, Everywhere.EVERYWHERE);
if (callee == null) {
callee = findOrCreateNode(target, Everywhere.EVERYWHERE);
@ -257,6 +266,12 @@ public class CHACallGraph extends BasicCallGraph<CHAContextInterpreter> {
}
}
private boolean isRelevantMethod(IMethod target) {
return !target.isAbstract()
&& (!applicationOnly
|| cha.getScope().isApplicationLoader(target.getDeclaringClass().getClassLoader()));
}
private CGNode makeNewNode(IMethod method, Context C) throws CancelException {
CGNode n;
Key k = new Key(method, C);
@ -270,7 +285,7 @@ public class CHACallGraph extends BasicCallGraph<CHAContextInterpreter> {
protected NumberedEdgeManager<CGNode> getEdgeManager() {
return new NumberedEdgeManager<CGNode>() {
private final Map<CGNode, SoftReference<Set<CGNode>>> predecessors = HashMapFactory.make();
private Set<CGNode> getPreds(CGNode n) {
if (predecessors.containsKey(n) && predecessors.get(n).get() != null) {
return predecessors.get(n).get();
@ -285,7 +300,7 @@ public class CHACallGraph extends BasicCallGraph<CHAContextInterpreter> {
return preds;
}
}
@Override
public Iterator<CGNode> getPredNodes(CGNode n) {
return getPreds(n).iterator();
@ -369,7 +384,7 @@ public class CHACallGraph extends BasicCallGraph<CHAContextInterpreter> {
}
return result;
}
};
}

View File

@ -13,6 +13,7 @@ package com.ibm.wala.ipa.callgraph.cha;
import java.util.Iterator;
import com.ibm.wala.classLoader.CallSiteReference;
import com.ibm.wala.classLoader.NewSiteReference;
import com.ibm.wala.ipa.callgraph.CGNode;
public interface CHAContextInterpreter {
@ -27,4 +28,5 @@ public interface CHAContextInterpreter {
*/
public abstract Iterator<CallSiteReference> iterateCallSites(CGNode node);
Iterator<NewSiteReference> iterateNewSites(CGNode node);
}

View File

@ -14,6 +14,7 @@ import java.util.Iterator;
import com.ibm.wala.classLoader.CallSiteReference;
import com.ibm.wala.classLoader.CodeScanner;
import com.ibm.wala.classLoader.NewSiteReference;
import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.shrikeCT.InvalidClassFileException;
import com.ibm.wala.util.debug.Assertions;
@ -39,4 +40,16 @@ public class ContextInsensitiveCHAContextInterpreter implements CHAContextInterp
}
}
@Override
public Iterator<NewSiteReference> iterateNewSites(CGNode node) {
if (node == null) {
throw new IllegalArgumentException("node is null");
}
try {
return CodeScanner.getNewSites(node.getMethod()).iterator();
} catch (InvalidClassFileException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -62,7 +62,7 @@ public class ReflectionHandler {
if (VERBOSE) {
System.err.println("Slice " + st);
}
Collection<Statement> slice = Slicer.computeForwardSlice(st, builder.callGraph, null, null, DataDependenceOptions.REFLECTION, ControlDependenceOptions.NONE);
Collection<Statement> slice = Slicer.computeForwardSlice(st, builder.callGraph, null, DataDependenceOptions.REFLECTION, ControlDependenceOptions.NONE);
if (VERBOSE) {
for (Statement x : slice) {
System.err.println(" " + x);

View File

@ -27,7 +27,7 @@ public class CallString implements ContextItem {
this.methods = new IMethod[] { method };
}
CallString(CallSiteReference site, IMethod method, int length, CallString base) {
protected CallString(CallSiteReference site, IMethod method, int length, CallString base) {
int sitesLength = Math.min(length, base.sites.length + 1);
int methodsLength = Math.min(length, base.methods.length + 1);
sites = new CallSiteReference[sitesLength];

View File

@ -35,7 +35,7 @@ public abstract class CallStringContextSelector implements ContextSelector {
private final Context base;
private CallStringContextPair(CallString cs, Context base) {
public CallStringContextPair(CallString cs, Context base) {
this.cs = cs;
this.base = base;
}
@ -74,7 +74,7 @@ public abstract class CallStringContextSelector implements ContextSelector {
}
};
private final ContextSelector base;
protected final ContextSelector base;
public CallStringContextSelector(ContextSelector base) {
this.base = base;
@ -82,7 +82,7 @@ public abstract class CallStringContextSelector implements ContextSelector {
protected abstract int getLength(CGNode caller, CallSiteReference site, IMethod target);
private CallString getCallString(CGNode caller, CallSiteReference site, IMethod target) {
protected CallString getCallString(CGNode caller, CallSiteReference site, IMethod target) {
int length = getLength(caller, site, target);
if (length > 0) {
if (caller.getContext().get(CALL_STRING) != null) {

View File

@ -44,7 +44,7 @@ import com.ibm.wala.util.intset.OrdinalSet;
*/
public class ModRef<T extends InstanceKey> {
public static <U extends InstanceKey> ModRef<U> make(Class<U> klass) {
public static <U extends InstanceKey> ModRef<U> make() {
return new ModRef<U>();
}
@ -342,9 +342,9 @@ public class ModRef<T extends InstanceKey> {
return makeModVisitor(n, result, pa, h, false);
}
protected ModVisitor makeModVisitor(CGNode n, Collection<PointerKey> result, PointerAnalysis<T> pa, ExtendedHeapModel h,
protected ModVisitor<T, ? extends ExtendedHeapModel> makeModVisitor(CGNode n, Collection<PointerKey> result, PointerAnalysis<T> pa, ExtendedHeapModel h,
boolean ignoreAllocHeapDefs) {
return new ModVisitor<T, ExtendedHeapModel>(n, result, h, pa, ignoreAllocHeapDefs);
return new ModVisitor<>(n, result, h, pa, ignoreAllocHeapDefs);
}
/**
@ -368,8 +368,8 @@ public class ModRef<T extends InstanceKey> {
return hexcl == null ? result : hexcl.filter(result);
}
protected RefVisitor makeRefVisitor(CGNode n, Collection<PointerKey> result, PointerAnalysis<T> pa, ExtendedHeapModel h) {
return new RefVisitor<T, ExtendedHeapModel>(n, result, pa, h);
protected RefVisitor<T, ? extends ExtendedHeapModel> makeRefVisitor(CGNode n, Collection<PointerKey> result, PointerAnalysis<T> pa, ExtendedHeapModel h) {
return new RefVisitor<>(n, result, pa, h);
}
/**

View File

@ -122,8 +122,8 @@ public class SDG<T extends InstanceKey> extends AbstractNumberedGraph<Statement>
*/
private boolean eagerComputed = false;
public SDG(final CallGraph cg, PointerAnalysis<T> pa, Class<T> instanceKeyClass, DataDependenceOptions dOptions, ControlDependenceOptions cOptions) {
this(cg, pa, ModRef.make(instanceKeyClass), dOptions, cOptions, null);
public SDG(final CallGraph cg, PointerAnalysis<T> pa, DataDependenceOptions dOptions, ControlDependenceOptions cOptions) {
this(cg, pa, ModRef.<T>make(), dOptions, cOptions, null);
}
public SDG(final CallGraph cg, PointerAnalysis<T> pa, DataDependenceOptions dOptions, ControlDependenceOptions cOptions) {

View File

@ -131,8 +131,8 @@ public class Slicer {
* @throws CancelException
*/
public static <U extends InstanceKey> Collection<Statement> computeBackwardSlice(Statement s, CallGraph cg, PointerAnalysis<U> pa,
Class<U> instanceKeyClass, DataDependenceOptions dOptions, ControlDependenceOptions cOptions) throws IllegalArgumentException, CancelException {
return computeSlice(new SDG<U>(cg, pa, ModRef.make(instanceKeyClass), dOptions, cOptions), Collections.singleton(s), true);
DataDependenceOptions dOptions, ControlDependenceOptions cOptions) throws IllegalArgumentException, CancelException {
return computeSlice(new SDG<U>(cg, pa, ModRef.<U>make(), dOptions, cOptions), Collections.singleton(s), true);
}
/**
@ -141,9 +141,9 @@ public class Slicer {
* @throws CancelException
*/
public static <U extends InstanceKey> Collection<Statement> computeForwardSlice(Statement s, CallGraph cg,
PointerAnalysis<U> pa, Class<U> instanceKeyClass,
PointerAnalysis<U> pa,
DataDependenceOptions dOptions, ControlDependenceOptions cOptions) throws IllegalArgumentException, CancelException {
return computeSlice(new SDG<U>(cg, pa, ModRef.make(instanceKeyClass), dOptions, cOptions), Collections.singleton(s), false);
return computeSlice(new SDG<U>(cg, pa, ModRef.<U>make(), dOptions, cOptions), Collections.singleton(s), false);
}
/**
@ -229,7 +229,7 @@ public class Slicer {
*/
public static Collection<Statement> computeBackwardSlice(Statement s, CallGraph cg, PointerAnalysis<InstanceKey> pointerAnalysis)
throws IllegalArgumentException, CancelException {
return computeBackwardSlice(s, cg, pointerAnalysis, InstanceKey.class, DataDependenceOptions.FULL, ControlDependenceOptions.FULL);
return computeBackwardSlice(s, cg, pointerAnalysis, DataDependenceOptions.FULL, ControlDependenceOptions.FULL);
}
/**

View File

@ -53,7 +53,7 @@ public class CISlicer {
private final Graph<Statement> depGraph;
public CISlicer(CallGraph cg, PointerAnalysis<InstanceKey> pa, DataDependenceOptions dOptions, ControlDependenceOptions cOptions) {
this(cg, pa, ModRef.make(InstanceKey.class), dOptions, cOptions);
this(cg, pa, ModRef.make(), dOptions, cOptions);
}
public CISlicer(CallGraph cg, PointerAnalysis<InstanceKey> pa, ModRef<InstanceKey> modRef, DataDependenceOptions dOptions, ControlDependenceOptions cOptions)
@ -95,7 +95,7 @@ public class CISlicer {
* Compute the set of pointer keys each statement mods
*/
public static Map<Statement, Set<PointerKey>> scanForMod(SDG<InstanceKey> sdg, PointerAnalysis<InstanceKey> pa) {
return scanForMod(sdg, pa, false, ModRef.make(InstanceKey.class));
return scanForMod(sdg, pa, false, ModRef.make());
}
/**
@ -105,7 +105,7 @@ public class CISlicer {
if (sdg == null) {
throw new IllegalArgumentException("null sdg");
}
return scanForRef(sdg, pa, ModRef.make(InstanceKey.class));
return scanForRef(sdg, pa, ModRef.make());
}
/**

View File

@ -31,7 +31,7 @@ import com.ibm.wala.ipa.slicer.Slicer.DataDependenceOptions;
public class ThinSlicer extends CISlicer {
public ThinSlicer(CallGraph cg, PointerAnalysis<InstanceKey> pa) {
this(cg, pa, ModRef.make(InstanceKey.class));
this(cg, pa, ModRef.make());
}
public ThinSlicer(CallGraph cg, PointerAnalysis<InstanceKey> pa, ModRef<InstanceKey> modRef) {

View File

@ -5,3 +5,4 @@ bin.includes = META-INF/,\
lib/dx.jar
jars.extra.classpath = lib/dx.jar
jre.compilation.profile = JavaSE-1.7
javacProjectSettings = true

View File

@ -4,3 +4,4 @@ output.. = bin/
bin.includes = META-INF/,\
.
jre.compilation.profile = JavaSE-1.7
javacProjectSettings = true

View File

@ -2,3 +2,4 @@ source.. = source/
output.. = bin/
bin.includes = META-INF/,\
.
javacProjectSettings = true

View File

@ -1,3 +1,4 @@
source.. = src/
bin.includes = META-INF/,\
.
javacProjectSettings = true

View File

@ -2,3 +2,4 @@ source.. = source/
output.. = bin/
bin.includes = META-INF/,\
.
javacProjectSettings = true

View File

@ -4,3 +4,4 @@ bin.includes = META-INF/,\
.,\
plugin.xml,\
plugin.properties
javacProjectSettings = true

View File

@ -4,3 +4,4 @@ bin.includes = META-INF/,\
jars.compile.order = .
source.. = src/
output.. = bin/
javacProjectSettings = true

View File

@ -4,3 +4,4 @@ bin.includes = META-INF/,\
jars.compile.order = .
source.. = src/
output.. = bin/
javacProjectSettings = true

View File

@ -3,3 +3,4 @@ bin.includes = META-INF/,\
jars.compile.order = .
source.. = src/
output.. = bin/
javacProjectSettings = true