Example usage for org.objectweb.asm Opcodes ILOAD

List of usage examples for org.objectweb.asm Opcodes ILOAD

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes ILOAD.

Prototype

int ILOAD

To view the source code for org.objectweb.asm Opcodes ILOAD.

Click Source Link

Usage

From source file:com.googlecode.gwt.test.internal.rewrite.RewriteSingleJsoImplDispatches.java

License:Apache License

/**
 * For regular Java objects that implement a SingleJsoImpl interface, write instance trampoline
 * dispatchers for mangled method names to the implementing method.
 *///from w  w w  .  j  a  v a 2  s  . c om
private void writeTrampoline(String stubIntr) {
    /*
     * This is almost the same kind of trampoline as the ones generated in WriteJsoImpl, however
     * there are enough small differences between the semantics of the dispatches that would make
     * a common implementation far more awkward than the duplication of code.
     */
    for (String mangledName : toImplement(stubIntr)) {
        for (Method method : jsoData.getDeclarations(mangledName)) {

            Method toCall = new Method(method.getName(), method.getDescriptor());

            // Must not be final
            MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, mangledName,
                    method.getDescriptor(), null, null);
            if (mv != null) {
                mv.visitCode();

                /*
                 * It just so happens that the stack and local variable sizes are the same, but
                 * they're kept distinct to aid in clarity should the dispatch logic change.
                 *
                 * These start at 1 because we need to load "this" onto the stack
                 */
                int var = 1;
                int size = 1;

                // load this
                mv.visitVarInsn(Opcodes.ALOAD, 0);

                // then the rest of the arguments
                for (Type t : toCall.getArgumentTypes()) {
                    size += t.getSize();
                    mv.visitVarInsn(t.getOpcode(Opcodes.ILOAD), var);
                    var += t.getSize();
                }

                // Make sure there's enough room for the return value
                size = Math.max(size, toCall.getReturnType().getSize());

                mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, currentTypeName, toCall.getName(),
                        toCall.getDescriptor());
                mv.visitInsn(toCall.getReturnType().getOpcode(Opcodes.IRETURN));
                mv.visitMaxs(size, var);
                mv.visitEnd();
            }
        }
    }
}

From source file:com.liferay.portal.nio.intraband.proxy.IntrabandProxyUtilTest.java

License:Open Source License

