private static DefinitelyDerefedParams getAnalysisDriver( IMethod mtd, AnalysisOptions options, AnalysisCache cache, IClassHierarchy cha) { IR ir = cache.getIRFactory().makeIR(mtd, Everywhere.EVERYWHERE, options.getSSAOptions()); ControlFlowGraph<SSAInstruction, ISSABasicBlock> cfg = ir.getControlFlowGraph(); accountCodeBytes(mtd); return new DefinitelyDerefedParams(mtd, ir, cfg, cha); }
public Iterator<SSAInstruction> getInvokeStatements() { ArrayList<SSAInstruction> result = new ArrayList<>(); SSAInstruction[] statements = getStatements(options.getSSAOptions()); for (SSAInstruction statement : statements) { if (statement instanceof SSAInvokeInstruction) { result.add(statement); } } return result.iterator(); }
public Iterator<SSAInstruction> getInvokeStatements() { ArrayList<SSAInstruction> result = new ArrayList<>(); SSAInstruction[] statements = getStatements(options.getSSAOptions()); for (SSAInstruction statement : statements) { if (statement instanceof SSAInvokeInstruction) { result.add(statement); } } return result.iterator(); }
public AnalysisCacheImpl(IRFactory<IMethod> irFactory) { this(irFactory, new AnalysisOptions().getSSAOptions()); }
public AnalysisCacheImpl(IRFactory<IMethod> irFactory) { this(irFactory, new AnalysisOptions().getSSAOptions()); }
@Override public Iterator<NewSiteReference> iterateNewSites(CGNode node) { ArrayList<NewSiteReference> result = new ArrayList<>(); SSAInstruction[] statements = getStatements(options.getSSAOptions()); for (SSAInstruction statement : statements) { if (statement instanceof SSANewInstruction) { SSANewInstruction s = (SSANewInstruction) statement; result.add(s.getNewSite()); } } return result.iterator(); }
@Override public Iterator<NewSiteReference> iterateNewSites(CGNode node) { ArrayList<NewSiteReference> result = new ArrayList<>(); SSAInstruction[] statements = getStatements(options.getSSAOptions()); for (SSAInstruction statement : statements) { if (statement instanceof SSANewInstruction) { SSANewInstruction s = (SSANewInstruction) statement; result.add(s.getNewSite()); } } return result.iterator(); }
private static IR getIr(IMethod method) { return irFactory.makeIR(method, Everywhere.EVERYWHERE, options.getSSAOptions()); }
public static IR getIr(IMethod method) { return irFactory.makeIR(method, Everywhere.EVERYWHERE, options.getSSAOptions()); }
private int addOriginalStatements(SummarizedMethod m) { SSAInstruction[] original = m.getStatements(options.getSSAOptions()); // local value number 1 is "this", so the next free value number is 2 int nextLocal = 2; for (SSAInstruction s : original) { allInstructions.add(s); if (s instanceof SSAInvokeInstruction) { calls.add(s); } if (s instanceof SSANewInstruction) { allocations.add(s); } for (int j = 0; j < s.getNumberOfDefs(); j++) { int def = s.getDef(j); if (def >= nextLocal) { nextLocal = def + 1; } } for (int j = 0; j < s.getNumberOfUses(); j++) { int use = s.getUse(j); if (use >= nextLocal) { nextLocal = use + 1; } } } return nextLocal; }
private static CallGraph doGraph(boolean usePiNodes) 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.PI_TEST_MAIN); AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints); SSAPiNodePolicy policy = usePiNodes ? SSAOptions.getAllBuiltInPiNodes() : null; options.getSSAOptions().setPiNodePolicy(policy); return CallGraphTestUtil.buildZeroCFA(options, new AnalysisCacheImpl(new DefaultIRFactory(), options.getSSAOptions()), cha, scope, false); }
@Test public void testLocalNamesWithPiNodes() { SSAPiNodePolicy save = options.getSSAOptions().getPiNodePolicy(); options.getSSAOptions().setPiNodePolicy(SSAOptions.getAllBuiltInPiNodes()); MethodReference mref = scope.findMethod(AnalysisScope.APPLICATION, "LcornerCases/Locals", Atom.findOrCreateUnicodeAtom("foo"), new ImmutableByteArray(UTF8Convert.toUTF8("([Ljava/lang/String;)V"))); Assert.assertNotNull("method not found", mref); IMethod imethod = cha.resolveMethod(mref); Assert.assertNotNull("imethod not found", imethod); IAnalysisCacheView cache = new AnalysisCacheImpl(options.getSSAOptions()); IR ir = cache.getIRFactory().makeIR(imethod, Everywhere.EVERYWHERE, options.getSSAOptions()); options.getSSAOptions().setPiNodePolicy(save); // v1 should be the parameter "a" at pc 0 String[] names = ir.getLocalNames(0, 1); Assert.assertTrue("failed local name resolution for v1@0", names != null); Assert.assertTrue("incorrect number of local names for v1@0: " + names.length, names.length == 1); Assert.assertTrue("incorrect local name resolution for v1@0: " + names[0], names[0].equals("a")); // v2 is a compiler-induced temporary Assert.assertTrue("didn't expect name for v2 at pc 2", ir.getLocalNames(2, 2) == null); // at pc 5, v1 should represent the locals "a" and "b" names = ir.getLocalNames(5, 1); Assert.assertTrue("failed local name resolution for v1@5", names != null); Assert.assertTrue("incorrect number of local names for v1@5: " + names.length, names.length == 2); Assert.assertTrue("incorrect local name resolution #0 for v1@5: " + names[0], names[0].equals("a")); Assert.assertTrue("incorrect local name resolution #1 for v1@5: " + names[1], names[1].equals("b")); } }
@Test public void test3() { MethodReference method = scope.findMethod(AnalysisScope.APPLICATION, "LtypeInference/TI", Atom.findOrCreateUnicodeAtom("inferInt"), new ImmutableByteArray(UTF8Convert.toUTF8("()V"))); Assert.assertNotNull("method not found", method); IMethod imethod = cha.resolveMethod(method); Assert.assertNotNull("imethod not found", imethod); IR ir = cache.getIRFactory().makeIR(imethod, Everywhere.EVERYWHERE, options.getSSAOptions()); System.out.println(ir); TypeInference ti = TypeInference.make(ir, true); TypeAbstraction type = ti.getType(7); Assert.assertNotNull("null type abstraction", type); Assert.assertTrue("inferred wrong type", type.toString().equals("int")); }
@BeforeClass public static void init() throws IOException, ClassHierarchyException { scope = AnalysisScopeReader.readJavaScope(TestConstants.WALA_TESTDATA, null, CLASS_LOADER); cha = ClassHierarchyFactory.make(scope); irFactory = new DefaultIRFactory(); options = new AnalysisOptions(); options.getSSAOptions().setPiNodePolicy(new AllIntegerDueToBranchePiPolicy()); }
@BeforeClass public static void init() throws IOException, ClassHierarchyException { scope = AnalysisScopeReader.readJavaScope(TestConstants.WALA_TESTDATA, null, CLASS_LOADER); cha = ClassHierarchyFactory.make(scope); irFactory = new DefaultIRFactory(); options = new AnalysisOptions(); options.getSSAOptions().setPiNodePolicy(new AllIntegerDueToBranchePiPolicy()); }
@Test public void test4() { MethodReference method = scope.findMethod(AnalysisScope.APPLICATION, "LtypeInference/TI", Atom.findOrCreateUnicodeAtom("useCast"), new ImmutableByteArray(UTF8Convert.toUTF8("(Ljava/lang/Object;)V"))); Assert.assertNotNull("method not found", method); IMethod imethod = cha.resolveMethod(method); Assert.assertNotNull("imethod not found", imethod); IR ir = cache.getIRFactory().makeIR(imethod, Everywhere.EVERYWHERE, options.getSSAOptions()); System.out.println(ir); TypeInference ti = TypeInference.make(ir, false); TypeAbstraction type = ti.getType(4); Assert.assertNotNull("null type abstraction", type); Assert.assertTrue("inferred wrong type " + type, type instanceof ConeType && ((ConeType)type).getTypeReference().getName().toString().equals("Ljava/lang/String")); }
@Test public void test1() { MethodReference method = scope.findMethod(AnalysisScope.APPLICATION, "LtypeInference/TI", Atom.findOrCreateUnicodeAtom("foo"), new ImmutableByteArray(UTF8Convert.toUTF8("()V"))); Assert.assertNotNull("method not found", method); IMethod imethod = cha.resolveMethod(method); Assert.assertNotNull("imethod not found", imethod); IR ir = cache.getIRFactory().makeIR(imethod, Everywhere.EVERYWHERE, options.getSSAOptions()); System.out.println(ir); TypeInference ti = TypeInference.make(ir, false); for (int i = 1; i <= ir.getSymbolTable().getMaxValueNumber(); i++) { System.err.println(i + " " + ti.getType(i)); } }
@Test public void test2() { MethodReference method = scope.findMethod(AnalysisScope.APPLICATION, "LtypeInference/TI", Atom.findOrCreateUnicodeAtom("bar"), new ImmutableByteArray(UTF8Convert.toUTF8("(I)V"))); Assert.assertNotNull("method not found", method); IMethod imethod = cha.resolveMethod(method); Assert.assertNotNull("imethod not found", imethod); IR ir = cache.getIRFactory().makeIR(imethod, Everywhere.EVERYWHERE, options.getSSAOptions()); System.out.println(ir); TypeInference ti = TypeInference.make(ir, true); Assert.assertNotNull("null type abstraction for parameter", ti.getType(2)); }
/** * test that type inference works in the presence of a getfield where the * field's declared type cannot be loaded */ @Test public void testBug38540() throws ClassHierarchyException, IOException { AnalysisScope scope = null; scope = AnalysisScopeReader.readJavaScope(TestConstants.WALA_TESTDATA, (new FileProvider()).getFile("J2SEClassHierarchyExclusions.txt"), MY_CLASSLOADER); AnalysisOptions options = new AnalysisOptions(); ClassHierarchy cha = ClassHierarchyFactory.make(scope); TypeReference t = TypeReference.findOrCreateClass(scope.getApplicationLoader(), "cornerCases", "Main"); IClass klass = cha.lookupClass(t); Assert.assertTrue(klass != null); ShrikeCTMethod m = (ShrikeCTMethod) klass.getMethod(new Selector(Atom.findOrCreateAsciiAtom("foo"), Descriptor .findOrCreateUTF8("()Ljava/lang/Object;"))); Assert.assertTrue(m != null); IR ir = new AnalysisCacheImpl().getSSACache().findOrCreateIR(m, Everywhere.EVERYWHERE, options.getSSAOptions()); TypeInference.make(ir, false); }
@BeforeClass public static void init() throws IOException, ClassHierarchyException, IllegalArgumentException, CallGraphBuilderCancelException { AnalysisOptions options; AnalysisScope scope; scope = AnalysisScopeReader.readJavaScope(TestConstants.WALA_TESTDATA, new File(REGRESSION_EXCLUSIONS), CLASS_LOADER); cha = ClassHierarchyFactory.make(scope); Iterable<Entrypoint> entrypoints = Util.makeMainEntrypoints(scope, cha, "Lexceptionpruning/TestPruning"); options = new AnalysisOptions(scope, entrypoints); options.getSSAOptions().setPiNodePolicy(new AllIntegerDueToBranchePiPolicy()); ReferenceCleanser.registerClassHierarchy(cha); IAnalysisCacheView cache = new AnalysisCacheImpl(); ReferenceCleanser.registerCache(cache); CallGraphBuilder<InstanceKey> builder = Util.makeZeroCFABuilder(Language.JAVA, options, cache, cha, scope); cg = builder.makeCallGraph(options, null); pointerAnalysis = builder.getPointerAnalysis(); /* * We will ignore some exceptions to focus on the exceptions we want to * raise (OwnException, ArrayIndexOutOfBoundException) */ filter = new CombinedInterproceduralExceptionFilter<>(); filter.add(new IgnoreExceptionsInterFilter<>(new IgnoreExceptionsFilter(TypeReference.JavaLangOutOfMemoryError))); filter.add(new IgnoreExceptionsInterFilter<>(new IgnoreExceptionsFilter( TypeReference.JavaLangNullPointerException))); filter.add(new IgnoreExceptionsInterFilter<>(new IgnoreExceptionsFilter( TypeReference.JavaLangExceptionInInitializerError))); filter.add(new IgnoreExceptionsInterFilter<>(new IgnoreExceptionsFilter( TypeReference.JavaLangNegativeArraySizeException))); }