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.thomas15v.packetlib.codegenerator.asm.ASMHelper.java

License:MIT License

public static Object getConstant(AbstractInsnNode insn) {
    if (insn == null) {
        return null;
    } else if (insn instanceof LdcInsnNode) {
        return ((LdcInsnNode) insn).cst;
    } else if (insn instanceof IntInsnNode) {
        int value = ((IntInsnNode) insn).operand;
        if (insn.getOpcode() == Opcodes.BIPUSH || insn.getOpcode() == Opcodes.SIPUSH) {
            return Integer.valueOf(value);
        }//  w w w.  ja v a  2  s.co  m
        throw new IllegalArgumentException(
                "IntInsnNode with invalid opcode " + insn.getOpcode() + " in getConstant");
    }

    int index = Ints.indexOf(ASMHelper.CONSTANTS_ALL, insn.getOpcode());
    return index < 0 ? null : ASMHelper.CONSTANTS_VALUES[index];
}

From source file:com.toolazydogs.maiden.agent.asm.AsmUtils.java

License:Apache License

/**
 * Generates the instruction to push the given value on the stack.
 *
 * @param methodVisitor the visitor to which to send the instruction
 * @param value         the value to be pushed on the stack.
 *//*from w  w w  .  ja v a2 s .c om*/
public static void push(MethodVisitor methodVisitor, int value) {
    if (value >= -1 && value <= 5) {
        methodVisitor.visitInsn(Opcodes.ICONST_0 + value);
    } else if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) {
        methodVisitor.visitIntInsn(Opcodes.BIPUSH, value);
    } else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) {
        methodVisitor.visitIntInsn(Opcodes.SIPUSH, value);
    } else {
        methodVisitor.visitLdcInsn(value);
    }
}

From source file:com.toolazydogs.maiden.agent.asm.AsmUtilsTest.java

License:Apache License

@Test
public void testPushInteger() {
    MethodVisitor methodVisitor = mock(MethodVisitor.class);

    AsmUtils.push(methodVisitor, 59);//from  w  w  w.  j  a  v a  2 s.  c om

    verify(methodVisitor).visitIntInsn(Opcodes.BIPUSH, 59);
    verify(methodVisitor, never()).visitIntInsn(Opcodes.SIPUSH, 59);

    AsmUtils.push(methodVisitor, 32760);

    verify(methodVisitor, never()).visitIntInsn(Opcodes.BIPUSH, 32760);
    verify(methodVisitor).visitIntInsn(Opcodes.SIPUSH, 32760);
}

From source file:com.toolazydogs.maiden.agent.asm.WaitNotifyMethodVisitor.java

License:Apache License

public void visitIntInsn(int opcode, int operand) {
    LOGGER.entering(CLASS_NAME, "visitInsn", new Object[] { opcode, operand });

    if (state == State.FOUND_MILLISECONDS && (opcode == Opcodes.BIPUSH || opcode == Opcodes.SIPUSH)) {
        nanoseconds = opcode;//  ww  w.  j a  v a 2  s.  c  om
        state = State.FOUND_NANOSECONDS;
    } else {
        flush();
        visitor.visitIntInsn(opcode, operand);
    }

    LOGGER.exiting(CLASS_NAME, "visitIntInsn");
}

From source file:com.trigersoft.jaque.expression.ExpressionMethodVisitor.java

License:Apache License

@Override
public void visitIntInsn(int opcode, int operand) {
    switch (opcode) {
    case Opcodes.BIPUSH:
    case Opcodes.SIPUSH:
        _exprStack.push(Expression.constant(operand, Integer.TYPE));
        break;/*  ww  w .  ja  v a2s. c  o m*/
    default:
        throw notLambda(opcode);
    }
}

From source file:de.fhkoeln.gm.cui.javahardener.CheckNullMethodVisitor.java

License:Open Source License

/**
 * Push the default value to the stack for the given type.
 * /*from w  w w.ja v a  2s.  c  o m*/
 * @param type
 */
private void pushDefault(Type type) {
    switch (type.getSort()) {
    case Type.VOID:
        break;
    case Type.BOOLEAN:
        super.visitIntInsn(Opcodes.BIPUSH, 0); // Push false to the stack
        break;
    case Type.BYTE:
        super.visitIntInsn(Opcodes.BIPUSH, 0); // Push byte 0 to the stack
        break;
    case Type.CHAR:
        super.visitIntInsn(Opcodes.BIPUSH, 0); // Push char 0 to the stack
        break;
    case Type.SHORT:
        super.visitIntInsn(Opcodes.SIPUSH, 0); // Push short 0 to the stack
        break;
    case Type.INT:
        super.visitInsn(Opcodes.ICONST_0); // Push int 0 to the stack
        break;
    case Type.FLOAT:
        super.visitInsn(Opcodes.FCONST_0); // Push float 0 to the stack
        break;
    case Type.LONG:
        super.visitInsn(Opcodes.LCONST_0); // Push long 0 to the stack
        break;
    case Type.DOUBLE:
        super.visitInsn(Opcodes.DCONST_0); // Push double 0 to the stack
        break;
    default:
        super.visitInsn(Opcodes.ACONST_NULL); // Push NULL to the stack
        break;
    }
}

From source file:de.sanandrew.core.manpack.transformer.TransformHorseArmor.java

License:Creative Commons License

