Example usage for org.objectweb.asm Opcodes DUP

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

Introduction

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

Prototype

int DUP

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

Click Source Link

Usage

From source file:org.evosuite.instrumentation.error.ArrayInstrumentation.java

License:Open Source License

@Override
public void visitIntInsn(int opcode, int operand) {
    if (opcode == Opcodes.NEWARRAY) {
        mv.visitInsn(Opcodes.DUP);
        insertBranch(Opcodes.IFGE, "java/lang/NegativeArraySizeException");
    }/*from w  w w .j a v  a2  s  .c  o  m*/
}

From source file:org.evosuite.instrumentation.error.ArrayInstrumentation.java

License:Open Source License

@Override
public void visitTypeInsn(int opcode, String type) {
    if (opcode == Opcodes.ANEWARRAY) {
        mv.visitInsn(Opcodes.DUP);
        insertBranch(Opcodes.IFGE, "java/lang/NegativeArraySizeException");
    }/*from w  w w.j  a v a  2s .com*/
}

From source file:org.evosuite.instrumentation.error.CastErrorInstrumentation.java

License:Open Source License

@Override
public void visitTypeInsn(int opcode, String type) {

    if (opcode == Opcodes.CHECKCAST) {
        Label origTarget = new Label();
        // Label origTarget = new AnnotatedLabel();
        // origTarget.info = Boolean.FALSE;
        mv.visitInsn(Opcodes.DUP);
        mv.tagBranch();//w  w w.  j a v a 2  s  .  co m
        mv.visitJumpInsn(Opcodes.IFNULL, origTarget);
        mv.visitInsn(Opcodes.DUP);
        mv.visitTypeInsn(Opcodes.INSTANCEOF, type);
        mv.tagBranch();
        mv.visitJumpInsn(Opcodes.IFNE, origTarget);
        mv.visitTypeInsn(Opcodes.NEW, "java/lang/ClassCastException");
        mv.visitInsn(Opcodes.DUP);
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/ClassCastException", "<init>", "()V", false);
        mv.visitInsn(Opcodes.ATHROW);
        mv.visitLabel(origTarget);
        mv.tagBranchExit();
    }
}

From source file:org.evosuite.instrumentation.error.DivisionByZeroInstrumentation.java

License:Open Source License

@Override
public void visitInsn(int opcode) {
    // Check *DIV for divisonbyzero
    if (opcode == Opcodes.IDIV || opcode == Opcodes.IREM) {
        mv.visitInsn(Opcodes.DUP);
        insertBranch(Opcodes.IFNE, "java/lang/ArithmeticException");

    } else if (opcode == Opcodes.LDIV || opcode == Opcodes.LREM) {
        mv.visitInsn(Opcodes.DUP2);// w  w w .  j  a  v a2s .  c  o  m
        mv.visitLdcInsn(0L);
        mv.visitInsn(Opcodes.LCMP);
        insertBranch(Opcodes.IFNE, "java/lang/ArithmeticException");
    }
}

From source file:org.evosuite.instrumentation.error.ErrorBranchInstrumenter.java

License:Open Source License

protected void insertBranch(int opcode, String exception) {
    Label origTarget = new Label();
    mv.tagBranch();//from   ww w .j  av  a2  s .  co m
    mv.visitJumpInsn(opcode, origTarget);
    mv.visitTypeInsn(Opcodes.NEW, exception);
    mv.visitInsn(Opcodes.DUP);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, exception, "<init>", "()V", false);
    mv.visitInsn(Opcodes.ATHROW);
    mv.visitLabel(origTarget);
    mv.tagBranchExit();
}

From source file:org.evosuite.instrumentation.error.ErrorBranchInstrumenter.java

License:Open Source License

protected void insertBranchWithoutTag(int opcode, String exception) {
    Label origTarget = new Label();
    mv.visitJumpInsn(opcode, origTarget);
    mv.visitTypeInsn(Opcodes.NEW, exception);
    mv.visitInsn(Opcodes.DUP);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, exception, "<init>", "()V", false);
    mv.visitInsn(Opcodes.ATHROW);/*from  w w w. j a  va  2s. c  o  m*/
    mv.visitLabel(origTarget);
}

From source file:org.evosuite.instrumentation.error.NullPointerExceptionInstrumentation.java

License:Open Source License

