1) change implementation of CGNode hierarchy to avoid type parameters.

2) nuke BasicEntrypoints
3) tweak interface to InstanceKeyFactory for constants
4) refactoring for HeadlessWALA application

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@1227 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
sjfink 2007-06-01 18:50:24 +00:00
parent 00f604ee6f
commit 56f4bec3ea
20 changed files with 221 additions and 287 deletions

View File

@ -8,7 +8,7 @@ Bundle-Vendor: IBM
Bundle-Localization: plugin
Require-Bundle: com.ibm.wala.emf;visibility:=reexport,
com.ibm.wala.shrike;visibility:=reexport,
org.eclipse.core.resources,
org.eclipse.core.resources;visibility:=reexport,
org.eclipse.jface,
org.eclipse.jdt.core;visibility:=reexport
Eclipse-LazyStart: true

View File

@ -1,32 +1,33 @@
package com.ibm.wala.classLoader;
import com.ibm.wala.types.*;
import com.ibm.wala.types.ClassLoaderReference;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.Atom;
public interface Language {
public static Language JAVA = new Language() {
public Atom getName() {
return ClassLoaderReference.Java;
public static Language JAVA = new Language() {
public Atom getName() {
return ClassLoaderReference.Java;
}
public TypeReference getRootType() {
return TypeReference.JavaLangObject;
}
public TypeReference getConstantType(Object o) {
if (o instanceof String) {
return TypeReference.JavaLangString;
} else {
return null;
}
}
};
public TypeReference getRootType() {
return TypeReference.JavaLangObject;
}
Atom getName();
public TypeReference getConstantType(Object o) {
if (o instanceof String) {
return TypeReference.JavaLangString;
} else {
return null;
}
}
};
TypeReference getRootType();
Atom getName();
TypeReference getRootType();
TypeReference getConstantType(Object o);
TypeReference getConstantType(Object o);
}

View File

@ -220,7 +220,6 @@ public class JdtUtil {
IJavaElement[] arr = new IJavaElement[projects.size()];
projects.toArray(arr);
IJavaSearchScope scope = SearchEngine.createJavaSearchScope(arr , false);
// IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
SearchEngine engine = new SearchEngine();
final Collection<IJavaElement> kludge = HashSetFactory.make();
SearchRequestor requestor = new SearchRequestor() {

View File

@ -10,11 +10,13 @@
*******************************************************************************/
package com.ibm.wala.ipa.callgraph.impl;
import java.util.HashSet;
import java.util.Iterator;
import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.ipa.callgraph.AnalysisScope;
import com.ibm.wala.ipa.callgraph.Entrypoint;
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.util.debug.Trace;
@ -25,7 +27,7 @@ import com.ibm.wala.util.debug.Trace;
* @author sfink
* @autor eyahav
*/
public class AllApplicationEntrypoints extends BasicEntrypoints {
public class AllApplicationEntrypoints extends HashSet<Entrypoint> {
private final static boolean DEBUG = false;
/**

View File

@ -173,11 +173,7 @@ public abstract class BasicCallGraph extends AbstractNumberedGraph<CGNode> imple
/**
* A class that represents the a normal node in a call graph.
*/
public abstract static class NodeImpl<T extends BasicCallGraph> extends NodeWithNumber implements CGNode {
/**
* The governing call graph
*/
protected final T CG;
public abstract class NodeImpl extends NodeWithNumber implements CGNode {
/**
* The method this node represents.
@ -189,8 +185,7 @@ public abstract class BasicCallGraph extends AbstractNumberedGraph<CGNode> imple
*/
private final Context context;
protected NodeImpl(T CG, IMethod method, Context C) {
this.CG = CG;
protected NodeImpl(IMethod method, Context C) {
this.method = method;
this.context = C;
if (Assertions.verifyAssertions) {

View File

@ -1,40 +0,0 @@
/*******************************************************************************
* Copyright (c) 2002 - 2006 IBM Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package com.ibm.wala.ipa.callgraph.impl;
import java.util.HashSet;
import java.util.Iterator;
import com.ibm.wala.ipa.callgraph.Entrypoint;
import com.ibm.wala.util.collections.HashSetFactory;
/**
*
* Bare bones implementation of entrypoints
*
* @author sfink
*/
public class BasicEntrypoints<T extends Entrypoint> implements Iterable<T> {
private HashSet<T> entrypoints = HashSetFactory.make();
public Iterator<T> iterator() {
return entrypoints.iterator();
}
public void add(T e) {
entrypoints.add(e);
}
public int size() {
return entrypoints.size();
}
}

View File

@ -23,26 +23,26 @@ import com.ibm.wala.util.collections.HashSetFactory;
* @author sfink
*
*/
public class ComposedEntrypoints<T extends Entrypoint> implements Iterable<T> {
public class ComposedEntrypoints implements Iterable<Entrypoint> {
private Set<T> entrypoints = HashSetFactory.make();
private Set<Entrypoint> entrypoints = HashSetFactory.make();
public ComposedEntrypoints(Iterable<T> A, Iterable<T> B) {
public ComposedEntrypoints(Iterable<Entrypoint> A, Iterable<Entrypoint> B) {
if (A == null) {
throw new IllegalArgumentException("A is null");
}
if (B == null) {
throw new IllegalArgumentException("B is null");
}
for (Iterator<T> it = A.iterator(); it.hasNext(); ) {
for (Iterator<Entrypoint> it = A.iterator(); it.hasNext(); ) {
entrypoints.add(it.next());
}
for (Iterator<T> it = B.iterator(); it.hasNext(); ) {
for (Iterator<Entrypoint> it = B.iterator(); it.hasNext(); ) {
entrypoints.add(it.next());
}
}
public Iterator<T> iterator() {
public Iterator<Entrypoint> iterator() {
return entrypoints.iterator();
}

View File

@ -19,6 +19,7 @@ import com.ibm.wala.classLoader.CallSiteReference;
import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.ipa.callgraph.AnalysisOptions;
import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.ipa.callgraph.Context;
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.shrikeBT.BytecodeConstants;
@ -80,7 +81,7 @@ public class ExplicitCallGraph extends BasicCallGraph implements BytecodeConstan
* subclasses may wish to override!
*/
protected ExplicitNode makeNode(IMethod method, Context context) {
return new ExplicitNode(this, method, context);
return new ExplicitNode(method, context);
}
/**
@ -128,7 +129,7 @@ public class ExplicitCallGraph extends BasicCallGraph implements BytecodeConstan
/**
* @author sfink
*/
public static class ExplicitNode<T extends ExplicitCallGraph> extends NodeImpl<T> {
public class ExplicitNode extends NodeImpl {
/**
* A Mapping from call site program counter (int) -> Object, where Object is
@ -143,8 +144,8 @@ public class ExplicitCallGraph extends BasicCallGraph implements BytecodeConstan
/**
* @param method
*/
protected ExplicitNode(T CG, IMethod method, Context C) {
super(CG, method, C);
protected ExplicitNode(IMethod method, Context C) {
super(method, C);
}
@Override
@ -160,7 +161,7 @@ public class ExplicitCallGraph extends BasicCallGraph implements BytecodeConstan
IntSet s = (IntSet) result;
HashSet<CGNode> h = HashSetFactory.make(s.size());
for (IntIterator it = s.intIterator(); it.hasNext();) {
h.add(CG.getNode(it.next()));
h.add(getCallGraph().getNode(it.next()));
}
return h;
}
@ -172,7 +173,7 @@ public class ExplicitCallGraph extends BasicCallGraph implements BytecodeConstan
if (t == null) {
return null;
} else if (t instanceof CGNode) {
return SparseIntSet.singleton(CG.getNumber((CGNode) t));
return SparseIntSet.singleton(getCallGraph().getNumber((CGNode) t));
} else {
return (IntSet) t;
}
@ -182,7 +183,7 @@ public class ExplicitCallGraph extends BasicCallGraph implements BytecodeConstan
* @see com.ibm.wala.ipa.callgraph.CGNode#getPossibleSites(com.ibm.wala.ipa.callgraph.CGNode)
*/
public Iterator<CallSiteReference> getPossibleSites(final CGNode to) {
final int n = CG.getNumber(to);
final int n = getCallGraph().getNumber(to);
return new FilterIterator<CallSiteReference>(iterateSites(), new Filter() {
public boolean accepts(Object o) {
IntSet s = getPossibleTargetNumbers((CallSiteReference) o);
@ -197,12 +198,12 @@ public class ExplicitCallGraph extends BasicCallGraph implements BytecodeConstan
}
protected boolean addTarget(int pc, CGNode tNode) {
allTargets.add(CG.getNumber(tNode));
allTargets.add(getCallGraph().getNumber(tNode));
Object S = targets.get(pc);
if (S == null) {
S = tNode;
targets.set(pc, S);
CG.addEdge(this, tNode);
getCallGraph().addEdge(this, tNode);
return true;
} else {
if (S instanceof CGNode) {
@ -210,18 +211,18 @@ public class ExplicitCallGraph extends BasicCallGraph implements BytecodeConstan
return false;
} else {
MutableSharedBitVectorIntSet s = new MutableSharedBitVectorIntSet();
s.add(CG.getNumber((CGNode) S));
s.add(CG.getNumber(tNode));
CG.addEdge(this, tNode);
s.add(getCallGraph().getNumber((CGNode) S));
s.add(getCallGraph().getNumber(tNode));
getCallGraph().addEdge(this, tNode);
targets.set(pc, s);
return true;
}
} else {
MutableIntSet s = (MutableIntSet) S;
int n = CG.getNumber(tNode);
int n = getCallGraph().getNumber(tNode);
if (!s.contains(n)) {
s.add(n);
CG.addEdge(this, tNode);
getCallGraph().addEdge(this, tNode);
return true;
} else {
return false;
@ -249,14 +250,14 @@ public class ExplicitCallGraph extends BasicCallGraph implements BytecodeConstan
* @see com.ibm.wala.ipa.callgraph.CGNode#iterateSites()
*/
public Iterator<CallSiteReference> iterateSites() {
return CG.getInterpreter(this).iterateCallSites(this);
return getCallGraph().getInterpreter(this).iterateCallSites(this);
}
/*
* @see com.ibm.wala.ipa.callgraph.impl.BasicCallGraph.NodeImpl#removeTarget(com.ibm.wala.ipa.callgraph.CGNode)
*/
public void removeTarget(CGNode target) {
allTargets.remove(CG.getNumber(target));
allTargets.remove(getCallGraph().getNumber(target));
for (IntIterator it = targets.safeIterateIndices(); it.hasNext();) {
int pc = it.next();
Object value = targets.get(pc);
@ -266,7 +267,7 @@ public class ExplicitCallGraph extends BasicCallGraph implements BytecodeConstan
}
} else {
MutableIntSet s = (MutableIntSet) value;
int n = CG.getNumber(target);
int n = getCallGraph().getNumber(target);
if (s.size() > 2) {
s.remove(n);
} else {
@ -276,7 +277,7 @@ public class ExplicitCallGraph extends BasicCallGraph implements BytecodeConstan
if (s.contains(n)) {
s.remove(n);
int i = s.intIterator().next();
targets.set(pc, CG.getNode(i));
targets.set(pc, getCallGraph().getNode(i));
}
}
}
@ -305,13 +306,13 @@ public class ExplicitCallGraph extends BasicCallGraph implements BytecodeConstan
allTargets.clear();
}
public T getCallGraph() {
return CG;
}
public IR getIR(WarningSet warnings) {
return getCallGraph().getInterpreter(this).getIR(this,warnings);
}
public CallGraph getCallGraph() {
return ExplicitCallGraph.this;
}
}
/*

View File

@ -21,8 +21,8 @@ import com.ibm.wala.util.warnings.WarningSet;
/**
* This class provides Instance Key call backs where each instance is in the
* same equivalence class as all other instances allocated at the same site.
*
* same equivalence class as all other instances allocated at the same site.
*
* @author sfink
*/
public class AllocationSiteInstanceKeys implements InstanceKeyFactory {
@ -60,7 +60,7 @@ public class AllocationSiteInstanceKeys implements InstanceKeyFactory {
public InstanceKey getInstanceKeyForAllocation(CGNode node, NewSiteReference allocation) {
IClass type = options.getClassTargetSelector().getAllocatedTarget(node, allocation);
if (type == null) {
warnings.add(ResolutionFailure.create(node,allocation));
warnings.add(ResolutionFailure.create(node, allocation));
return null;
}
@ -81,7 +81,7 @@ public class AllocationSiteInstanceKeys implements InstanceKeyFactory {
public InstanceKey getInstanceKeyForMultiNewArray(CGNode node, NewSiteReference allocation, int dim) {
IClass type = options.getClassTargetSelector().getAllocatedTarget(node, allocation);
if (type == null) {
warnings.add(ResolutionFailure.create(node,allocation));
warnings.add(ResolutionFailure.create(node, allocation));
return null;
}
InstanceKey key = new MultiNewArrayAllocationSiteKey(node, allocation, type, dim);
@ -89,15 +89,14 @@ public class AllocationSiteInstanceKeys implements InstanceKeyFactory {
return key;
}
public InstanceKey getInstanceKeyForConstant(CGNode node, Object S) {
Language l = node.getMethod().getDeclaringClass().getClassLoader().getLanguage();
public InstanceKey getInstanceKeyForConstant(TypeReference type, Object S) {
if (options.getUseConstantSpecificKeys())
return new ConstantKey(S, cha.lookupClass(l.getConstantType(S)));
return new ConstantKey(S, cha.lookupClass(type));
else
return new ConcreteTypeKey(cha.lookupClass(l.getConstantType(S)));
return new ConcreteTypeKey(cha.lookupClass(type));
}
public String getStringConstantForInstanceKey(CGNode node, InstanceKey I) {
public String getStringConstantForInstanceKey(InstanceKey I) {
if (I instanceof StringConstantKey) {
return ((StringConstantKey) I).getString();
} else {

View File

@ -44,7 +44,6 @@ public class ClassBasedInstanceKeys implements InstanceKeyFactory {
this.warnings = warnings;
}
public InstanceKey getInstanceKeyForAllocation(CGNode node, NewSiteReference allocation) {
if (allocation == null) {
throw new IllegalArgumentException("allocation is null");
@ -107,21 +106,19 @@ public class ClassBasedInstanceKeys implements InstanceKeyFactory {
return key;
}
public InstanceKey getInstanceKeyForConstant(CGNode node, Object S) {
Language l = node.getMethod().getDeclaringClass().getClassLoader().getLanguage();
TypeReference type = l.getConstantType(S);
public InstanceKey getInstanceKeyForConstant(TypeReference type, Object S) {
if (type == null || cha.lookupClass(type) == null) {
return null;
} else {
if (options.getUseConstantSpecificKeys()) {
return new ConstantKey(S, cha.lookupClass(type));
return new ConstantKey(S, cha.lookupClass(type));
} else {
return new ConcreteTypeKey(cha.lookupClass(type));
return new ConcreteTypeKey(cha.lookupClass(type));
}
}
}
public String getStringConstantForInstanceKey(CGNode node, InstanceKey I) {
public String getStringConstantForInstanceKey(InstanceKey I) {
if (I instanceof StringConstantKey)
return ((StringConstantKey) I).getString();
else

View File

@ -22,35 +22,36 @@ import com.ibm.wala.types.TypeReference;
*/
public interface InstanceKeyFactory {
/**
* @param node
* @param allocation
* @return the instance key that represents a particular allocation
*/
public abstract InstanceKey getInstanceKeyForAllocation(CGNode node, NewSiteReference allocation);
/**
* @param node
* @param allocation
* @param dim
* @return the instance key that represents the array allocated as the dimth dimension at a particular allocation
* @return the instance key that represents the array allocated as the dimth
* dimension at a particular allocation
*/
public abstract InstanceKey getInstanceKeyForMultiNewArray(CGNode node, NewSiteReference allocation, int dim);
/**
* @param S
* @return the instance key that represents a constant with value S
* @return the instance key that represents a constant with value S, when considered as a particular type
*/
public abstract InstanceKey getInstanceKeyForConstant(CGNode node, Object S);
public abstract InstanceKey getInstanceKeyForConstant(TypeReference type, Object S);
/**
* @param I
* @return if I was allocated by this for a specific string constant, return that constant (return null otherwise).
* @return if I was allocated by this for a specific string constant, return
* that constant (return null otherwise).
*/
public abstract String getStringConstantForInstanceKey(CGNode node, InstanceKey I);
public abstract String getStringConstantForInstanceKey(InstanceKey I);
/**
* @param node
* @param instr
* @param type
* @return the instance key that represents the exception of type _type_ thrown by a particular PEI.
* @return the instance key that represents the exception of type _type_
* thrown by a particular PEI.
*/
public abstract InstanceKey getInstanceKeyForPEI(CGNode node, ProgramCounter instr, TypeReference type);
/**
* @return the instance key that represents the class object of type _type_.
*/

View File

@ -453,37 +453,23 @@ public class PointerAnalysisImpl extends AbstractPointerAnalysis {
private class HModel implements HeapModel {
/*
* @see com.ibm.wala.ipa.callgraph.propagation.HeapModel#iteratePointerKeys()
*/
public Iterator iteratePointerKeys() {
return pointsToMap.iterateKeys();
}
/*
* @see com.ibm.wala.ipa.callgraph.propagation.InstanceKeyFactory#getInstanceKeyForAllocation(com.ibm.detox.ipa.callgraph.CGNode,
* com.ibm.wala.ssa.NewInstruction)
*/
public InstanceKey getInstanceKeyForAllocation(CGNode node, NewSiteReference allocation) {
return iKeyFactory.getInstanceKeyForAllocation(node, allocation);
}
/*
* @see com.ibm.wala.ipa.callgraph.propagation.InstanceKeyFactory#getInstanceKeyForMultiNewArray(com.ibm.detox.ipa.callgraph.CGNode,
* com.ibm.wala.ssa.NewInstruction, int)
*/
public InstanceKey getInstanceKeyForMultiNewArray(CGNode node, NewSiteReference allocation, int dim) {
return iKeyFactory.getInstanceKeyForMultiNewArray(node, allocation, dim);
}
/*
* @see com.ibm.wala.ipa.callgraph.propagation.InstanceKeyFactory#getInstanceKeyForStringConstant(java.lang.String)
*/
public InstanceKey getInstanceKeyForConstant(CGNode node, Object S) {
return iKeyFactory.getInstanceKeyForConstant(node, S);
public InstanceKey getInstanceKeyForConstant(TypeReference type, Object S) {
return iKeyFactory.getInstanceKeyForConstant(type, S);
}
public String getStringConstantForInstanceKey(CGNode node, InstanceKey I) {
public String getStringConstantForInstanceKey(InstanceKey I) {
Assertions.UNREACHABLE();
return null;
}
@ -506,10 +492,6 @@ public class PointerAnalysisImpl extends AbstractPointerAnalysis {
return pointerKeys.getPointerKeyForLocal(node, valueNumber);
}
/*
* @see com.ibm.wala.ipa.callgraph.propagation.PointerKeyFactory#getPointerKeyForLocal(com.ibm.detox.ipa.callgraph.CGNode,
* int)
*/
public FilteredPointerKey getFilteredPointerKeyForLocal(CGNode node, int valueNumber, FilteredPointerKey.TypeFilter filter) {
return pointerKeys.getFilteredPointerKeyForLocal(node, valueNumber, filter);
}

View File

@ -1033,16 +1033,12 @@ public abstract class PropagationCallGraphBuilder implements CallGraphBuilder {
return instanceKeyFactory.getInstanceKeyForMultiNewArray(node, allocation, dim);
}
/**
* @return the InstanceKey that acts as a representative for the class of
* objects that includes the String constant
*/
public InstanceKey getInstanceKeyForConstant(CGNode node, Object S) {
return instanceKeyFactory.getInstanceKeyForConstant(node, S);
public InstanceKey getInstanceKeyForConstant(TypeReference type, Object S) {
return instanceKeyFactory.getInstanceKeyForConstant(type, S);
}
public String getStringConstantForInstanceKey(CGNode node, InstanceKey I) {
return instanceKeyFactory.getStringConstantForInstanceKey(node, I);
public String getStringConstantForInstanceKey(InstanceKey I) {
return instanceKeyFactory.getStringConstantForInstanceKey(I);
}
public InstanceKey getInstanceKeyForClassObject(TypeReference type) {

View File

@ -186,7 +186,8 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
* @param type
* @return the instance key that represents the exception of type _type_
* thrown by a particular PEI.
* @throws IllegalArgumentException if ikFactory is null
* @throws IllegalArgumentException
* if ikFactory is null
*/
public static InstanceKey getInstanceKeyForPEI(CGNode node, ProgramCounter x, TypeReference type, InstanceKeyFactory ikFactory) {
if (ikFactory == null) {
@ -511,7 +512,8 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
/**
* @return a List of Instructions that may transfer control to bb via an
* exceptional edge
* @throws IllegalArgumentException if ir is null
* @throws IllegalArgumentException
* if ir is null
*/
public static List<ProgramCounter> getIncomingPEIs(IR ir, IBasicBlock bb) {
if (ir == null) {
@ -549,9 +551,8 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
protected static class ConstraintVisitor extends SSAInstruction.Visitor {
/**
* The governing call graph builder. This field is used instead of
* an inner class in order to allow more flexible reuse of this
* visitor in subclasses
* The governing call graph builder. This field is used instead of an inner
* class in order to allow more flexible reuse of this visitor in subclasses
*/
protected final SSAPropagationCallGraphBuilder builder;
@ -560,7 +561,7 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
*/
protected final ExplicitCallGraph.ExplicitNode node;
/**
/**
* The governing call graph.
*/
private final ExplicitCallGraph callGraph;
@ -592,7 +593,7 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
private final boolean debug;
public ConstraintVisitor(SSAPropagationCallGraphBuilder builder, ExplicitCallGraph.ExplicitNode node) {
public ConstraintVisitor(SSAPropagationCallGraphBuilder builder, ExplicitCallGraph.ExplicitNode node) {
this.builder = builder;
this.node = node;
@ -604,7 +605,7 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
this.symbolTable = this.ir.getSymbolTable();
this.du = builder.getCFAContextInterpreter().getDU(node, builder.getWarnings());
this.debug = DEBUG_METHOD_SUBSTRING == null || node.toString().indexOf(DEBUG_METHOD_SUBSTRING) > -1;
if (Assertions.verifyAssertions) {
Assertions._assert(symbolTable != null);
@ -642,7 +643,7 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
public PointerKey getPointerKeyForStaticField(IField f) {
return getBuilder().getPointerKeyForStaticField(f);
}
public PointerKey getPointerKeyForInstanceField(InstanceKey I, IField f) {
return getBuilder().getPointerKeyForInstanceField(I, f);
}
@ -660,11 +661,12 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
}
public InstanceKey getInstanceKeyForConstant(Object S) {
return getBuilder().getInstanceKeyForConstant(node, S);
TypeReference type = node.getMethod().getDeclaringClass().getClassLoader().getLanguage().getConstantType(S);
return getBuilder().getInstanceKeyForConstant(type, S);
}
public String getStringConstantForInstanceKey(InstanceKey I) {
return getBuilder().getStringConstantForInstanceKey(node, I);
return getBuilder().getStringConstantForInstanceKey(I);
}
public InstanceKey getInstanceKeyForPEI(ProgramCounter instr, TypeReference type) {
@ -1091,7 +1093,7 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
if (n == null) {
getWarnings().add(ResolutionFailure.create(node, instruction));
} else {
getBuilder().processResolvedCall(node, instruction, n, computeInvariantParameters(instruction), uniqueCatch);
getBuilder().processResolvedCall(node, instruction, n, computeInvariantParameters(instruction), uniqueCatch);
if (DEBUG) {
Trace.guardedPrintln("visitInvoke class init " + n, DEBUG_METHOD_SUBSTRING);
}
@ -1127,8 +1129,8 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
if (DEBUG && debug) {
Trace.println("Add side effect, dispatch to " + instruction + ", receiver " + receiver);
}
DispatchOperator dispatchOperator = getBuilder().new DispatchOperator(instruction, node, computeInvariantParameters(instruction),
uniqueCatch);
DispatchOperator dispatchOperator = getBuilder().new DispatchOperator(instruction, node,
computeInvariantParameters(instruction), uniqueCatch);
system.newSideEffect(dispatchOperator, receiver);
}
}
@ -1404,12 +1406,12 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
}
try {
IClass sc = klass.getSuperclass();
IClass sc = klass.getSuperclass();
if (sc != null) {
processClassInitializer(sc);
processClassInitializer(sc);
}
} catch (ClassHierarchyException e) {
Assertions.UNREACHABLE();
Assertions.UNREACHABLE();
}
}
}
@ -1428,12 +1430,8 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
* if non-null, then this is the unique PointerKey that catches all
* exceptions from this call site.
*/
private void processResolvedCall(CGNode caller,
SSAAbstractInvokeInstruction instruction,
CGNode target,
InstanceKey[][] constParams,
PointerKey uniqueCatchKey)
{
private void processResolvedCall(CGNode caller, SSAAbstractInvokeInstruction instruction, CGNode target,
InstanceKey[][] constParams, PointerKey uniqueCatchKey) {
if (DEBUG) {
Trace.println("processResolvedCall: " + caller + " ," + instruction + " , " + target);
@ -1443,15 +1441,15 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
Trace.println("addTarget: " + caller + " ," + instruction + " , " + target);
}
caller.addTarget(instruction.getCallSite(), target);
if (FakeRootMethod.isFakeRootMethod(caller.getMethod().getReference())) {
if (entrypointCallSites.contains(instruction.getSite())) {
callGraph.registerEntrypoint(target);
}
callGraph.registerEntrypoint(target);
}
}
if (!haveAlreadyVisited(target)) {
markDiscovered(target);
markDiscovered(target);
}
// TODO: i'd like to enable this optimization, but it's a little tricky
@ -1484,11 +1482,11 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
* (!target.getMethod().isStatic() && !target.getMethod().isClinit()) {
* nExpected++; }
*/
if (nUses != nExpected) {
// some sort of unverifiable code mismatch. give up.
getWarnings().add(ResolutionFailure.create(target, instruction, "found " + nUses + " uses but expected " + nExpected));
return;
// some sort of unverifiable code mismatch. give up.
getWarnings().add(ResolutionFailure.create(target, instruction, "found " + nUses + " uses but expected " + nExpected));
return;
}
boolean needsFilter = !instruction.getSite().isStatic() && needsFilterForReceiver(instruction, target);
@ -1498,73 +1496,73 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
// the various types of dispatch logic. We need a filter that expresses
// "the set of types s.t. x.foo resolves to y.foo."
for (int i = 0; i < instruction.getNumberOfParameters(); i++) {
// we rely on the invariant that the value number for the ith parameter
// is i+1
final int vn = i + 1;
// we rely on the invariant that the value number for the ith parameter
// is i+1
final int vn = i + 1;
if (target.getMethod().getParameterType(i).isReferenceType()) {
// if (constParams != null && constParams[i] != null &&
// !supportFullPointerFlowGraph) {
if (constParams != null && constParams[i] != null) {
InstanceKey[] ik = constParams[i];
for (int j = 0; j < ik.length; j++) {
if (needsFilter && (i == 0)) {
if (target.getMethod().getParameterType(i).isReferenceType()) {
// if (constParams != null && constParams[i] != null &&
// !supportFullPointerFlowGraph) {
if (constParams != null && constParams[i] != null) {
InstanceKey[] ik = constParams[i];
for (int j = 0; j < ik.length; j++) {
if (needsFilter && (i == 0)) {
FilteredPointerKey.TypeFilter C = getFilter(target);
PointerKey formal = null;
if (isRootType(C)) {
// TODO: we need much better filtering here ... see comments
// above.
formal = getPointerKeyForLocal(target, vn);
} else {
formal = getFilteredPointerKeyForLocal(target, vn, C);
}
system.newConstraint(formal, ik[j]);
} else {
PointerKey formal = getPointerKeyForLocal(target, vn);
system.newConstraint(formal, ik[j]);
}
}
} else {
if (Assertions.verifyAssertions) {
PointerKey formal = null;
if (isRootType(C)) {
// TODO: we need much better filtering here ... see comments
// above.
formal = getPointerKeyForLocal(target, vn);
} else {
formal = getFilteredPointerKeyForLocal(target, vn, C);
}
system.newConstraint(formal, ik[j]);
} else {
PointerKey formal = getPointerKeyForLocal(target, vn);
system.newConstraint(formal, ik[j]);
}
}
} else {
if (Assertions.verifyAssertions) {
if (instruction.getUse(i) < 0) {
Assertions.UNREACHABLE("unexpected " + instruction + " in " + caller);
}
}
PointerKey actual = getPointerKeyForLocal(caller, instruction.getUse(i));
if (needsFilter && (i == 0)) {
FilteredPointerKey.TypeFilter C = getFilter(target);
if (isRootType(C)) {
// TODO: we need much better filtering here ... see comments
// above.
PointerKey formal = getPointerKeyForLocal(target, vn);
system.newConstraint(formal, assignOperator, actual);
} else {
FilteredPointerKey formal = getFilteredPointerKeyForLocal(target, vn, C);
system.newConstraint(formal, filterOperator, actual);
}
} else {
PointerKey formal = getPointerKeyForLocal(target, vn);
system.newConstraint(formal, assignOperator, actual);
}
}
}
}
}
PointerKey actual = getPointerKeyForLocal(caller, instruction.getUse(i));
if (needsFilter && (i == 0)) {
FilteredPointerKey.TypeFilter C = getFilter(target);
if (isRootType(C)) {
// TODO: we need much better filtering here ... see comments
// above.
PointerKey formal = getPointerKeyForLocal(target, vn);
system.newConstraint(formal, assignOperator, actual);
} else {
FilteredPointerKey formal = getFilteredPointerKeyForLocal(target, vn, C);
system.newConstraint(formal, filterOperator, actual);
}
} else {
PointerKey formal = getPointerKeyForLocal(target, vn);
system.newConstraint(formal, assignOperator, actual);
}
}
}
}
// generate contraints from return value.
if (instruction.hasDef() && instruction.getDeclaredResultType().isReferenceType()) {
PointerKey result = getPointerKeyForLocal(caller, instruction.getDef());
PointerKey ret = getPointerKeyForReturnValue(target);
system.newConstraint(result, assignOperator, ret);
PointerKey result = getPointerKeyForLocal(caller, instruction.getDef());
PointerKey ret = getPointerKeyForReturnValue(target);
system.newConstraint(result, assignOperator, ret);
}
// generate contraints from exception return value.
PointerKey e = getPointerKeyForLocal(caller, instruction.getException());
PointerKey er = getPointerKeyForExceptionalReturnValue(target);
if (SHORT_CIRCUIT_SINGLE_USES && uniqueCatchKey != null) {
// e has exactly one use. so, represent e implicitly
system.newConstraint(uniqueCatchKey, assignOperator, er);
// e has exactly one use. so, represent e implicitly
system.newConstraint(uniqueCatchKey, assignOperator, er);
} else {
system.newConstraint(e, assignOperator, er);
}
system.newConstraint(e, assignOperator, er);
}
// }
}
@ -1777,7 +1775,7 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
return true;
}
}
public boolean hasNoInterestingUses(CGNode node, int vn, DefUse du) {
if (du == null) {
@ -2029,11 +2027,13 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
InstanceKey[] result;
if (isConstantRef(symbolTable, valueNumber)) {
Object S = symbolTable.getConstantValue(valueNumber);
InstanceKey ik = hm.getInstanceKeyForConstant(node, S);
if (ik != null)
TypeReference type = node.getMethod().getDeclaringClass().getClassLoader().getLanguage().getConstantType(S);
InstanceKey ik = hm.getInstanceKeyForConstant(type, S);
if (ik != null) {
result = new InstanceKey[] { ik };
else
} else {
result = new InstanceKey[0];
}
} else {
SSANewInstruction def = (SSANewInstruction) du.getDef(valueNumber);
InstanceKey iKey = hm.getInstanceKeyForAllocation(node, def.getNewSite());

View File

@ -21,9 +21,9 @@ import com.ibm.wala.util.warnings.WarningSet;
/**
*
* This class provides instance keys where for a given type T in a CGNode
* N, there is one "abstract allocation site" instance for all T allocations
* in node N.
* This class provides instance keys where for a given type T in a CGNode N,
* there is one "abstract allocation site" instance for all T allocations in
* node N.
*
* @author sfink
*/
@ -62,7 +62,7 @@ public class SmushedAllocationSiteInstanceKeys implements InstanceKeyFactory {
public InstanceKey getInstanceKeyForAllocation(CGNode node, NewSiteReference allocation) {
IClass type = options.getClassTargetSelector().getAllocatedTarget(node, allocation);
if (type == null) {
warnings.add(ResolutionFailure.create(node,allocation));
warnings.add(ResolutionFailure.create(node, allocation));
return null;
}
@ -83,7 +83,7 @@ public class SmushedAllocationSiteInstanceKeys implements InstanceKeyFactory {
public InstanceKey getInstanceKeyForMultiNewArray(CGNode node, NewSiteReference allocation, int dim) {
IClass type = options.getClassTargetSelector().getAllocatedTarget(node, allocation);
if (type == null) {
warnings.add(ResolutionFailure.create(node,allocation));
warnings.add(ResolutionFailure.create(node, allocation));
return null;
}
InstanceKey key = new MultiNewArrayAllocationSiteKey(node, allocation, type, dim);
@ -91,15 +91,14 @@ public class SmushedAllocationSiteInstanceKeys implements InstanceKeyFactory {
return key;
}
public InstanceKey getInstanceKeyForConstant(CGNode node, Object S) {
Language l = node.getMethod().getDeclaringClass().getClassLoader().getLanguage();
public InstanceKey getInstanceKeyForConstant(TypeReference type, Object S) {
if (options.getUseConstantSpecificKeys())
return new ConstantKey(S, cha.lookupClass(l.getConstantType(S)));
return new ConstantKey(S, cha.lookupClass(type));
else
return new ConcreteTypeKey(cha.lookupClass(l.getConstantType(S)));
return new ConcreteTypeKey(cha.lookupClass(type));
}
public String getStringConstantForInstanceKey(CGNode node, InstanceKey I) {
public String getStringConstantForInstanceKey(InstanceKey I) {
if (I instanceof StringConstantKey) {
return ((StringConstantKey) I).getString();
} else {

View File

@ -240,15 +240,15 @@ public class ZeroXInstanceKeys implements InstanceKeyFactory {
}
}
public InstanceKey getInstanceKeyForConstant(CGNode node, Object S) {
return classBased.getInstanceKeyForConstant(node, S);
public InstanceKey getInstanceKeyForConstant(TypeReference type, Object S) {
return classBased.getInstanceKeyForConstant(type, S);
}
/*
* @see com.ibm.wala.ipa.callgraph.propagation.InstanceKeyFactory#getStringConstantForInstanceKey(com.ibm.wala.ipa.callgraph.propagation.InstanceKey)
*/
public String getStringConstantForInstanceKey(CGNode node, InstanceKey I) {
return classBased.getStringConstantForInstanceKey(node, I);
public String getStringConstantForInstanceKey(InstanceKey I) {
return classBased.getStringConstantForInstanceKey(I);
}
/*

View File

@ -63,10 +63,10 @@ public class DelegatingExplicitCallGraph extends ExplicitCallGraph {
* <li> a CallSite if we're delegating these edges to another node
* </ul>
*/
public static class DelegatingCGNode<T extends DelegatingExplicitCallGraph> extends ExplicitNode<T> {
public class DelegatingCGNode extends ExplicitNode {
protected DelegatingCGNode(T CG, IMethod method, Context C) {
super(CG, method, C);
protected DelegatingCGNode(IMethod method, Context C) {
super(method, C);
}
/*
@ -151,11 +151,10 @@ public class DelegatingExplicitCallGraph extends ExplicitCallGraph {
public void delegate(CallSiteReference site, CGNode delegateNode, CallSiteReference delegateSite) {
CallSite d = new CallSite(delegateSite, delegateNode);
targets.set(site.getProgramCounter(), d);
int y = CG.getNumber(this);
int x = CG.getNumber(delegateNode);
CG.delegateR.add(x, y);
int y = getCallGraph().getNumber(this);
int x = getCallGraph().getNumber(delegateNode);
delegateR.add(x, y);
}
}
/*
@ -164,7 +163,7 @@ public class DelegatingExplicitCallGraph extends ExplicitCallGraph {
*/
@Override
protected ExplicitNode makeNode(IMethod method, Context context) {
return new DelegatingCGNode(this, method, context);
return new DelegatingCGNode(method, context);
}
private class DelegatingEdgeManager extends ExplicitEdgeManager {

View File

@ -66,7 +66,7 @@ public class TypeBasedHeapModel implements HeapModel {
private final Collection<IClass> klasses;
private final CallGraph cg;
private final Collection<CGNode> nodesHandled = HashSetFactory.make();
/**
@ -75,12 +75,13 @@ public class TypeBasedHeapModel implements HeapModel {
*
* computed lazily
*/
private Map<PointerKey,Object> pKeys;
private Map<PointerKey, Object> pKeys;
/**
* @param klasses
* Collection<IClass>
* @throws IllegalArgumentException if cg is null
* @throws IllegalArgumentException
* if cg is null
*/
public TypeBasedHeapModel(AnalysisOptions options, Collection<IClass> klasses, CallGraph cg) {
if (cg == null) {
@ -104,7 +105,7 @@ public class TypeBasedHeapModel implements HeapModel {
initPKeysForNode(node);
}
}
private void initPKeysForNode(CGNode node) {
if (pKeys == null) {
pKeys = HashMapFactory.make();
@ -123,7 +124,7 @@ public class TypeBasedHeapModel implements HeapModel {
if (ir == null) {
return Collections.emptyMap();
}
Map<PointerKey,Object> result = HashMapFactory.make();
Map<PointerKey, Object> result = HashMapFactory.make();
SymbolTable s = ir.getSymbolTable();
if (s == null) {
return Collections.emptyMap();
@ -134,14 +135,14 @@ public class TypeBasedHeapModel implements HeapModel {
for (int i = 1; i <= s.getMaxValueNumber(); i++) {
if (s.isConstant(i)) {
if (s.isStringConstant(i)) {
result.put(pointerKeys.getPointerKeyForLocal(node, i), getInstanceKeyForConstant(node, s.getConstantValue(i)));
TypeReference type = node.getMethod().getDeclaringClass().getClassLoader().getLanguage().getConstantType(s.getStringValue(i));
result.put(pointerKeys.getPointerKeyForLocal(node, i), getInstanceKeyForConstant(type, s.getConstantValue(i)));
}
} else {
TypeAbstraction t = ti.getType(i);
if (t.getType() != null && t.getType().isReferenceType()) {
result.put(
pointerKeys.getPointerKeyForLocal(node, i),
pointerKeys.getFilteredPointerKeyForLocal(node, i, new FilteredPointerKey.SingleClassFilter(t.getType())));
result.put(pointerKeys.getPointerKeyForLocal(node, i), pointerKeys.getFilteredPointerKeyForLocal(node, i,
new FilteredPointerKey.SingleClassFilter(t.getType())));
}
}
}
@ -150,7 +151,7 @@ public class TypeBasedHeapModel implements HeapModel {
/**
*/
private Map<PointerKey,Object> computePointerKeys(IClass klass) {
private Map<PointerKey, Object> computePointerKeys(IClass klass) {
Map<PointerKey, Object> result = HashMapFactory.make();
if (klass.isArrayClass()) {
ArrayClass a = (ArrayClass) klass;
@ -204,11 +205,11 @@ public class TypeBasedHeapModel implements HeapModel {
return null;
}
public InstanceKey getInstanceKeyForConstant(CGNode node, Object S) {
return iKeyFactory.getInstanceKeyForConstant(node, S);
public InstanceKey getInstanceKeyForConstant(TypeReference type, Object S) {
return iKeyFactory.getInstanceKeyForConstant(type, S);
}
public String getStringConstantForInstanceKey(CGNode node, InstanceKey I) {
public String getStringConstantForInstanceKey(InstanceKey I) {
Assertions.UNREACHABLE();
return null;
}
@ -238,7 +239,8 @@ public class TypeBasedHeapModel implements HeapModel {
ConcreteTypeKey c = (ConcreteTypeKey) result;
if (c.getConcreteType().getReference().equals(TypeReference.JavaLangString)) {
// a string constant;
return pointerKeys.getFilteredPointerKeyForLocal(node, valueNumber, new FilteredPointerKey.SingleClassFilter(c.getConcreteType()));
return pointerKeys.getFilteredPointerKeyForLocal(node, valueNumber, new FilteredPointerKey.SingleClassFilter(c
.getConcreteType()));
} else {
Assertions.UNREACHABLE("need to handle " + result.getClass());
return null;

View File

@ -54,8 +54,8 @@ public class DelegatingExtendedHeapModel implements ExtendedHeapModel {
return h.getInstanceKeyForClassObject(type);
}
public InstanceKey getInstanceKeyForConstant(CGNode node, Object S) {
return h.getInstanceKeyForConstant(node, S);
public InstanceKey getInstanceKeyForConstant(TypeReference type, Object S) {
return h.getInstanceKeyForConstant(type, S);
}
public InstanceKey getInstanceKeyForMultiNewArray(CGNode node, NewSiteReference allocation, int dim) {
@ -96,8 +96,8 @@ public class DelegatingExtendedHeapModel implements ExtendedHeapModel {
return h.getPointerKeyForStaticField(f);
}
public String getStringConstantForInstanceKey(CGNode node, InstanceKey I) {
return h.getStringConstantForInstanceKey(node, I);
public String getStringConstantForInstanceKey(InstanceKey I) {
return h.getStringConstantForInstanceKey(I);
}
public Iterator iteratePointerKeys() {

View File

@ -14,6 +14,7 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.jar.Attributes;
@ -26,8 +27,8 @@ import org.osgi.framework.Constants;
import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.ipa.callgraph.AnalysisScope;
import com.ibm.wala.ipa.callgraph.Entrypoint;
import com.ibm.wala.ipa.callgraph.impl.ArgumentTypeEntrypoint;
import com.ibm.wala.ipa.callgraph.impl.BasicEntrypoints;
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.util.StringStuff;
import com.ibm.wala.util.collections.HashSetFactory;
@ -43,7 +44,7 @@ import com.ibm.wala.util.warnings.WalaException;
* @author sfink
*/
@Deprecated
public class EclipseEntrypoints extends BasicEntrypoints {
public class EclipseEntrypoints extends HashSet<Entrypoint> {
private final static boolean DEBUG = false;