Example usage for org.objectweb.asm Opcodes BIPUSH

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

Introduction

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

Prototype

int BIPUSH

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

Click Source Link

Usage

From source file:com.liferay.portal.upgrade.test.BaseBuildAutoUpgradeTestCase.java

License:Open Source License

private void _initTableColumns(MethodVisitor methodVisitor, Object[][] tableColumns) {

    methodVisitor.visitCode();//from w ww  .j  av  a2s . co m

    methodVisitor.visitInsn(Opcodes.ICONST_0 + tableColumns.length);
    methodVisitor.visitTypeInsn(Opcodes.ANEWARRAY, Type.getDescriptor(Object[].class));
    methodVisitor.visitInsn(Opcodes.DUP);

    for (int i = 0; i < tableColumns.length; i++) {
        Object[] tableColumn = tableColumns[i];

        methodVisitor.visitInsn(Opcodes.ICONST_0 + i);
        methodVisitor.visitInsn(Opcodes.ICONST_2);
        methodVisitor.visitTypeInsn(Opcodes.ANEWARRAY, Type.getInternalName(Object.class));
        methodVisitor.visitInsn(Opcodes.DUP);
        methodVisitor.visitInsn(Opcodes.ICONST_0);
        methodVisitor.visitLdcInsn(tableColumn[0]);
        methodVisitor.visitInsn(Opcodes.AASTORE);
        methodVisitor.visitInsn(Opcodes.DUP);
        methodVisitor.visitInsn(Opcodes.ICONST_1);
        methodVisitor.visitIntInsn(Opcodes.BIPUSH, (Integer) tableColumn[1]);
        methodVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Integer.class), "valueOf",
                Type.getMethodDescriptor(Type.getType(Integer.class), Type.INT_TYPE), false);

        methodVisitor.visitInsn(Opcodes.AASTORE);
        methodVisitor.visitInsn(Opcodes.AASTORE);

        if (i < (tableColumns.length - 1)) {
            methodVisitor.visitInsn(Opcodes.DUP);
        }
    }

    methodVisitor.visitFieldInsn(Opcodes.PUTSTATIC,
            Type.getInternalName(BuildAutoUpgradeTestEntityModelImpl.class), "TABLE_COLUMNS",
            Type.getDescriptor(Object[][].class));
    methodVisitor.visitInsn(Opcodes.RETURN);
    methodVisitor.visitMaxs(0, 0);
    methodVisitor.visitEnd();
}

From source file:com.lion328.thaifixes.coremod.patcher.GuiChatBytecodePatcher.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);//w  w w  .ja  va2 s.  c  o m

    for (MethodNode method : classNode.methods) {
        boolean drawScreenFlag;
        if ((drawScreenFlag = (method.name.equals(CLASSMAP.getMethod("drawScreen"))
                && method.desc.equals("(IIF)V")))
                || (method.name.equals(CLASSMAP.getMethod("initGui")) && method.desc.equals("()V"))) {
            for (int i = 0; i < method.instructions.size(); i++) {
                if ((method.instructions.get(i).getOpcode() == Opcodes.BIPUSH)
                        && (method.instructions.get(i + 1).getOpcode() == Opcodes.ISUB)) {
                    IntInsnNode node = (IntInsnNode) method.instructions.get(i);
                    if (node.operand == (drawScreenFlag ? 14 : 12))
                        method.instructions.set(node,
                                new VarInsnNode(Opcodes.BIPUSH,
                                        (drawScreenFlag ? ThaiFixesFontRenderer.MCPX_CHATBLOCK_HEIGHT + 2
                                                : ThaiFixesFontRenderer.MCPX_CHATBLOCK_TEXT_YPOS + 2)));
                }
            }
        }
    }

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

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);/*w  w  w  .j a  v a2s.  c om*/

    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.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);// w  w w. j  a v a 2s .  co 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 performIntInsn(int opcode, int operand) {
    switch (opcode) {
    case Opcodes.BIPUSH: {
        Operand op = new Operand();
        op.setSignature("B");
        op.setConstant(Byte.valueOf((byte) operand));
        push(op);//from w  w  w  .j av  a2s . c  o  m
    }
        break;

    case Opcodes.SIPUSH: {
        Operand op = new Operand();
        op.setSignature("S");
        op.setConstant(Short.valueOf((short) operand));
        push(op);
    }
        break;

    case Opcodes.NEWARRAY: {
        Operand op = new Operand();
        op.setSignature("[Ljava/lang/Object;");
        push(op);
    }
        break;
    }
}

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

License:Open Source License

protected TempArrayVar createArray(int length) {
    mv.visitIntInsn(Opcodes.BIPUSH, length);
    mv.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/Object");
    mv.visitVarInsn(Opcodes.ASTORE, firstEmptyIndexForLocalVariable);

    return new TempArrayVar(firstEmptyIndexForLocalVariable);
}

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

License:Open Source License

protected void prepareArrayEntry(int arrayIndex, int entryIndex) {
    mv.visitVarInsn(Opcodes.ALOAD, arrayIndex);
    mv.visitIntInsn(Opcodes.BIPUSH, entryIndex);
}

From source file:com.navercorp.pinpoint.profiler.instrument.ASMMethodVariables.java

License:Apache License

void push(InsnList insnList, final int value) {
    if (value >= -1 && value <= 5) {
        insnList.add(new InsnNode(Opcodes.ICONST_0 + value));
    } else if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) {
        insnList.add(new IntInsnNode(Opcodes.BIPUSH, value));
    } else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) {
        insnList.add(new IntInsnNode(Opcodes.SIPUSH, value));
    } else {/*  w  w w  .ja v a2 s.c  om*/
        insnList.add(new LdcInsnNode(value));
    }
}

From source file:com.nway.spring.jdbc.bean.AsmBeanProcessor.java

License:Apache License

private void visitInsn(MethodVisitor mv, int index) {

    switch (index) {
    case 1:/*from  w w w . ja va 2 s.c o m*/
        mv.visitInsn(Opcodes.ICONST_1);
        break;
    case 2:
        mv.visitInsn(Opcodes.ICONST_2);
        break;
    case 3:
        mv.visitInsn(Opcodes.ICONST_3);
        break;
    case 4:
        mv.visitInsn(Opcodes.ICONST_4);
        break;
    case 5:
        mv.visitInsn(Opcodes.ICONST_5);
        break;
    default:
        mv.visitIntInsn(Opcodes.BIPUSH, index);
    }
}

From source file:com.thomas15v.packetlib.codegenerator.asm.ASMHelper.java

License:MIT License

/**
 * Gets an instruction that pushes a integer onto the stack.  The
 * instruction uses the smallest push possible (ICONST_*, BIPUSH, SIPUSH or
 * Integer constant)./* www . j  a v  a  2 s.  c  om*/
 *
 * @param c the integer to push onto the stack
 * @return insn node to insert
 */
public static AbstractInsnNode pushIntConstant(int c) {
    if (c == -1) {
        return new InsnNode(Opcodes.ICONST_M1);
    } else if (c >= 0 && c <= 5) {
        return new InsnNode(ASMHelper.CONSTANTS_INT[c + 1]);
    } else if (c >= Byte.MIN_VALUE && c <= Byte.MAX_VALUE) {
        return new IntInsnNode(Opcodes.BIPUSH, c);
    } else if (c >= Short.MIN_VALUE && c <= Short.MAX_VALUE) {
        return new IntInsnNode(Opcodes.SIPUSH, c);
    } else {
        return new LdcInsnNode(c);
    }
}