fix a bug with object-sensitivity context selection and recursion

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@2939 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
sjfink 2008-07-01 20:45:24 +00:00
parent 711d039714
commit 47857f7041
2 changed files with 21 additions and 12 deletions

View File

@ -17,6 +17,7 @@ import com.ibm.wala.classLoader.NewSiteReference;
import com.ibm.wala.classLoader.ProgramCounter; import com.ibm.wala.classLoader.ProgramCounter;
import com.ibm.wala.ipa.callgraph.AnalysisOptions; import com.ibm.wala.ipa.callgraph.AnalysisOptions;
import com.ibm.wala.ipa.callgraph.CGNode; import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.propagation.cfa.CallerContext;
import com.ibm.wala.ipa.callgraph.propagation.cfa.ContainerContextSelector; import com.ibm.wala.ipa.callgraph.propagation.cfa.ContainerContextSelector;
import com.ibm.wala.ipa.cha.IClassHierarchy; import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.types.TypeReference; import com.ibm.wala.types.TypeReference;
@ -67,16 +68,16 @@ public class AllocationSiteInNodeFactory implements InstanceKeyFactory {
} }
// disallow recursion in contexts. // disallow recursion in contexts.
if (node.getContext() instanceof ReceiverInstanceContext) { if (node.getContext() instanceof ReceiverInstanceContext || node.getContext() instanceof CallerContext) {
IMethod m = node.getMethod(); IMethod m = node.getMethod();
CGNode n = ContainerContextSelector.findNodeRecursiveMatchingContext(m, node.getContext()); CGNode n = ContainerContextSelector.findNodeRecursiveMatchingContext(m, node.getContext());
if (n != null) { if (n != null) {
return new NormalAllocationInNode(n, allocation, type); return new NormalAllocationInNode(n, allocation, type);
} }
} }
InstanceKey key = new NormalAllocationInNode(node, allocation, type); InstanceKey key = new NormalAllocationInNode(node, allocation, type);
return key; return key;
} }

View File

@ -200,21 +200,29 @@ public class ContainerContextSelector implements ContextSelector {
* If C is a ReceiverInstanceContext, Let N be the node that allocated C.instance. If N.method == M, return N. Else * If C is a ReceiverInstanceContext, Let N be the node that allocated C.instance. If N.method == M, return N. Else
* return findRecursiveMatchingContext(M, N.context) Else return null * return findRecursiveMatchingContext(M, N.context) Else return null
*/ */
public static CGNode findNodeRecursiveMatchingContext(IMethod M, Context C) { public static CGNode findNodeRecursiveMatchingContext(IMethod m, Context c) {
if (DEBUG) { if (DEBUG) {
System.err.println("findNodeRecursiveMatchingContext " + M + " in context " + C); System.err.println("findNodeRecursiveMatchingContext " + m + " in context " + c);
} }
if (C instanceof ReceiverInstanceContext) { if (c instanceof ReceiverInstanceContext) {
ReceiverInstanceContext ric = (ReceiverInstanceContext) C; ReceiverInstanceContext ric = (ReceiverInstanceContext) c;
if (!(ric.getReceiver() instanceof AllocationSiteInNode)) { if (!(ric.getReceiver() instanceof AllocationSiteInNode)) {
return null; return null;
} }
AllocationSiteInNode I = (AllocationSiteInNode) ric.getReceiver(); AllocationSiteInNode i = (AllocationSiteInNode) ric.getReceiver();
CGNode N = I.getNode(); CGNode n = i.getNode();
if (N.getMethod().equals(M)) { if (n.getMethod().equals(m)) {
return N; return n;
} else { } else {
return findNodeRecursiveMatchingContext(M, N.getContext()); return findNodeRecursiveMatchingContext(m, n.getContext());
}
} else if (c instanceof CallerContext) {
CallerContext cc = (CallerContext)c;
CGNode n = cc.getCaller();
if (n.getMethod().equals(m)) {
return n;
} else {
return findNodeRecursiveMatchingContext(m, n.getContext());
} }
} else { } else {
return null; return null;