Java Code Examples for jdk.internal.org.objectweb.asm.type#ARRAY

The following examples show how to use jdk.internal.org.objectweb.asm.type#ARRAY . 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: 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 2
Source File: Remapper.java    From hottub 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 3
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 4
Source File: SimpleVerifier.java    From jdk8u-dev-jdk 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 5
Source File: Remapper.java    From dragonwell8_jdk 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 6
Source File: SimpleVerifier.java    From jdk8u-dev-jdk 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 7
Source File: SimpleVerifier.java    From openjdk-jdk8u-backup 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 8
Source File: SimpleVerifier.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected BasicValue getElementValue(final BasicValue objectArrayValue)
        throws AnalyzerException {
    Type arrayType = objectArrayValue.getType();
    if (arrayType != null) {
        if (arrayType.getSort() == Type.ARRAY) {
            return newValue(Type.getType(arrayType.getDescriptor()
                    .substring(1)));
        } else if ("Lnull;".equals(arrayType.getDescriptor())) {
            return objectArrayValue;
        }
    }
    throw new Error("Internal error");
}
 
Example 9
Source File: SimpleVerifier.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected BasicValue getElementValue(final BasicValue objectArrayValue)
        throws AnalyzerException {
    Type arrayType = objectArrayValue.getType();
    if (arrayType != null) {
        if (arrayType.getSort() == Type.ARRAY) {
            return newValue(Type.getType(arrayType.getDescriptor()
                    .substring(1)));
        } else if ("Lnull;".equals(arrayType.getDescriptor())) {
            return objectArrayValue;
        }
    }
    throw new Error("Internal error");
}
 
Example 10
Source File: BasicInterpreter.java    From nashorn 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: SimpleVerifier.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
protected Class<?> getClass(final Type t) {
    try {
        if (t.getSort() == Type.ARRAY) {
            return Class.forName(t.getDescriptor().replace('/', '.'),
                    false, loader);
        }
        return Class.forName(t.getClassName(), false, loader);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e.toString());
    }
}
 
Example 12
Source File: CheckMethodAdapter.java    From openjdk-jdk8u 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 13
Source File: SimpleVerifier.java    From openjdk-8 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 14
Source File: AnalyzerAdapter.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visitLdcInsn(final Object cst) {
    if (mv != null) {
        mv.visitLdcInsn(cst);
    }
    if (this.locals == null) {
        labels = null;
        return;
    }
    if (cst instanceof Integer) {
        push(Opcodes.INTEGER);
    } else if (cst instanceof Long) {
        push(Opcodes.LONG);
        push(Opcodes.TOP);
    } else if (cst instanceof Float) {
        push(Opcodes.FLOAT);
    } else if (cst instanceof Double) {
        push(Opcodes.DOUBLE);
        push(Opcodes.TOP);
    } else if (cst instanceof String) {
        push("java/lang/String");
    } else if (cst instanceof Type) {
        int sort = ((Type) cst).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 (cst instanceof Handle) {
        push("java/lang/invoke/MethodHandle");
    } else {
        throw new IllegalArgumentException();
    }
    labels = null;
}
 
Example 15
Source File: GeneratorAdapter.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generates an invoke method instruction.
 *
 * @param opcode the instruction's opcode.
 * @param type the class in which the method is defined.
 * @param method the method to be invoked.
 */
private void invokeInsn(
    final int opcode,
    final Type type,
    final Method method)
{
    String owner = type.getSort() == Type.ARRAY
            ? type.getDescriptor()
            : type.getInternalName();
    mv.visitMethodInsn(opcode,
            owner,
            method.getName(),
            method.getDescriptor());
}
 
Example 16
Source File: SimpleVerifier.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected BasicValue getElementValue(final BasicValue objectArrayValue)
        throws AnalyzerException {
    Type arrayType = objectArrayValue.getType();
    if (arrayType != null) {
        if (arrayType.getSort() == Type.ARRAY) {
            return newValue(Type.getType(arrayType.getDescriptor()
                    .substring(1)));
        } else if ("Lnull;".equals(arrayType.getDescriptor())) {
            return objectArrayValue;
        }
    }
    throw new Error("Internal error");
}
 
Example 17
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 18
Source File: BasicInterpreter.java    From nashorn 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.");
    }
}
 
Example 19
Source File: AnalyzerAdapter.java    From openjdk-jdk8u-backup 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: GeneratorAdapter.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Generates an invoke method instruction.
 *
 * @param opcode
 *            the instruction's opcode.
 * @param type
 *            the class in which the method is defined.
 * @param method
 *            the method to be invoked.
 */
private void invokeInsn(final int opcode, final Type type,
        final Method method, final boolean itf) {
    String owner = type.getSort() == Type.ARRAY ? type.getDescriptor()
            : type.getInternalName();
    mv.visitMethodInsn(opcode, owner, method.getName(),
            method.getDescriptor(), itf);
}