@Override public Iterator<CGNode> getSuccNodes(final CGNode n) { return new FilterIterator<>(new ComposedIterator<CallSiteReference, CGNode>(n.iterateCallSites()) { @Override public Iterator<? extends CGNode> makeInner(CallSiteReference outer) { return getPossibleTargets(n, outer).iterator(); } }, new Predicate<CGNode>() { private final MutableIntSet nodes = IntSetUtil.make(); @Override public boolean test(CGNode o) { if (nodes.contains(o.getGraphNodeId())) { return false; } else { nodes.add(o.getGraphNodeId()); return true; } } }); }
public static String nodeToString(CallGraph CG, CGNode n) { StringBuilder result = new StringBuilder(n.toString() + '\n'); if (n.getMethod() != null) { for (CallSiteReference site : Iterator2Iterable.make(n.iterateCallSites())) { Iterator<CGNode> targets = CG.getPossibleTargets(n, site).iterator(); if (targets.hasNext()) { result.append(" - ").append(site).append('\n'); } for (CGNode target : Iterator2Iterable.make(targets)) { result.append(" -> ").append(target).append('\n'); } } } return result.toString(); }
@Override public Iterator<CGNode> getSuccNodes(final CGNode n) { return new FilterIterator<>(new ComposedIterator<CallSiteReference, CGNode>(n.iterateCallSites()) { @Override public Iterator<? extends CGNode> makeInner(CallSiteReference outer) { return getPossibleTargets(n, outer).iterator(); } }, new Predicate<CGNode>() { private final MutableIntSet nodes = IntSetUtil.make(); @Override public boolean test(CGNode o) { if (nodes.contains(o.getGraphNodeId())) { return false; } else { nodes.add(o.getGraphNodeId()); return true; } } }); }
public static String nodeToString(CallGraph CG, CGNode n) { StringBuilder result = new StringBuilder(n.toString() + '\n'); if (n.getMethod() != null) { for (CallSiteReference site : Iterator2Iterable.make(n.iterateCallSites())) { Iterator<CGNode> targets = CG.getPossibleTargets(n, site).iterator(); if (targets.hasNext()) { result.append(" - ").append(site).append('\n'); } for (CGNode target : Iterator2Iterable.make(targets)) { result.append(" -> ").append(target).append('\n'); } } } return result.toString(); }
private void expandNode(DefaultMutableTreeNode treeNode, int rec) { if (rec == 0) { return; } if (treeNode.getChildCount() == 0) { List<DefaultMutableTreeNode> newChilds = new ArrayList<>(); Object userObject = treeNode.getUserObject(); if (userObject instanceof CGNode) { CGNode cgNode = (CGNode) userObject; for (CallSiteReference csr : Iterator2Iterable.make(cgNode.iterateCallSites())) { newChilds.add(new DefaultMutableTreeNode(csr)); } } else { assert userObject instanceof CallSiteReference; CallSiteReference csr = (CallSiteReference) userObject; CGNode cgNode = (CGNode) ((DefaultMutableTreeNode) treeNode.getParent()).getUserObject(); Set<CGNode> successors = cg.getPossibleTargets(cgNode, csr); for (CGNode successor : successors) { newChilds.add(new DefaultMutableTreeNode(successor)); } } for (DefaultMutableTreeNode newChild : newChilds) { treeNode.add(newChild); } } for (int i = 0; i < treeNode.getChildCount(); i++) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) treeNode.getChildAt(i); expandNode(child, rec - 1); } }
private void expandNode(DefaultMutableTreeNode treeNode, int rec) { if (rec == 0) { return; } if (treeNode.getChildCount() == 0) { List<DefaultMutableTreeNode> newChilds = new ArrayList<>(); Object userObject = treeNode.getUserObject(); if (userObject instanceof CGNode) { CGNode cgNode = (CGNode) userObject; for (CallSiteReference csr : Iterator2Iterable.make(cgNode.iterateCallSites())) { newChilds.add(new DefaultMutableTreeNode(csr)); } } else { assert userObject instanceof CallSiteReference; CallSiteReference csr = (CallSiteReference) userObject; CGNode cgNode = (CGNode) ((DefaultMutableTreeNode) treeNode.getParent()).getUserObject(); Set<CGNode> successors = cg.getPossibleTargets(cgNode, csr); for (CGNode successor : successors) { newChilds.add(new DefaultMutableTreeNode(successor)); } } for (DefaultMutableTreeNode newChild : newChilds) { treeNode.add(newChild); } } for (int i = 0; i < treeNode.getChildCount(); i++) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) treeNode.getChildAt(i); expandNode(child, rec - 1); } }
private void closure() throws CancelException { while (! newNodes.isEmpty()) { CGNode n = newNodes.pop(); for(CallSiteReference site : Iterator2Iterable.make(n.iterateCallSites())) { Iterator<IMethod> methods = getPossibleTargets(site); while (methods.hasNext()) { IMethod target = methods.next(); if (isRelevantMethod(target)) { CGNode callee = getNode(target, Everywhere.EVERYWHERE); if (callee == null) { callee = findOrCreateNode(target, Everywhere.EVERYWHERE); if (n == getFakeRootNode()) { registerEntrypoint(callee); } } } } } } }
private void closure() throws CancelException { while (! newNodes.isEmpty()) { CGNode n = newNodes.pop(); for(CallSiteReference site : Iterator2Iterable.make(n.iterateCallSites())) { Iterator<IMethod> methods = getPossibleTargets(site); while (methods.hasNext()) { IMethod target = methods.next(); if (isRelevantMethod(target)) { CGNode callee = getNode(target, Everywhere.EVERYWHERE); if (callee == null) { callee = findOrCreateNode(target, Everywhere.EVERYWHERE); if (n == getFakeRootNode()) { registerEntrypoint(callee); } } } } } } }
private void checkCaughtExceptions(CGNode node, IntraproceduralExceptionAnalysis analysis) { String text = "Number of caught exceptions did not match in " + node.getMethod().getName().toString() + ". The follwoing exceptions were caught: "; Iterator<CallSiteReference> it = node.iterateCallSites(); while (it.hasNext()) { Set<TypeReference> caught = analysis.getCaughtExceptions(it.next()); if (node.getMethod().getName().toString().matches("testTryCatch.*")) { if (node.getMethod().getName().toString().equals("testTryCatchMultipleExceptions")) { collector.checkThat(text + caught.toString(), caught.size(), equalTo(2)); } else if (node.getMethod().getName().toString().equals("testTryCatchSuper")) { collector.checkThat(text + caught.toString(), caught.size(), not(anyOf(equalTo(0), equalTo(1), equalTo(2), equalTo(3)))); } else { collector.checkThat(text + caught.toString(), caught.size(), equalTo(1)); } } else { collector.checkThat(text + caught.toString(), caught.size(), equalTo(0)); } } }
protected void checkCompareToCalls(CallGraph cg, Set<CGNode> ctnodes, String x, int expected) { // Find node corresponding to id1 TypeReference tid1 = TypeReference.findOrCreate(ClassLoaderReference.Application, "Llambda/SortingExample"); MethodReference mid1 = MethodReference.findOrCreate(tid1, x, "(I)I"); Assert.assertTrue("expect " + x + " node", cg.getNodes(mid1).iterator().hasNext()); CGNode id1node = cg.getNodes(mid1).iterator().next(); // caller of id1 is dynamic from sortForward, and has 1 compareTo CGNode sfnode = cg.getPredNodes(id1node).next(); int count = 0; for(CallSiteReference site : Iterator2Iterable.make(sfnode.iterateCallSites())) { if (ctnodes.containsAll(cg.getPossibleTargets(sfnode, site))) { count++; } } Assert.assertEquals("expected one call to compareTo", expected, count); System.err.println("found " + count + " compareTo calls in " + sfnode); } }
public static Map<String, Set<String>> extractEdges(CallGraph cg) { Map<String, Set<String>> edges = HashMapFactory.make(); for(CGNode nd : cg) { if(!isRealFunction(nd.getMethod())) continue; AstMethod method = (AstMethod)nd.getMethod(); for(CallSiteReference callsite : Iterator2Iterable.make(nd.iterateCallSites())) { Set<IMethod> targets = Util.mapToSet(cg.getPossibleTargets(nd, callsite), CGNode::getMethod); serializeCallSite(method, callsite, targets, edges); } } return edges; }
public static Map<String, Set<String>> extractEdges(CallGraph cg) { Map<String, Set<String>> edges = HashMapFactory.make(); for(CGNode nd : cg) { if(!isRealFunction(nd.getMethod())) continue; AstMethod method = (AstMethod)nd.getMethod(); for(CallSiteReference callsite : Iterator2Iterable.make(nd.iterateCallSites())) { Set<IMethod> targets = Util.mapToSet(cg.getPossibleTargets(nd, callsite), CGNode::getMethod); serializeCallSite(method, callsite, targets, edges); } } return edges; }
for (CallSiteReference sr : Iterator2Iterable.make(src.iterateCallSites())) {
private static void checkCallAssertions(CallGraph cg, int desiredNumberOfTargets, int desiredNumberOfCalls, int numLocalCastCallees) { int numberOfCalls = 0; Set<CGNode> callerNodes = HashSetFactory.make(); callerNodes.addAll(cg.getNodes(thisBinaryRef)); callerNodes.addAll(cg.getNodes(thatBinaryRef)); assert callerNodes.size() == 2; for (CGNode n : callerNodes) { for (CallSiteReference csRef : Iterator2Iterable.make(n.iterateCallSites())) { if (csRef.getDeclaredTarget().equals(unary2Ref)) { numberOfCalls++; assert cg.getNumberOfTargets(n, csRef) == desiredNumberOfTargets; } } } assert numberOfCalls == desiredNumberOfCalls; CGNode localCastNode = cg.getNodes(MethodReference.findOrCreate(TypeReference.findOrCreate(loader, TestConstants.PI_TEST_MAIN), "localCast", "()V")).iterator().next(); int actualLocalCastCallees = cg.getSuccNodeCount(localCastNode); Assert.assertEquals(numLocalCastCallees, actualLocalCastCallees); }
for (CallSiteReference site : Iterator2Iterable.make(node.iterateCallSites())) { if (site.isSpecial()) { if (site.getDeclaredTarget().getDeclaringClass().equals(TypeReference.JavaLangObject)) {
Iterator<CallSiteReference> sites = ctorCaller.iterateCallSites(); while(sites.hasNext()) { CallSiteReference r = sites.next();
Iterator<CallSiteReference> sites = ctorCaller.iterateCallSites(); while(sites.hasNext()) { CallSiteReference r = sites.next();