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.pitest.mutationtest.engine.gregor.mutators.experimental.extended.UOIMutator1.java

License:Apache License

@Override
public void visitFieldInsn(int opcode, String owner, String name, String desc) {
    // GETFIELD I,F,L,D + B,S
    if ((opcode == Opcodes.GETFIELD)) {
        if (desc.equals("I")) {
            if (this.shouldMutate("Incremented (a++) integer field " + name)) {
                // Assuming we have the reference to [this] on the stack
                mv.visitInsn(Opcodes.DUP); // dup [this]
                mv.visitFieldInsn(opcode, owner, name, desc); // stack = [this] [this.field]
                mv.visitInsn(Opcodes.DUP_X1); // stack = [this.field] [this] [this.field]
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD); // stack = [this.field] [this] [this.field +1]
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }/*  w w w  . j  a v  a  2s  .com*/
        }
        if (desc.equals("F")) {
            if (this.shouldMutate("Incremented (a++) float field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP_X1);
                mv.visitInsn(Opcodes.FCONST_1);
                mv.visitInsn(Opcodes.FADD);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("J")) {
            if (this.shouldMutate("Incremented (a++) long field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP2_X1);
                mv.visitInsn(Opcodes.LCONST_1);
                mv.visitInsn(Opcodes.LADD);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("D")) {
            if (this.shouldMutate("Incremented (a++) double field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP2_X1);
                mv.visitInsn(Opcodes.DCONST_1);
                mv.visitInsn(Opcodes.DADD);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("B")) {
            if (this.shouldMutate("Incremented (a++) byte field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP_X1);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD);
                mv.visitInsn(Opcodes.I2B);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("S")) {
            if (this.shouldMutate("Incremented (a++) short field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP_X1);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD);
                mv.visitInsn(Opcodes.I2S);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
    }

    // GETSTATIC I,F,L,D + B,S
    if (opcode == Opcodes.GETSTATIC) {
        if (desc.equals("I")) {
            if (this.shouldMutate("Incremented (a++) static integer field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("F")) {
            if (this.shouldMutate("Incremented (a++) static float field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP);
                mv.visitInsn(Opcodes.FCONST_1);
                mv.visitInsn(Opcodes.FADD);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("J")) {
            if (this.shouldMutate("Incremented (a++) static long field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP2);
                mv.visitInsn(Opcodes.LCONST_1);
                mv.visitInsn(Opcodes.LADD);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("D")) {
            if (this.shouldMutate("Incremented (a++) static double field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP2);
                mv.visitInsn(Opcodes.DCONST_1);
                mv.visitInsn(Opcodes.DADD);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("B")) {
            if (this.shouldMutate("Incremented (a++) static byte field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD);
                mv.visitInsn(Opcodes.I2B);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("S")) {
            if (this.shouldMutate("Incremented (a++) static short field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD);
                mv.visitInsn(Opcodes.I2S);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
    }
    mv.visitFieldInsn(opcode, owner, name, desc);
}

From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.extended.UOIMutator2.java

License:Apache License

@Override
public void visitVarInsn(int opcode, int var) {
    mv.visitVarInsn(opcode, var);
    switch (opcode) {
    case Opcodes.ILOAD:
        if (this.shouldMutate("Decremented (a--) integer local variable number " + var)) {
            mv.visitIincInsn(var, -1);
        }/*from  w w w  .  j  av  a 2 s  .c  om*/
        break;
    case Opcodes.FLOAD:
        if (this.shouldMutate("Decremented (a--) float local variable number " + var)) {
            mv.visitInsn(Opcodes.DUP);
            mv.visitInsn(Opcodes.FCONST_1);
            mv.visitInsn(Opcodes.FSUB);
            mv.visitVarInsn(Opcodes.FSTORE, var);
        }
        break;
    case Opcodes.LLOAD:
        if (this.shouldMutate("Decremented (a--) long local variable number " + var)) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(Opcodes.LCONST_1);
            mv.visitInsn(Opcodes.LSUB);
            mv.visitVarInsn(Opcodes.LSTORE, var);
        }
        break;
    case Opcodes.DLOAD:
        if (this.shouldMutate("Decremented (a--) double local variable number " + var)) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(Opcodes.DCONST_1);
            mv.visitInsn(Opcodes.DSUB);
            mv.visitVarInsn(Opcodes.DSTORE, var);
        }
        break;
    default:
        break;
    }
}

From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.extended.UOIMutator2.java

License:Apache License

@Override
public void visitFieldInsn(int opcode, String owner, String name, String desc) {
    // GETFIELD I,F,L,D + B,S
    if ((opcode == Opcodes.GETFIELD)) {
        if (desc.equals("I")) {
            if (this.shouldMutate("Decremented (a--) integer field " + name)) {
                // stack  = [this]

                mv.visitInsn(Opcodes.DUP);
                // stack = [this] [this]

                mv.visitFieldInsn(opcode, owner, name, desc);
                // stack = [this] [this.field]

                mv.visitInsn(Opcodes.DUP_X1);
                // stack = [this.field] [this] [this.field]

                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);

                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }//w  ww . j  a va  2 s. c o m
        }
        if (desc.equals("F")) {
            if (this.shouldMutate("Decremented (a--) float field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP_X1);
                mv.visitInsn(Opcodes.FCONST_1);
                mv.visitInsn(Opcodes.FSUB);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("J")) {
            if (this.shouldMutate("Decremented (a--) long field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP2_X1);
                mv.visitInsn(Opcodes.LCONST_1);
                mv.visitInsn(Opcodes.LSUB);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("D")) {
            if (this.shouldMutate("Decremented (a--) double field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP2_X1);
                mv.visitInsn(Opcodes.DCONST_1);
                mv.visitInsn(Opcodes.DSUB);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("B")) {
            if (this.shouldMutate("Decremented (a--) byte field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP_X1);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                mv.visitInsn(Opcodes.I2B);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("S")) {
            if (this.shouldMutate("Decremented (a--) short field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP_X1);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                mv.visitInsn(Opcodes.I2S);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
    }

    // GETSTATIC I,F,L,D + B,S
    if (opcode == Opcodes.GETSTATIC) {
        if (desc.equals("I")) {
            if (this.shouldMutate("Decremented (a--) static integer field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                // stack = [this.sfield]

                mv.visitInsn(Opcodes.DUP);
                // stack = [this.sfield] [this.sfield]

                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                // stack = [this.sfield] [this.sfield -1]

                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("F")) {
            if (this.shouldMutate("Decremented (a--) static float field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP);
                mv.visitInsn(Opcodes.FCONST_1);
                mv.visitInsn(Opcodes.FSUB);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("J")) {
            if (this.shouldMutate("Decremented (a--) static long field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP2);
                mv.visitInsn(Opcodes.LCONST_1);
                mv.visitInsn(Opcodes.LSUB);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("D")) {
            if (this.shouldMutate("Decremented (a--) static double field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP2);
                mv.visitInsn(Opcodes.DCONST_1);
                mv.visitInsn(Opcodes.DSUB);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("B")) {
            if (this.shouldMutate("Decremented (a--) static byte field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                mv.visitInsn(Opcodes.I2B);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("S")) {
            if (this.shouldMutate("Decremented (a--) static short field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DUP);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                mv.visitInsn(Opcodes.I2S);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
    }
    mv.visitFieldInsn(opcode, owner, name, desc);
}

From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.extended.UOIMutator3.java

License:Apache License

@Override
public void visitFieldInsn(int opcode, String owner, String name, String desc) {
    // GETFIELD I,F,L,D + B,S
    if ((opcode == Opcodes.GETFIELD)) {
        if (desc.equals("I")) {
            if (this.shouldMutate("Incremented (++a) integer field " + name)) {
                // stack = [this]

                mv.visitInsn(Opcodes.DUP);
                // stack = [this] [this]

                mv.visitFieldInsn(opcode, owner, name, desc);
                // stack = [this] [this.field]

                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD);
                // stack = [this] [this.field +1]

                mv.visitInsn(Opcodes.DUP_X1);
                // stack = [this.field +1] [this] [this.field +1]

                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }//  www  .  ja  va 2 s.c  o  m
        }
        if (desc.equals("F")) {
            if (this.shouldMutate("Incremented (++a) float field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.FCONST_1);
                mv.visitInsn(Opcodes.FADD);
                mv.visitInsn(Opcodes.DUP_X1);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("J")) {
            if (this.shouldMutate("Incremented (++a) long field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.LCONST_1);
                mv.visitInsn(Opcodes.LADD);
                mv.visitInsn(Opcodes.DUP2_X1);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("D")) {
            if (this.shouldMutate("Incremented (++a) double field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DCONST_1);
                mv.visitInsn(Opcodes.DADD);
                mv.visitInsn(Opcodes.DUP2_X1);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("B")) {
            if (this.shouldMutate("Incremented (++a) byte field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD);
                mv.visitInsn(Opcodes.I2B);
                mv.visitInsn(Opcodes.DUP_X1);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("S")) {
            if (this.shouldMutate("Incremented (++a) short field " + name)) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD);
                mv.visitInsn(Opcodes.I2S);
                mv.visitInsn(Opcodes.DUP_X1);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
    }

    // GETSTATIC I,F,L,D + B,S
    if (opcode == Opcodes.GETSTATIC) {
        if (desc.equals("I")) {
            if (this.shouldMutate("Incremented (++a) static integer field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD);
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("F")) {
            if (this.shouldMutate("Incremented (++a) static float field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.FCONST_1);
                mv.visitInsn(Opcodes.FADD);
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("J")) {
            if (this.shouldMutate("Incremented (++a) static long field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.LCONST_1);
                mv.visitInsn(Opcodes.LADD);
                mv.visitInsn(Opcodes.DUP2);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("D")) {
            if (this.shouldMutate("Incremented (++a) static double field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DCONST_1);
                mv.visitInsn(Opcodes.DADD);
                mv.visitInsn(Opcodes.DUP2);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("B")) {
            if (this.shouldMutate("Incremented (++a) static byte field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD);
                mv.visitInsn(Opcodes.I2B);
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("S")) {
            if (this.shouldMutate("Incremented (++a) static short field " + name)) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.IADD);
                mv.visitInsn(Opcodes.I2S);
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
    }
    mv.visitFieldInsn(opcode, owner, name, desc);
}

From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.extended.UOIMutator4.java

License:Apache License

@Override
public void visitFieldInsn(int opcode, String owner, String name, String desc) {

    // GETFIELD I,F,L,D + B,S
    if ((opcode == Opcodes.GETFIELD)) {
        if (desc.equals("I")) {
            if (this.shouldMutate("Decremented (--a) integer field")) {
                // stack = [this]

                mv.visitInsn(Opcodes.DUP);
                // stack = [this] [this]

                mv.visitFieldInsn(opcode, owner, name, desc);
                // stack = [this] [this.field]

                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                // stack = [this] [this.field -1]

                mv.visitInsn(Opcodes.DUP_X1);
                // stack = [this.field -1] [this] [this.field -1]

                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }/*from   w w w  . j a  va 2 s  .  c o m*/
        }
        if (desc.equals("F")) {
            if (this.shouldMutate("Decremented (--a) float field")) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.FCONST_1);
                mv.visitInsn(Opcodes.FSUB);
                mv.visitInsn(Opcodes.DUP_X1);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("J")) {
            if (this.shouldMutate("Decremented (--a) long field")) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.LCONST_1);
                mv.visitInsn(Opcodes.LSUB);
                mv.visitInsn(Opcodes.DUP2_X1);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("D")) {
            if (this.shouldMutate("Decremented (--a) double field")) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DCONST_1);
                mv.visitInsn(Opcodes.DSUB);
                mv.visitInsn(Opcodes.DUP2_X1);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("B")) {
            if (this.shouldMutate("Decremented (--a) double field")) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                mv.visitInsn(Opcodes.I2B);
                mv.visitInsn(Opcodes.DUP_X1);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
        if (desc.equals("S")) {
            if (this.shouldMutate("Decremented (--a) short field")) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                mv.visitInsn(Opcodes.I2S);
                mv.visitInsn(Opcodes.DUP_X1);
                mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc);
                return;
            }
        }
    }

    // GETSTATIC I,F,L,D + B,S
    if (opcode == Opcodes.GETSTATIC) {
        if (desc.equals("I")) {
            if (this.shouldMutate("Decremented (--a) static integer field")) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("F")) {
            if (this.shouldMutate("Decremented (--a) static float field")) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.FCONST_1);
                mv.visitInsn(Opcodes.FSUB);
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("J")) {
            if (this.shouldMutate("Decremented (--a) static long field")) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.LCONST_1);
                mv.visitInsn(Opcodes.LSUB);
                mv.visitInsn(Opcodes.DUP2);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("D")) {
            if (this.shouldMutate("Decremented (--a) static double field")) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.DCONST_1);
                mv.visitInsn(Opcodes.DSUB);
                mv.visitInsn(Opcodes.DUP2);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("B")) {
            if (this.shouldMutate("Decremented (--a) static byte field")) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                mv.visitInsn(Opcodes.I2B);
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
        if (desc.equals("S")) {
            if (this.shouldMutate("Decremented (--a) static short field")) {
                mv.visitFieldInsn(opcode, owner, name, desc);
                mv.visitInsn(Opcodes.ICONST_1);
                mv.visitInsn(Opcodes.ISUB);
                mv.visitInsn(Opcodes.I2S);
                mv.visitInsn(Opcodes.DUP);
                mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc);
                return;
            }
        }
    }
    mv.visitFieldInsn(opcode, owner, name, desc);
}

From source file:org.pitest.mutationtest.engine.gregor.mutators.ReturnValsMutator.java

License:Apache License

private static ZeroOperandMutation areturnMutation() {
    return new ZeroOperandMutation() {

        public void apply(final int opCode, final MethodVisitor mv) {

            // Strategy translated from jumble BCEL code
            // if result is non-null make it null, otherwise hard case
            // for moment throw runtime exception
            final Label l1 = new Label();
            mv.visitJumpInsn(Opcodes.IFNONNULL, l1);
            mv.visitTypeInsn(Opcodes.NEW, "java/lang/RuntimeException");
            mv.visitInsn(Opcodes.DUP);
            mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/RuntimeException", "<init>", "()V", false);
            mv.visitInsn(Opcodes.ATHROW);
            mv.visitLabel(l1);//from   w  ww  .  ja v  a 2 s .c  o m
            mv.visitInsn(Opcodes.ACONST_NULL);
            mv.visitInsn(Opcodes.ARETURN);
        }

        public String decribe(final int opCode, final MethodInfo methodInfo) {
            return "mutated return of Object value for " + methodInfo.getDescription()
                    + " to ( if (x != null) null else throw new RuntimeException )";
        }

    };
}

From source file:org.pitest.mutationtest.engine.gregor.mutators.ReturnValsMutator.java

License:Apache License

private static ZeroOperandMutation freturnMutation() {
    return new ZeroOperandMutation() {

        public void apply(final int opcode, final MethodVisitor mv) {
            // Strategy translated from jumble BCEL code
            // The following is complicated by the problem of NaNs. By default
            // the new value is -(x + 1), but this doesn't work for NaNs. But
            // for a NaN x != x is true, and we use this to detect them.
            mv.visitInsn(Opcodes.DUP);
            mv.visitInsn(Opcodes.DUP);//  ww  w. j a  v a  2s  .  co m
            mv.visitInsn(Opcodes.FCMPG);
            final Label l1 = new Label();
            mv.visitJumpInsn(Opcodes.IFEQ, l1);
            mv.visitInsn(Opcodes.POP);
            mv.visitInsn(Opcodes.FCONST_0);
            mv.visitLabel(l1);
            mv.visitInsn(Opcodes.FCONST_1);
            mv.visitInsn(Opcodes.FADD);
            mv.visitInsn(Opcodes.FNEG);
            mv.visitInsn(Opcodes.FRETURN);
        }

        public String decribe(final int opCode, final MethodInfo methodInfo) {
            return "replaced return of float value with -(x + 1) for " + methodInfo.getDescription();
        }

    };
}

From source file:org.sonar.java.bytecode.se.BytecodeEGWalkerExecuteTest.java

License:Open Source License

@Test
public void test_dup() throws Exception {
    SymbolicValue sv = new SymbolicValue();
    ProgramState programState = execute(new Instruction(Opcodes.DUP), ProgramState.EMPTY_STATE.stackValue(sv));
    ProgramState.Pop pop = programState.unstackValue(2);
    assertThat(pop.values).containsOnly(sv);
    assertThat(pop.state).isEqualTo(ProgramState.EMPTY_STATE);

    assertThatThrownBy(() -> execute(new Instruction(Opcodes.DUP))).hasMessage("DUP on empty stack");
}

From source file:org.spongepowered.asm.mixin.injection.callback.CallbackInjector.java

License:MIT License

/**
 * Generates a method which throws an error
 * //from  w  ww  .ja v  a 2s  . c o m
 * @param callback callback handle
 * @param errorClass error class to throw
 * @param message message for the error
 * @return generated method
 */
private MethodNode generateErrorMethod(Callback callback, String errorClass, String message) {
    MethodNode method = this.info.addMethod(this.methodNode.access, this.methodNode.name + "$missing",
            callback.getDescriptor());
    method.maxLocals = ASMHelper.getFirstNonArgLocalIndex(Type.getArgumentTypes(callback.getDescriptor()),
            !this.isStatic);
    method.maxStack = 3;
    InsnList insns = method.instructions;
    insns.add(new TypeInsnNode(Opcodes.NEW, errorClass));
    insns.add(new InsnNode(Opcodes.DUP));
    insns.add(new LdcInsnNode(message));
    insns.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, errorClass, "<init>", "(Ljava/lang/String;)V", false));
    insns.add(new InsnNode(Opcodes.ATHROW));
    return method;
}

From source file:org.spongepowered.asm.mixin.injection.callback.CallbackInjector.java

License:MIT License

/**
 * @param callback callback handle//w  w  w .  jav a  2 s .c  om
 */
private void createCallbackInfo(final Callback callback) {
    this.dupReturnValue(callback);

    callback.add(new TypeInsnNode(Opcodes.NEW, callback.target.callbackInfoClass), true, false);
    callback.add(new InsnNode(Opcodes.DUP), true, true);

    this.invokeCallbackInfoCtor(callback);
    callback.add(new VarInsnNode(Opcodes.ASTORE, callback.marshallVar));
}