public CGNode nodeForMethod(IMethod method) { return cg.getNode(method, Everywhere.EVERYWHERE); } }
@Override public CGNode getNode(IMethod method, Context C) { CGNode x = cg.getNode(method, C); if (x == null) { return null; } return (containsNode(x) ? x : null); }
@Override public CGNode getNode(int index) { CGNode n = cg.getNode(index); return (containsNode(n) ? n : null); }
@Override public CGNode getNode(IMethod method, Context C) { CGNode x = cg.getNode(method, C); if (x == null) { return null; } return (containsNode(x) ? x : null); }
@Override public CGNode getNode(int index) { CGNode n = cg.getNode(index); return (containsNode(n) ? n : null); }
@Override protected List<Object> getChildrenFor(Object node) { List<Object> ret = new ArrayList<>(); if (node == cgNodesRoot){ for (int nodeId = 0 ; nodeId < cg.getNumberOfNodes(); nodeId++){ CGNode cgNode = cg.getNode(nodeId); ret.add(cgNode); } } else if (node == globalsRoot){ ret.addAll(globalsPointerKeys); } else { ret.addAll(super.getChildrenFor(node)); } return ret; } }
@Override protected List<Object> getChildrenFor(Object node) { List<Object> ret = new ArrayList<>(); if (node == cgNodesRoot){ for (int nodeId = 0 ; nodeId < cg.getNumberOfNodes(); nodeId++){ CGNode cgNode = cg.getNode(nodeId); ret.add(cgNode); } } else if (node == globalsRoot){ ret.addAll(globalsPointerKeys); } else { ret.addAll(super.getChildrenFor(node)); } return ret; } }
private void run(final CallGraph cg, final IProgressMonitor progress) throws WalaException, UnsoundGraphException, CancelException { if (this.cgFiltered != null) { throw new IllegalStateException("This analysis has already been computed."); } // we filter out everything we do not need now this.cg = cg; this.cgFiltered = computeFilteredCallgraph(cg); // we start with the first node final CGNode firstNode = cgFiltered.getNode(0); findAndInjectInvokes(firstNode, new ParameterState(), new HashSet<CGNode>(), progress); }
private void run(final CallGraph cg, final IProgressMonitor progress) throws WalaException, UnsoundGraphException, CancelException { if (this.cgFiltered != null) { throw new IllegalStateException("This analysis has already been computed."); } // we filter out everything we do not need now this.cg = cg; this.cgFiltered = computeFilteredCallgraph(cg); // we start with the first node final CGNode firstNode = cgFiltered.getNode(0); findAndInjectInvokes(firstNode, new ParameterState(), new HashSet<CGNode>(), progress); }
@Override public Iterator<Pair<CGNode, NewSiteReference>> getCreationSites(CallGraph CG) { CGNode cgn = CG.getNode(node, Everywhere.EVERYWHERE); assert cgn != null : node; return NonNullSingletonIterator.make(Pair.make(cgn, NewSiteReference.make(instructionIndex, createdType))); }
@Override public Iterator<Pair<CGNode, NewSiteReference>> getCreationSites(CallGraph CG) { CGNode cgn = CG.getNode(node, Everywhere.EVERYWHERE); assert cgn != null : node; return NonNullSingletonIterator.make(Pair.make(cgn, NewSiteReference.make(instructionIndex, createdType))); }
private static IR getIR(CallGraph cg, String fullyQualifiedTypeName, String methodName, String methodParameter, String methodReturnType) { IClassHierarchy classHierarchy = cg.getClassHierarchy(); MethodReference methodRef = IRTests .descriptorToMethodRef( String.format("Source#%s#%s#(%s)%s", fullyQualifiedTypeName, methodName, methodParameter, methodReturnType), classHierarchy); IMethod method = classHierarchy.resolveMethod(methodRef); CGNode node = cg.getNode(method, Everywhere.EVERYWHERE); return node.getIR(); }
@Test public void testNList() throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException { AnalysisScope scope = CallGraphTestUtil.makeJ2SEAnalysisScope(TestConstants.WALA_TESTDATA, CallGraphTestUtil.REGRESSION_EXCLUSIONS); ClassHierarchy cha = ClassHierarchyFactory.make(scope); Iterable<Entrypoint> entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, "Lrecurse/NList"); AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints); CallGraph cg = CallGraphTestUtil.buildZeroCFA(options, new AnalysisCacheImpl(), cha, scope, false); IBinaryNaturalRelation backEdges = Acyclic.computeBackEdges(cg, cg.getFakeRootNode()); Assert.assertTrue("NList should have cycles", backEdges.iterator().hasNext()); Map<CGNode, Set<CGNode>> cgBackEdges = HashMapFactory.make(); for (IntPair p : backEdges) { CGNode src = cg.getNode(p.getX()); if (!cgBackEdges.containsKey(src)) { cgBackEdges.put(src, HashSetFactory.<CGNode>make()); } cgBackEdges.get(src).add(cg.getNode(p.getY())); } PrunedCallGraph pcg = new PrunedCallGraph(cg, Iterator2Collection.toSet(cg.iterator()), cgBackEdges); Assert.assertTrue("cycles should be gone", !Acyclic.computeBackEdges(pcg, pcg.getFakeRootNode()).iterator().hasNext()); }
/** * Test that when analyzing Reflect18, the call graph includes a node for * java.lang.Integer.toString() */ @Test public void testReflect18() throws WalaException, IllegalArgumentException, CancelException, IOException { AnalysisScope scope = findOrCreateAnalysisScope(); IClassHierarchy cha = findOrCreateCHA(scope); Iterable<Entrypoint> entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, TestConstants.REFLECT18_MAIN); AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints); CallGraph cg = CallGraphTestUtil.buildZeroOneCFA(options, new AnalysisCacheImpl(), cha, scope, false); TypeReference tr = TypeReference.findOrCreate(ClassLoaderReference.Application, "Lreflection/Helper"); MethodReference mr = MethodReference.findOrCreate(tr, "t", "(Ljava/lang/Integer;)V"); CGNode node = cg.getNode(cg.getClassHierarchy().resolveMethod(mr), Everywhere.EVERYWHERE); Assert.assertEquals(1, cg.getSuccNodeCount(node)); CGNode succ = cg.getSuccNodes(node).next(); Assert.assertEquals("Node: < Primordial, Ljava/lang/Integer, toString()Ljava/lang/String; > Context: Everywhere", succ.toString()); }
/** * Test that when analyzing Reflect17, the call graph does not include any * edges from reflection.Helper.t() */ @Test public void testReflect17() throws WalaException, IllegalArgumentException, CancelException, IOException { AnalysisScope scope = findOrCreateAnalysisScope(); IClassHierarchy cha = findOrCreateCHA(scope); Iterable<Entrypoint> entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, TestConstants.REFLECT17_MAIN); AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints); CallGraph cg = CallGraphTestUtil.buildZeroOneCFA(options, new AnalysisCacheImpl(), cha, scope, false); TypeReference tr = TypeReference.findOrCreate(ClassLoaderReference.Application, "Lreflection/Helper"); MethodReference mr = MethodReference.findOrCreate(tr, "t", "(Ljava/lang/Integer;)V"); CGNode node = cg.getNode(cg.getClassHierarchy().resolveMethod(mr), Everywhere.EVERYWHERE); Assert.assertEquals(0, cg.getSuccNodeCount(node)); }
@Test public void testZeroLengthArray() throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException { AnalysisScope scope = CallGraphTestUtil.makeJ2SEAnalysisScope(TestConstants.WALA_TESTDATA, CallGraphTestUtil.REGRESSION_EXCLUSIONS); ClassHierarchy cha = ClassHierarchyFactory.make(scope); Iterable<Entrypoint> entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, TestConstants.ZERO_LENGTH_ARRAY_MAIN); AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints); CallGraphBuilder<InstanceKey> builder = Util.makeVanillaZeroOneCFABuilder(Language.JAVA, options, new AnalysisCacheImpl(), cha, scope); CallGraph cg = builder.makeCallGraph(options, null); PointerAnalysis<InstanceKey> pa = builder.getPointerAnalysis(); // System.err.println(pa); HeapModel heapModel = pa.getHeapModel(); CGNode mainNode = cg.getNode( cha.resolveMethod(MethodReference.findOrCreate( TypeReference.findOrCreate(ClassLoaderReference.Application, TestConstants.ZERO_LENGTH_ARRAY_MAIN), Selector.make("main([Ljava/lang/String;)V"))), Everywhere.EVERYWHERE); OrdinalSet<InstanceKey> pointsToSet = pa.getPointsToSet(heapModel.getPointerKeyForLocal(mainNode, 4)); Assert.assertEquals(1, pointsToSet.size()); InstanceKey arrayKey = pointsToSet.iterator().next(); OrdinalSet<InstanceKey> arrayContents = pa.getPointsToSet(heapModel.getPointerKeyForArrayContents(arrayKey)); System.err.println(arrayContents); Assert.assertEquals(0, arrayContents.size()); } }