Java Code Examples for jdk.internal.org.objectweb.asm.Type#getSort()

The following examples show how to use jdk.internal.org.objectweb.asm.Type#getSort() . 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: MemberInfo.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private static boolean isScriptObject(final Type type) {
    if (type.getDescriptor().equals(SCRIPTOBJECT_DESC)) {
        return true;
    }

    if (type.getSort() == Type.OBJECT) {
        try {
            final Class<?> clazz = Class.forName(type.getClassName(), false, myLoader);
            return ScriptObject.class.isAssignableFrom(clazz);
        } catch (final ClassNotFoundException cnfe) {
            return false;
        }
    }

    return false;
}
 
Example 2
Source File: GeneratorAdapter.java    From jdk8u-jdk 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 3
Source File: Remapper.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private Type mapType(Type t) {
    switch (t.getSort()) {
    case Type.ARRAY:
        String s = mapDesc(t.getElementType().getDescriptor());
        for (int i = 0; i < t.getDimensions(); ++i) {
            s = '[' + s;
        }
        return Type.getType(s);
    case Type.OBJECT:
        s = map(t.getInternalName());
        return s != null ? Type.getObjectType(s) : t;
    case Type.METHOD:
        return Type.getMethodType(mapMethodDesc(t.getDescriptor()));
    }
    return t;
}
 
Example 4
Source File: Remapper.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
public String mapDesc(String desc) {
    Type t = Type.getType(desc);
    switch (t.getSort()) {
        case Type.ARRAY:
            String s = mapDesc(t.getElementType().getDescriptor());
            for (int i = 0; i < t.getDimensions(); ++i) {
                s = '[' + s;
            }
            return s;
        case Type.OBJECT:
            String newType = map(t.getInternalName());
            if (newType != null) {
                return 'L' + newType + ';';
            }
    }
    return desc;
}
 
Example 5
Source File: GeneratorAdapter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Generates the instructions to box the top stack value. This value is
 * replaced by its boxed equivalent on top of the stack.
 *
 * @param type
 *            the type of the top stack value.
 */
public void box(final Type type) {
    if (type.getSort() == Type.OBJECT || type.getSort() == Type.ARRAY) {
        return;
    }
    if (type == Type.VOID_TYPE) {
        push((String) null);
    } else {
        Type boxed = getBoxedType(type);
        newInstance(boxed);
        if (type.getSize() == 2) {
            // Pp -> Ppo -> oPpo -> ooPpo -> ooPp -> o
            dupX2();
            dupX2();
            pop();
        } else {
            // p -> po -> opo -> oop -> o
            dupX1();
            swap();
        }
        invokeConstructor(boxed, new Method("<init>", Type.VOID_TYPE,
                new Type[] { type }));
    }
}
 
Example 6
Source File: GeneratorAdapter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generates the instructions to box the top stack value using Java 5's
 * valueOf() method. This value is replaced by its boxed equivalent on top
 * of the stack.
 *
 * @param type
 *            the type of the top stack value.
 */
public void valueOf(final Type type) {
    if (type.getSort() == Type.OBJECT || type.getSort() == Type.ARRAY) {
        return;
    }
    if (type == Type.VOID_TYPE) {
        push((String) null);
    } else {
        Type boxed = getBoxedType(type);
        invokeStatic(boxed, new Method("valueOf", boxed,
                new Type[] { type }));
    }
}
 
Example 7
Source File: LocalVariablesSorter.java    From openjdk-jdk8u-backup 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 8
Source File: GeneratorAdapter.java    From jdk8u-jdk 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 9
Source File: MemberInfo.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static boolean isJSPrimitiveType(final Type type) {
    switch (type.getSort()) {
        case Type.BOOLEAN:
        case Type.INT:
        case Type.LONG:
        case Type.DOUBLE:
            return true;
        default:
            return false;
    }
}
 
Example 10
Source File: LocalVariablesSorter.java    From jdk8u-dev-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 11
Source File: BasicInterpreter.java    From jdk8u60 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 12
Source File: GeneratorAdapter.java    From openjdk-jdk9 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 13
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 14
Source File: SimpleVerifier.java    From jdk8u-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;
    }

    boolean isArray = type.getSort() == Type.ARRAY;
    if (isArray) {
        switch (type.getElementType().getSort()) {
        case Type.BOOLEAN:
        case Type.CHAR:
        case Type.BYTE:
        case Type.SHORT:
            return new BasicValue(type);
        }
    }

    BasicValue v = super.newValue(type);
    if (BasicValue.REFERENCE_VALUE.equals(v)) {
        if (isArray) {
            v = newValue(type.getElementType());
            String desc = v.getType().getDescriptor();
            for (int i = 0; i < type.getDimensions(); ++i) {
                desc = '[' + desc;
            }
            v = new BasicValue(Type.getType(desc));
        } else {
            v = new BasicValue(type);
        }
    }
    return v;
}
 
