public static CallGraph makeHTMLCG(URL url, Supplier<JSSourceExtractor> fExtractor) throws IllegalArgumentException, CancelException, WalaException { SSAPropagationCallGraphBuilder b = makeHTMLCGBuilder(url, fExtractor); CallGraph CG = b.makeCallGraph(b.getOptions()); dumpCG(b.getCFAContextInterpreter(), b.getPointerAnalysis(), CG); return CG; }
protected boolean hasNoInterestingUses(int vn) { return getBuilder().hasNoInterestingUses(node, vn, du); }
/** * make a {@link CallGraphBuilder} that uses call-string context sensitivity, * with call-string length limited to n, and a context-sensitive * allocation-site-based heap abstraction. Standard optimizations in the heap * abstraction like smushing of strings are disabled. */ public static SSAPropagationCallGraphBuilder makeVanillaNCFABuilder(int n, AnalysisOptions options, IAnalysisCacheView cache, IClassHierarchy cha, AnalysisScope scope) { if (options == null) { throw new IllegalArgumentException("options is null"); } addDefaultSelectors(options, cha); addDefaultBypassLogic(options, scope, Util.class.getClassLoader(), cha); ContextSelector appSelector = null; SSAContextInterpreter appInterpreter = null; SSAPropagationCallGraphBuilder result = new nCFABuilder(n, Language.JAVA.getFakeRootMethod(cha, options, cache), options, cache, appSelector, appInterpreter); // nCFABuilder uses type-based heap abstraction by default, but we want allocation sites result.setInstanceKeys(new ZeroXInstanceKeys(options, cha, result.getContextInterpreter(), ZeroXInstanceKeys.ALLOCATIONS | ZeroXInstanceKeys.CONSTANT_SPECIFIC)); return result; }
public ConstraintVisitor(SSAPropagationCallGraphBuilder builder, CGNode node) { this.builder = builder; this.node = node; this.callGraph = builder.getCallGraph(); this.system = builder.getPropagationSystem(); SSAContextInterpreter interp = builder.getCFAContextInterpreter(); this.ir = interp.getIRView(node); this.symbolTable = this.ir.getSymbolTable(); this.du = interp.getDU(node); assert symbolTable != null; }
System.err.println("\n\nAdd constraints from node " + node); IRView ir = getCFAContextInterpreter().getIRView(node); if (DEBUG) { if (ir == null) { addNodeInstructionConstraints(node, monitor); addNodeValueConstraints(node, monitor); DefUse du = getCFAContextInterpreter().getDU(node); addNodePassthruExceptionConstraints(node, ir, du);
public static void analyzeMethodHandles(AnalysisOptions options, SSAPropagationCallGraphBuilder builder) { options.setSelector(new InvokeExactTargetSelector(options.getMethodTargetSelector())); builder.setContextSelector(new ContextSelectorImpl(builder.getContextSelector())); builder.setContextInterpreter(new DelegatingSSAContextInterpreter(new InvokeContextInterpreterImpl(), builder.getCFAContextInterpreter())); builder.setContextInterpreter(new DelegatingSSAContextInterpreter(new FindContextInterpreterImpl(), builder.getCFAContextInterpreter())); } }
builder.setInstanceKeys(new ZeroXInstanceKeys(options, cha, builder.getContextInterpreter(), ZeroXInstanceKeys.ALLOCATIONS CallGraph cg = builder.makeCallGraph(options, null); System.err.println("Statement: " + s); final PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis(); Collection<Statement> slice = Slicer.computeBackwardSlice(s, pcg, pointerAnalysis, DataDependenceOptions.FULL, ControlDependenceOptions.NONE);
public static CallGraph buildZeroCFA(AnalysisOptions options, IAnalysisCacheView cache, IClassHierarchy cha, AnalysisScope scope, boolean testPAtoString) throws IllegalArgumentException, CancelException { StopwatchGC S = null; if (CHECK_FOOTPRINT) { S = new StopwatchGC("build RTA graph"); S.start(); } SSAPropagationCallGraphBuilder builder = Util.makeZeroCFABuilder(Language.JAVA, options, cache, cha, scope); CallGraph cg = builder.makeCallGraph(options, null); if (testPAtoString) { builder.getPointerAnalysis().toString(); } if (CHECK_FOOTPRINT) { S.stop(); System.err.println(S.report()); } return cg; }
PointerKey e = getPointerKeyForLocal(node, s.getException()); addAssignmentsForCatchPointerKey(exceptionVar, catchClasses, e); PointerKey e = getPointerKeyForLocal(node, s.getException()); if (contentsAreInvariant(ir.getSymbolTable(), du, s.getException())) { InstanceKey[] ik = getInvariantContents(ir.getSymbolTable(), du, node, s.getException(), this); for (InstanceKey element : ik) { system.findOrCreateIndexForInstanceKey(element); assignInstanceToCatch(exceptionVar, catchClasses, element); addAssignmentsForCatchPointerKey(exceptionVar, catchClasses, e); for (TypeReference type : types) { if (type != null) { InstanceKey ik = getInstanceKeyForPEI(node, peiLoc, type, instanceKeyFactory); if (ik == null) { continue; IClass klass = ck.getType(); if (PropagationCallGraphBuilder.catches(catchClasses, klass, cha)) { system.newConstraint(exceptionVar, getInstanceKeyForPEI(node, peiLoc, type, instanceKeyFactory));
cg = cgb.makeCallGraph(cgb.getOptions()); } catch (Exception e) { graphBuilt = false; pa = cgb.getPointerAnalysis(); partialGraph = GraphSlicer.prune(cg, node -> LoaderUtils.fromLoader(node, ClassLoaderReference.Application) || node.getMethod().isWalaSynthetic()); if (options.includeLibrary()) {
if (hasUniqueCatchBlock(instruction, ir)) { uniqueCatch = getBuilder().getUniqueCatchKey(instruction, ir, node); IntSet params = getBuilder().getContextSelector().getRelevantParameters(node, instruction.getCallSite()); if (!instruction.getCallSite().isStatic() && !params.contains(0) && (invariantParameters == null || invariantParameters[0] == null)) { params = IntSetUtil.makeMutableCopy(params); for (CGNode n : getBuilder().getTargetsForCall(node, instruction, invariantParameters)) { getBuilder().processResolvedCall(node, instruction, n, invariantParameters, uniqueCatch); if (DEBUG) { for(CGNode n : getBuilder().getTargetsForCall(node, instruction, invariantParameters)) { getBuilder().processResolvedCall(node, instruction, n, invariantParameters, uniqueCatch); params.foreach(x -> { if (!contentsAreInvariant(symbolTable, du, instruction.getUse(x))) { pks.add(getBuilder().getPointerKeyForLocal(node, instruction.getUse(x)));
continue; PointerKey def = getPointerKeyForLocal(node, phi.getDef()); if (hasNoInterestingUses(node, phi.getDef(), v.du)) { system.recordImplicitPointsToSet(def); } else { PointerKey use = getPointerKeyForLocal(node, phi.getUse(n)); if (contentsAreInvariant(v.symbolTable, v.du, phi.getUse(n))) { system.recordImplicitPointsToSet(use); InstanceKey[] ik = getInvariantContents(v.symbolTable, v.du, node, phi.getUse(n), this); for (InstanceKey element : ik) { system.newConstraint(def, element);
private static void doCPATest(String testClass, String testIdSignature) 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, testClass); AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints); SSAPropagationCallGraphBuilder builder = Util.makeZeroCFABuilder(Language.JAVA, options, new AnalysisCacheImpl(), cha, scope); builder.setContextSelector(new CPAContextSelector(builder.getContextSelector())); CallGraph cg = builder.makeCallGraph(options, null); // Find id TypeReference str = TypeReference.findOrCreate(ClassLoaderReference.Application, testClass); MethodReference ct = MethodReference.findOrCreate(str, Atom.findOrCreateUnicodeAtom("id"), Descriptor.findOrCreateUTF8(testIdSignature)); Set<CGNode> idNodes = cg.getNodes(ct); System.err.println(cg); Assert.assertEquals(2, idNodes.size()); } }
if (!getBuilder().getOptions().getHandleStaticInit()) { return; AbstractRootMethod fakeWorldClinitMethod = (AbstractRootMethod) callGraph.getFakeWorldClinitNode().getMethod(); SSAAbstractInvokeInstruction s = fakeWorldClinitMethod.addInvocation(new int[0], site); PointerKey uniqueCatch = getBuilder().getPointerKeyForExceptionalReturnValue(callGraph.getFakeRootNode()); getBuilder().processResolvedCall(callGraph.getFakeWorldClinitNode(), s, target, null, uniqueCatch);
private void testOCamlJar(String jarFile, String... args) throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException, ClassNotFoundException, InvalidClassFileException, FailureException, SecurityException, InterruptedException { File F = TemporaryFile.urlToFile(jarFile.replace('.', '_') + ".jar", getClass().getClassLoader().getResource(jarFile)); F.deleteOnExit(); AnalysisScope scope = CallGraphTestUtil.makeJ2SEAnalysisScope("base.txt", CallGraphTestUtil.REGRESSION_EXCLUSIONS); scope.addToScope(ClassLoaderReference.Application, new JarFile(F, false)); ClassHierarchy cha = ClassHierarchyFactory.make(scope); Iterable<Entrypoint> entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, "Lpack/ocamljavaMain"); AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints); options.setUseConstantSpecificKeys(true); IAnalysisCacheView cache = new AnalysisCacheImpl(); SSAPropagationCallGraphBuilder builder = Util.makeZeroCFABuilder(Language.JAVA, options, cache, cha, scope); MethodHandles.analyzeMethodHandles(options, builder); CallGraph cg = builder.makeCallGraph(options, null); System.err.println(cg); instrument(F.getAbsolutePath()); run("pack.ocamljavaMain", null, args); checkNodes(cg, t -> { String s = t.toString(); return s.contains("Lpack/") || s.contains("Locaml/stdlib/"); }); }
public SSAContextInterpreter getCFAContextInterpreter() { return (SSAContextInterpreter) getContextInterpreter(); }
private static Pair<CallGraph,PointerAnalysis<InstanceKey>> makeJavaBuilder(String scopeFile, String mainClass) throws IOException, ClassHierarchyException, IllegalArgumentException, CancelException { AnalysisScope scope = CallGraphTestUtil.makeJ2SEAnalysisScope(scopeFile, CallGraphTestUtil.REGRESSION_EXCLUSIONS); ClassHierarchy cha = ClassHierarchyFactory.make(scope); Iterable<Entrypoint> entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, mainClass); AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints); SSAPropagationCallGraphBuilder builder = Util.makeZeroCFABuilder(Language.JAVA, options, new AnalysisCacheImpl(), cha, scope); CallGraph CG = builder.makeCallGraph(options); return Pair.make(CG, builder.getPointerAnalysis()); }
PointerKey e = getPointerKeyForLocal(node, s.getException()); addAssignmentsForCatchPointerKey(exceptionVar, catchClasses, e); PointerKey e = getPointerKeyForLocal(node, s.getException()); if (contentsAreInvariant(ir.getSymbolTable(), du, s.getException())) { InstanceKey[] ik = getInvariantContents(ir.getSymbolTable(), du, node, s.getException(), this); for (InstanceKey element : ik) { system.findOrCreateIndexForInstanceKey(element); assignInstanceToCatch(exceptionVar, catchClasses, element); addAssignmentsForCatchPointerKey(exceptionVar, catchClasses, e); for (TypeReference type : types) { if (type != null) { InstanceKey ik = getInstanceKeyForPEI(node, peiLoc, type, instanceKeyFactory); if (ik == null) { continue; IClass klass = ck.getType(); if (PropagationCallGraphBuilder.catches(catchClasses, klass, cha)) { system.newConstraint(exceptionVar, getInstanceKeyForPEI(node, peiLoc, type, instanceKeyFactory));
public static void analyzeMethodHandles(AnalysisOptions options, SSAPropagationCallGraphBuilder builder) { options.setSelector(new InvokeExactTargetSelector(options.getMethodTargetSelector())); builder.setContextSelector(new ContextSelectorImpl(builder.getContextSelector())); builder.setContextInterpreter(new DelegatingSSAContextInterpreter(new InvokeContextInterpreterImpl(), builder.getCFAContextInterpreter())); builder.setContextInterpreter(new DelegatingSSAContextInterpreter(new FindContextInterpreterImpl(), builder.getCFAContextInterpreter())); } }
if (hasUniqueCatchBlock(instruction, ir)) { uniqueCatch = getBuilder().getUniqueCatchKey(instruction, ir, node); IntSet params = getBuilder().getContextSelector().getRelevantParameters(node, instruction.getCallSite()); if (!instruction.getCallSite().isStatic() && !params.contains(0) && (invariantParameters == null || invariantParameters[0] == null)) { params = IntSetUtil.makeMutableCopy(params); for (CGNode n : getBuilder().getTargetsForCall(node, instruction, invariantParameters)) { getBuilder().processResolvedCall(node, instruction, n, invariantParameters, uniqueCatch); if (DEBUG) { for(CGNode n : getBuilder().getTargetsForCall(node, instruction, invariantParameters)) { getBuilder().processResolvedCall(node, instruction, n, invariantParameters, uniqueCatch); params.foreach(x -> { if (!contentsAreInvariant(symbolTable, du, instruction.getUse(x))) { pks.add(getBuilder().getPointerKeyForLocal(node, instruction.getUse(x)));