Java Code Examples for jdk.internal.org.objectweb.asm.Type#FLOAT

The following examples show how to use jdk.internal.org.objectweb.asm.Type#FLOAT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GeneratorAdapter.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
private static Type getBoxedType(final Type type) {
    switch (type.getSort()) {
        case Type.BYTE:
            return BYTE_TYPE;
        case Type.BOOLEAN:
            return BOOLEAN_TYPE;
        case Type.SHORT:
            return SHORT_TYPE;
        case Type.CHAR:
            return CHARACTER_TYPE;
        case Type.INT:
            return INTEGER_TYPE;
        case Type.FLOAT:
            return FLOAT_TYPE;
        case Type.LONG:
            return LONG_TYPE;
        case Type.DOUBLE:
            return DOUBLE_TYPE;
    }
    return type;
}
 
Example 2
Source File: InstructionAdapter.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void newarray(final Type type) {
    int typ;
    switch (type.getSort()) {
    case Type.BOOLEAN:
        typ = Opcodes.T_BOOLEAN;
        break;
    case Type.CHAR:
        typ = Opcodes.T_CHAR;
        break;
    case Type.BYTE:
        typ = Opcodes.T_BYTE;
        break;
    case Type.SHORT:
        typ = Opcodes.T_SHORT;
        break;
    case Type.INT:
        typ = Opcodes.T_INT;
        break;
    case Type.FLOAT:
        typ = Opcodes.T_FLOAT;
        break;
    case Type.LONG:
        typ = Opcodes.T_LONG;
        break;
    case Type.DOUBLE:
        typ = Opcodes.T_DOUBLE;
        break;
    default:
        mv.visitTypeInsn(Opcodes.ANEWARRAY, type.getInternalName());
        return;
    }
    mv.visitIntInsn(Opcodes.NEWARRAY, typ);
}
 
Example 3
Source File: LocalVariablesSorter.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new local variable of the given type.
 *
 * @param type
 *            the type of the local variable to be created.
 * @return the identifier of the newly created local variable.
 */
public int newLocal(final Type type) {
    Object t;
    switch (type.getSort()) {
    case Type.BOOLEAN:
    case Type.CHAR:
    case Type.BYTE:
    case Type.SHORT:
    case Type.INT:
        t = Opcodes.INTEGER;
        break;
    case Type.FLOAT:
        t = Opcodes.FLOAT;
        break;
    case Type.LONG:
        t = Opcodes.LONG;
        break;
    case Type.DOUBLE:
        t = Opcodes.DOUBLE;
        break;
    case Type.ARRAY:
        t = type.getDescriptor();
        break;
    // case Type.OBJECT:
    default:
        t = type.getInternalName();
        break;
    }
    int local = newLocalMapping(type);
    setLocalType(local, type);
    setFrameLocal(local, t);
    changed = true;
    return local;
}
 
Example 4
Source File: GeneratorAdapter.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generates the instruction to create a new array.
 *
 * @param type
 *            the type of the array elements.
 */
public void newArray(final Type type) {
    int typ;
    switch (type.getSort()) {
    case Type.BOOLEAN:
        typ = Opcodes.T_BOOLEAN;
        break;
    case Type.CHAR:
        typ = Opcodes.T_CHAR;
        break;
    case Type.BYTE:
        typ = Opcodes.T_BYTE;
        break;
    case Type.SHORT:
        typ = Opcodes.T_SHORT;
        break;
    case Type.INT:
        typ = Opcodes.T_INT;
        break;
    case Type.FLOAT:
        typ = Opcodes.T_FLOAT;
        break;
    case Type.LONG:
        typ = Opcodes.T_LONG;
        break;
    case Type.DOUBLE:
        typ = Opcodes.T_DOUBLE;
        break;
    default:
        typeInsn(Opcodes.ANEWARRAY, type);
        return;
    }
    mv.visitIntInsn(Opcodes.NEWARRAY, typ);
}
 
Example 5
Source File: GeneratorAdapter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generates the instructions to unbox the top stack value. This value is
 * replaced by its unboxed equivalent on top of the stack.
 *
 * @param type
 *            the type of the top stack value.
 */
