small cleanups

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@2893 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
sjfink 2008-06-18 21:06:24 +00:00
parent fd26dd0327
commit 60bff330b9
1 changed files with 19 additions and 38 deletions

View File

@ -36,7 +36,6 @@ import com.ibm.wala.util.collections.HashSetFactory;
import com.ibm.wala.util.collections.IntMapIterator; import com.ibm.wala.util.collections.IntMapIterator;
import com.ibm.wala.util.collections.SparseVector; import com.ibm.wala.util.collections.SparseVector;
import com.ibm.wala.util.debug.Assertions; import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.debug.Trace;
import com.ibm.wala.util.functions.IntFunction; import com.ibm.wala.util.functions.IntFunction;
import com.ibm.wala.util.graph.EdgeManager; import com.ibm.wala.util.graph.EdgeManager;
import com.ibm.wala.util.graph.NumberedEdgeManager; import com.ibm.wala.util.graph.NumberedEdgeManager;
@ -49,22 +48,18 @@ import com.ibm.wala.util.intset.MutableSharedBitVectorIntSet;
import com.ibm.wala.util.intset.SparseIntSet; import com.ibm.wala.util.intset.SparseIntSet;
/** /**
* A call graph which explicitly holds the target for each call site in each * A call graph which explicitly holds the target for each call site in each node.
* node.
*
* *
* @author sfink * @author sfink
*/ */
public class ExplicitCallGraph extends BasicCallGraph implements BytecodeConstants { public class ExplicitCallGraph extends BasicCallGraph implements BytecodeConstants {
private static final boolean DEBUG = false;
protected final IClassHierarchy cha; protected final IClassHierarchy cha;
protected final AnalysisOptions options; protected final AnalysisOptions options;
private final AnalysisCache cache; private final AnalysisCache cache;
private final long maxNumberOfNodes; private final long maxNumberOfNodes;
/** /**
@ -90,16 +85,16 @@ public class ExplicitCallGraph extends BasicCallGraph implements BytecodeConstan
/** /**
* subclasses may wish to override! * subclasses may wish to override!
* @throws CancelException * @throws CancelException
*/ */
@Override @Override
protected CGNode makeFakeRootNode() throws CancelException { protected CGNode makeFakeRootNode() throws CancelException {
return findOrCreateNode(new FakeRootMethod(cha, options, cache), Everywhere.EVERYWHERE); return findOrCreateNode(new FakeRootMethod(cha, options, cache), Everywhere.EVERYWHERE);
} }
/** /**
* subclasses may wish to override! * subclasses may wish to override!
* @throws CancelException * @throws CancelException
*/ */
@Override @Override
protected CGNode makeFakeWorldClinitNode() throws CancelException { protected CGNode makeFakeWorldClinitNode() throws CancelException {
@ -107,27 +102,16 @@ public class ExplicitCallGraph extends BasicCallGraph implements BytecodeConstan
} }
/** /**
* Method findOrCreateNode.
*
* @param method
* @return NodeImpl
*/ */
@Override @Override
public CGNode findOrCreateNode(IMethod method, Context C) throws CancelException { public CGNode findOrCreateNode(IMethod method, Context C) throws CancelException {
if (Assertions.verifyAssertions) { assert method != null : "null method";
if (method == null || C == null) { assert C != null : "null context for method " + method;
Assertions._assert(method != null, "null method");
Assertions._assert(C != null, "null context for method " + method);
}
}
Key k = new Key(method, C); Key k = new Key(method, C);
NodeImpl result = getNode(k); NodeImpl result = getNode(k);
if (result == null) { if (result == null) {
if (maxNumberOfNodes == -1 || getNumberOfNodes() <= maxNumberOfNodes) { if (maxNumberOfNodes == -1 || getNumberOfNodes() <= maxNumberOfNodes) {
result = makeNode(method, C); result = makeNode(method, C);
if (DEBUG) {
Trace.println("Create node for " + method + "hash code " + method.hashCode());
}
registerNode(k, result); registerNode(k, result);
} else { } else {
throw CancelException.make("Too many nodes"); throw CancelException.make("Too many nodes");
@ -139,10 +123,8 @@ public class ExplicitCallGraph extends BasicCallGraph implements BytecodeConstan
public class ExplicitNode extends NodeImpl { public class ExplicitNode extends NodeImpl {
/** /**
* A Mapping from call site program counter (int) -> Object, where Object is * A Mapping from call site program counter (int) -> Object, where Object is a CGNode if we've discovered exactly
* a CGNode if we've discovered exactly one target for the site, or an * one target for the site, or an IntSet of node numbers if we've discovered more than one target for the site.
* IntSet of node numbers if we've discovered more than one target for the
* site.
*/ */
protected final SparseVector<Object> targets = new SparseVector<Object>(); protected final SparseVector<Object> targets = new SparseVector<Object>();
@ -161,7 +143,7 @@ public class ExplicitCallGraph extends BasicCallGraph implements BytecodeConstan
if (result == null) { if (result == null) {
return Collections.emptySet(); return Collections.emptySet();
} else if (result instanceof CGNode) { } else if (result instanceof CGNode) {
Set<CGNode> s = Collections.singleton((CGNode)result); Set<CGNode> s = Collections.singleton((CGNode) result);
return s; return s;
} else { } else {
IntSet s = (IntSet) result; IntSet s = (IntSet) result;
@ -197,7 +179,6 @@ public class ExplicitCallGraph extends BasicCallGraph implements BytecodeConstan
} }
}); });
} }
protected int getNumberOfTargets(CallSiteReference site) { protected int getNumberOfTargets(CallSiteReference site) {
Object result = targets.get(site.getProgramCounter()); Object result = targets.get(site.getProgramCounter());
@ -306,7 +287,7 @@ public class ExplicitCallGraph extends BasicCallGraph implements BytecodeConstan
public IR getIR() { public IR getIR() {
return getCallGraph().getInterpreter(this).getIR(this); return getCallGraph().getInterpreter(this).getIR(this);
} }
public DefUse getDU() { public DefUse getDU() {
return getCallGraph().getInterpreter(this).getDU(this); return getCallGraph().getInterpreter(this).getDU(this);
} }
@ -350,8 +331,8 @@ public class ExplicitCallGraph extends BasicCallGraph implements BytecodeConstan
/** /**
* for each y, the {x | (x,y) is an edge) * for each y, the {x | (x,y) is an edge)
*/ */
final IBinaryNaturalRelation predecessors = new BasicNaturalRelation( final IBinaryNaturalRelation predecessors = new BasicNaturalRelation(new byte[] { BasicNaturalRelation.SIMPLE_SPACE_STINGY },
new byte[] { BasicNaturalRelation.SIMPLE_SPACE_STINGY }, BasicNaturalRelation.SIMPLE); BasicNaturalRelation.SIMPLE);
public IntSet getSuccNodeNumbers(CGNode node) { public IntSet getSuccNodeNumbers(CGNode node) {
ExplicitNode n = (ExplicitNode) node; ExplicitNode n = (ExplicitNode) node;
@ -446,7 +427,7 @@ public class ExplicitCallGraph extends BasicCallGraph implements BytecodeConstan
throw new IllegalArgumentException("node not in callgraph " + node); throw new IllegalArgumentException("node not in callgraph " + node);
} }
assert (node instanceof ExplicitNode); assert (node instanceof ExplicitNode);
ExplicitNode n = (ExplicitNode)node; ExplicitNode n = (ExplicitNode) node;
return n.getNumberOfTargets(site); return n.getNumberOfTargets(site);
} }
@ -458,7 +439,7 @@ public class ExplicitCallGraph extends BasicCallGraph implements BytecodeConstan
throw new IllegalArgumentException("node not in callgraph " + target); throw new IllegalArgumentException("node not in callgraph " + target);
} }
assert (src instanceof ExplicitNode); assert (src instanceof ExplicitNode);
ExplicitNode n = (ExplicitNode)src; ExplicitNode n = (ExplicitNode) src;
return n.getPossibleSites(target); return n.getPossibleSites(target);
} }
@ -467,16 +448,16 @@ public class ExplicitCallGraph extends BasicCallGraph implements BytecodeConstan
throw new IllegalArgumentException("node not in callgraph " + node); throw new IllegalArgumentException("node not in callgraph " + node);
} }
assert (node instanceof ExplicitNode); assert (node instanceof ExplicitNode);
ExplicitNode n = (ExplicitNode)node; ExplicitNode n = (ExplicitNode) node;
return n.getPossibleTargets(site); return n.getPossibleTargets(site);
} }
public IntSet getPossibleTargetNumbers(CGNode node, CallSiteReference site) { public IntSet getPossibleTargetNumbers(CGNode node, CallSiteReference site) {
if (!containsNode(node)) { if (!containsNode(node)) {
throw new IllegalArgumentException("node not in callgraph " + node); throw new IllegalArgumentException("node not in callgraph " + node);
} }
assert (node instanceof ExplicitNode); assert (node instanceof ExplicitNode);
ExplicitNode n = (ExplicitNode)node; ExplicitNode n = (ExplicitNode) node;
return n.getPossibleTargetNumbers(site); return n.getPossibleTargetNumbers(site);
} }