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

The following examples show how to use jdk.internal.org.objectweb.asm.Type#OBJECT . 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 jdk8u60 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: Remapper.java    From jdk8u_jdk 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 3
Source File: GeneratorAdapter.java    From jdk8u-jdk 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 4
Source File: GeneratorAdapter.java    From openjdk-jdk9 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 5
Source File: SimpleVerifier.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 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 ("Lnull;".equals(type.getDescriptor())) {
            return true;
        } else if (type.getSort() == Type.OBJECT
                || type.getSort() == Type.ARRAY) {
            return isAssignableFrom(expectedType, type);
        } else {
            return false;
        }
    default:
        throw new Error("Internal error");
    }
}
 
Example 6
Source File: Remapper.java    From TencentKona-8 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 7
Source File: GeneratorAdapter.java    From openjdk-jdk8u 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 8
Source File: SimpleVerifier.java    From openjdk-8-source with GNU General Public License v2.0 6 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 ("Lnull;".equals(type.getDescriptor())) {
            return true;
        } else if (type.getSort() == Type.OBJECT
                || type.getSort() == Type.ARRAY) {
            return isAssignableFrom(expectedType, type);
        } else {
            return false;
        }
    default:
        throw new Error("Internal error");
    }
}
 
Example 9
Source File: CheckAnnotationAdapter.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void visit(final String name, final Object value) {
    checkEnd();
    checkName(name);
    if (!(value instanceof Byte || value instanceof Boolean
            || value instanceof Character || value instanceof Short
            || value instanceof Integer || value instanceof Long
            || value instanceof Float || value instanceof Double
            || value instanceof String || value instanceof Type
            || value instanceof byte[] || value instanceof boolean[]
            || value instanceof char[] || value instanceof short[]
            || value instanceof int[] || value instanceof long[]
            || value instanceof float[] || value instanceof double[])) {
        throw new IllegalArgumentException("Invalid annotation value");
    }
    if (value instanceof Type) {
        int sort = ((Type) value).getSort();
        if (sort != Type.OBJECT && sort != Type.ARRAY) {
            throw new IllegalArgumentException("Invalid annotation value");
        }
    }
    if (av != null) {
        av.visit(name, value);
    }
}
 
Example 10
Source File: SimpleVerifier.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
protected boolean isAssignableFrom(final Type t, final Type u) {
    if (t.equals(u)) {
        return true;
    }
    if (currentClass != null && t.equals(currentClass)) {
        if (getSuperClass(u) == null) {
            return false;
        } else {
            if (isInterface) {
                return u.getSort() == Type.OBJECT || u.getSort() == Type.ARRAY;
            }
            return isAssignableFrom(t, getSuperClass(u));
        }
    }
    if (currentClass != null && u.equals(currentClass)) {
        if (isAssignableFrom(t, currentSuperClass)) {
            return true;
        }
        if (currentClassInterfaces != null) {
            for (int i = 0; i < currentClassInterfaces.size(); ++i) {
                Type v = currentClassInterfaces.get(i);
                if (isAssignableFrom(t, v)) {
                    return true;
                }
            }
        }
        return false;
    }
    Class<?> tc = getClass(t);
    if (tc.isInterface()) {
        tc = Object.class;
    }
    return tc.isAssignableFrom(getClass(u));
}
 
Example 11
Source File: BasicInterpreter.java    From TencentKona-8 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 nashorn 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 13
Source File: CheckMethodAdapter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
void checkLDCConstant(final Object cst) {
    if (cst instanceof Type) {
        int s = ((Type) cst).getSort();
        if (s != Type.OBJECT && s != Type.ARRAY && s != Type.METHOD) {
            throw new IllegalArgumentException("Illegal LDC constant value");
        }
        if (s != Type.METHOD && (version & 0xFFFF) < Opcodes.V1_5) {
            throw new IllegalArgumentException(
                    "ldc of a constant class requires at least version 1.5");
        }
        if (s == Type.METHOD && (version & 0xFFFF) < Opcodes.V1_7) {
            throw new IllegalArgumentException(
                    "ldc of a method type requires at least version 1.7");
        }
    } else if (cst instanceof Handle) {
        if ((version & 0xFFFF) < Opcodes.V1_7) {
            throw new IllegalArgumentException(
                    "ldc of a handle requires at least version 1.7");
        }
        int tag = ((Handle) cst).getTag();
        if (tag < Opcodes.H_GETFIELD || tag > Opcodes.H_INVOKEINTERFACE) {
            throw new IllegalArgumentException("invalid handle tag " + tag);
        }
    } else {
        checkConstant(cst);
    }
}
 