private void _doTestCreateProxyMethodNode(Method method, int index, String skeletonId,
        String stubInternalName) {

    MethodNode proxyMethodNode = IntrabandProxyUtil.createProxyMethodNode(method, index, skeletonId,
            Type.getType(stubInternalName));

    _assertMethodNodeSignature(proxyMethodNode, method.getModifiers() & ~Modifier.ABSTRACT, method.getName(),
            Type.getMethodDescriptor(method), method.getExceptionTypes());

    InsnList insnList = proxyMethodNode.instructions;

    Iterator<AbstractInsnNode> iterator = insnList.iterator();

    // NEW com/liferay/portal/kernel/io/Serializer

    _assertTypeInsnNode(iterator.next(), Opcodes.NEW, Serializer.class);

    // DUP/*from   ww  w  .  j  a  v  a2s .  com*/

    _assertInsnNode(iterator.next(), Opcodes.DUP);

    // INVOKESPECIAL com/liferay/portal/kernel/io/Serializer <init> ()V

    _assertMethodInsnNode(iterator.next(), Opcodes.INVOKESPECIAL, Type.getInternalName(Serializer.class),
            "<init>", Type.VOID_TYPE);

    // ASTORE argumentsSize

    Type methodType = Type.getType(method);

    int argumentsAndReturnSizes = methodType.getArgumentsAndReturnSizes();

    int argumentsSize = argumentsAndReturnSizes >> 2;

    _assertVarInsnNode(iterator.next(), Opcodes.ASTORE, argumentsSize);

    // ALOAD argumentsSize

    _assertVarInsnNode(iterator.next(), Opcodes.ALOAD, argumentsSize);

    // LDC skeletonId

    _assertLdcInsnNode(iterator.next(), Opcodes.LDC, skeletonId);

    // INVOKEVIRTUAL com/liferay/portal/kernel/io/Serializer writeString
    // (Ljava/lang/String;)V

    _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL, Type.getInternalName(Serializer.class),
            "writeString", Type.VOID_TYPE, Type.getType(String.class));

    // ALOAD argumentsSize

    _assertVarInsnNode(iterator.next(), Opcodes.ALOAD, argumentsSize);

    // ALOAD 0

    _assertVarInsnNode(iterator.next(), Opcodes.ALOAD, 0);

    // GETFIELD stubInternalName _id Ljava/lang/String;

    _assertFieldInsnNode(iterator.next(), Opcodes.GETFIELD, stubInternalName, "_id", String.class);

    // INVOKEVIRTUAL com/liferay/portal/kernel/io/Serializer writeString
    // (Ljava/lang/String;)V

    _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL, Type.getInternalName(Serializer.class),
            "writeString", Type.VOID_TYPE, Type.getType(String.class));

    // ALOAD argumentsSize

    _assertVarInsnNode(iterator.next(), Opcodes.ALOAD, argumentsSize);

    if (index <= 5) {

        // ICONST_index

        _assertInsnNode(iterator.next(), Opcodes.ICONST_0 + index);
    } else {

        // BIPUSH index

        _assertIntInsnNode(iterator.next(), Opcodes.BIPUSH, index);
    }

    // INVOKEVIRTUAL com/liferay/portal/kernel/io/Serializer writeInt (I)V

    _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL, Type.getInternalName(Serializer.class),
            "writeInt", Type.VOID_TYPE, Type.INT_TYPE);

    Class<?>[] parameterTypes = method.getParameterTypes();

    int offset = 1;

    for (int i = 0; i < parameterTypes.length; i++) {
        Class<?> parameterClass = parameterTypes[i];

        // ALOAD argumentsSize

        _assertVarInsnNode(iterator.next(), Opcodes.ALOAD, argumentsSize);

        // xLOAD i

        Type parameterType = Type.getType(parameterClass);

        _assertVarInsnNode(iterator.next(), parameterType.getOpcode(Opcodes.ILOAD), offset);

        offset += parameterType.getSize();

        if (parameterClass.isPrimitive() || (parameterClass == String.class)) {

            String name = TextFormatter.format(parameterClass.getSimpleName(), TextFormatter.G);

            _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL,
                    Type.getInternalName(Serializer.class), "write".concat(name), Type.VOID_TYPE,
                    parameterType);
        } else {
            _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL,
                    Type.getInternalName(Serializer.class), "writeObject", Type.VOID_TYPE,
                    Type.getType(Serializable.class));
        }
    }

    // ALOAD 0

    _assertVarInsnNode(iterator.next(), Opcodes.ALOAD, 0);

    // ALOAD argumentsSize

    _assertVarInsnNode(iterator.next(), Opcodes.ALOAD, argumentsSize);

    Class<?> returnClass = method.getReturnType();

    Type returnType = Type.getType(returnClass);

    if (returnClass == void.class) {

        // INVOKESPECIAL stubInternalName _send
        // (Lcom/liferay/portal/kernel/io/Serializer;)V

        _assertMethodInsnNode(iterator.next(), Opcodes.INVOKESPECIAL, stubInternalName, "_send", Type.VOID_TYPE,
                Type.getType(Serializer.class));

        _assertInsnNode(iterator.next(), Opcodes.RETURN);
    } else {

        // INVOKESPECIAL stubInternalName _syncSend
        // (Lcom/liferay/portal/kernel/io/Serializer;)Ljava/io/Serializable;

        _assertMethodInsnNode(iterator.next(), Opcodes.INVOKESPECIAL, stubInternalName, "_syncSend",
                Type.getType(Serializable.class), Type.getType(Serializer.class));

        if (returnClass.isPrimitive()) {

            // ASTORE argumentsSize + 1

            _assertVarInsnNode(iterator.next(), Opcodes.ASTORE, argumentsSize + 1);

            // ALOAD argumentsSize + 1

            _assertVarInsnNode(iterator.next(), Opcodes.ALOAD, argumentsSize + 1);

            // IFNULL nullCheckLabel

            LabelNode nullCheckLabelNode = _assertJumpInsnNode(iterator.next(), Opcodes.IFNULL);

            // ALOAD argumentsSize + 1

            _assertVarInsnNode(iterator.next(), Opcodes.ALOAD, argumentsSize + 1);

            // CHECKCAST returnType

            _assertTypeInsnNode(iterator.next(), Opcodes.CHECKCAST, _autoboxingMap.get(returnClass));

            if (returnClass == boolean.class) {

                // INVOKEVIRTUAL java/lang/Boolean booleanValue ()Z

                _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL,
                        Type.getInternalName(Boolean.class), "booleanValue", Type.BOOLEAN_TYPE);
            } else if (returnClass == byte.class) {

                // INVOKEVIRTUAL java/lang/Number intValue ()I

                _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL,
                        Type.getInternalName(Number.class), "intValue", Type.INT_TYPE);
            } else if (returnClass == char.class) {

                // INVOKEVIRTUAL java/lang/Character charValue ()C

                _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL,
                        Type.getInternalName(Character.class), "charValue", Type.CHAR_TYPE);
            } else if (returnClass == double.class) {

                // INVOKEVIRTUAL java/lang/Number doubleValue ()D

                _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL,
                        Type.getInternalName(Number.class), "doubleValue", Type.DOUBLE_TYPE);
            } else if (returnClass == float.class) {

                // INVOKEVIRTUAL java/lang/Number floatValue ()F

                _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL,
                        Type.getInternalName(Number.class), "floatValue", Type.FLOAT_TYPE);
            } else if (returnClass == int.class) {

                // INVOKEVIRTUAL java/lang/Number intValue ()I

                _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL,
                        Type.getInternalName(Number.class), "intValue", Type.INT_TYPE);
            } else if (returnClass == long.class) {

                // INVOKEVIRTUAL java/lang/Number longValue ()J

                _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL,
                        Type.getInternalName(Number.class), "longValue", Type.LONG_TYPE);
            } else if (returnClass == short.class) {

                // INVOKEVIRTUAL java/lang/Number intValue ()I

                _assertMethodInsnNode(iterator.next(), Opcodes.INVOKEVIRTUAL,
                        Type.getInternalName(Number.class), "intValue", Type.INT_TYPE);
            }

            // xRETURN

            _assertInsnNode(iterator.next(), returnType.getOpcode(Opcodes.IRETURN));

            // nullCheckLabel

            Assert.assertSame(nullCheckLabelNode, iterator.next());

            // xRETURN null/0

            if (!returnClass.isPrimitive()) {
                _assertInsnNode(iterator.next(), Opcodes.ACONST_NULL);
                _assertInsnNode(iterator.next(), Opcodes.ARETURN);
            } else if (returnClass == void.class) {
                _assertInsnNode(iterator.next(), Opcodes.RETURN);
            } else if (returnClass == float.class) {
                _assertInsnNode(iterator.next(), Opcodes.FCONST_0);
                _assertInsnNode(iterator.next(), Opcodes.FRETURN);
            } else if (returnClass == double.class) {
                _assertInsnNode(iterator.next(), Opcodes.DCONST_0);
                _assertInsnNode(iterator.next(), Opcodes.DRETURN);
            } else if (returnClass == long.class) {
                _assertInsnNode(iterator.next(), Opcodes.LCONST_0);
                _assertInsnNode(iterator.next(), Opcodes.LRETURN);
            } else {
                _assertInsnNode(iterator.next(), Opcodes.ICONST_0);
                _assertInsnNode(iterator.next(), Opcodes.IRETURN);
            }
        } else {
            if (returnClass != Object.class) {

                // CHECKCAST

                _assertTypeInsnNode(iterator.next(), Opcodes.CHECKCAST, returnClass);
            }

            // ARETURN

            _assertInsnNode(iterator.next(), Opcodes.ARETURN);
        }
    }

    Assert.assertFalse(iterator.hasNext());
}

