private ProgramEmitter(Program program, BasicBlock block, ClassHierarchy hierarchy) { this.program = program; this.block = block; this.classSource = hierarchy.getClassSource(); this.hierarchy = hierarchy; }
public ValueEmitter assertIs(ValueType type) { if (!pe.hierarchy.isSuperType(type, this.type, true)) { throw new EmitException("Value type " + this.type + " is not subtype of " + type); } return this; }
public static void emit(Action action) { Fragment fragment = (Fragment) action; MethodReader method = hierarchy.resolve(fragment.method); generator.addProgram(method.getProgram(), fragment.capturedValues); }
private Set<MethodReference> getImplementations(String[] classNames, MethodReference ref) { OptionalPredicate<String> isSuperclass = hierarchy.getSuperclassPredicate(ref.getClassName()); Set<MethodReference> methods = new HashSet<>(); for (String className : classNames) { if (className.startsWith("[")) { className = "java.lang.Object"; } ClassReader cls = hierarchy.getClassSource().get(className); if (cls == null || !isSuperclass.test(cls.getName(), false)) { continue; } MethodDependencyInfo methodDep = dependency.getMethodImplementation(new MethodReference( className, ref.getDescriptor())); if (methodDep != null) { methods.add(methodDep.getReference()); } } return methods; }
return Arrays.asList(accessInsn); ClassReader iface = hierarchy.getClassSource().get(method.getClassName()); if (iface == null || !hierarchy.isSuperType(Resource.class.getName(), iface.getName(), false)) { return null;
DependencyClassSource(ClassReaderSource innerSource, Diagnostics diagnostics, IncrementalDependencyRegistration dependencyRegistration) { this.innerSource = innerSource; this.diagnostics = diagnostics; innerHierarchy = new ClassHierarchy(innerSource); this.dependencyRegistration = dependencyRegistration; }
public boolean isSuperType(String superType, String subType, boolean defaultValue) { if (subType.equals(superType)) { return true; } return getSuperclassPredicate(superType).test(subType, defaultValue); }
Inlining inlining = new Inlining(new ClassHierarchy(classes), dependencyAnalyzer); for (String className : classes.getClassNames()) { ClassHolder cls = classes.get(className);
SuperClassFilter(DependencyAnalyzer dependencyAnalyzer, DependencyType superType) { this.superType = superType; predicate = dependencyAnalyzer.getClassHierarchy().getSuperclassPredicate(superType.getName()); }
private boolean calculateDestSubsetOfSrc() { if (source.typeFilter == null) { return true; } if (destination.typeFilter == null) { return false; } ValueType sourceType = source.typeFilter; ValueType destType = destination.typeFilter; ClassHierarchy hierarchy = source.dependencyAnalyzer.getClassHierarchy(); return hierarchy.isSuperType(sourceType, destType, false); } }
public Inlining(ClassHierarchy hierarchy, DependencyInfo dependencyInfo) { this.hierarchy = hierarchy; this.classes = hierarchy.getClassSource(); this.dependencyInfo = dependencyInfo; }
public MethodReader resolve(MethodReference method) { return resolve(method.getClassName(), method.getDescriptor()); }
DependencyAnalyzer(ClassReaderSource classSource, ClassLoader classLoader, ServiceRepository services, Diagnostics diagnostics) { unprocessedClassSource = classSource; this.diagnostics = diagnostics; this.classSource = new DependencyClassSource(classSource, diagnostics, incrementalCache); classHierarchy = new ClassHierarchy(this.classSource); this.classLoader = classLoader; this.services = services; fieldReaderCache = new CachedMapper<>(preimage -> this.classSource.resolveMutable(preimage)); fieldCache = new CachedMapper<>(preimage -> { FieldReader field = fieldReaderCache.map(preimage); if (field != null && !field.getReference().equals(preimage)) { return fieldCache.map(field.getReference()); } FieldDependency node = createFieldNode(preimage, field); if (field != null && field.getInitialValue() instanceof String) { node.getValue().propagate(getType("java.lang.String")); } return node; }); classCache = new CachedMapper<>(this::createClassDependency); agent = new DependencyAgent(this); }
public boolean isSuperType(ValueType superType, ValueType subType, boolean defaultValue) { if (superType.equals(subType)) { return true; } if (superType instanceof ValueType.Primitive || subType instanceof ValueType.Primitive) { return false; } if (superType.isObject("java.lang.Object")) { return true; } if (superType instanceof ValueType.Object && subType instanceof ValueType.Object) { return isSuperType(((ValueType.Object) superType).getClassName(), ((ValueType.Object) subType).getClassName(), defaultValue); } else if (superType instanceof ValueType.Array & subType instanceof ValueType.Array) { return isSuperType(((ValueType.Array) superType).getItemType(), ((ValueType.Array) subType).getItemType(), defaultValue); } else { return false; } }
public ReflectContext(ClassHierarchy hierarchy, ClassLoader classLoader) { this.classSource = hierarchy.getClassSource(); this.hierarchy = hierarchy; this.classLoader = classLoader; }
public FieldReader resolve(FieldReference field) { return resolve(field.getClassName(), field.getFieldName()); }
private boolean matchSignature(ClassHierarchy hierarchy, MethodReader functionMethod, MethodReader candidateMethod) { if (functionMethod.parameterCount() > candidateMethod.parameterCount()) { return false; } for (int i = 0; i < functionMethod.parameterCount(); ++i) { if (!hierarchy.isSuperType(functionMethod.parameterType(i), candidateMethod.parameterType(i), false)) { return false; } } return true; }
private ExposedClass createExposedClass(String name) { ClassReader cls = hierarchy.getClassSource().get(name); ExposedClass exposedCls = new ExposedClass(); if (cls != null) { createExposedClass(cls, exposedCls); } return exposedCls; }
public FieldReader resolve(String className, String fieldName) { Map<String, Optional<FieldReader>> cache = resolveFieldCache.computeIfAbsent(className, k -> new HashMap<>()); Optional<FieldReader> opt = cache.get(fieldName); if (opt == null) { FieldReader reader = null; ClassReader cls = classSource.get(className); if (cls != null) { if (cls.getParent() != null) { reader = resolve(cls.getParent(), fieldName); } if (reader == null) { for (String itf : cls.getInterfaces()) { reader = resolve(itf, fieldName); if (reader != null) { break; } } } } opt = Optional.ofNullable(reader); cache.put(fieldName, opt); } return opt.orElse(null); }
public void raise() { if (!pe.hierarchy.isSuperType(ValueType.object("java.lang.Throwable"), type, true)) { throw new EmitException("Can't throw non-exception value: " + type); } RaiseInstruction insn = new RaiseInstruction(); insn.setException(variable); pe.addInstruction(insn); }