@Override public void methodReached(DependencyAgent agent, MethodDependency method) { switch (method.getReference().getName()) { case "asJavaClass": method.getResult().propagate(agent.getType("java.lang.Class")); return; case "clone": method.getVariable(1).connect(method.getResult()); break; case "startThread": case "schedule": { MethodDependency launchMethod = agent.linkMethod(new MethodReference(Platform.class, "launchThread", PlatformRunnable.class, void.class)); method.getVariable(1).connect(launchMethod.getVariable(1)); launchMethod.use(); break; } case "getCurrentThread": method.getResult().propagate(agent.getType("java.lang.Thread")); break; case "getEnumConstants": method.getResult().propagate(agent.getType("[Ljava/lang/Enum;")); break; } }
methodDep.addLocation(location); if (!methodDep.isMissing()) { methodDep.use(); DependencyNode[] targetParams = methodDep.getVariables(); if (parameters[0] != null && targetParams[0] != null) { parameters[0].connect(targetParams[0], analyzer.getSuperClassFilter(methodDep.getMethod().getOwnerName())); if (result != null && methodDep.getResult() != null) { methodDep.getResult().connect(result); methodDep.getThrown().addConsumer(exceptionConsumer);
@Override public void methodReached(DependencyAgent agent, MethodDependency method) { if (method.getReference().getClassName().equals(Platform.class.getName()) && method.getReference().getName().equals("getAnnotations")) { method.getResult().propagate(agent.getType("[" + ValueType.parse(Annotation.class).toString())); if (getAnnotationsDep == null) { getAnnotationsDep = agent.linkMethod(new MethodReference(PlatformAnnotationProvider.class, "getAnnotations", Annotation[].class)); method.addLocationListener(getAnnotationsDep::addLocation); MethodDependency initMethod = agent.linkMethod(new MethodReference(className, "<init>", ValueType.VOID)); initMethod.propagate(0, className); initMethod.use(); MethodDependency readMethod = agent.linkMethod(new MethodReference(className, "getAnnotations", ValueType.parse(Annotation[].class))); readMethod.getResult().getArrayItem().connect(method.getResult().getArrayItem()); readMethod.use(); method.addLocationListener(location -> { initMethod.addLocation(location); readMethod.addLocation(location); }); });
@Override public void methodReached(DependencyAgent agent, MethodDependency method) { switch (method.getMethod().getName()) { case "clone": method.getVariable(0).connect(method.getResult()); break; } } }
@Override public void methodReached(DependencyAgent agent, MethodDependency method) { MethodReference ref = method.getReference(); Set<MethodReference> callbackMethods = repository.callbackMethods.get(ref); if (callbackMethods != null) { for (MethodReference callbackMethod : callbackMethods) { agent.linkMethod(callbackMethod).addLocation(new CallLocation(ref)).use(); } } }
@Override public void methodReached(final DependencyAgent agent, MethodDependency method) { if (!method.getReference().getClassName().equals(Platform.class.getName())) { return; } switch (method.getReference().getName()) { case "objectFromResource": allClasses.connect(method.getResult()); break; } } }
public void buildGraph(MethodDependency dep) { caller = dependencyAnalyzer.callGraph.getNode(dep.getReference()); MethodHolder method = dep.method; if (method.getProgram() == null || method.getProgram().basicBlockCount() == 0) { resultNode = dep.getResult(); boolean[] significantParams = new boolean[dep.getParameterCount()]; significantParams[0] = true; for (int i = 1; i < dep.getParameterCount(); ++i) { ValueType arg = method.parameterType(i - 1); if (!(arg instanceof ValueType.Primitive)) { DependencyNode[] nodeClasses = Arrays.copyOf(dep.getVariables(), nodeClassCount); MethodReference ref = method.getReference(); for (int i = dep.getVariableCount(); i < nodeClasses.length; ++i) { nodeClasses[i] = dependencyAnalyzer.createNode(); nodeClasses[i].method = ref; if (DependencyAnalyzer.shouldTag) { nodeClasses[i].setTag(dep.getMethod().getReference() + ":" + i); nodes = new DependencyNode[dep.getMethod().getProgram().variableCount()]; for (int i = 0; i < nodes.length; ++i) { int mappedNode = nodeMapping[i]; nodes[i] = mappedNode >= 0 ? nodeClasses[mappedNode] : null; dep.setVariables(nodes); if (dependencyAnalyzer.asyncSupported) { methodDep = dependencyAnalyzer.linkMethod(MONITOR_ENTER_METHOD);
@Override public void methodReached(DependencyAgent agent, MethodDependency method) { reachedMethods.put(method.getReference(), new HashSet<>()); if (method.isMissing()) { return; AnnotationReader annot = method.getMethod().getAnnotations().get(JavaScriptBody.class.getName()); if (annot != null) { includeDefaultDependencies(agent); AnnotationValue javacall = annot.getValue("javacall"); if (method.getResult() != null) { allClassesNode.connect(method.getResult()); allClassesNode.addConsumer(new OneDirectionalConnection(method.getResult().getArrayItem())); allClassesNode.addConsumer(new OneDirectionalConnection(method.getResult().getArrayItem() .getArrayItem())); for (int i = 0; i < method.getParameterCount(); ++i) { method.getVariable(i).connect(allClassesNode); method.getVariable(i).addConsumer(type -> { if (agent.getClassHierarchy().isSuperType("java.lang.Enum", type.getName(), false)) { MethodReference toStringMethod = new MethodReference(type.getName(), "toString", ValueType.parse(String.class)); MethodDependency dependency = agent.linkMethod(toStringMethod); dependency.getVariable(0).propagate(type); dependency.use(); allClassesNode.addConsumer(new OneDirectionalConnection(method.getVariable(i).getArrayItem())); allClassesNode.addConsumer(new OneDirectionalConnection(method.getVariable(i).getArrayItem() .getArrayItem()));
@Override public void methodReached(DependencyAgent agent, MethodDependency method) { switch (method.getReference().getName()) { case "invoke": case "instantiate": case "function": if (reachedFunctorMethods.add(method.getReference()) && !method.isMissing()) { for (int i = 0; i < method.getReference().parameterCount(); ++i) { DependencyNode node = method.getVariable(i); if (functorParamNodes.add(node)) { node.addConsumer(type -> { if (agent.getClassHierarchy().isSuperType(method.getMethod().getOwnerName(), type.getName(), false)) { reachFunctorMethods(agent, type.getName()); } }); } } } break; case "unwrapString": method.getResult().propagate(agent.getType("java.lang.String")); break; } }
private void attachConstructor(DependencyAgent agent, String type, CallLocation location) { MethodReference ref = new MethodReference(type, "<init>", ValueType.VOID); MethodDependency methodDep = agent.linkMethod(ref); methodDep.addLocation(location); methodDep.getVariable(0).propagate(agent.getType(type)); methodDep.use(); } }
private void reachGetLength(DependencyAgent agent, MethodDependency method) { method.getVariable(1).addConsumer(type -> { if (!type.getName().startsWith("[")) { MethodReference cons = new MethodReference(IllegalArgumentException.class, "<init>", void.class); agent.linkMethod(cons).use(); } }); }
@Override public void methodReached(DependencyAgent agent, MethodDependency method) { AnnotationReader delegateAnnot = method.getMethod().getAnnotations().get(DelegateTo.class.getName()); if (delegateAnnot != null) { String delegateMethodName = delegateAnnot.getValue("value").getString(); ClassReader cls = agent.getClassSource().get(method.getReference().getClassName()); for (MethodReader delegate : cls.getMethods()) { if (delegate.getName().equals(delegateMethodName)) { if (delegate != method.getMethod()) { MethodDependency dep = agent.linkMethod(delegate.getReference()); dep.use(); method.addLocationListener(dep::addLocation); } } } } }
@Override public void cloneArray(VariableReader receiver, VariableReader array) { DependencyNode arrayNode = getNode(array); MethodDependency cloneDep = getAnalyzer().linkMethod(CLONE_METHOD); cloneDep.addLocation(impreciseLocation); cloneDep.use(); }
@Override public void methodReached(DependencyAgent agent, MethodDependency method) { switch (method.getReference().getName()) { case "newEmptyInstance": method.getVariable(0).getClassValueNode().connect(method.getResult()); break; case "getSuperclass": reachGetSuperclass(agent, method); break; case "getInterfaces": reachGetInterfaces(agent, method); break; case "getComponentType": reachGetComponentType(agent, method); break; } }
@Override protected CharSequence callMethod(String ident, String fqn, String method, String params) { MethodDescriptor desc = MethodDescriptor.parse(method + params + "V"); MethodReference methodRef = new MethodReference(fqn, desc); MethodReader reader = findMethod(agent.getClassSource(), fqn, desc); if (reader == null) { agent.getDiagnostics().error(new CallLocation(caller.getReference()), "Can't resolve method {{m0}}", methodRef); } methodRef = reader.getReference(); MethodDependency methodDep = agent.linkMethod(methodRef); if (ident == null) { reachedMethods.get(caller.getReference()).add(methodRef); methodDep.use(); for (int i = 0; i < methodDep.getParameterCount(); ++i) { allClassesNode.connect(methodDep.getVariable(i)); } } else { allClassesNode.addConsumer(new VirtualCallbackConsumer(agent, methodRef)); } return ""; } }
@Override public void methodReached(DependencyAgent agent, MethodDependency method) { MethodDependency addMethod = agent.linkMethod(new MethodReference(PlatformQueue.class, "wrap", Object.class, PlatformObject.class)); addMethod.getVariable(1).connect(method.getResult()); }
throw new AssertionError(type.toString()); MethodDependency boxMethodDep = agent.linkMethod(boxMethod).addLocation(location); boxMethodDep.use(); boxMethodDep.getResult().connect(targetNode); } else if (type instanceof ValueType.Array || type instanceof ValueType.Object) { sourceNode.connect(targetNode);
private void reachGet(DependencyAgent agent, MethodDependency method) { method.getVariable(1).getArrayItem().connect(method.getResult()); method.getVariable(1).addConsumer(type -> { if (type.getName().startsWith("[")) { String typeName = type.getName().substring(1); for (int i = 0; i < primitiveTypes.length; ++i) { if (primitiveTypes[i].toString().equals(typeName)) { String wrapper = "java.lang." + primitiveWrappers[i]; MethodReference methodRef = new MethodReference(wrapper, "valueOf", primitiveTypes[i], ValueType.object(wrapper)); agent.linkMethod(methodRef).use(); method.getResult().propagate(agent.getType("java.lang." + primitiveWrappers[i])); } } } }); }
@Override public void methodReached(DependencyAgent agent, MethodDependency method) { if (!reachedMethods.add(method.getReference())) { return; } ValueType type = method.getMethod().getResultType(); while (type instanceof ValueType.Array) { type = ((ValueType.Array) type).getItemType(); } if (type instanceof ValueType.Object) { String className = ((ValueType.Object) type).getClassName(); ClassReader cls = agent.getClassSource().get(className); if (cls != null && cls.hasModifier(ElementModifier.ANNOTATION)) { agent.linkClass(className); } } if (method.getMethod().hasModifier(ElementModifier.STATIC) && method.getMethod().getName().equals("$$__readAnnotations__$$")) { ClassReader cls = agent.getClassSource().get(method.getReference().getClassName()); if (cls != null) { for (AnnotationReader annotation : cls.getAnnotations().all()) { agent.linkClass(annotation.getType()); } } } MethodReference methodRef = method.getMethod().getReference(); if (methodRef.getClassName().equals("java.lang.Class") && methodRef.getName().equals("getAnnotations")) { reachGetAnnotations(agent, method.getVariable(0)); } }
@Override public void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location) { if (method.getReference().getClassName().equals(Platform.class.getName()) && method.getReference().getName().equals("getAnnotations")) { method.getResult().propagate(agent.getType("[" + Annotation.class.getName())); agent.linkMethod(new MethodReference(PlatformAnnotationProvider.class, "getAnnotations", Annotation[].class), location); allClasses.addConsumer(type -> { if (type.getName().endsWith("$$__annotations__$$")) { return; } String className = type.getName() + "$$__annotations__$$"; agent.linkMethod(new MethodReference(className, "<init>", ValueType.VOID), location) .propagate(0, className) .use(); MethodDependency readMethod = agent.linkMethod(new MethodReference(className, "getAnnotations", ValueType.parse(Annotation[].class)), location); readMethod.getResult().getArrayItem().connect(method.getResult().getArrayItem()); readMethod.use(); }); } } }