From source file:com.lion328.thaifixes.coremod.patcher.GuiNewChatBytecodePatcher.java

License:Open Source License

@Override
public byte[] patchClass(byte[] source) {
    if (ThaiFixesConfiguration.getFontStyle() != ThaiFixesFontStyle.MCPX)
        return source;

    ClassReader classReader = new ClassReader(source);
    ClassNode classNode = new ClassNode();
    classReader.accept(classNode, 0);/*from w w w .  j  ava 2s . co m*/

    for (MethodNode method : classNode.methods) {
        if (method.name.equals(CLASSMAP.getMethod("drawChat")) && method.desc.equals("(I)V")) {
            AbstractInsnNode currentNode = null;
            for (int i = 0; i < method.instructions.size(); i++) {
                currentNode = method.instructions.get(i);
                if (currentNode.getOpcode() == Opcodes.BIPUSH) {
                    if (method.instructions.get(i + 1).getOpcode() == Opcodes.IMUL)
                        method.instructions.set(currentNode,
                                new VarInsnNode(Opcodes.BIPUSH, ThaiFixesFontRenderer.MCPX_CHATBLOCK_HEIGHT));
                    else if (method.instructions.get(i + 1).getOpcode() == Opcodes.ISUB
                            && method.instructions.get(i - 1).getOpcode() == Opcodes.ILOAD) {
                        IntInsnNode node = (IntInsnNode) currentNode;
                        if (node.operand == 9)
                            method.instructions.set(currentNode, new VarInsnNode(Opcodes.BIPUSH,
                                    ThaiFixesFontRenderer.MCPX_CHATBLOCK_HEIGHT));
                        else if (node.operand == 8)
                            method.instructions.set(currentNode, new VarInsnNode(Opcodes.BIPUSH,
                                    ThaiFixesFontRenderer.MCPX_CHATBLOCK_TEXT_YPOS));
                    }
                }
            }
        } else if (method.name.equals(CLASSMAP.getMethod("func_146236_a"))
                && method.desc.equals("(II)L" + ClassMap.getClassMap("net.minecraft.util.IChatComponent")
                        .getClassInfo().getProductionClassName().replace('.', '/') + ";")) {
            for (int i = 0; i < method.instructions.size(); i++) {
                if (method.instructions.get(i).getOpcode() == Opcodes.GETFIELD) {
                    FieldInsnNode node = (FieldInsnNode) method.instructions.get(i);
                    if (node.owner.equals(ClassMap.getClassMap("net.minecraft.client.gui.FontRenderer")
                            .getClassInfo().getProductionClassName().replace('.', '/'))
                            && node.name.equals(ClassMap.getClassMap("net.minecraft.client.gui.FontRenderer")
                                    .getField("FONT_HEIGHT"))) {
                        method.instructions.set(node,
                                new VarInsnNode(Opcodes.BIPUSH, ThaiFixesFontRenderer.MCPX_CHATBLOCK_HEIGHT));
                        method.instructions.remove(method.instructions.get(i - 1)); // GETFIELD Minecraft.mc
                        method.instructions.remove(method.instructions.get(i - 2)); // GETFIELD GuiNewChat.mc
                        method.instructions.remove(method.instructions.get(i - 3)); // ALOAD 0
                    }
                }
            }
        }
    }

    ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    classNode.accept(writer);
    return writer.toByteArray();
}

