private SqlTypeBytecodeExpression(Type type, Binding binding, Method bootstrapMethod) { super(type(Type.class)); this.type = requireNonNull(type, "type is null"); this.binding = requireNonNull(binding, "binding is null"); this.bootstrapMethod = requireNonNull(bootstrapMethod, "bootstrapMethod is null"); }
private static CompiledLambda defineLambdaMethod( RowExpressionCompiler innerExpressionCompiler, ClassDefinition classDefinition, String methodName, List<Parameter> inputParameters, LambdaDefinitionExpression lambda) { checkCondition(inputParameters.size() <= 254, NOT_SUPPORTED, "Too many arguments for lambda expression"); Class<?> returnType = Primitives.wrap(lambda.getBody().getType().getJavaType()); MethodDefinition method = classDefinition.declareMethod(a(PUBLIC), methodName, type(returnType), inputParameters); Scope scope = method.getScope(); Variable wasNull = scope.declareVariable(boolean.class, "wasNull"); BytecodeNode compiledBody = innerExpressionCompiler.compile(lambda.getBody(), scope, Optional.empty()); method.getBody() .putVariable(wasNull, false) .append(compiledBody) .append(boxPrimitiveIfNecessary(scope, returnType)) .ret(returnType); Handle lambdaAsmHandle = new Handle( Opcodes.H_INVOKEVIRTUAL, method.getThis().getType().getClassName(), method.getName(), method.getMethodDescriptor(), false); return new CompiledLambda( lambdaAsmHandle, method.getReturnType(), method.getParameterTypes()); }
private <T> Class<? extends T> compileProcessor( RowExpression filter, List<RowExpression> projections, BodyCompiler bodyCompiler, Class<? extends T> superType) { ClassDefinition classDefinition = new ClassDefinition( a(PUBLIC, FINAL), makeClassName(superType.getSimpleName()), type(Object.class), type(superType)); CallSiteBinder callSiteBinder = new CallSiteBinder(); bodyCompiler.generateMethods(classDefinition, callSiteBinder, filter, projections); // // toString method // generateToString( classDefinition, callSiteBinder, toStringHelper(classDefinition.getType().getJavaClassName()) .add("filter", filter) .add("projections", projections) .toString()); return defineClass(classDefinition, superType, callSiteBinder.getBindings(), getClass().getClassLoader()); }
compiledLambda.getReturnType().getAsmType(), compiledLambda.getParameterTypes().stream() .skip(captureExpressions.size() + 1) // skip capture variables and ConnectorSession instantiatedMethodAsmType), "apply", type(lambdaInterface), captureVariables)); return block;
private ParameterizedType(Class<?> type, ParameterizedType... parameters) { requireNonNull(type, "type is null"); this.type = toInternalIdentifier(type); this.className = getPathName(type); this.simpleName = type.getSimpleName(); ImmutableList.Builder<String> builder = ImmutableList.builder(); for (ParameterizedType parameter : parameters) { builder.add(parameter.toString()); } this.parameters = builder.build(); this.isInterface = type.isInterface(); this.primitiveType = type.isPrimitive() ? type : null; this.arrayComponentType = type.isArray() ? type(type.getComponentType()) : null; }
private ParameterizedType(Class<?> type) { requireNonNull(type, "type is null"); this.type = toInternalIdentifier(type); this.className = getPathName(type); this.simpleName = type.getSimpleName(); this.parameters = ImmutableList.of(); this.isInterface = type.isInterface(); this.primitiveType = type.isPrimitive() ? type : null; this.arrayComponentType = type.isArray() ? type(type.getComponentType()) : null; }
AnnotationVisitor annotationVisitor = visitor.visitAnnotation(name, annotation.type.getType()); annotation.visit(annotationVisitor); visitor.visitEnum(name, type(enumConstant.getDeclaringClass()).getClassName(), enumConstant.name()); visitor.visit(name, Type.getType(parameterizedType.getType()));
bytecodes.put(classDefinition.getType().getJavaClassName(), bytecode); String name = typeFromJavaClassName(className).getClassName() + ".class"; Path file = path.resolve(name).toAbsolutePath(); try {
private static Class<?> unwrapPrimitiveType(ParameterizedType boxedPrimitiveType) { switch (boxedPrimitiveType.getJavaClassName()) { case "java.lang.Boolean": return boolean.class; case "java.lang.Byte": return byte.class; case "java.lang.Character": return char.class; case "java.lang.Short": return short.class; case "java.lang.Integer": return int.class; case "java.lang.Long": return long.class; case "java.lang.Float": return float.class; case "java.lang.Double": return double.class; default: return null; } }
String classFileName = type.getClassName() + ".class"; try (InputStream is = classLoader.getResourceAsStream(classFileName)) { classReader = new ClassReader(is); Class<?> aClass = classLoader.loadClass(type.getJavaClassName()); return new ClassInfo(this, aClass); superClass = typeFromPathName(classReader.readUTF8(superClassIndex, buf)); header += 8; for (int i = 0; i < interfaceCount; ++i) { interfaces.add(typeFromPathName(classReader.readClass(header, buf))); header += 2;
public String getName() { return type.getClassName(); }
@Override protected String getCommonSuperClass(String aType, String bType) { ClassInfo aClassInfo = classInfoLoader.loadClassInfo(typeFromPathName(aType)); ClassInfo bClassInfo = classInfoLoader.loadClassInfo(typeFromPathName(bType)); if (aClassInfo.isAssignableFrom(bClassInfo)) { return aType; } if (bClassInfo.isAssignableFrom(aClassInfo)) { return bType; } if (aClassInfo.isInterface() || bClassInfo.isInterface()) { return "java/lang/Object"; } else { do { aClassInfo = aClassInfo.getSuperclass(); } while (!aClassInfo.isAssignableFrom(bClassInfo)); return aClassInfo.getType().getClassName(); } } }
@Override public void accept(MethodVisitor visitor, MethodGenerationContext generationContext) { visitor.visitFieldInsn(opCode.getOpCode(), classType.getClassName(), fieldName, fieldType.getType()); }
@Override public void accept(MethodVisitor visitor, MethodGenerationContext generationContext) { visitor.visitMethodInsn(opCode.getOpCode(), target.getClassName(), name, getMethodDescription(), target.isInterface()); }
public static ParameterizedType makeClassName(String baseName, Optional<String> suffix) { String className = baseName + "_" + suffix.orElseGet(() -> Instant.now().atZone(UTC).format(TIMESTAMP_FORMAT)) + "_" + CLASS_ID.incrementAndGet(); return typeFromJavaClassName("com.facebook.presto.$gen." + toJavaIdentifierString(className)); }
@Override public void accept(MethodVisitor visitor, MethodGenerationContext generationContext) { if (opCode == NEWARRAY) { checkState(type.isPrimitive(), "need primitive type for NEWARRAY"); visitor.visitIntInsn(opCode.getOpCode(), getPrimitiveArrayType(type)); } else { visitor.visitTypeInsn(opCode.getOpCode(), type.getClassName()); } }
if (superClass.isGeneric() || any(interfaces, ParameterizedType::isGeneric)) { signature = genericClassSignature(superClass, interfaces); interfaces[i] = this.interfaces.get(i).getClassName(); visitor.visit(V1_8, isInterface() ? accessModifier : accessModifier | ACC_SUPER, type.getClassName(), signature, superClass.getClassName(), interfaces);
private static ParameterizedType toCodecType(ThriftStructMetadata metadata) { String className = getPathName(metadata.getStructClass()) + "Codec"; Type type = metadata.getStructType(); if (type instanceof java.lang.reflect.ParameterizedType) { className += Arrays.stream(((java.lang.reflect.ParameterizedType) type).getActualTypeArguments()) .map(arg -> arg.getTypeName().replaceAll("[^a-zA-Z0-9]+", "_")) .collect(joining("$", "$$", "")); } return typeFromPathName(PACKAGE + "/" + className); }
return "[" + toInternalIdentifier(n); return "L" + getPathName(n) + ";";
public ClassInfo(ClassInfoLoader loader, ClassNode classNode) { this(loader, typeFromPathName(classNode.name), classNode.access, classNode.superName == null ? null : typeFromPathName(classNode.superName), transform((List<String>) classNode.interfaces, ParameterizedType::typeFromPathName), (List<MethodNode>) classNode.methods); }