/** * @return an object which creates contexts for call graph nodes based on the container disambiguation policy */ protected ContextSelector makeContainerContextSelector(IClassHierarchy cha, ZeroXInstanceKeys keys) { return new ContainerContextSelector(cha, keys); }
/** * This method walks recursively up the definition of a context C, to see if * the chain of contexts that give rise to C includes the method M. * * If C is a ReceiverInstanceContext, Let N be the node that allocated * C.instance. If N.method == M, return N.context. Else return * findRecursiveMatchingContext(M, N.context) Else return null */ public static Context findRecursiveMatchingContext(IMethod M, Context C) { CGNode n = findNodeRecursiveMatchingContext(M, C); return (n == null) ? null : n.getContext(); }
/** * Does m represent a static factory method we know about from the standard libraries, that we usually wish to model with one * level of call-string context? */ public static boolean isWellKnownStaticFactory(MethodReference m) { if (isArrayCopyingMethod(m)) { return true; } if (isArrayToStringMethod(m)) { return true; } if (m.equals(StringValueOf)) { return true; } if (m.equals(HashtableNewEntry)) { return true; } return false; }
@Override public Context getCalleeTarget(CGNode caller, CallSiteReference site, IMethod callee, InstanceKey[] keys) { if (DEBUG) { System.err.println("ContainerContextSelector: getCalleeTarget " + callee); } InstanceKey receiver = null; if (keys != null && keys.length > 0 && keys[0] != null) { receiver = keys[0]; } if (mayUnderstand(site, callee, receiver)) { if (DEBUG) { System.err.println("May Understand: " + callee + " recv " + receiver); } if (isWellKnownStaticFactory(callee.getReference())) { return new CallerSiteContext(caller, site); } else { if (receiver == null) { Assertions.UNREACHABLE("null receiver for " + site); } return new ReceiverInstanceContext(receiver); } } else { return null; } }
throw new IllegalArgumentException("targetMethod is null"); if (isWellKnownStaticFactory(targetMethod.getReference())) { return true; } else { if (isContainer(targetMethod.getDeclaringClass())) { return true;
/** * Does m represent a library method that copies arrays? */ public static boolean isArrayCopyingMethod(MethodReference m) { if (m == null) { throw new IllegalArgumentException("null m"); } if (m.getDeclaringClass().equals(TypeReference.JavaLangSystem)) { if (m.getName().toString().equals("arraycopy")) { return true; } } if (m.equals(synthArraycopy)) { return true; } if (isArrayCopyMethod(m)) { return true; } return false; }
/** * This method walks recursively up the definition of a context C, to see if * the chain of contexts that give rise to C a) includes the method M. or b) * includes the method in which the receiver was allocated * * @return the matching context if found, null otherwise */ public static Context findRecursiveMatchingContext(IMethod M, Context C, InstanceKey receiver) { if (DEBUG) { System.err.println("findRecursiveMatchingContext for " + M + " in context " + C + " receiver " + receiver); } Context result = findRecursiveMatchingContext(M, C); if (result != null) { return result; } else { if (receiver instanceof AllocationSiteInNode) { AllocationSiteInNode a = (AllocationSiteInNode) receiver; IMethod m = a.getNode().getMethod(); return findRecursiveMatchingContext(m, C); } else { return null; } } }
@Override public Context getCalleeTarget(CGNode caller, CallSiteReference site, IMethod callee, InstanceKey[] keys) { if (DEBUG) { System.err.println("ContainerContextSelector: getCalleeTarget " + callee); } InstanceKey receiver = null; if (keys != null && keys.length > 0 && keys[0] != null) { receiver = keys[0]; } if (mayUnderstand(site, callee, receiver)) { if (DEBUG) { System.err.println("May Understand: " + callee + " recv " + receiver); } if (isWellKnownStaticFactory(callee.getReference())) { return new CallerSiteContext(caller, site); } else { if (receiver == null) { Assertions.UNREACHABLE("null receiver for " + site); } return new ReceiverInstanceContext(receiver); } } else { return null; } }
throw new IllegalArgumentException("targetMethod is null"); if (isWellKnownStaticFactory(targetMethod.getReference())) { return true; } else { if (isContainer(targetMethod.getDeclaringClass())) { return true;
/** * Does m represent a library method that copies arrays? */ public static boolean isArrayCopyingMethod(MethodReference m) { if (m == null) { throw new IllegalArgumentException("null m"); } if (m.getDeclaringClass().equals(TypeReference.JavaLangSystem)) { if (m.getName().toString().equals("arraycopy")) { return true; } } if (m.equals(synthArraycopy)) { return true; } if (isArrayCopyMethod(m)) { return true; } return false; }
/** * This method walks recursively up the definition of a context C, to see if * the chain of contexts that give rise to C a) includes the method M. or b) * includes the method in which the receiver was allocated * * @return the matching context if found, null otherwise */ public static Context findRecursiveMatchingContext(IMethod M, Context C, InstanceKey receiver) { if (DEBUG) { System.err.println("findRecursiveMatchingContext for " + M + " in context " + C + " receiver " + receiver); } Context result = findRecursiveMatchingContext(M, C); if (result != null) { return result; } else { if (receiver instanceof AllocationSiteInNode) { AllocationSiteInNode a = (AllocationSiteInNode) receiver; IMethod m = a.getNode().getMethod(); return findRecursiveMatchingContext(m, C); } else { return null; } } }
/** * @return an object which creates contexts for call graph nodes based on the container disambiguation policy */ protected ContextSelector makeContainerContextSelector(IClassHierarchy cha, ZeroXInstanceKeys keys) { return new ContainerContextSelector(cha, keys); }
/** * This method walks recursively up the definition of a context C, to see if * the chain of contexts that give rise to C includes the method M. * * If C is a ReceiverInstanceContext, Let N be the node that allocated * C.instance. If N.method == M, return N.context. Else return * findRecursiveMatchingContext(M, N.context) Else return null */ public static Context findRecursiveMatchingContext(IMethod M, Context C) { CGNode n = findNodeRecursiveMatchingContext(M, C); return (n == null) ? null : n.getContext(); }
/** * Does m represent a static factory method we know about from the standard libraries, that we usually wish to model with one * level of call-string context? */ public static boolean isWellKnownStaticFactory(MethodReference m) { if (isArrayCopyingMethod(m)) { return true; } if (isArrayToStringMethod(m)) { return true; } if (m.equals(StringValueOf)) { return true; } if (m.equals(HashtableNewEntry)) { return true; } return false; }
/** * @return an object which creates contexts for call graph nodes based on the container disambiguation policy */ protected ContextSelector makeContainerContextSelector(IClassHierarchy cha, ZeroXInstanceKeys keys) { return new ContainerContextSelector(cha, keys); }
return n; } else { return findNodeRecursiveMatchingContext(m, n.getContext()); return n; } else { return findNodeRecursiveMatchingContext(m, n.getContext());
/** * @return an object which creates contexts for call graph nodes based on the container disambiguation policy */ protected ContextSelector makeContainerContextSelector(IClassHierarchy cha, ZeroXInstanceKeys keys) { return new ContainerContextSelector(cha, keys); }
return n; } else { return findNodeRecursiveMatchingContext(m, n.getContext()); return n; } else { return findNodeRecursiveMatchingContext(m, n.getContext());
@Override public InstanceKey getInstanceKeyForAllocation(CGNode node, NewSiteReference allocation) { IClass type = options.getClassTargetSelector().getAllocatedTarget(node, allocation); if (type == null) { return null; } // disallow recursion in contexts. if (node.getContext().isA(ReceiverInstanceContext.class)) { IMethod m = node.getMethod(); CGNode n = ContainerContextSelector.findNodeRecursiveMatchingContext(m, node.getContext()); if (n != null) { return new SmushedAllocationSiteInNode(n, type); } } InstanceKey key = new SmushedAllocationSiteInNode(node, type); return key; }
@Override public InstanceKey getInstanceKeyForAllocation(CGNode node, NewSiteReference allocation) { IClass type = options.getClassTargetSelector().getAllocatedTarget(node, allocation); if (type == null) { return null; } // disallow recursion in contexts. if (node.getContext().isA(ReceiverInstanceContext.class)) { IMethod m = node.getMethod(); CGNode n = ContainerContextSelector.findNodeRecursiveMatchingContext(m, node.getContext()); if (n != null) { return new SmushedAllocationSiteInNode(n, type); } } InstanceKey key = new SmushedAllocationSiteInNode(node, type); return key; }