Example 14
Source File: AnalyzerAdapter.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@Override
public void visitLdcInsn(final Object value) {
    super.visitLdcInsn(value);
    if (this.locals == null) {
        labels = null;
        return;
    }
    if (value instanceof Integer) {
        push(Opcodes.INTEGER);
    } else if (value instanceof Long) {
        push(Opcodes.LONG);
        push(Opcodes.TOP);
    } else if (value instanceof Float) {
        push(Opcodes.FLOAT);
    } else if (value instanceof Double) {
        push(Opcodes.DOUBLE);
        push(Opcodes.TOP);
    } else if (value instanceof String) {
        push("java/lang/String");
    } else if (value instanceof Type) {
        int sort = ((Type) value).getSort();
        if (sort == Type.OBJECT || sort == Type.ARRAY) {
            push("java/lang/Class");
        } else if (sort == Type.METHOD) {
            push("java/lang/invoke/MethodType");
        } else {
            throw new IllegalArgumentException();
        }
    } else if (value instanceof Handle) {
        push("java/lang/invoke/MethodHandle");
    } else if (value instanceof ConstantDynamic) {
        pushDescriptor(((ConstantDynamic) value).getDescriptor());
    } else {
        throw new IllegalArgumentException();
    }
    labels = null;
}
 
Example 15
Source File: GeneratorAdapter.java    From openjdk-8 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 16
Source File: GeneratorAdapter.java    From openjdk-jdk8u with GNU General Public License v2.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 <tt>true</tt>.
 */
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:
        switch (mode) {
        case EQ:
            mv.visitJumpInsn(Opcodes.IF_ACMPEQ, label);
            return;
        case NE:
            mv.visitJumpInsn(Opcodes.IF_ACMPNE, label);
            return;
        }
        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;
        }
        mv.visitJumpInsn(intOp, label);
        return;
    }
    mv.visitJumpInsn(mode, label);
}
 
Example 17
Source File: BasicValue.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
public boolean isReference() {
    return type != null
            && (type.getSort() == Type.OBJECT || type.getSort() == Type.ARRAY);
}
 
Example 18
Source File: CheckMethodAdapter.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
  * Checks that the given value is a valid operand for the LDC instruction.
  *
  * @param value the value to be checked.
  */
private void checkLdcConstant(final Object value) {
    if (value instanceof Type) {
        int sort = ((Type) value).getSort();
        if (sort != Type.OBJECT && sort != Type.ARRAY && sort != Type.METHOD) {
            throw new IllegalArgumentException("Illegal LDC constant value");
        }
        if (sort != Type.METHOD && (version & 0xFFFF) < Opcodes.V1_5) {
            throw new IllegalArgumentException("ldc of a constant class requires at least version 1.5");
        }
        if (sort == Type.METHOD && (version & 0xFFFF) < Opcodes.V1_7) {
            throw new IllegalArgumentException("ldc of a method type requires at least version 1.7");
        }
    } else if (value instanceof Handle) {
        if ((version & 0xFFFF) < Opcodes.V1_7) {
            throw new IllegalArgumentException("ldc of a Handle requires at least version 1.7");
        }
        Handle handle = (Handle) value;
        int tag = handle.getTag();
        if (tag < Opcodes.H_GETFIELD || tag > Opcodes.H_INVOKEINTERFACE) {
            throw new IllegalArgumentException("invalid handle tag " + tag);
        }
        checkInternalName(this.version, handle.getOwner(), "handle owner");
        if (tag <= Opcodes.H_PUTSTATIC) {
            checkDescriptor(this.version, handle.getDesc(), false);
        } else {
            checkMethodDescriptor(this.version, handle.getDesc());
        }
        String handleName = handle.getName();
        if (!("<init>".equals(handleName) && tag == Opcodes.H_NEWINVOKESPECIAL)) {
            checkMethodIdentifier(this.version, handleName, "handle name");
        }
    } else if (value instanceof ConstantDynamic) {
        if ((version & 0xFFFF) < Opcodes.V11) {
            throw new IllegalArgumentException("ldc of a ConstantDynamic requires at least version 11");
        }
        ConstantDynamic constantDynamic = (ConstantDynamic) value;
        checkMethodIdentifier(this.version, constantDynamic.getName(), "constant dynamic name");
        checkDescriptor(this.version, constantDynamic.getDescriptor(), false);
        checkLdcConstant(constantDynamic.getBootstrapMethod());
        int bootstrapMethodArgumentCount = constantDynamic.getBootstrapMethodArgumentCount();
        for (int i = 0; i < bootstrapMethodArgumentCount; ++i) {
            checkLdcConstant(constantDynamic.getBootstrapMethodArgument(i));
        }
    } else {
        checkConstant(value);
    }
}
 