Example 15
Source File: SimpleVerifier.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
@Override
public BasicValue merge(final BasicValue value1, final BasicValue value2) {
    if (!value1.equals(value2)) {
        Type type1 = value1.getType();
        Type type2 = value2.getType();
        if (type1 != null
                && (type1.getSort() == Type.OBJECT || type1.getSort() == Type.ARRAY)
                && type2 != null
                && (type2.getSort() == Type.OBJECT || type2.getSort() == Type.ARRAY)) {
            if (type1.equals(NULL_TYPE)) {
                return value2;
            }
            if (type2.equals(NULL_TYPE)) {
                return value1;
            }
            if (isAssignableFrom(type1, type2)) {
                return value1;
            }
            if (isAssignableFrom(type2, type1)) {
                return value2;
            }
            int numDimensions = 0;
            if (type1.getSort() == Type.ARRAY
                    && type2.getSort() == Type.ARRAY
                    && type1.getDimensions() == type2.getDimensions()
                    && type1.getElementType().getSort() == Type.OBJECT
                    && type2.getElementType().getSort() == Type.OBJECT) {
                numDimensions = type1.getDimensions();
                type1 = type1.getElementType();
                type2 = type2.getElementType();
            }
            do {
                if (type1 == null || isInterface(type1)) {
                    return newArrayValue(Type.getObjectType("java/lang/Object"), numDimensions);
                }
                type1 = getSuperClass(type1);
                if (isAssignableFrom(type1, type2)) {
                    return newArrayValue(type1, numDimensions);
                }
            } while (true);
        }
        return BasicValue.UNINITIALIZED_VALUE;
    }
    return value1;
}
 
Example 16
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 17
Source File: GeneratorAdapter.java    From openjdk-8-source 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 18
Source File: Textifier.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void visitInvokeDynamicInsn(String name, String desc, Handle bsm,
        Object... bsmArgs) {
    buf.setLength(0);
    buf.append(tab2).append("INVOKEDYNAMIC").append(' ');
    buf.append(name);
    appendDescriptor(METHOD_DESCRIPTOR, desc);
    buf.append(" [");
    buf.append('\n');
    buf.append(tab3);
    appendHandle(bsm);
    buf.append('\n');
    buf.append(tab3).append("// arguments:");
    if (bsmArgs.length == 0) {
        buf.append(" none");
    } else {
        buf.append('\n');
        for (int i = 0; i < bsmArgs.length; i++) {
            buf.append(tab3);
            Object cst = bsmArgs[i];
            if (cst instanceof String) {
                Printer.appendString(buf, (String) cst);
            } else if (cst instanceof Type) {
                Type type = (Type) cst;
                if(type.getSort() == Type.METHOD){
                    appendDescriptor(METHOD_DESCRIPTOR, type.getDescriptor());
                } else {
                    buf.append(type.getDescriptor()).append(".class");
                }
            } else if (cst instanceof Handle) {
                appendHandle((Handle) cst);
            } else {
                buf.append(cst);
            }
            buf.append(", \n");
        }
        buf.setLength(buf.length() - 3);
    }
    buf.append('\n');
    buf.append(tab2).append("]\n");
    text.add(buf.toString());
}
 
Example 19
Source File: AnalyzerAdapter.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a new {@link AnalyzerAdapter}.
 *
 * @param api
 *            the ASM API version implemented by this visitor. Must be one
 *            of {@link Opcodes#ASM4} or {@link Opcodes#ASM5}.
 * @param owner
 *            the owner's class name.
 * @param access
 *            the method's access flags (see {@link Opcodes}).
 * @param name
 *            the method's name.
 * @param desc
 *            the method's descriptor (see {@link Type Type}).
 * @param mv
 *            the method visitor to which this adapter delegates calls. May
 *            be <tt>null</tt>.
 */
protected AnalyzerAdapter(final int api, final String owner,
        final int access, final String name, final String desc,
        final MethodVisitor mv) {
    super(api, mv);
    this.owner = owner;
    locals = new ArrayList<Object>();
    stack = new ArrayList<Object>();
    uninitializedTypes = new HashMap<Object, Object>();

    if ((access & Opcodes.ACC_STATIC) == 0) {
        if ("<init>".equals(name)) {
            locals.add(Opcodes.UNINITIALIZED_THIS);
        } else {
            locals.add(owner);
        }
    }
    Type[] types = Type.getArgumentTypes(desc);
    for (int i = 0; i < types.length; ++i) {
        Type type = types[i];
        switch (type.getSort()) {
        case Type.BOOLEAN:
        case Type.CHAR:
        case Type.BYTE:
        case Type.SHORT:
        case Type.INT:
            locals.add(Opcodes.INTEGER);
            break;
        case Type.FLOAT:
            locals.add(Opcodes.FLOAT);
            break;
        case Type.LONG:
            locals.add(Opcodes.LONG);
            locals.add(Opcodes.TOP);
            break;
        case Type.DOUBLE:
            locals.add(Opcodes.DOUBLE);
            locals.add(Opcodes.TOP);
            break;
        case Type.ARRAY:
            locals.add(types[i].getDescriptor());
            break;
        // case Type.OBJECT:
        default:
            locals.add(types[i].getInternalName());
        }
    }
    maxLocals = locals.size();
}
 
Example 20
Source File: TypeConvertingMethodAdapter.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
void boxIfTypePrimitive(Type t) {
    Wrapper w = FROM_TYPE_SORT[t.getSort()];
    if (w != null) {
        box(w);
    }
}