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

The following examples show how to use jdk.internal.org.objectweb.asm.Type. These examples are extracted from open source projects. 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 Project: jdk8u-jdk   Source File: GeneratorAdapter.java    License: 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 2
Source Project: jdk8u60   Source File: Remapper.java    License: GNU General Public License v2.0 6 votes vote down vote up
public String mapMethodDesc(String desc) {
    if ("()V".equals(desc)) {
        return desc;
    }

    Type[] args = Type.getArgumentTypes(desc);
    StringBuilder sb = new StringBuilder("(");
    for (int i = 0; i < args.length; i++) {
        sb.append(mapDesc(args[i].getDescriptor()));
    }
    Type returnType = Type.getReturnType(desc);
    if (returnType == Type.VOID_TYPE) {
        sb.append(")V");
        return sb.toString();
    }
    sb.append(')').append(mapDesc(returnType.getDescriptor()));
    return sb.toString();
}
 
Example 3
Source Project: jdk8u60   Source File: AdviceAdapter.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void visitInvokeDynamicInsn(String name, String desc, Handle bsm,
        Object... bsmArgs) {
    mv.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs);
    if (constructor) {
        Type[] types = Type.getArgumentTypes(desc);
        for (int i = 0; i < types.length; i++) {
            popValue();
            if (types[i].getSize() == 2) {
                popValue();
            }
        }

        Type returnType = Type.getReturnType(desc);
        if (returnType != Type.VOID_TYPE) {
            pushValue(OTHER);
            if (returnType.getSize() == 2) {
                pushValue(OTHER);
            }
        }
    }
}
 
Example 4
/**
 * 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 Project: openjdk-jdk8u   Source File: AdviceAdapter.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void visitInvokeDynamicInsn(String name, String desc, Handle bsm,
        Object... bsmArgs) {
    mv.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs);
    if (constructor) {
        Type[] types = Type.getArgumentTypes(desc);
        for (int i = 0; i < types.length; i++) {
            popValue();
            if (types[i].getSize() == 2) {
                popValue();
            }
        }

        Type returnType = Type.getReturnType(desc);
        if (returnType != Type.VOID_TYPE) {
            pushValue(OTHER);
            if (returnType.getSize() == 2) {
                pushValue(OTHER);
            }
        }
    }
}
 
Example 6
@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.METHOD) {
            throw new IllegalArgumentException("Invalid annotation value");
        }
    }
    if (av != null) {
        av.visit(name, value);
    }
}
 
Example 7
Source Project: jdk8u-jdk   Source File: AdviceAdapter.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void visitInvokeDynamicInsn(String name, String desc, Handle bsm,
        Object... bsmArgs) {
    mv.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs);
    if (constructor) {
        Type[] types = Type.getArgumentTypes(desc);
        for (int i = 0; i < types.length; i++) {
            popValue();
            if (types[i].getSize() == 2) {
                popValue();
            }
        }

        Type returnType = Type.getReturnType(desc);
        if (returnType != Type.VOID_TYPE) {
            pushValue(OTHER);
            if (returnType.getSize() == 2) {
                pushValue(OTHER);
            }
        }
    }
}
 
Example 8
@Override
public void visitTypeInsn(final int opcode, final String type) {
    Type t = Type.getObjectType(type);
    switch (opcode) {
    case Opcodes.NEW:
        anew(t);
        break;
    case Opcodes.ANEWARRAY:
        newarray(t);
        break;
    case Opcodes.CHECKCAST:
        checkcast(t);
        break;
    case Opcodes.INSTANCEOF:
        instanceOf(t);
        break;
    default:
        throw new IllegalArgumentException();
    }
}
 
Example 9
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 10
@Override
public AnnotationVisitor visitLocalVariableAnnotation(int typeRef,
        TypePath typePath, Label[] start, Label[] end, int[] index,
        String desc, boolean visible) {
    Type t = Type.getType(desc);
    int[] newIndex = new int[index.length];
    for (int i = 0; i < newIndex.length; ++i) {
        newIndex[i] = remap(index[i], t);
    }
    return mv.visitLocalVariableAnnotation(typeRef, typePath, start, end,
            newIndex, desc, visible);
}
 
Example 11
Source Project: hottub   Source File: CheckMethodAdapter.java    License: 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 12
Source Project: hottub   Source File: BasicInterpreter.java    License: 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 13
Source Project: nashorn   Source File: GeneratorAdapter.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generates the instructions to load the given method arguments on the
 * stack.
 *
 * @param arg the index of the first method argument to be loaded.
 * @param count the number of method arguments to be loaded.
 */
public void loadArgs(final int arg, final int count) {
    int index = getArgIndex(arg);
    for (int i = 0; i < count; ++i) {
        Type t = argumentTypes[arg + i];
        loadInsn(t, index);
        index += t.getSize();
    }
}
 
