Search in sources :

Example 26 with Type

use of jdk.internal.org.objectweb.asm.Type in project Bytecoder by mirkosertic.

the class GeneratorAdapter method box.

/**
 * 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 }));
    }
}
Also used : Type(jdk.internal.org.objectweb.asm.Type)

Example 27 with Type

use of jdk.internal.org.objectweb.asm.Type in project Bytecoder by mirkosertic.

the class GeneratorAdapter method unbox.

/**
 * 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);
    }
}
Also used : Type(jdk.internal.org.objectweb.asm.Type)

Example 28 with Type

use of jdk.internal.org.objectweb.asm.Type in project Bytecoder by mirkosertic.

the class LocalVariablesSorter method visitVarInsn.

@Override
public void visitVarInsn(final int opcode, final int var) {
    Type type;
    switch(opcode) {
        case Opcodes.LLOAD:
        case Opcodes.LSTORE:
            type = Type.LONG_TYPE;
            break;
        case Opcodes.DLOAD:
        case Opcodes.DSTORE:
            type = Type.DOUBLE_TYPE;
            break;
        case Opcodes.FLOAD:
        case Opcodes.FSTORE:
            type = Type.FLOAT_TYPE;
            break;
        case Opcodes.ILOAD:
        case Opcodes.ISTORE:
            type = Type.INT_TYPE;
            break;
        default:
            // case Opcodes.ALOAD:
            // case Opcodes.ASTORE:
            // case RET:
            type = OBJECT_TYPE;
            break;
    }
    mv.visitVarInsn(opcode, remap(var, type));
}
Also used : Type(jdk.internal.org.objectweb.asm.Type)

Example 29 with Type

use of jdk.internal.org.objectweb.asm.Type in project Bytecoder by mirkosertic.

the class LocalVariablesSorter method visitFrame.

@Override
public void visitFrame(final int type, final int nLocal, final Object[] local, final int nStack, final Object[] stack) {
    if (type != Opcodes.F_NEW) {
        // uncompressed frame
        throw new IllegalStateException("ClassReader.accept() should be called with EXPAND_FRAMES flag");
    }
    // creates a copy of newLocals
    Object[] oldLocals = new Object[newLocals.length];
    System.arraycopy(newLocals, 0, oldLocals, 0, oldLocals.length);
    updateNewLocals(newLocals);
    // copies types from 'local' to 'newLocals'
    // 'newLocals' already contains the variables added with 'newLocal'
    // old local variable index
    int index = 0;
    // old local variable number
    int number = 0;
    for (; number < nLocal; ++number) {
        Object t = local[number];
        int size = t == Opcodes.LONG || t == Opcodes.DOUBLE ? 2 : 1;
        if (t != Opcodes.TOP) {
            Type typ = OBJECT_TYPE;
            if (t == Opcodes.INTEGER) {
                typ = Type.INT_TYPE;
            } else if (t == Opcodes.FLOAT) {
                typ = Type.FLOAT_TYPE;
            } else if (t == Opcodes.LONG) {
                typ = Type.LONG_TYPE;
            } else if (t == Opcodes.DOUBLE) {
                typ = Type.DOUBLE_TYPE;
            } else if (t instanceof String) {
                typ = Type.getObjectType((String) t);
            }
            setFrameLocal(remap(index, typ), t);
        }
        index += size;
    }
    // removes TOP after long and double types as well as trailing TOPs
    index = 0;
    number = 0;
    for (int i = 0; index < newLocals.length; ++i) {
        Object t = newLocals[index++];
        if (t != null && t != Opcodes.TOP) {
            newLocals[i] = t;
            number = i + 1;
            if (t == Opcodes.LONG || t == Opcodes.DOUBLE) {
                index += 1;
            }
        } else {
            newLocals[i] = Opcodes.TOP;
        }
    }
    // visits remapped frame
    mv.visitFrame(type, number, newLocals, nStack, stack);
    // restores original value of 'newLocals'
    newLocals = oldLocals;
}
Also used : Type(jdk.internal.org.objectweb.asm.Type)

Example 30 with Type

use of jdk.internal.org.objectweb.asm.Type in project Bytecoder by mirkosertic.

the class Remapper method mapMethodDesc.

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();
}
Also used : Type(jdk.internal.org.objectweb.asm.Type)

Aggregations

Type (jdk.internal.org.objectweb.asm.Type)30 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)2 List (java.util.List)2 AbstractInsnNode (jdk.internal.org.objectweb.asm.tree.AbstractInsnNode)2 ClassNode (jdk.internal.org.objectweb.asm.tree.ClassNode)2 IincInsnNode (jdk.internal.org.objectweb.asm.tree.IincInsnNode)2 InsnList (jdk.internal.org.objectweb.asm.tree.InsnList)2 JumpInsnNode (jdk.internal.org.objectweb.asm.tree.JumpInsnNode)2 LabelNode (jdk.internal.org.objectweb.asm.tree.LabelNode)2 LookupSwitchInsnNode (jdk.internal.org.objectweb.asm.tree.LookupSwitchInsnNode)2 MethodNode (jdk.internal.org.objectweb.asm.tree.MethodNode)2 TableSwitchInsnNode (jdk.internal.org.objectweb.asm.tree.TableSwitchInsnNode)2 TryCatchBlockNode (jdk.internal.org.objectweb.asm.tree.TryCatchBlockNode)2 VarInsnNode (jdk.internal.org.objectweb.asm.tree.VarInsnNode)2 Analyzer (jdk.internal.org.objectweb.asm.tree.analysis.Analyzer)2 BasicValue (jdk.internal.org.objectweb.asm.tree.analysis.BasicValue)2 SimpleVerifier (jdk.internal.org.objectweb.asm.tree.analysis.SimpleVerifier)2