Example 19
Source File: GeneratorAdapter.java    From jdk8u-jdk with GNU General Public License v2.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 <tt>true</tt>.
 */
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:
        switch (mode) {
        case EQ:
            mv.visitJumpInsn(Opcodes.IF_ACMPEQ, label);
            return;
        case NE:
            mv.visitJumpInsn(Opcodes.IF_ACMPNE, label);
            return;
        }
        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;
        }
        mv.visitJumpInsn(intOp, label);
        return;
    }
    mv.visitJumpInsn(mode, label);
}
 
Example 20
Source File: BasicInterpreter.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Override
public BasicValue newOperation(final AbstractInsnNode insn)
        throws AnalyzerException {
    switch (insn.getOpcode()) {
    case ACONST_NULL:
        return newValue(Type.getObjectType("null"));
    case ICONST_M1:
    case ICONST_0:
    case ICONST_1:
    case ICONST_2:
    case ICONST_3:
    case ICONST_4:
    case ICONST_5:
        return BasicValue.INT_VALUE;
    case LCONST_0:
    case LCONST_1:
        return BasicValue.LONG_VALUE;
    case FCONST_0:
    case FCONST_1:
    case FCONST_2:
        return BasicValue.FLOAT_VALUE;
    case DCONST_0:
    case DCONST_1:
        return BasicValue.DOUBLE_VALUE;
    case BIPUSH:
    case SIPUSH:
        return BasicValue.INT_VALUE;
    case LDC:
        Object cst = ((LdcInsnNode) insn).cst;
        if (cst instanceof Integer) {
            return BasicValue.INT_VALUE;
        } else if (cst instanceof Float) {
            return BasicValue.FLOAT_VALUE;
        } else if (cst instanceof Long) {
            return BasicValue.LONG_VALUE;
        } else if (cst instanceof Double) {
            return BasicValue.DOUBLE_VALUE;
        } else if (cst instanceof String) {
            return newValue(Type.getObjectType("java/lang/String"));
        } else if (cst instanceof Type) {
            int sort = ((Type) cst).getSort();
            if (sort == Type.OBJECT || sort == Type.ARRAY) {
                return newValue(Type.getObjectType("java/lang/Class"));
            } else if (sort == Type.METHOD) {
                return newValue(Type
                        .getObjectType("java/lang/invoke/MethodType"));
            } else {
                throw new IllegalArgumentException("Illegal LDC constant "
                        + cst);
            }
        } else if (cst instanceof Handle) {
            return newValue(Type
                    .getObjectType("java/lang/invoke/MethodHandle"));
        } else {
            throw new IllegalArgumentException("Illegal LDC constant "
                    + cst);
        }
    case JSR:
        return BasicValue.RETURNADDRESS_VALUE;
    case GETSTATIC:
        return newValue(Type.getType(((FieldInsnNode) insn).desc));
    case NEW:
        return newValue(Type.getObjectType(((TypeInsnNode) insn).desc));
    default:
        throw new Error("Internal error.");
    }
}