private static MethodNode injectMethodGetCustomArmorItem() {
    MethodNode method = ASMHelper.getMethodNode(Opcodes.ACC_PRIVATE, ASMNames.MD_SAP_GET_CUSTOM_ARMOR_ITEM);
    method.visitCode();/* w  w w .  ja  v  a 2 s. co  m*/
    Label l0 = new Label();
    method.visitLabel(l0);
    method.visitVarInsn(Opcodes.ALOAD, 0);
    ASMHelper.visitFieldInsn(method, Opcodes.GETFIELD, ASMNames.FD_HORSE_DATAWATCHER);
    method.visitIntInsn(Opcodes.BIPUSH, 23);
    ASMHelper.visitMethodInsn(method, Opcodes.INVOKEVIRTUAL, ASMNames.MD_DATAWATCHER_GET_OBJ_STACK, false);
    method.visitInsn(Opcodes.ARETURN);
    Label l1 = new Label();
    method.visitLabel(l1);
    method.visitLocalVariable("this", ASMNames.CL_T_ENTITY_HORSE, null, l0, l1, 0);
    method.visitMaxs(2, 1);
    method.visitEnd();

    return method;
}

From source file:de.sanandrew.core.manpack.transformer.TransformHorseArmor.java

License:Creative Commons License

private static MethodNode injectMethodSetCustomArmorItem() {
    MethodNode method = ASMHelper.getMethodNode(Opcodes.ACC_PRIVATE, ASMNames.MD_SAP_SET_CUSTOM_ARMOR_ITEM);
    method.visitCode();//from w w w.  j a  v a  2s . co m
    Label l0 = new Label();
    method.visitLabel(l0);
    method.visitVarInsn(Opcodes.ALOAD, 1);
    Label l1 = new Label();
    method.visitJumpInsn(Opcodes.IFNONNULL, l1);
    method.visitTypeInsn(Opcodes.NEW, ASMNames.CL_ITEM_STACK);
    method.visitInsn(Opcodes.DUP);
    ASMHelper.visitFieldInsn(method, Opcodes.GETSTATIC, ASMNames.FD_ITEMS_IRON_SHOVEL);
    method.visitInsn(Opcodes.ICONST_0);
    ASMHelper.visitMethodInsn(method, Opcodes.INVOKESPECIAL, ASMNames.MD_ITEMSTACK_INIT, false);
    method.visitVarInsn(Opcodes.ASTORE, 1);
    method.visitLabel(l1);
    method.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    method.visitVarInsn(Opcodes.ALOAD, 0);
    ASMHelper.visitFieldInsn(method, Opcodes.GETFIELD, ASMNames.FD_HORSE_DATAWATCHER);
    method.visitIntInsn(Opcodes.BIPUSH, 23);
    method.visitVarInsn(Opcodes.ALOAD, 1);
    ASMHelper.visitMethodInsn(method, Opcodes.INVOKEVIRTUAL, ASMNames.MD_DATAWATCHER_UPDATE_OBJ, false);
    Label l3 = new Label();
    method.visitLabel(l3);
    method.visitInsn(Opcodes.RETURN);
    Label l4 = new Label();
    method.visitLabel(l4);
    method.visitLocalVariable("this", ASMNames.CL_T_ENTITY_HORSE, null, l0, l3, 0);
    method.visitLocalVariable("stack", ASMNames.CL_T_ITEM_STACK, null, l0, l3, 1);
    method.visitMaxs(5, 2);
    method.visitEnd();

    return method;
}

From source file:de.sanandrew.core.manpack.transformer.TransformHorseArmor.java

License:Creative Commons License

private static void transformEntityInit(MethodNode method) {
    InsnList needle = new InsnList();
    needle.add(new VarInsnNode(Opcodes.ALOAD, 0));
    needle.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_HORSE_DATAWATCHER));
    needle.add(new IntInsnNode(Opcodes.BIPUSH, 22));
    needle.add(new InsnNode(Opcodes.ICONST_0));
    needle.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKESTATIC, ASMNames.MD_INTEGER_VALUE_OF, false));
    needle.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_DATAWATCHER_ADD_OBJECT, false));

    AbstractInsnNode pointer = ASMHelper.findLastNodeFromNeedle(method.instructions, needle);

    InsnList newInstr = new InsnList();
    newInstr.add(new LabelNode());
    newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0));
    newInstr.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_HORSE_DATAWATCHER));
    newInstr.add(new IntInsnNode(Opcodes.BIPUSH, 23));
    newInstr.add(new TypeInsnNode(Opcodes.NEW, ASMNames.CL_ITEM_STACK));
    newInstr.add(new InsnNode(Opcodes.DUP));
    newInstr.add(ASMHelper.getFieldInsnNode(Opcodes.GETSTATIC, ASMNames.FD_ITEMS_IRON_SHOVEL));
    newInstr.add(new InsnNode(Opcodes.ICONST_0));
    newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKESPECIAL, ASMNames.MD_ITEMSTACK_INIT, false));
    newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_DATAWATCHER_ADD_OBJECT, false));

    method.instructions.insert(pointer, newInstr);
}

From source file:de.tuberlin.uebb.jbop.optimizer.utils.NodeHelper.java

License:Open Source License

/**
 * Gets the correct push opcode for the number.
 * /*from   ww  w  .ja  v  a  2s.  c o m*/
 * @param newNumber
 *          the new number
 * @return the opcode push
 */
public static int getopcodePush(final int newNumber) {
    if (newNumber >= CONST_LOW_BYTE && newNumber <= CONST_HIGH_BYTE) {
        return Opcodes.BIPUSH;
    }
    return Opcodes.SIPUSH;
}