public void unbox(final Type type) {
    Type t = NUMBER_TYPE;
    Method sig = null;
    switch (type.getSort()) {
    case Type.VOID:
        return;
    case Type.CHAR:
        t = CHARACTER_TYPE;
        sig = CHAR_VALUE;
        break;
    case Type.BOOLEAN:
        t = BOOLEAN_TYPE;
        sig = BOOLEAN_VALUE;
        break;
    case Type.DOUBLE:
        sig = DOUBLE_VALUE;
        break;
    case Type.FLOAT:
        sig = FLOAT_VALUE;
        break;
    case Type.LONG:
        sig = LONG_VALUE;
        break;
    case Type.INT:
    case Type.SHORT:
    case Type.BYTE:
        sig = INT_VALUE;
    }
    if (sig == null) {
        checkCast(type);
    } else {
        checkCast(t);
        invokeVirtual(t, sig);
    }
}
 
Example 6
Source File: GeneratorAdapter.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generates the instructions to unbox the top stack value. This value is
 * replaced by its unboxed equivalent on top of the stack.
 *
 * @param type the type of the top stack value.
 */
public void unbox(final Type type) {
    Type t = NUMBER_TYPE;
    Method sig = null;
    switch (type.getSort()) {
        case Type.VOID:
            return;
        case Type.CHAR:
            t = CHARACTER_TYPE;
            sig = CHAR_VALUE;
            break;
        case Type.BOOLEAN:
            t = BOOLEAN_TYPE;
            sig = BOOLEAN_VALUE;
            break;
        case Type.DOUBLE:
            sig = DOUBLE_VALUE;
            break;
        case Type.FLOAT:
            sig = FLOAT_VALUE;
            break;
        case Type.LONG:
            sig = LONG_VALUE;
            break;
        case Type.INT:
        case Type.SHORT:
        case Type.BYTE:
            sig = INT_VALUE;
    }
    if (sig == null) {
        checkCast(type);
    } else {
        checkCast(t);
        invokeVirtual(t, sig);
    }
}
 
Example 7
Source File: GeneratorAdapter.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generates the instruction to create a new array.
 *
 * @param type
 *            the type of the array elements.
 */
public void newArray(final Type type) {
    int typ;
    switch (type.getSort()) {
    case Type.BOOLEAN:
        typ = Opcodes.T_BOOLEAN;
        break;
    case Type.CHAR:
        typ = Opcodes.T_CHAR;
        break;
    case Type.BYTE:
        typ = Opcodes.T_BYTE;
        break;
    case Type.SHORT:
        typ = Opcodes.T_SHORT;
        break;
    case Type.INT:
        typ = Opcodes.T_INT;
        break;
    case Type.FLOAT:
        typ = Opcodes.T_FLOAT;
        break;
    case Type.LONG:
        typ = Opcodes.T_LONG;
        break;
    case Type.DOUBLE:
        typ = Opcodes.T_DOUBLE;
        break;
    default:
        typeInsn(Opcodes.ANEWARRAY, type);
        return;
    }
    mv.visitIntInsn(Opcodes.NEWARRAY, typ);
}
 
Example 8
Source File: SimpleVerifier.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean isSubTypeOf(final BasicValue value, final BasicValue expected) {
    Type expectedType = expected.getType();
    Type type = value.getType();
    switch (expectedType.getSort()) {
        case Type.INT:
        case Type.FLOAT:
        case Type.LONG:
        case Type.DOUBLE:
            return type.equals(expectedType);
        case Type.ARRAY:
        case Type.OBJECT:
            if (type.equals(NULL_TYPE)) {
                return true;
            } else if (type.getSort() == Type.OBJECT || type.getSort() == Type.ARRAY) {
                if (isAssignableFrom(expectedType, type)) {
                    return true;
                } else if (getClass(expectedType).isInterface()) {
                    // The merge of class or interface types can only yield class types (because it is not
                    // possible in general to find an unambiguous common super interface, due to multiple
                    // inheritance). Because of this limitation, we need to relax the subtyping check here
                    // if 'value' is an interface.
                    return Object.class.isAssignableFrom(getClass(type));
                } else {
                    return false;
                }
            } else {
                return false;
            }
        default:
            throw new AssertionError();
    }
}
 