From source file:com.lodgon.parboiled.transform.AsmUtils.java

License:Open Source License

public static int getLoadingOpcode(Type argType) {
    checkArgNotNull(argType, "argType");
    switch (argType.getSort()) {
    case Type.BOOLEAN:
    case Type.BYTE:
    case Type.CHAR:
    case Type.SHORT:
    case Type.INT:
        return Opcodes.ILOAD;
    case Type.DOUBLE:
        return Opcodes.DLOAD;
    case Type.FLOAT:
        return Opcodes.FLOAD;
    case Type.LONG:
        return Opcodes.LLOAD;
    case Type.OBJECT:
    case Type.ARRAY:
        return Opcodes.ALOAD;
    default://from   w w  w .  ja va 2  s .  co m
        throw new IllegalStateException();
    }
}

From source file:com.lucidtechnics.blackboard.TargetConstructor.java

License:Apache License

private static int getLoadOpcode(String _parameterType) {
    int opCode = 0;
    char typeChar = _parameterType.toCharArray()[0];

    switch (typeChar) {
    case 'Z':
    case 'B':
    case 'C':
    case 'I':
    case 'S':
        opCode = Opcodes.ILOAD;
        break;// ww  w  .j  av  a2s  . c o m

    case 'D':
        opCode = Opcodes.DLOAD;
        break;

    case 'F':
        opCode = Opcodes.FLOAD;
        break;

    case 'J':
        opCode = Opcodes.LLOAD;
        break;

    case 'L':
    case '[':
        opCode = Opcodes.ALOAD;
        break;

    default:
        if (true)
            throw new RuntimeException(
                    "Cannot handle parameter type identified by first character: " + typeChar);
        break;
    }

    return opCode;
}

