@Override public void methodReached(DependencyAgent agent, MethodDependency method) { if (method.getMethod() == null || method.getMethod().getProgram() == null) { return; } ProgramReader program = method.getMethod().getProgram(); FunctionGetFinder finder = new FunctionGetFinder(program.variableCount()); for (BasicBlockReader block : program.getBasicBlocks()) { block.readAllInstructions(finder); } if (!finder.invocations.isEmpty()) { processInvocations(agent, method.getMethod(), finder); } }
private void attachDependencyPlugin(MethodDependency methodDep) { if (methodDep.dependencyPluginAttached) { return; } methodDep.dependencyPluginAttached = true; methodDep.dependencyPlugin = dependencyPlugins.get(methodDep.getReference()); if (methodDep.dependencyPlugin != null || isBootstrap()) { return; } AnnotationReader depAnnot = methodDep.getMethod().getAnnotations().get(PluggableDependency.class.getName()); if (depAnnot == null) { return; } ValueType depType = depAnnot.getValue("value").getJavaClass(); String depClassName = ((ValueType.Object) depType).getClassName(); Class<?> depClass; try { depClass = Class.forName(depClassName, true, classLoader); } catch (ClassNotFoundException e) { throw new RuntimeException("Dependency plugin not found: " + depClassName, e); } try { methodDep.dependencyPlugin = (DependencyPlugin) depClass.newInstance(); } catch (IllegalAccessException | InstantiationException e) { throw new RuntimeException("Can't instantiate dependency plugin " + depClassName, e); } }
@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) { MethodReader reader = method.getMethod(); if (reader.getOwnerName().equals(Platform.class.getName()) && reader.getName().equals("newInstanceImpl")) { allClassesNode.connect(method.getResult()); MethodReference methodRef = reader.getReference(); method.getResult().addConsumer(type -> attachConstructor(agent, type.getName(), new CallLocation(methodRef))); } }
@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 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 delegateDep = agent.linkMethod(delegate.getReference()); method.addLocationListener(delegateDep::addLocation); delegateDep.use(); } } } } }
@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 methodDep) { MethodModel proxy = describer.getMethod(methodDep.getReference()); if (proxy != null && installedProxies.add(proxy)) { agent.getIncrementalCache().setNoCache(methodDep.getReference()); ClassReader cls = agent.getClassSource().get(methodDep.getMethod().getOwnerName()); int index = 0; for (MethodReader method : cls.getMethods()) { if (method.getDescriptor().equals(methodDep.getMethod().getDescriptor())) { break; } ++index; } new UsageGenerator(agent, proxy, methodDep, proxyClassLoader, index).installProxyEmitter(); } }
private MethodDependency createMethodDep(MethodReference methodRef, MethodHolder method) { ValueType[] arguments = methodRef.getParameterTypes(); int paramCount = arguments.length + 1; DependencyNode[] parameterNodes = new DependencyNode[arguments.length + 1]; parameterNodes[0] = createParameterNode(methodRef, ValueType.object(methodRef.getClassName()), 0); for (int i = 0; i < arguments.length; ++i) { parameterNodes[i + 1] = createParameterNode(methodRef, arguments[i], i + 1); } DependencyNode resultNode; if (methodRef.getDescriptor().getResultType() == ValueType.VOID) { resultNode = null; } else { resultNode = createResultNode(methodRef); } DependencyNode thrown = createThrownNode(methodRef); MethodDependency dep = new MethodDependency(this, parameterNodes, paramCount, resultNode, thrown, method, methodRef); if (method != null) { deferredTasks.add(() -> linkClass(dep.getMethod().getOwnerName()) .initClass(new CallLocation(dep.getMethod().getReference()))); } return dep; }
if (parameters[0] != null && targetParams[0] != null) { parameters[0].connect(targetParams[0], analyzer.getSuperClassFilter(methodDep.getMethod().getOwnerName()));
@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; } }
@Override public void methodReached(DependencyAgent agent, MethodDependency method) { switch (method.getMethod().getName()) { case "initialize": method.getVariable(0).getClassValueNode().addConsumer(type -> { ClassDependency classDep = agent.linkClass(type.getName()); if (classDep != null) { classDep.initClass(new CallLocation(method.getReference())); } }); break; case "getSimpleNameCacheLowLevel": method.getResult().propagate(agent.getType("java.lang.String")); break; } } }
@Override protected void processMethod(MethodDependency methodDep) { MethodReader method = methodDep.getMethod(); ProgramReader program = method.getProgram(); if (program != null) { FastInstructionAnalyzer instructionAnalyzer = new FastInstructionAnalyzer(this); instructionAnalyzer.setCaller(method.getReference()); for (BasicBlockReader block : program.getBasicBlocks()) { block.readAllInstructions(instructionAnalyzer); for (TryCatchBlockReader tryCatch : block.readTryCatchBlocks()) { if (tryCatch.getExceptionType() != null) { linkClass(tryCatch.getExceptionType()); } } } methodDep.variableNodes = new DependencyNode[program.variableCount()]; for (int i = 0; i < methodDep.variableNodes.length; ++i) { methodDep.variableNodes[i] = instancesNode; } } if (method.hasModifier(ElementModifier.SYNCHRONIZED)) { processAsyncMethod(methodDep); } }
return; AnnotationReader annot = method.getMethod().getAnnotations().get(JavaScriptBody.class.getName()); if (annot != null) { includeDefaultDependencies(agent);
methodDep.getReference(), indy.getMethod(), indy.getInstance() != null ? pe.var(indy.getInstance(), ValueType.object(methodDep.getMethod().getOwnerName())) : null, arguments, indy.getBootstrapMethod(), indy.getBootstrapArguments(), agent);
@Override public void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location) { MethodReader reader = method.getMethod(); if (reader.getOwnerName().equals(Platform.class.getName()) && reader.getName().equals("newInstanceImpl")) { allClassesNode.connect(method.getResult()); MethodReference methodRef = reader.getReference(); method.getResult().addConsumer(type -> attachConstructor(agent, type.getName(), new CallLocation(methodRef))); } }
@Override public void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location) { 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()) { agent.linkMethod(delegate.getReference(), location).use(); } } } } }
private void invokeVirtual(VariableReader receiver, VariableReader instance, MethodReference method, List<? extends VariableReader> arguments) { MethodDependency methodDep = dependencyChecker.linkMethod(method, new CallLocation(caller.getMethod(), currentLocation)); if (methodDep.isMissing()) { return; } DependencyNode[] actualArgs = new DependencyNode[arguments.size() + 1]; for (int i = 0; i < arguments.size(); ++i) { actualArgs[i + 1] = nodes[arguments.get(i).getIndex()]; } actualArgs[0] = nodes[instance.getIndex()]; DependencyConsumer listener = new VirtualCallConsumer(nodes[instance.getIndex()], dependencyChecker.getClassSource().get(methodDep.getMethod().getOwnerName()), method.getDescriptor(), dependencyChecker, actualArgs, receiver != null ? nodes[receiver.getIndex()] : null, caller, currentLocation, currentExceptionConsumer); nodes[instance.getIndex()].addConsumer(listener); }