Example 14
Source Project: nashorn   Source File: SimpleVerifier.java    License: 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 15
/**
 * 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 Project: nashorn   Source File: Textifier.java    License: GNU General Public License v2.0 5 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(" [");
    appendHandle(bsm);
    buf.append(tab3).append("// arguments:");
    if(bsmArgs.length == 0) {
        buf.append(" none");
    } else {
        buf.append('\n').append(tab3);
        for(int i = 0; i < bsmArgs.length; i++) {
            Object cst = bsmArgs[i];
            if (cst instanceof String) {
                Printer.appendString(buf, (String) cst);
            } else if (cst instanceof Type) {
                buf.append(((Type) cst).getDescriptor()).append(".class");
            } else if (cst instanceof Handle) {
                appendHandle((Handle) cst);
            } else {
                buf.append(cst);
            }
            buf.append(", ");
        }
        buf.setLength(buf.length() - 2);
    }
    buf.append('\n');
    buf.append(tab2).append("]\n");
    text.add(buf.toString());
}
 
Example 17
@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 18
Source Project: hottub   Source File: Remapper.java    License: GNU General Public License v2.0 5 votes vote down vote up
public Object mapValue(Object value) {
    if (value instanceof Type) {
        return mapType((Type) value);
    }
    if (value instanceof Handle) {
        Handle h = (Handle) value;
        return new Handle(h.getTag(), mapType(h.getOwner()), mapMethodName(
                h.getOwner(), h.getName(), h.getDesc()),
                mapMethodDesc(h.getDesc()));
    }
    return value;
}
 
Example 19
Source Project: jdk8u60   Source File: ClassGenerator.java    License: GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("fallthrough")
private static Type memInfoType(final MemberInfo memInfo) {
    switch (memInfo.getJavaDesc().charAt(0)) {
        case 'I': return Type.INT_TYPE;
        case 'J': return Type.LONG_TYPE;
        case 'D': return Type.DOUBLE_TYPE;
        default:  assert false : memInfo.getJavaDesc();
        case 'L': return TYPE_OBJECT;
    }
}
 
Example 20
@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 21
/**
 * 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 22
MethodGenerator(final MethodVisitor mv, final int access, final String name, final String descriptor) {
    super(ASM4, mv);
    this.access        = access;
    this.name          = name;
    this.descriptor    = descriptor;
    this.returnType    = Type.getReturnType(descriptor);
    this.argumentTypes = Type.getArgumentTypes(descriptor);
}
 
Example 23
private static void boxStackTop(final InstructionAdapter mv, final Type t) {
    switch(t.getSort()) {
    case Type.BOOLEAN:
        invokeValueOf(mv, "Boolean", 'Z');
        break;
    case Type.BYTE:
    case Type.SHORT:
    case Type.INT:
        // bytes and shorts get boxed as integers
        invokeValueOf(mv, "Integer", 'I');
        break;
    case Type.CHAR:
        invokeValueOf(mv, "Character", 'C');
        break;
    case Type.FLOAT:
        // floats get boxed as doubles
        mv.visitInsn(Opcodes.F2D);
        invokeValueOf(mv, "Double", 'D');
        break;
    case Type.LONG:
        invokeValueOf(mv, "Long", 'J');
        break;
    case Type.DOUBLE:
        invokeValueOf(mv, "Double", 'D');
        break;
    case Type.ARRAY:
    case Type.METHOD:
        // Already boxed
        break;
    case Type.OBJECT:
        if(t.equals(OBJECT_TYPE)) {
            mv.invokestatic(SCRIPTUTILS_TYPE_NAME, "unwrap", UNWRAP_METHOD_DESCRIPTOR, false);
        }
        break;
    default:
        // Not expecting anything else (e.g. VOID)
        assert false;
        break;
    }
}
 
Example 24
Source Project: Bytecoder   Source File: BasicInterpreter.java    License: 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 25
Source Project: jdk8u-jdk   Source File: BasicInterpreter.java    License: 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 26
/**
 * Given a list of class objects, return an array with their binary names. Used to generate the array of interface
 * names to implement.
 * @param classes the classes
 * @return an array of names
 */
private static String[] getInternalTypeNames(final List<Class<?>> classes) {
    final int interfaceCount = classes.size();
    final String[] interfaceNames = new String[interfaceCount];
    for(int i = 0; i < interfaceCount; ++i) {
        interfaceNames[i] = Type.getInternalName(classes.get(i));
    }
    return interfaceNames;
}
 
Example 27
Source Project: jdk8u-jdk   Source File: SimpleVerifier.java    License: GNU General Public License v2.0 4 votes vote down vote up
protected boolean isInterface(final Type t) {
    if (currentClass != null && t.equals(currentClass)) {
        return isInterface;
    }
    return getClass(t).isInterface();
}
 
Example 28
Source Project: jdk8u-jdk   Source File: InstructionAdapter.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void shl(final Type type) {
    mv.visitInsn(type.getOpcode(Opcodes.ISHL));
}
 
Example 29
public void sub(final Type type) {
    mv.visitInsn(type.getOpcode(Opcodes.ISUB));
}
 
Example 30
public void neg(final Type type) {
    mv.visitInsn(type.getOpcode(Opcodes.INEG));
}