From source file:com.mebigfatguy.exagent.StackTraceMethodVisitor.java

License:Apache License

@Override
public void visitInsn(int opcode) {

    if (RETURN_CODES.get(opcode)) {
        super.visitVarInsn(Opcodes.ILOAD, depthLocalSlot);
        super.visitMethodInsn(Opcodes.INVOKESTATIC, EXASUPPORT_CLASS_NAME, "popMethodInfo", "(I)V", false);
    } else if (opcode == Opcodes.ATHROW) {

        super.visitVarInsn(Opcodes.ASTORE, exLocalSlot);

        Label tryLabel = new Label();
        Label endTryLabel = new Label();
        Label catchLabel = new Label();
        Label continueLabel = new Label();

        super.visitTryCatchBlock(tryLabel, endTryLabel, catchLabel, EXCEPTION_CLASS_NAME);

        super.visitLabel(tryLabel);

        super.visitVarInsn(Opcodes.ALOAD, exLocalSlot);
        super.visitMethodInsn(Opcodes.INVOKESTATIC, EXASUPPORT_CLASS_NAME, "embellishMessage",
                "(Ljava/lang/Throwable;)V", false);
        super.visitVarInsn(Opcodes.ILOAD, depthLocalSlot);
        super.visitMethodInsn(Opcodes.INVOKESTATIC, EXASUPPORT_CLASS_NAME, "popMethodInfo", "(I)V", false);

        super.visitJumpInsn(Opcodes.GOTO, continueLabel);
        super.visitLabel(endTryLabel);

        super.visitLabel(catchLabel);
        super.visitInsn(Opcodes.POP);

        super.visitLabel(continueLabel);
        super.visitVarInsn(Opcodes.ALOAD, exLocalSlot);
    }/*from  ww  w  . ja  va 2 s  . c o m*/
    super.visitInsn(opcode);
}

From source file:com.mebigfatguy.exagent.StackTraceMethodVisitor.java

License:Apache License

