Search in sources :

Example 1 with Type

use of jdk.internal.org.objectweb.asm.Type in project jdk8u_jdk by JetBrains.

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");
    }
    if (!changed) {
        // optimization for the case where mapping = identity
        mv.visitFrame(type, nLocal, local, nStack, stack);
        return;
    }
    // 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 2 with Type

use of jdk.internal.org.objectweb.asm.Type in project jdk8u_jdk by JetBrains.

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)

Example 3 with Type

use of jdk.internal.org.objectweb.asm.Type in project jdk8u_jdk by JetBrains.

the class GeneratorAdapter method loadArgs.

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

Example 4 with Type

use of jdk.internal.org.objectweb.asm.Type in project jdk8u_jdk by JetBrains.

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 5 with Type

use of jdk.internal.org.objectweb.asm.Type in project jdk8u_jdk by JetBrains.

the class AdviceAdapter method doVisitMethodInsn.

private void doVisitMethodInsn(int opcode, final String owner, final String name, final String desc, final boolean itf) {
    mv.visitMethodInsn(opcode, owner, name, desc, itf);
    if (constructor) {
        Type[] types = Type.getArgumentTypes(desc);
        for (int i = 0; i < types.length; i++) {
            popValue();
            if (types[i].getSize() == 2) {
                popValue();
            }
        }
        switch(opcode) {
            // break;
            case INVOKEINTERFACE:
            case INVOKEVIRTUAL:
                // objectref
                popValue();
                break;
            case INVOKESPECIAL:
                // objectref
                Object type = popValue();
                if (type == THIS && !superInitialized) {
                    onMethodEnter();
                    superInitialized = true;
                    // once super has been initialized it is no longer
                    // necessary to keep track of stack state
                    constructor = false;
                }
                break;
        }
        Type returnType = Type.getReturnType(desc);
        if (returnType != Type.VOID_TYPE) {
            pushValue(OTHER);
            if (returnType.getSize() == 2) {
                pushValue(OTHER);
            }
        }
    }
}
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