Example 9
Source File: LocalVariablesSorter.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new local variable of the given type.
 *
 * @param type
 *            the type of the local variable to be created.
 * @return the identifier of the newly created local variable.
 */
public int newLocal(final Type type) {
    Object t;
    switch (type.getSort()) {
    case Type.BOOLEAN:
    case Type.CHAR:
    case Type.BYTE:
    case Type.SHORT:
    case Type.INT:
        t = Opcodes.INTEGER;
        break;
    case Type.FLOAT:
        t = Opcodes.FLOAT;
        break;
    case Type.LONG:
        t = Opcodes.LONG;
        break;
    case Type.DOUBLE:
        t = Opcodes.DOUBLE;
        break;
    case Type.ARRAY:
        t = type.getDescriptor();
        break;
    // case Type.OBJECT:
    default:
        t = type.getInternalName();
        break;
    }
    int local = newLocalMapping(type);
    setLocalType(local, type);
    setFrameLocal(local, t);
    changed = true;
    return local;
}
 
Example 10
Source File: BasicInterpreter.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public BasicValue newValue(final Type type) {
    if (type == null) {
        return BasicValue.UNINITIALIZED_VALUE;
    }
    switch (type.getSort()) {
    case Type.VOID:
        return null;
    case Type.BOOLEAN:
    case Type.CHAR:
    case Type.BYTE:
    case Type.SHORT:
    case Type.INT:
        return BasicValue.INT_VALUE;
    case Type.FLOAT:
        return BasicValue.FLOAT_VALUE;
    case Type.LONG:
        return BasicValue.LONG_VALUE;
    case Type.DOUBLE:
        return BasicValue.DOUBLE_VALUE;
    case Type.ARRAY:
    case Type.OBJECT:
        return BasicValue.REFERENCE_VALUE;
    default:
        throw new Error("Internal error");
    }
}
 
Example 11
Source File: LocalVariablesSorter.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new local variable of the given type.
 *
 * @param type
 *            the type of the local variable to be created.
 * @return the identifier of the newly created local variable.
 */
public int newLocal(final Type type) {
    Object t;
    switch (type.getSort()) {
    case Type.BOOLEAN:
    case Type.CHAR:
    case Type.BYTE:
    case Type.SHORT:
    case Type.INT:
        t = Opcodes.INTEGER;
        break;
    case Type.FLOAT:
        t = Opcodes.FLOAT;
        break;
    case Type.LONG:
        t = Opcodes.LONG;
        break;
    case Type.DOUBLE:
        t = Opcodes.DOUBLE;
        break;
    case Type.ARRAY:
        t = type.getDescriptor();
        break;
    // case Type.OBJECT:
    default:
        t = type.getInternalName();
        break;
    }
    int local = newLocalMapping(type);
    setLocalType(local, type);
    setFrameLocal(local, t);
    changed = true;
    return local;
}
 
Example 12
Source File: BasicInterpreter.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@Override
public BasicValue newValue(final Type type) {
    if (type == null) {
        return BasicValue.UNINITIALIZED_VALUE;
    }
    switch (type.getSort()) {
        case Type.VOID:
            return null;
        case Type.BOOLEAN:
        case Type.CHAR:
        case Type.BYTE:
        case Type.SHORT:
        case Type.INT:
            return BasicValue.INT_VALUE;
        case Type.FLOAT:
            return BasicValue.FLOAT_VALUE;
        case Type.LONG:
            return BasicValue.LONG_VALUE;
        case Type.DOUBLE:
            return BasicValue.DOUBLE_VALUE;
        case Type.ARRAY:
        case Type.OBJECT:
            return BasicValue.REFERENCE_VALUE;
        default:
            throw new AssertionError();
    }
}
 
Example 13
Source File: GeneratorAdapter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generates the instructions to unbox the top stack value. This value is
 * replaced by its unboxed equivalent on top of the stack.
 *
 * @param type
 *            the type of the top stack value.
 */