private void injectCallStackPopulation() {

    // ExAgent.METHOD_INFO.get();
    super.visitFieldInsn(Opcodes.GETSTATIC, EXASUPPORT_CLASS_NAME, "METHOD_INFO",
            signaturizeClass(THREADLOCAL_CLASS_NAME));
    super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, THREADLOCAL_CLASS_NAME, "get", "()Ljava/lang/Object;", false);
    super.visitTypeInsn(Opcodes.CHECKCAST, LIST_CLASS_NAME);

    super.visitInsn(Opcodes.DUP);
    super.visitMethodInsn(Opcodes.INVOKEINTERFACE, LIST_CLASS_NAME, "size", "()I", true);
    super.visitVarInsn(Opcodes.ISTORE, depthLocalSlot);

    //new MethodInfo(cls, name, parmMap);
    super.visitTypeInsn(Opcodes.NEW, METHODINFO_CLASS_NAME);
    super.visitInsn(Opcodes.DUP);
    super.visitLdcInsn(clsName.replace('.', '/'));
    super.visitLdcInsn(methodName);

    if (parms.isEmpty()) {
        super.visitMethodInsn(Opcodes.INVOKESTATIC, COLLECTIONS_CLASS_NAME, "emptyList", "()Ljava/util/List;",
                false);//from  w w  w.j av  a 2 s . c  o m
    } else {
        super.visitTypeInsn(Opcodes.NEW, ARRAYLIST_CLASS_NAME);
        super.visitInsn(Opcodes.DUP);
        super.visitIntInsn(Opcodes.BIPUSH, parms.size());
        super.visitMethodInsn(Opcodes.INVOKESPECIAL, ARRAYLIST_CLASS_NAME, CTOR_NAME, "(I)V", false);

        for (Parm parm : parms) {
            super.visitInsn(Opcodes.DUP);

            switch (parm.signature) {

            case "C":
                super.visitVarInsn(Opcodes.ILOAD, parm.register);
                super.visitMethodInsn(Opcodes.INVOKESTATIC, STRING_CLASS_NAME, "valueOf",
                        "(C)Ljava/lang/String;", false);
                break;

            case "Z":
                super.visitVarInsn(Opcodes.ILOAD, parm.register);
                super.visitMethodInsn(Opcodes.INVOKESTATIC, STRING_CLASS_NAME, "valueOf",
                        "(Z)Ljava/lang/String;", false);
                break;

            case "B":
            case "S":
            case "I":
                super.visitVarInsn(Opcodes.ILOAD, parm.register);
                super.visitMethodInsn(Opcodes.INVOKESTATIC, STRING_CLASS_NAME, "valueOf",
                        "(I)Ljava/lang/String;", false);
                break;

            case "J":
                super.visitVarInsn(Opcodes.LLOAD, parm.register);
                super.visitMethodInsn(Opcodes.INVOKESTATIC, STRING_CLASS_NAME, "valueOf",
                        "(J)Ljava/lang/String;", false);
                break;

            case "F":
                super.visitVarInsn(Opcodes.FLOAD, parm.register);
                super.visitMethodInsn(Opcodes.INVOKESTATIC, STRING_CLASS_NAME, "valueOf",
                        "(F)Ljava/lang/String;", false);
                break;

            case "D":
                super.visitVarInsn(Opcodes.DLOAD, parm.register);
                super.visitMethodInsn(Opcodes.INVOKESTATIC, STRING_CLASS_NAME, "valueOf",
                        "(D)Ljava/lang/String;", false);
                break;

            default:
                super.visitVarInsn(Opcodes.ALOAD, parm.register);
                if (parm.signature.startsWith("[")) {
                    char arrayElemTypeChar = parm.signature.charAt(1);
                    if ((arrayElemTypeChar == 'L') || (arrayElemTypeChar == '[')) {
                        super.visitMethodInsn(Opcodes.INVOKESTATIC, ARRAYS_CLASS_NAME, "toString",
                                "([Ljava/lang/Object;)Ljava/lang/String;", false);
                    } else {
                        super.visitMethodInsn(Opcodes.INVOKESTATIC, ARRAYS_CLASS_NAME, "toString",
                                "([" + arrayElemTypeChar + ")Ljava/lang/String;", false);
                    }
                } else {
                    super.visitMethodInsn(Opcodes.INVOKESTATIC, STRING_CLASS_NAME, "valueOf",
                            "(Ljava/lang/Object;)Ljava/lang/String;", false);
                }
                break;
            }

            if (maxParmSize > 0) {
                super.visitInsn(Opcodes.DUP);
                super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, STRING_CLASS_NAME, "length", "()I", false);
                if (maxParmSize <= 127) {
                    super.visitIntInsn(Opcodes.BIPUSH, maxParmSize);
                } else {
                    super.visitLdcInsn(maxParmSize);
                }
                Label falseLabel = new Label();
                super.visitJumpInsn(Opcodes.IF_ICMPLE, falseLabel);
                super.visitIntInsn(Opcodes.BIPUSH, 0);
                super.visitLdcInsn(maxParmSize);
                super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, STRING_CLASS_NAME, "substring",
                        "(II)Ljava/lang/String;", false);
                super.visitLabel(falseLabel);
            }

            super.visitMethodInsn(Opcodes.INVOKEINTERFACE, LIST_CLASS_NAME, "add", "(Ljava/lang/Object;)Z",
                    true);
            super.visitInsn(Opcodes.POP);
        }
    }

    super.visitMethodInsn(Opcodes.INVOKESPECIAL, METHODINFO_CLASS_NAME, CTOR_NAME,
            "(Ljava/lang/String;Ljava/lang/String;Ljava/util/List;)V", false);

    //add(methodInfo);
    super.visitMethodInsn(Opcodes.INVOKEINTERFACE, LIST_CLASS_NAME, "add", "(Ljava/lang/Object;)Z", true);
    super.visitInsn(Opcodes.POP);
}

