@Override public ClassReader get(String name) { return cache.computeIfAbsent(name, key -> { if (underlyingSource == null) { return Optional.empty(); } return Optional.ofNullable(underlyingSource.get(key)); }).orElse(null); }
ClassReader cls = classSource.get(className); if (cls == null) { return null; methodDescriptor, visited); if (resultFromSuperClass != null) { if (mostSpecificMethod == null || classSource.isSuperType(mostSpecificMethod.getOwnerName(), resultFromSuperClass.getOwnerName()).orElse(false)) { mostSpecificMethod = resultFromSuperClass;
private boolean computeIsManaged(MethodReference methodReference) { MethodReader method = classSource.resolve(methodReference); if (method == null) { return true; } ClassReader cls = classSource.get(method.getOwnerName()); if (cls.getAnnotations().get(Unmanaged.class.getName()) != null) { return false; } return method == null || method.getAnnotations().get(Unmanaged.class.getName()) == null; } }
@Override public boolean canHandle(MethodReference methodReference) { MethodReader method = classSource.resolve(methodReference); if (method == null) { return false; } return method.getAnnotations().get(MetadataProvider.class.getName()) != null; }
ClassReader cls = classSource.get(className); if (cls == null) { return; for (MethodDescriptor method : newDescriptors) { if (!table.entries.containsKey(method)) { MethodReader implementation = classSource.resolveImplementation( className, method); MethodReference implementationRef = implementation != null
@Override public boolean canHandle(MethodReference method) { return classSource.isSuperType(Resource.class.getTypeName(), method.getClassName()).orElse(false); }
private MethodReader findOverriddenMethod(String className, MethodReader finalMethod) { if (finalMethod.getName().equals("<init>")) { return null; } return classSource.getAncestors(className) .skip(1) .map(cls -> cls.getMethod(finalMethod.getDescriptor())) .filter(Objects::nonNull) .findFirst() .orElse(null); }
private void devirtualize(Program program, MethodReference method, DependencyInfo dependencyInfo) { ClassInference inference = new ClassInference(dependencyInfo, hierarchy); inference.infer(program, method); for (BasicBlock block : program.getBasicBlocks()) { for (Instruction instruction : block) { if (!(instruction instanceof InvokeInstruction)) { continue; } InvokeInstruction invoke = (InvokeInstruction) instruction; if (invoke.getType() != InvocationType.VIRTUAL) { continue; } Set<MethodReference> implementations = new HashSet<>(); for (String className : inference.classesOf(invoke.getInstance().getIndex())) { MethodReference rawMethod = new MethodReference(className, invoke.getMethod().getDescriptor()); MethodReader resolvedMethod = dependencyInfo.getClassSource().resolveImplementation(rawMethod); if (resolvedMethod != null) { implementations.add(resolvedMethod.getReference()); } } if (implementations.size() == 1) { invoke.setType(InvocationType.SPECIAL); invoke.setMethod(implementations.iterator().next()); } } } }
@Override public boolean isApplicable(MethodReference methodReference) { MethodReader method = classSource.resolve(methodReference); if (method == null) { return false; } return method.getAnnotations().get(MetadataProvider.class.getName()) != null; }
@Override public boolean isApplicable(MethodReference methodReference) { return classSource.isSuperType(Resource.class.getTypeName(), methodReference.getClassName()).orElse(false); }
default MethodReader resolve(MethodReference method) { return getAncestors(method.getClassName()) .map(cls -> cls.getMethod(method.getDescriptor())) .filter(Objects::nonNull) .findFirst().orElse(null); }
MethodReader resolvedMethod = classSource.resolveImplementation(rawMethod);
private ClassHolder findClass(String name) { ClassReader cls = innerSource.get(name); if (cls != null) { return ModelUtils.copyClass(cls); } return generatedClasses.get(name); }
@Override public void visit(InvocationExpr expr) { ClassReader cls = context.getClassSource().get(expr.getMethod().getClassName()); if (cls != null) { processInclude(cls.getAnnotations()); writer.print(", "); MethodReader method = context.getClassSource().resolve(expr.getMethod()); writer.print(names.forMethod(method.getReference())); MethodReader method = context.getClassSource().resolve(expr.getMethod()); if (isWrappedNativeCall(method)) { generateWrappedNativeCall(method, expr);
private Set<MethodReference> getImplementations(String[] classNames, MethodReference ref) { Set<MethodReference> methods = new HashSet<>(); for (String className : classNames) { if (className.startsWith("[")) { className = "java.lang.Object"; } ClassReader cls = classSource.get(className); if (cls == null || !classSource.isSuperType(ref.getClassName(), cls.getName()).orElse(false)) { continue; } MethodDependencyInfo methodDep = dependency.getMethodImplementation(new MethodReference( className, ref.getDescriptor())); if (methodDep != null) { methods.add(methodDep.getReference()); } } return methods; } }
private String getSpecialName(MethodReference methodReference) { MethodReader method = classSource.resolve(methodReference); if (method == null) { return null; } AnnotationReader exportAnnot = method.getAnnotations().get(Export.class.getName()); if (exportAnnot != null) { return exportAnnot.getValue("name").getString(); } AnnotationReader importAnnot = method.getAnnotations().get(Import.class.getName()); if (importAnnot != null) { return importAnnot.getValue("name").getString(); } return null; }
@Override public boolean isApplicable(MethodReference methodReference) { if (!classSource.isSuperType(Structure.class.getName(), methodReference.getClassName()).orElse(false)) { return false; } switch (methodReference.getName()) { case "toAddress": case "cast": case "sizeOf": case "add": return true; } return false; }
default FieldReader resolve(FieldReference field) { return getAncestors(field.getClassName()) .map(cls -> cls.getField(field.getFieldName())) .filter(Objects::nonNull) .findFirst().orElse(null); }
@Override public void consume(DependencyType type) { if (!agent.getClassHierarchy().isSuperType(superMethod.getClassName(), type.getName(), false)) { return; } MethodReader method = agent.getClassSource().resolveImplementation(new MethodReference( type.getName(), superMethod.getDescriptor())); if (method == null) { return; } virtualMethods.add(method.getReference()); MethodDependency methodDep = agent.linkMethod(method.getReference()); methodDep.use(); for (int i = 0; i < methodDep.getParameterCount(); ++i) { allClassesNode.connect(methodDep.getVariable(i)); allClassesNode.connect(methodDep.getVariable(i).getArrayItem()); } } }
private ClassHolder copyClass(String className) { ClassReader original = innerSource.get(className); if (original == null) { return null; } return ModelUtils.copyClass(original); } }