optimizations
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@2755 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
0e13e78df8
commit
90a5719e5c
|
@ -171,7 +171,7 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
|
|||
for (CGNode callee : cg) {
|
||||
for (Iterator<? extends CGNode> predNodes = cg.getPredNodes(callee); predNodes.hasNext();) {
|
||||
CGNode caller = predNodes.next();
|
||||
for (Iterator<CallSiteReference> iterator = cg.getPossibleSites(caller, callee); iterator.hasNext(); ) {
|
||||
for (Iterator<CallSiteReference> iterator = cg.getPossibleSites(caller, callee); iterator.hasNext();) {
|
||||
CallSiteReference site = iterator.next();
|
||||
try {
|
||||
caller.getIR().getCalls(site);
|
||||
|
@ -181,7 +181,7 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
|
|||
System.err.println(caller.getIR());
|
||||
if (caller.getMethod() instanceof ShrikeBTMethod) {
|
||||
try {
|
||||
Instruction[] instructions = ((ShrikeBTMethod)caller.getMethod()).getInstructions();
|
||||
Instruction[] instructions = ((ShrikeBTMethod) caller.getMethod()).getInstructions();
|
||||
for (int i = 0; i < instructions.length; i++) {
|
||||
System.err.println(i + ": " + instructions[i]);
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
|
|||
}
|
||||
Assertions.UNREACHABLE();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -726,7 +726,9 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
|
|||
if (pointsToQueried.put(pkAndState.getPointerKey(), pkAndState.getState())) {
|
||||
if (Assertions.verifyAssertions && pkAndState.getPointerKey() instanceof LocalPointerKey) {
|
||||
CGNode node = ((LocalPointerKey) pkAndState.getPointerKey()).getNode();
|
||||
Assertions._assert(g.hasSubgraphForNode(node), "missing constraints for node of var " + pkAndState);
|
||||
if (!g.hasSubgraphForNode(node)) {
|
||||
Assertions._assert(false, "missing constraints for node of var " + pkAndState);
|
||||
}
|
||||
}
|
||||
if (DEBUG) {
|
||||
// System.err.println("adding to init_ " + pkAndState);
|
||||
|
@ -743,7 +745,9 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
|
|||
protected void addToTrackedPToWorklist(PointerKeyAndState pkAndState) {
|
||||
if (Assertions.verifyAssertions && pkAndState.getPointerKey() instanceof LocalPointerKey) {
|
||||
CGNode node = ((LocalPointerKey) pkAndState.getPointerKey()).getNode();
|
||||
Assertions._assert(g.hasSubgraphForNode(node), "missing constraints for " + node);
|
||||
if (!g.hasSubgraphForNode(node)) {
|
||||
Assertions._assert(false, "missing constraints for " + node);
|
||||
}
|
||||
}
|
||||
if (DEBUG) {
|
||||
// System.err.println("adding to tracked points-to " + pkAndState);
|
||||
|
@ -1596,7 +1600,9 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
|
|||
// System.err.println("ASSERTION WILL FAIL");
|
||||
// System.err.println("QUERIED: " + queriedPkAndStates);
|
||||
// }
|
||||
Assertions._assert(basePointerOkay, "queried " + loadedValAndState + " but not " + baseAndStateToHandle);
|
||||
if (!basePointerOkay) {
|
||||
Assertions._assert(false, "queried " + loadedValAndState + " but not " + baseAndStateToHandle);
|
||||
}
|
||||
}
|
||||
final IntSet curP2Set = find(pkToP2Set, baseAndStateToHandle);
|
||||
// int startSize = curP2Set.size();
|
||||
|
@ -1662,6 +1668,11 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
|
|||
return node.getIR();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private SSAAbstractInvokeInstruction[] getCallInstrs(CGNode node, CallSiteReference site) {
|
||||
return node.getIR().getCalls(site);
|
||||
}
|
||||
|
||||
private Object doTransition(State curState, IFlowLabel label, Function<State, Object> func) {
|
||||
State nextState = stateMachine.transition(curState, label);
|
||||
Object ret = null;
|
||||
|
|
|
@ -40,6 +40,7 @@ package com.ibm.wala.demandpa.flowgraph;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.cfg.ControlFlowGraph;
|
||||
|
@ -64,6 +65,7 @@ import com.ibm.wala.ssa.SSAInstruction;
|
|||
import com.ibm.wala.ssa.SSAInvokeInstruction;
|
||||
import com.ibm.wala.ssa.SSAPhiInstruction;
|
||||
import com.ibm.wala.util.collections.EmptyIterator;
|
||||
import com.ibm.wala.util.collections.HashMapFactory;
|
||||
import com.ibm.wala.util.collections.HashSetFactory;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.debug.Trace;
|
||||
|
@ -77,7 +79,7 @@ import com.ibm.wala.util.ref.ReferenceCleanser;
|
|||
*
|
||||
*/
|
||||
public abstract class AbstractDemandFlowGraph extends AbstractFlowGraph {
|
||||
private final static boolean DEBUG = true;
|
||||
private final static boolean DEBUG = false;
|
||||
|
||||
/**
|
||||
* Counter for wiping soft caches
|
||||
|
@ -89,33 +91,34 @@ public abstract class AbstractDemandFlowGraph extends AbstractFlowGraph {
|
|||
*/
|
||||
final BitVectorIntSet cgNodesVisited = new BitVectorIntSet();
|
||||
|
||||
/*
|
||||
/*
|
||||
* @see com.ibm.wala.demandpa.flowgraph.IFlowGraph#addSubgraphForNode(com.ibm.wala.ipa.callgraph.CGNode)
|
||||
*/
|
||||
public void addSubgraphForNode(CGNode node) throws IllegalArgumentException {
|
||||
if (node == null) {
|
||||
throw new IllegalArgumentException("node == null");
|
||||
}
|
||||
if (node.getIR() == null) {
|
||||
IR ir = node.getIR();
|
||||
if (ir == null) {
|
||||
throw new IllegalArgumentException("no ir for node " + node);
|
||||
}
|
||||
int n = cg.getNumber(node);
|
||||
if (!cgNodesVisited.contains(n)) {
|
||||
cgNodesVisited.add(n);
|
||||
unconditionallyAddConstraintsFromNode(node);
|
||||
addNodesForInvocations(node);
|
||||
addNodesForParameters(node);
|
||||
unconditionallyAddConstraintsFromNode(node, ir);
|
||||
addNodesForInvocations(node, ir);
|
||||
addNodesForParameters(node, ir);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* @see com.ibm.wala.demandpa.flowgraph.IFlowGraph#hasSubgraphForNode(com.ibm.wala.ipa.callgraph.CGNode)
|
||||
*/
|
||||
public boolean hasSubgraphForNode(CGNode node) {
|
||||
return cgNodesVisited.contains(cg.getNumber(node));
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* @see com.ibm.wala.demandpa.flowgraph.IFlowGraph#getParamSuccs(com.ibm.wala.ipa.callgraph.propagation.LocalPointerKey)
|
||||
*/
|
||||
public Iterator<PointerKeyAndCallSite> getParamSuccs(LocalPointerKey pk) {
|
||||
|
@ -152,7 +155,7 @@ public abstract class AbstractDemandFlowGraph extends AbstractFlowGraph {
|
|||
return paramSuccs.iterator();
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* @see com.ibm.wala.demandpa.flowgraph.IFlowGraph#getParamPreds(com.ibm.wala.ipa.callgraph.propagation.LocalPointerKey)
|
||||
*/
|
||||
public Iterator<PointerKeyAndCallSite> getParamPreds(LocalPointerKey pk) {
|
||||
|
@ -186,7 +189,7 @@ public abstract class AbstractDemandFlowGraph extends AbstractFlowGraph {
|
|||
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* @see com.ibm.wala.demandpa.flowgraph.IFlowGraph#getReturnSuccs(com.ibm.wala.ipa.callgraph.propagation.LocalPointerKey)
|
||||
*/
|
||||
public Iterator<PointerKeyAndCallSite> getReturnSuccs(LocalPointerKey pk) {
|
||||
|
@ -213,7 +216,7 @@ public abstract class AbstractDemandFlowGraph extends AbstractFlowGraph {
|
|||
return returnSuccs.iterator();
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* @see com.ibm.wala.demandpa.flowgraph.IFlowGraph#getReturnPreds(com.ibm.wala.ipa.callgraph.propagation.LocalPointerKey)
|
||||
*/
|
||||
public Iterator<PointerKeyAndCallSite> getReturnPreds(LocalPointerKey pk) {
|
||||
|
@ -249,9 +252,9 @@ public abstract class AbstractDemandFlowGraph extends AbstractFlowGraph {
|
|||
return returnPreds.iterator();
|
||||
}
|
||||
|
||||
protected abstract void addNodesForParameters(CGNode node);
|
||||
protected abstract void addNodesForParameters(CGNode node, IR ir);
|
||||
|
||||
protected void unconditionallyAddConstraintsFromNode(CGNode node) {
|
||||
protected void unconditionallyAddConstraintsFromNode(CGNode node, IR ir) {
|
||||
|
||||
if (DEBUG) {
|
||||
Trace.println("Adding constraints for CGNode " + node);
|
||||
|
@ -265,7 +268,6 @@ public abstract class AbstractDemandFlowGraph extends AbstractFlowGraph {
|
|||
}
|
||||
}
|
||||
|
||||
IR ir = node.getIR();
|
||||
debugPrintIR(ir);
|
||||
|
||||
if (ir == null) {
|
||||
|
@ -274,8 +276,8 @@ public abstract class AbstractDemandFlowGraph extends AbstractFlowGraph {
|
|||
|
||||
DefUse du = node.getDU();
|
||||
addNodeInstructionConstraints(node, ir, du);
|
||||
addNodePassthruExceptionConstraints(node);
|
||||
addNodeConstantConstraints(node);
|
||||
addNodePassthruExceptionConstraints(node, ir);
|
||||
addNodeConstantConstraints(node, ir);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -364,22 +366,28 @@ public abstract class AbstractDemandFlowGraph extends AbstractFlowGraph {
|
|||
}
|
||||
}
|
||||
|
||||
final Map<CGNode, Set<CallSiteAndCGNode>> callerCache = HashMapFactory.make();
|
||||
|
||||
public Set<CallSiteAndCGNode> getPotentialCallers(PointerKey formalPk) {
|
||||
CGNode callee = null;
|
||||
if (formalPk instanceof LocalPointerKey) {
|
||||
callee = ((LocalPointerKey)formalPk).getNode();
|
||||
callee = ((LocalPointerKey) formalPk).getNode();
|
||||
} else if (formalPk instanceof ReturnValueKey) {
|
||||
callee = ((ReturnValueKey)formalPk).getNode();
|
||||
callee = ((ReturnValueKey) formalPk).getNode();
|
||||
} else {
|
||||
throw new IllegalArgumentException("formalPk must represent a local");
|
||||
}
|
||||
Set<CallSiteAndCGNode> ret = HashSetFactory.make();
|
||||
for (Iterator<? extends CGNode> predNodes = cg.getPredNodes(callee); predNodes.hasNext(); ) {
|
||||
CGNode caller = predNodes.next();
|
||||
for (Iterator<CallSiteReference> iterator = cg.getPossibleSites(caller, callee); iterator.hasNext(); ) {
|
||||
CallSiteReference call = iterator.next();
|
||||
ret.add(new CallSiteAndCGNode(call,caller));
|
||||
}
|
||||
Set<CallSiteAndCGNode> ret = callerCache.get(callee);
|
||||
if (ret == null) {
|
||||
ret = HashSetFactory.make();
|
||||
for (Iterator<? extends CGNode> predNodes = cg.getPredNodes(callee); predNodes.hasNext();) {
|
||||
CGNode caller = predNodes.next();
|
||||
for (Iterator<CallSiteReference> iterator = cg.getPossibleSites(caller, callee); iterator.hasNext();) {
|
||||
CallSiteReference call = iterator.next();
|
||||
ret.add(new CallSiteAndCGNode(call, caller));
|
||||
}
|
||||
}
|
||||
callerCache.put(callee, ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -393,7 +401,7 @@ public abstract class AbstractDemandFlowGraph extends AbstractFlowGraph {
|
|||
}
|
||||
|
||||
public AbstractDemandFlowGraph(final CallGraph cg, final HeapModel heapModel, final MemoryAccessMap mam, final ClassHierarchy cha) {
|
||||
super(mam,heapModel,cha,cg);
|
||||
super(mam, heapModel, cha, cg);
|
||||
}
|
||||
|
||||
}
|
|
@ -169,8 +169,7 @@ public abstract class AbstractFlowGraph extends SlowSparseNumberedLabeledGraph<O
|
|||
* For each invocation in the method, add nodes for actual parameters and return values
|
||||
* @param node
|
||||
*/
|
||||
protected void addNodesForInvocations(CGNode node) {
|
||||
final IR ir = node.getIR();
|
||||
protected void addNodesForInvocations(CGNode node, IR ir) {
|
||||
for (Iterator<CallSiteReference> iter = ir.iterateCallSites(); iter.hasNext(); ) {
|
||||
CallSiteReference site = iter.next();
|
||||
SSAAbstractInvokeInstruction[] calls = ir.getCalls(site);
|
||||
|
@ -380,10 +379,9 @@ public abstract class AbstractFlowGraph extends SlowSparseNumberedLabeledGraph<O
|
|||
* Add constraints to represent the flow of exceptions to the exceptional
|
||||
* return value for this node
|
||||
*/
|
||||
protected void addNodePassthruExceptionConstraints(CGNode node) {
|
||||
protected void addNodePassthruExceptionConstraints(CGNode node, IR ir) {
|
||||
// add constraints relating to thrown exceptions that reach the exit
|
||||
// block.
|
||||
IR ir = node.getIR();
|
||||
List<ProgramCounter> peis = SSAPropagationCallGraphBuilder.getIncomingPEIs(ir, ir.getExitBlock());
|
||||
PointerKey exception = heapModel.getPointerKeyForExceptionalReturnValue(node);
|
||||
|
||||
|
@ -454,8 +452,7 @@ public abstract class AbstractFlowGraph extends SlowSparseNumberedLabeledGraph<O
|
|||
/**
|
||||
* add constraints for reference constants assigned to vars
|
||||
*/
|
||||
protected void addNodeConstantConstraints(CGNode node) {
|
||||
IR ir = node.getIR();
|
||||
protected void addNodeConstantConstraints(CGNode node, IR ir) {
|
||||
SymbolTable symbolTable = ir.getSymbolTable();
|
||||
for (int i = 1; i <= symbolTable.getMaxValueNumber(); i++) {
|
||||
if (symbolTable.isConstant(i)) {
|
||||
|
|
|
@ -102,7 +102,7 @@ public class DemandPointerFlowGraph extends AbstractDemandFlowGraph implements I
|
|||
* @param node
|
||||
*/
|
||||
@Override
|
||||
protected void addNodesForParameters(CGNode node) {
|
||||
protected void addNodesForParameters(CGNode node, IR ir) {
|
||||
for (Iterator<Integer> iter = new PointerParamValueNumIterator(node); iter.hasNext();) {
|
||||
int parameter = iter.next();
|
||||
PointerKey paramPk = heapModel.getPointerKeyForLocal(node, parameter);
|
||||
|
|
|
@ -98,8 +98,7 @@ public class DemandValueFlowGraph extends AbstractDemandFlowGraph {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void addNodesForParameters(CGNode node) {
|
||||
IR ir = node.getIR();
|
||||
protected void addNodesForParameters(CGNode node, IR ir) {
|
||||
SymbolTable symbolTable = ir.getSymbolTable();
|
||||
int numParams = symbolTable.getNumberOfParameters();
|
||||
for (int i = 0; i < numParams; i++) {
|
||||
|
|
Loading…
Reference in New Issue