public void unbox(final Type type) {
    Type t = NUMBER_TYPE;
    Method sig = null;
    switch (type.getSort()) {
    case Type.VOID:
        return;
    case Type.CHAR:
        t = CHARACTER_TYPE;
        sig = CHAR_VALUE;
        break;
    case Type.BOOLEAN:
        t = BOOLEAN_TYPE;
        sig = BOOLEAN_VALUE;
        break;
    case Type.DOUBLE:
        sig = DOUBLE_VALUE;
        break;
    case Type.FLOAT:
        sig = FLOAT_VALUE;
        break;
    case Type.LONG:
        sig = LONG_VALUE;
        break;
    case Type.INT:
    case Type.SHORT:
    case Type.BYTE:
        sig = INT_VALUE;
    }
    if (sig == null) {
        checkCast(type);
    } else {
        checkCast(t);
        invokeVirtual(t, sig);
    }
}
 
Example 14
Source File: InstructionAdapter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void newarray(final Type type) {
    int typ;
    switch (type.getSort()) {
    case Type.BOOLEAN:
        typ = Opcodes.T_BOOLEAN;
        break;
    case Type.CHAR:
        typ = Opcodes.T_CHAR;
        break;
    case Type.BYTE:
        typ = Opcodes.T_BYTE;
        break;
    case Type.SHORT:
        typ = Opcodes.T_SHORT;
        break;
    case Type.INT:
        typ = Opcodes.T_INT;
        break;
    case Type.FLOAT:
        typ = Opcodes.T_FLOAT;
        break;
    case Type.LONG:
        typ = Opcodes.T_LONG;
        break;
    case Type.DOUBLE:
        typ = Opcodes.T_DOUBLE;
        break;
    default:
        mv.visitTypeInsn(Opcodes.ANEWARRAY, type.getInternalName());
        return;
    }
    mv.visitIntInsn(Opcodes.NEWARRAY, typ);
}
 
Example 15
Source File: InstructionAdapter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void newarray(final Type type) {
    int typ;
    switch (type.getSort()) {
    case Type.BOOLEAN:
        typ = Opcodes.T_BOOLEAN;
        break;
    case Type.CHAR:
        typ = Opcodes.T_CHAR;
        break;
    case Type.BYTE:
        typ = Opcodes.T_BYTE;
        break;
    case Type.SHORT:
        typ = Opcodes.T_SHORT;
        break;
    case Type.INT:
        typ = Opcodes.T_INT;
        break;
    case Type.FLOAT:
        typ = Opcodes.T_FLOAT;
        break;
    case Type.LONG:
        typ = Opcodes.T_LONG;
        break;
    case Type.DOUBLE:
        typ = Opcodes.T_DOUBLE;
        break;
    default:
        mv.visitTypeInsn(Opcodes.ANEWARRAY, type.getInternalName());
        return;
    }
    mv.visitIntInsn(Opcodes.NEWARRAY, typ);
}
 
Example 16
Source File: LocalVariablesSorter.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new local variable of the given type.
 *
 * @param type
 *            the type of the local variable to be created.
 * @return the identifier of the newly created local variable.
 */
public int newLocal(final Type type) {
    Object t;
    switch (type.getSort()) {
    case Type.BOOLEAN:
    case Type.CHAR:
    case Type.BYTE:
    case Type.SHORT:
    case Type.INT:
        t = Opcodes.INTEGER;
        break;
    case Type.FLOAT:
        t = Opcodes.FLOAT;
        break;
    case Type.LONG:
        t = Opcodes.LONG;
        break;
    case Type.DOUBLE:
        t = Opcodes.DOUBLE;
        break;
    case Type.ARRAY:
        t = type.getDescriptor();
        break;
    // case Type.OBJECT:
    default:
        t = type.getInternalName();
        break;
    }
    int local = newLocalMapping(type);
    setLocalType(local, type);
    setFrameLocal(local, t);
    changed = true;
    return local;
}
 