@Override
public void visitFieldInsn(int opcode, String owner, String name, String desc) {
    // If non-static, add a null check

    if (opcode == Opcodes.GETFIELD) {
        mv.visitInsn(Opcodes.DUP);
        insertBranch(Opcodes.IFNONNULL, "java/lang/NullPointerException");

    } else if (opcode == Opcodes.PUTFIELD && !methodName.equals("<init>")) {
        if (Type.getType(desc).getSize() == 2) {
            // 2 words
            // v1 v2 v3
            mv.visitInsn(Opcodes.DUP2_X1);
            // v2 v3 v1 v2 v3

            mv.visitInsn(Opcodes.POP2);//from w w  w  .  ja  v a2  s.  c  om
            // v2 v3 v1

            mv.visitInsn(Opcodes.DUP_X2);
            // v1 v2 v3 v1

        } else {
            // 1 word
            mv.visitInsn(Opcodes.DUP2);
            //mv.visitInsn(Opcodes.SWAP);
            mv.visitInsn(Opcodes.POP);
        }
        insertBranch(Opcodes.IFNONNULL, "java/lang/NullPointerException");
    }
}

From source file:org.evosuite.instrumentation.ExplicitExceptionHandler.java

License:Open Source License

/** {@inheritDoc} */
@Override//from  w w w .ja v a  2 s  .c o m
public void visitInsn(int opcode) {
    if (opcode == Opcodes.ATHROW && !inErrorBranch) {
        super.visitInsn(Opcodes.DUP);
        this.visitLdcInsn(className);
        this.visitLdcInsn(fullMethodName);
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ExecutionTracer.class),
                "exceptionThrown", "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;)V", false);
    }
    super.visitInsn(opcode);
}

From source file:org.evosuite.instrumentation.mutation.DeleteField.java

License:Open Source License

/**
 * <p>// w w w. j  a  v a2s  .c  om
 * getInfectionDistance
 * </p>
 * 
 * @param original
 *            a {@link org.objectweb.asm.tree.FieldInsnNode} object.
 * @param mutant
 *            a {@link org.objectweb.asm.tree.InsnList} object.
 * @return a {@link org.objectweb.asm.tree.InsnList} object.
 */
public InsnList getInfectionDistance(FieldInsnNode original, InsnList mutant) {
    InsnList distance = new InsnList();

    if (original.getOpcode() == Opcodes.GETFIELD)
        distance.add(new InsnNode(Opcodes.DUP)); //make sure to re-load this for GETFIELD

    distance.add(new FieldInsnNode(original.getOpcode(), original.owner, original.name, original.desc));
    Type type = Type.getType(original.desc);

    if (type.getDescriptor().startsWith("L") || type.getDescriptor().startsWith("[")) {
        ReplaceVariable.addReferenceDistanceCheck(distance, type, mutant);
    } else {
        ReplaceVariable.addPrimitiveDistanceCheck(distance, type, mutant);
    }

    return distance;
}

From source file:org.evosuite.instrumentation.mutation.ReplaceComparisonOperator.java

License:Open Source License

/**
 * <p>getInfectionDistance</p>
 *
 * @param opcodeOrig a int.//w  w  w.jav a 2 s  .  c om
 * @param opcodeNew a int.
 * @return a {@link org.objectweb.asm.tree.InsnList} object.
 */
public InsnList getInfectionDistance(int opcodeOrig, int opcodeNew) {
    InsnList distance = new InsnList();
    switch (opcodeOrig) {
    case Opcodes.IF_ICMPEQ:
    case Opcodes.IF_ICMPNE:
    case Opcodes.IF_ICMPLE:
    case Opcodes.IF_ICMPLT:
    case Opcodes.IF_ICMPGE:
    case Opcodes.IF_ICMPGT:
        distance.add(new InsnNode(Opcodes.DUP2));
        distance.add(new LdcInsnNode(opcodeOrig));
        distance.add(new LdcInsnNode(opcodeNew));
        distance.add(new MethodInsnNode(Opcodes.INVOKESTATIC,
                PackageInfo.getNameWithSlash(ReplaceComparisonOperator.class), "getInfectionDistance",
                "(IIII)D", false));
        break;

    case Opcodes.IFEQ:
    case Opcodes.IFNE:
    case Opcodes.IFLE:
    case Opcodes.IFLT:
    case Opcodes.IFGE:
    case Opcodes.IFGT:
        distance.add(new InsnNode(Opcodes.DUP));
        distance.add(new LdcInsnNode(opcodeOrig));
        distance.add(new LdcInsnNode(opcodeNew));
        distance.add(new MethodInsnNode(Opcodes.INVOKESTATIC,
                PackageInfo.getNameWithSlash(ReplaceComparisonOperator.class), "getInfectionDistance", "(III)D",
                false));
        break;

    default:
        distance.add(new LdcInsnNode(0.0));
    }

    return distance;
}