From source file:com.mebigfatguy.junitflood.jvm.OperandStack.java

License:Apache License

public void performVarInsn(int opcode, int var) {
    switch (opcode) {
    case Opcodes.ILOAD:
    case Opcodes.LLOAD:
    case Opcodes.FLOAD:
    case Opcodes.DLOAD:
    case Opcodes.ALOAD:
        stack.add(registers.get(Integer.valueOf(var)));
        break;//from   w w w  . j  a va 2 s . c  o  m

    case Opcodes.ISTORE:
    case Opcodes.LSTORE:
    case Opcodes.FSTORE:
    case Opcodes.DSTORE:
    case Opcodes.ASTORE:
        registers.put(Integer.valueOf(var), stack.remove(stack.size() - 1));
        break;

    case Opcodes.RET:
        //nop - a fudge
        break;
    }
}

From source file:com.microsoft.applicationinsights.agent.internal.agent.redis.JedisMethodVisitor.java

License:Open Source License

protected void boxVariable(Type argumentType, int argumentIndex) {
    if (argumentType.equals(Type.BOOLEAN_TYPE)) {
        mv.visitVarInsn(Opcodes.ILOAD, argumentIndex);
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;",
                false);/*from w  w  w . j av  a  2s.  c om*/
    } else if (argumentType.equals(Type.BYTE_TYPE)) {
        mv.visitVarInsn(Opcodes.ILOAD, argumentIndex);
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Byte", "valueOf", "(B)Ljava/lang/Byte;", false);
    } else if (argumentType.equals(Type.CHAR_TYPE)) {
        mv.visitVarInsn(Opcodes.ILOAD, argumentIndex);
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Character", "valueOf", "(C)Ljava/lang/Character;",
                false);
    } else if (argumentType.equals(Type.SHORT_TYPE)) {
        mv.visitVarInsn(Opcodes.ILOAD, argumentIndex);
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Short", "valueOf", "(S)Ljava/lang/Short;", false);
    } else if (argumentType.equals(Type.INT_TYPE)) {
        mv.visitVarInsn(Opcodes.ILOAD, argumentIndex);
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;",
                false);
    } else if (argumentType.equals(Type.LONG_TYPE)) {
        mv.visitVarInsn(Opcodes.LLOAD, argumentIndex);
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;", false);
    } else if (argumentType.equals(Type.FLOAT_TYPE)) {
        mv.visitVarInsn(Opcodes.FLOAD, argumentIndex);
        super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Float", "valueOf", "(F)Ljava/lang/Long;",
                false);
    } else if (argumentType.equals(Type.DOUBLE_TYPE)) {
        mv.visitVarInsn(Opcodes.DLOAD, argumentIndex);
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;", false);
    } else {
        mv.visitVarInsn(Opcodes.ALOAD, argumentIndex);
    }
}

From source file:com.mogujie.instantrun.ByteCodeUtils.java

License:Apache License

/**
 * Given an array on the stack, it loads it with the values of the given variables stating at
 * offset./* ww w  . j  a v  a  2 s  .co  m*/
 */
static void loadVariableArray(GeneratorAdapter mv, List<LocalVariable> variables, int offset) {
    // we need to maintain the stack index when loading parameters from, as for long and double
    // values, it uses 2 stack elements, all others use only 1 stack element.
    for (int i = offset; i < variables.size(); i++) {
        LocalVariable variable = variables.get(i);
        // duplicate the array of objects reference, it will be used to store the value in.
        mv.dup();
        // index in the array of objects to store the boxed parameter.
        mv.push(i);
        // Pushes the appropriate local variable on the stack
        mv.visitVarInsn(variable.type.getOpcode(Opcodes.ILOAD), variable.var);
        // potentially box up intrinsic types.
        mv.box(variable.type);
        // store it in the array
        mv.arrayStore(Type.getType(Object.class));
    }
}