Example 17
Source File: GeneratorAdapter.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
  * Generates the instructions to jump to a label based on the comparison of the top two stack
  * values.
  *
  * @param type the type of the top two stack values.
  * @param mode how these values must be compared. One of EQ, NE, LT, GE, GT, LE.
  * @param label where to jump if the comparison result is {@literal true}.
  */
public void ifCmp(final Type type, final int mode, final Label label) {
    switch (type.getSort()) {
        case Type.LONG:
            mv.visitInsn(Opcodes.LCMP);
            break;
        case Type.DOUBLE:
            mv.visitInsn(mode == GE || mode == GT ? Opcodes.DCMPL : Opcodes.DCMPG);
            break;
        case Type.FLOAT:
            mv.visitInsn(mode == GE || mode == GT ? Opcodes.FCMPL : Opcodes.FCMPG);
            break;
        case Type.ARRAY:
        case Type.OBJECT:
            if (mode == EQ) {
                mv.visitJumpInsn(Opcodes.IF_ACMPEQ, label);
                return;
            } else if (mode == NE) {
                mv.visitJumpInsn(Opcodes.IF_ACMPNE, label);
                return;
            } else {
                throw new IllegalArgumentException("Bad comparison for type " + type);
            }
        default:
            int intOp = -1;
            switch (mode) {
                case EQ:
                    intOp = Opcodes.IF_ICMPEQ;
                    break;
                case NE:
                    intOp = Opcodes.IF_ICMPNE;
                    break;
                case GE:
                    intOp = Opcodes.IF_ICMPGE;
                    break;
                case LT:
                    intOp = Opcodes.IF_ICMPLT;
                    break;
                case LE:
                    intOp = Opcodes.IF_ICMPLE;
                    break;
                case GT:
                    intOp = Opcodes.IF_ICMPGT;
                    break;
                default:
                    throw new IllegalArgumentException("Bad comparison mode " + mode);
            }
            mv.visitJumpInsn(intOp, label);
            return;
    }
    mv.visitJumpInsn(mode, label);
}
 
Example 18
Source File: GeneratorAdapter.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Generates the instruction to push the given value on the stack.
 *
 * @param value
 *            the value to be pushed on the stack.
 */
public void push(final Type value) {
    if (value == null) {
        mv.visitInsn(Opcodes.ACONST_NULL);
    } else {
        switch (value.getSort()) {
        case Type.BOOLEAN:
            mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Boolean",
                    "TYPE", CLDESC);
            break;
        case Type.CHAR:
            mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Character",
                    "TYPE", CLDESC);
            break;
        case Type.BYTE:
            mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Byte", "TYPE",
                    CLDESC);
            break;
        case Type.SHORT:
            mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Short", "TYPE",
                    CLDESC);
            break;
        case Type.INT:
            mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Integer",
                    "TYPE", CLDESC);
            break;
        case Type.FLOAT:
            mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Float", "TYPE",
                    CLDESC);
            break;
        case Type.LONG:
            mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Long", "TYPE",
                    CLDESC);
            break;
        case Type.DOUBLE:
            mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Double",
                    "TYPE", CLDESC);
            break;
        default:
            mv.visitLdcInsn(value);
        }
    }
}
 
