@Override public String toString() { StringBuilder s = new StringBuilder("synthetic "); if (isFactoryMethod()) { s.append(" factory "); } s.append(method.toString()); return s.toString(); }
@Override public String toString() { StringBuilder s = new StringBuilder("synthetic "); if (isFactoryMethod()) { s.append(" factory "); } s.append(method.toString()); return s.toString(); }
@Override public String toString() { return getReference().toString(); }
@Override public String toString() { return getReference().toString(); }
@Override public String toString() { return getReference().toString(); }
@Override public String toString() { return getReference().toString(); }
@Override public boolean shouldRefine(CallerSiteContext callSiteAndCGNode) throws IllegalArgumentException { if (callSiteAndCGNode == null) { throw new IllegalArgumentException("callSiteAndCGNode == null"); } MethodReference declaredTarget = callSiteAndCGNode.getCallSite().getDeclaredTarget(); if (declaredTarget.toString().indexOf("toString()Ljava/lang/String") != -1) { return false; } return true; }
@Override public boolean shouldRefine(CallerSiteContext callSiteAndCGNode) throws IllegalArgumentException { if (callSiteAndCGNode == null) { throw new IllegalArgumentException("callSiteAndCGNode == null"); } MethodReference declaredTarget = callSiteAndCGNode.getCallSite().getDeclaredTarget(); if (declaredTarget.toString().indexOf("toString()Ljava/lang/String") != -1) { return false; } return true; }
public DefaultEntrypoint(MethodReference method, IClassHierarchy cha) { super(method, cha); if (method == null) { throw new IllegalArgumentException("method is null"); } this.cha = cha; paramTypes = makeParameterTypes(getMethod()); assert paramTypes != null : method.toString(); }
public DefaultEntrypoint(MethodReference method, IClassHierarchy cha) { super(method, cha); if (method == null) { throw new IllegalArgumentException("method is null"); } this.cha = cha; paramTypes = makeParameterTypes(getMethod()); assert paramTypes != null : method.toString(); }
/** * Extensive output for debugging purposes. */ public String dump() { final StringBuilder ret = new StringBuilder().append("Parameter Accessor for ") .append((this.mRef != null) ? "mRef:" + this.mRef.toString() : "IMethod: " + this.method.toString()) .append("\nContains ").append(this.numberOfParameters).append(" Parameters ").append(this.base) .append('\n'); /*for (int i = 1; i <= this.numberOfParameters; ++i) { try { ret += "\t" + getParameter(i).toString() + "\n"; } catch (Exception e) { ret += "\tNone at " + i + "\n"; } }*/ ret.append("\nAnd all is:\n"); for (Parameter p : all()) { ret.append('\t').append(p).append('\n'); } if (hasImplicitThis ()) { ret.append("This: ").append(getThis()); } else { ret.append("Is static"); } return ret.toString(); }
/** * Extensive output for debugging purposes. */ public String dump() { final StringBuilder ret = new StringBuilder().append("Parameter Accessor for ") .append((this.mRef != null) ? "mRef:" + this.mRef.toString() : "IMethod: " + this.method.toString()) .append("\nContains ").append(this.numberOfParameters).append(" Parameters ").append(this.base) .append('\n'); /*for (int i = 1; i <= this.numberOfParameters; ++i) { try { ret += "\t" + getParameter(i).toString() + "\n"; } catch (Exception e) { ret += "\tNone at " + i + "\n"; } }*/ ret.append("\nAnd all is:\n"); for (Parameter p : all()) { ret.append('\t').append(p).append('\n'); } if (hasImplicitThis ()) { ret.append("This: ").append(getThis()); } else { ret.append("Is static"); } return ret.toString(); }
@Override public String toString(SymbolTable symbolTable) { String code = site.getInvocationString(); StringBuilder s = new StringBuilder(); if (hasDef()) { s.append(getValueString(symbolTable, getDef())).append(" = "); } s.append("invoke").append(code); s.append(' '); s.append(site.getDeclaredTarget().toString()); if (getNumberOfPositionalParameters() > 0) { s.append(' ').append(getValueString(symbolTable, getUse(0))); for (int i = 1; i < getNumberOfPositionalParameters(); i++) { s.append(',').append(getValueString(symbolTable, getUse(i))); } } s.append(" @"); s.append(site.getProgramCounter()); if (exception == -1) { s.append(" exception: NOT MODELED"); } else { s.append(" exception:").append(getValueString(symbolTable, exception)); } return s.toString(); }
@Override public String toString(SymbolTable symbolTable) { String code = site.getInvocationString(); StringBuilder s = new StringBuilder(); if (hasDef()) { s.append(getValueString(symbolTable, getDef())).append(" = "); } s.append("invoke").append(code); s.append(' '); s.append(site.getDeclaredTarget().toString()); if (getNumberOfPositionalParameters() > 0) { s.append(' ').append(getValueString(symbolTable, getUse(0))); for (int i = 1; i < getNumberOfPositionalParameters(); i++) { s.append(',').append(getValueString(symbolTable, getUse(i))); } } s.append(" @"); s.append(site.getProgramCounter()); if (exception == -1) { s.append(" exception: NOT MODELED"); } else { s.append(" exception:").append(getValueString(symbolTable, exception)); } return s.toString(); }
/** * map a call graph node from one call graph to the corresponding node in another. Note that the target call graph must be * context-insensitive for the method, i.e., the only context for the method should be Everywhere.EVERYWHERE. * * @return the corresponding node, or {@code null} if the method is not in the target call graph * @throws IllegalArgumentException if fromCG == null */ public static CGNode mapCGNode(CGNode orig, CallGraph fromCG, CallGraph toCG) throws IllegalArgumentException { if (fromCG == null) { throw new IllegalArgumentException("fromCG == null"); } if (orig == fromCG.getFakeRootNode()) { return toCG.getFakeRootNode(); } else { MethodReference methodRef = orig.getMethod().getReference(); if (methodRef.toString().equals("< Primordial, Ljava/lang/Object, clone()Ljava/lang/Object; >")) { // NOTE: clone() is cloned one level, even by RTA, so we need to handle it CGNode ret = toCG.getNode(orig.getMethod(), orig.getContext()); if (ret == null) { System.err.println(("WEIRD can't map node " + orig)); } return ret; } else { Set<CGNode> nodes = toCG.getNodes(methodRef); int size = nodes.size(); assert size <= 1; return (size == 0) ? null : nodes.iterator().next(); } } }
private static boolean knownBug(InstanceKey key) { // if (key instanceof MultiNewArrayAllocationSiteKey) { // return true; // } if (key instanceof InstanceKeyWithNode) { CGNode node = ((InstanceKeyWithNode) key).getNode(); MethodReference methodRef = node.getMethod().getReference(); if (methodRef.toString().equals("< Primordial, Ljava/lang/Object, clone()Ljava/lang/Object; >")) { return true; } } return false; }
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/"); }); }
private void testMethodAnnotations(MethodReference methodRefUnderTest, Collection<TypeAnnotation> expectedRuntimeInvisibleAnnotations, Collection<TypeAnnotation> expectedRuntimeVisibleAnnotations) throws InvalidClassFileException { IMethod methodUnderTest = cha.resolveMethod(methodRefUnderTest); harness.assertNotNull(methodRefUnderTest.toString() + " not found", methodUnderTest); harness.assertTrue(methodUnderTest + " must be ShrikeCTMethod", methodUnderTest instanceof ShrikeCTMethod); ShrikeCTMethod bcMethodUnderTest = (ShrikeCTMethod) methodUnderTest; Collection<TypeAnnotation> runtimeInvisibleAnnotations = HashSetFactory.make(); runtimeInvisibleAnnotations.addAll(bcMethodUnderTest.getTypeAnnotationsAtCode(true)); runtimeInvisibleAnnotations.addAll(bcMethodUnderTest.getTypeAnnotationsAtMethodInfo(true)); harness.assertEqualCollections(expectedRuntimeInvisibleAnnotations, runtimeInvisibleAnnotations); Collection<TypeAnnotation> runtimeVisibleAnnotations = HashSetFactory.make(); runtimeVisibleAnnotations.addAll(bcMethodUnderTest.getTypeAnnotationsAtCode(false)); runtimeVisibleAnnotations.addAll(bcMethodUnderTest.getTypeAnnotationsAtMethodInfo(false)); harness.assertEqualCollections(expectedRuntimeVisibleAnnotations, runtimeVisibleAnnotations); }
protected void checkParameterAnnots(TypeReference typeRef, String selector, String[]... expected) { MethodReference methodRefUnderTest = MethodReference.findOrCreate(typeRef, Selector.make(selector)); IMethod methodUnderTest = cha.resolveMethod(methodRefUnderTest); harness.assertTrue(methodRefUnderTest.toString() + " not found", methodUnderTest != null); harness.assertTrue(methodUnderTest + " must be bytecode method", methodUnderTest instanceof IBytecodeMethod); IBytecodeMethod<?> IBytecodeMethodUnderTest = (IBytecodeMethod<?>) methodUnderTest; Collection<Annotation>[] parameterAnnotations = IBytecodeMethodUnderTest.getParameterAnnotations(); harness.assertEquals(expected.length, parameterAnnotations.length); for (int i = 0; i < expected.length; i++) { Set<String> e = HashSetFactory.make(); e.addAll(Arrays.asList(expected[i])); Set<String> a = HashSetFactory.make(); if (parameterAnnotations[i] != null) { for(Annotation x : parameterAnnotations[i]) { a.add(x.toString()); } } harness.assertTrue(e + " must be " + a, e.equals(a)); } }
@Test public void testClassAnnotations3() throws Exception { TypeReference typeRef = TypeReference.findOrCreate(ClassLoaderReference.Application, "Lannotations/AnnotatedClass3"); IClass klass = cha.lookupClass(typeRef); harness.assertNotNull(typeRef + " must exist", klass); BytecodeClass<?> shrikeClass = (BytecodeClass<?>) klass; Collection<Annotation> classAnnotations = shrikeClass.getAnnotations(true); harness.assertEquals("[Annotation type <Application,Lannotations/AnnotationWithParams> {strParam=classStrParam}]", classAnnotations.toString()); MethodReference methodRefUnderTest = MethodReference.findOrCreate(typeRef, Selector.make("foo()V")); IMethod methodUnderTest = cha.resolveMethod(methodRefUnderTest); harness.assertNotNull(methodRefUnderTest.toString() + " not found", methodUnderTest); harness.assertTrue(methodUnderTest + " must be IBytecodeMethod", methodUnderTest instanceof IBytecodeMethod); IBytecodeMethod<IInstruction> bcMethodUnderTest = (IBytecodeMethod<IInstruction>) methodUnderTest; Collection<Annotation> runtimeInvisibleAnnotations = bcMethodUnderTest.getAnnotations(true); harness.assertEquals(1, runtimeInvisibleAnnotations.size()); Annotation x = runtimeInvisibleAnnotations.iterator().next(); harness.assertEquals(TypeReference.findOrCreate(ClassLoaderReference.Application, "Lannotations/AnnotationWithParams"), x.getType()); for(Pair<String,String> n : new Pair[]{Pair.make("enumParam", "EnumElementValue [type=Lannotations/AnnotationEnum;, val=VAL1]"), Pair.make("strArrParam", "ArrayElementValue [vals=[biz, boz]]"), Pair.make("annotParam", "AnnotationElementValue [type=Lannotations/AnnotationWithSingleParam;, elementValues={value=sdfevs}]"), Pair.make("strParam", "sdfsevs"), Pair.make("intParam", "25"), Pair.make("klassParam", "Ljava/lang/Integer;")}) { harness.assertEquals(n.snd, x.getNamedArguments().get(n.fst).toString()); } }