Example 19
Source File: JavaAdapterBytecodeGenerator.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private void convertReturnValue(final InstructionAdapter mv, final Class<?> returnType, final Type asmReturnType) {
    switch(asmReturnType.getSort()) {
    case Type.VOID:
        mv.pop();
        break;
    case Type.BOOLEAN:
        JSType.TO_BOOLEAN.invoke(mv);
        break;
    case Type.BYTE:
        JSType.TO_INT32.invoke(mv);
        mv.visitInsn(Opcodes.I2B);
        break;
    case Type.SHORT:
        JSType.TO_INT32.invoke(mv);
        mv.visitInsn(Opcodes.I2S);
        break;
    case Type.CHAR:
        // JSType doesn't have a TO_CHAR, so we have services supply us one.
        mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "toCharPrimitive", TO_CHAR_PRIMITIVE_METHOD_DESCRIPTOR, false);
        break;
    case Type.INT:
        JSType.TO_INT32.invoke(mv);
        break;
    case Type.LONG:
        JSType.TO_LONG.invoke(mv);
        break;
    case Type.FLOAT:
        JSType.TO_NUMBER.invoke(mv);
        mv.visitInsn(Opcodes.D2F);
        break;
    case Type.DOUBLE:
        JSType.TO_NUMBER.invoke(mv);
        break;
    default:
        if(asmReturnType.equals(OBJECT_TYPE)) {
            // Must hide ConsString (and potentially other internal Nashorn types) from callers
            mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "exportReturnValue", EXPORT_RETURN_VALUE_METHOD_DESCRIPTOR, false);
        } else if(asmReturnType.equals(STRING_TYPE)){
            // Well-known conversion to String. Not using the JSType one as we want to preserve null as null instead
            // of the string "n,u,l,l".
            mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "toString", TO_STRING_METHOD_DESCRIPTOR, false);
        } else {
            // Invoke converter method handle for everything else. Note that we could have just added an asType or
            // filterReturnValue to the invoked handle instead, but then every instance would have the function
            // method handle wrapped in a separate converter method handle, making handle.invokeExact() megamorphic.
            if(classOverride) {
                mv.getstatic(generatedClassName, converterFields.get(returnType), METHOD_HANDLE_TYPE_DESCRIPTOR);
            } else {
                mv.visitVarInsn(ALOAD, 0);
                mv.getfield(generatedClassName, converterFields.get(returnType), METHOD_HANDLE_TYPE_DESCRIPTOR);
            }
            mv.swap();
            emitInvokeExact(mv, MethodType.methodType(returnType, Object.class));
        }
    }
}
 
Example 20
Source File: JavaAdapterBytecodeGenerator.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private void convertReturnValue(final InstructionAdapter mv, final Class<?> returnType, final Type asmReturnType) {
    switch(asmReturnType.getSort()) {
    case Type.VOID:
        mv.pop();
        break;
    case Type.BOOLEAN:
        JSType.TO_BOOLEAN.invoke(mv);
        break;
    case Type.BYTE:
        JSType.TO_INT32.invoke(mv);
        mv.visitInsn(Opcodes.I2B);
        break;
    case Type.SHORT:
        JSType.TO_INT32.invoke(mv);
        mv.visitInsn(Opcodes.I2S);
        break;
    case Type.CHAR:
        // JSType doesn't have a TO_CHAR, so we have services supply us one.
        mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "toCharPrimitive", TO_CHAR_PRIMITIVE_METHOD_DESCRIPTOR, false);
        break;
    case Type.INT:
        JSType.TO_INT32.invoke(mv);
        break;
    case Type.LONG:
        JSType.TO_LONG.invoke(mv);
        break;
    case Type.FLOAT:
        JSType.TO_NUMBER.invoke(mv);
        mv.visitInsn(Opcodes.D2F);
        break;
    case Type.DOUBLE:
        JSType.TO_NUMBER.invoke(mv);
        break;
    default:
        if(asmReturnType.equals(OBJECT_TYPE)) {
            // Must hide ConsString (and potentially other internal Nashorn types) from callers
            mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "exportReturnValue", EXPORT_RETURN_VALUE_METHOD_DESCRIPTOR, false);
        } else if(asmReturnType.equals(STRING_TYPE)){
            // Well-known conversion to String. Not using the JSType one as we want to preserve null as null instead
            // of the string "n,u,l,l".
            mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "toString", TO_STRING_METHOD_DESCRIPTOR, false);
        } else {
            // Invoke converter method handle for everything else. Note that we could have just added an asType or
            // filterReturnValue to the invoked handle instead, but then every instance would have the function
            // method handle wrapped in a separate converter method handle, making handle.invokeExact() megamorphic.
            if(classOverride) {
                mv.getstatic(generatedClassName, converterFields.get(returnType), METHOD_HANDLE_TYPE_DESCRIPTOR);
            } else {
                mv.visitVarInsn(ALOAD, 0);
                mv.getfield(generatedClassName, converterFields.get(returnType), METHOD_HANDLE_TYPE_DESCRIPTOR);
            }
            mv.swap();
            emitInvokeExact(mv, MethodType.methodType(returnType, Object.class));
        }
    }
}