Example usage for org.objectweb.asm Opcodes IFNE

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

Introduction

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

Prototype

int IFNE

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

Click Source Link

Usage

From source file:org.apache.lucene.expressions.js.XJavascriptCompiler.java

License:Apache License

private void recursiveCompile(Tree current, Type expected) {
    int type = current.getType();
    String text = current.getText();

    switch (type) {
    case XJavascriptParser.AT_CALL:
        Tree identifier = current.getChild(0);
        String call = identifier.getText();
        int arguments = current.getChildCount() - 1;

        Method method = functions.get(call);
        if (method == null) {
            throw new IllegalArgumentException("Unrecognized method call (" + call + ").");
        }/*from w ww.j  a  v  a2 s .  com*/

        int arity = method.getParameterTypes().length;
        if (arguments != arity) {
            throw new IllegalArgumentException("Expected (" + arity + ") arguments for method call (" + call
                    + "), but found (" + arguments + ").");
        }

        for (int argument = 1; argument <= arguments; ++argument) {
            recursiveCompile(current.getChild(argument), Type.DOUBLE_TYPE);
        }

        gen.invokeStatic(Type.getType(method.getDeclaringClass()),
                org.objectweb.asm.commons.Method.getMethod(method));

        gen.cast(Type.DOUBLE_TYPE, expected);
        break;
    case XJavascriptParser.VARIABLE:
        int index;

        // normalize quotes
        text = normalizeQuotes(text);

        if (externalsMap.containsKey(text)) {
            index = externalsMap.get(text);
        } else {
            index = externalsMap.size();
            externalsMap.put(text, index);
        }

        gen.loadArg(1);
        gen.push(index);
        gen.arrayLoad(FUNCTION_VALUES_TYPE);
        gen.loadArg(0);
        gen.invokeVirtual(FUNCTION_VALUES_TYPE, DOUBLE_VAL_METHOD);
        gen.cast(Type.DOUBLE_TYPE, expected);
        break;
    case XJavascriptParser.HEX:
        pushLong(expected, Long.parseLong(text.substring(2), 16));
        break;
    case XJavascriptParser.OCTAL:
        pushLong(expected, Long.parseLong(text.substring(1), 8));
        break;
    case XJavascriptParser.DECIMAL:
        gen.push(Double.parseDouble(text));
        gen.cast(Type.DOUBLE_TYPE, expected);
        break;
    case XJavascriptParser.AT_NEGATE:
        recursiveCompile(current.getChild(0), Type.DOUBLE_TYPE);
        gen.visitInsn(Opcodes.DNEG);
        gen.cast(Type.DOUBLE_TYPE, expected);
        break;
    case XJavascriptParser.AT_ADD:
        pushArith(Opcodes.DADD, current, expected);
        break;
    case XJavascriptParser.AT_SUBTRACT:
        pushArith(Opcodes.DSUB, current, expected);
        break;
    case XJavascriptParser.AT_MULTIPLY:
        pushArith(Opcodes.DMUL, current, expected);
        break;
    case XJavascriptParser.AT_DIVIDE:
        pushArith(Opcodes.DDIV, current, expected);
        break;
    case XJavascriptParser.AT_MODULO:
        pushArith(Opcodes.DREM, current, expected);
        break;
    case XJavascriptParser.AT_BIT_SHL:
        pushShift(Opcodes.LSHL, current, expected);
        break;
    case XJavascriptParser.AT_BIT_SHR:
        pushShift(Opcodes.LSHR, current, expected);
        break;
    case XJavascriptParser.AT_BIT_SHU:
        pushShift(Opcodes.LUSHR, current, expected);
        break;
    case XJavascriptParser.AT_BIT_AND:
        pushBitwise(Opcodes.LAND, current, expected);
        break;
    case XJavascriptParser.AT_BIT_OR:
        pushBitwise(Opcodes.LOR, current, expected);
        break;
    case XJavascriptParser.AT_BIT_XOR:
        pushBitwise(Opcodes.LXOR, current, expected);
        break;
    case XJavascriptParser.AT_BIT_NOT:
        recursiveCompile(current.getChild(0), Type.LONG_TYPE);
        gen.push(-1L);
        gen.visitInsn(Opcodes.LXOR);
        gen.cast(Type.LONG_TYPE, expected);
        break;
    case XJavascriptParser.AT_COMP_EQ:
        pushCond(GeneratorAdapter.EQ, current, expected);
        break;
    case XJavascriptParser.AT_COMP_NEQ:
        pushCond(GeneratorAdapter.NE, current, expected);
        break;
    case XJavascriptParser.AT_COMP_LT:
        pushCond(GeneratorAdapter.LT, current, expected);
        break;
    case XJavascriptParser.AT_COMP_GT:
        pushCond(GeneratorAdapter.GT, current, expected);
        break;
    case XJavascriptParser.AT_COMP_LTE:
        pushCond(GeneratorAdapter.LE, current, expected);
        break;
    case XJavascriptParser.AT_COMP_GTE:
        pushCond(GeneratorAdapter.GE, current, expected);
        break;
    case XJavascriptParser.AT_BOOL_NOT:
        Label labelNotTrue = new Label();
        Label labelNotReturn = new Label();

        recursiveCompile(current.getChild(0), Type.INT_TYPE);
        gen.visitJumpInsn(Opcodes.IFEQ, labelNotTrue);
        pushBoolean(expected, false);
        gen.goTo(labelNotReturn);
        gen.visitLabel(labelNotTrue);
        pushBoolean(expected, true);
        gen.visitLabel(labelNotReturn);
        break;
    case XJavascriptParser.AT_BOOL_AND:
        Label andFalse = new Label();
        Label andEnd = new Label();

        recursiveCompile(current.getChild(0), Type.INT_TYPE);
        gen.visitJumpInsn(Opcodes.IFEQ, andFalse);
        recursiveCompile(current.getChild(1), Type.INT_TYPE);
        gen.visitJumpInsn(Opcodes.IFEQ, andFalse);
        pushBoolean(expected, true);
        gen.goTo(andEnd);
        gen.visitLabel(andFalse);
        pushBoolean(expected, false);
        gen.visitLabel(andEnd);
        break;
    case XJavascriptParser.AT_BOOL_OR:
        Label orTrue = new Label();
        Label orEnd = new Label();

        recursiveCompile(current.getChild(0), Type.INT_TYPE);
        gen.visitJumpInsn(Opcodes.IFNE, orTrue);
        recursiveCompile(current.getChild(1), Type.INT_TYPE);
        gen.visitJumpInsn(Opcodes.IFNE, orTrue);
        pushBoolean(expected, false);
        gen.goTo(orEnd);
        gen.visitLabel(orTrue);
        pushBoolean(expected, true);
        gen.visitLabel(orEnd);
        break;
    case XJavascriptParser.AT_COND_QUE:
        Label condFalse = new Label();
        Label condEnd = new Label();

        recursiveCompile(current.getChild(0), Type.INT_TYPE);
        gen.visitJumpInsn(Opcodes.IFEQ, condFalse);
        recursiveCompile(current.getChild(1), expected);
        gen.goTo(condEnd);
        gen.visitLabel(condFalse);
        recursiveCompile(current.getChild(2), expected);
        gen.visitLabel(condEnd);
        break;
    default:
        throw new IllegalStateException("Unknown operation specified: (" + current.getText() + ").");
    }
}

From source file:org.batoo.jpa.core.impl.instance.Enhancer.java

License:Open Source License

private static void createMethodCheck(final String enhancedClassName, final String descEnhancer,
        final ClassWriter cw) {
    final MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PRIVATE, Enhancer.METHOD_ENHANCED_CHECK,
            Enhancer.makeDescription(Void.TYPE), null, null);
    mv.visitCode();/*from w w  w  .  ja  v a 2 s . c o m*/

    final Label lCheckInternal = new Label();
    final Label lCheckInitialized = new Label();
    final Label lReturn = new Label();
    final Label lFind = new Label();
    final Label lInitialized = new Label();
    final Label lChanged = new Label();
    final Label lOut = new Label();

    // if (!this.__enhanced__$$__internal) { return }
    mv.visitLabel(lCheckInternal);
    mv.visitFrame(Opcodes.F_NEW, 1, new Object[] { enhancedClassName }, 0, new Object[] {});
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_INTERNAL,
            Enhancer.DESCRIPTOR_BOOLEAN);
    mv.visitJumpInsn(Opcodes.IFEQ, lCheckInitialized);
    mv.visitInsn(Opcodes.RETURN);

    // if (!this.__enhanced__$$__initialized) {
    mv.visitLabel(lCheckInitialized);
    mv.visitFrame(Opcodes.F_NEW, 1, new Object[] { enhancedClassName }, 0, new Object[] {});
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_INITIALIZED,
            Enhancer.DESCRIPTOR_BOOLEAN);
    mv.visitJumpInsn(Opcodes.IFNE, lChanged);

    //     if (this.__enhanced_$$__session == null)
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_SESSION,
            Enhancer.DESCRIPTOR_SESSION);
    mv.visitJumpInsn(Opcodes.IFNONNULL, lFind);

    //         throw new PersistenceException("No session to initialize the instance");
    mv.visitTypeInsn(Opcodes.NEW, Enhancer.INTERNAL_PERSISTENCE_EXCEPTION);
    mv.visitInsn(Opcodes.DUP);
    mv.visitLdcInsn("No session to initialize the instance");
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Enhancer.INTERNAL_PERSISTENCE_EXCEPTION,
            Enhancer.CONSTRUCTOR_INIT, Enhancer.makeDescription(Void.TYPE, String.class));
    mv.visitInsn(Opcodes.ATHROW);

    //       this.__enhanced_$$__session.getEntityManager().find(this.__enhanced_$$__type, this.__enhanced__$$__id);
    mv.visitLabel(lFind);
    mv.visitFrame(Opcodes.F_NEW, 1, new Object[] { enhancedClassName }, 0, new Object[] {});
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_SESSION,
            Enhancer.DESCRIPTOR_SESSION);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Enhancer.INTERNAL_SESSION, Enhancer.METHOD_GET_ENTITY_MANAGER,
            Enhancer.makeDescription(EntityManagerImpl.class));
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_TYPE,
            Enhancer.DESCRIPTOR_CLASS);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_ID,
            Enhancer.DESCRIPTOR_OBJECT);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Enhancer.INTERNAL_ENTITY_MANAGER, Enhancer.METHOD_FIND,
            Enhancer.makeDescription(Object.class, Class.class, Object.class));
    mv.visitInsn(Opcodes.POP);

    //   this.__enhanced__$$__initialized = true;
    mv.visitLabel(lInitialized);
    mv.visitFrame(Opcodes.F_NEW, 1, new Object[] { enhancedClassName }, 0, new Object[] {});
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitInsn(Opcodes.ICONST_1);
    mv.visitFieldInsn(Opcodes.PUTFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_INITIALIZED,
            Enhancer.DESCRIPTOR_BOOLEAN);

    // if (this.__enhanced_$$__session != null)
    mv.visitLabel(lChanged);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_SESSION,
            Enhancer.DESCRIPTOR_SESSION);
    mv.visitJumpInsn(Opcodes.IFNULL, lReturn);

    //     this.__enhanced__$$__managedInstance.changed();
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_MANAGED_INSTANCE,
            Enhancer.DESCRIPTOR_MANAGED_INSTANCE);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Enhancer.INTERNAL_MANAGED_INSTANCE, Enhancer.METHOD_CHANGED,
            Enhancer.makeDescription(Void.TYPE));

    // return;
    mv.visitLabel(lReturn);
    mv.visitFrame(Opcodes.F_NEW, 1, new Object[] { enhancedClassName }, 0, new Object[] {});
    mv.visitInsn(Opcodes.RETURN);

    mv.visitLabel(lOut);
    mv.visitLocalVariable(Enhancer.THIS, descEnhancer, null, lCheckInternal, lOut, 0);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
}

From source file:org.decojer.cavaj.readers.asm.ReadMethodVisitor.java

License:Open Source License

@Override
public void visitJumpInsn(final int opcode, final Label label) {
    T t = null;//from  ww  w  .  j  a v a2 s .c  om
    Object oValue = null;

    final int targetPc = getPc(label);

    switch (opcode) {
    /********
     * GOTO *
     ********/
    case Opcodes.GOTO: {
        final GOTO op = new GOTO(this.ops.size(), opcode, this.line);
        add(op);
        op.setTargetPc(targetPc);
        if (targetPc < 0) {
            getUnresolved(label).add(op);
        }
        break;
    }
    /********
     * JCMP *
     ********/
    case Opcodes.IF_ACMPEQ:
        t = T.REF;
        oValue = CmpType.T_EQ;
        // fall through
    case Opcodes.IF_ACMPNE:
        if (t == null) {
            t = T.REF;
            oValue = CmpType.T_NE;
        }
        // fall through
    case Opcodes.IF_ICMPEQ:
        if (t == null) {
            t = T.AINT; // boolean too
            oValue = CmpType.T_EQ;
        }
        // fall through
    case Opcodes.IF_ICMPGE:
        if (t == null) {
            t = T.INT;
            oValue = CmpType.T_GE;
        }
        // fall through
    case Opcodes.IF_ICMPGT:
        if (t == null) {
            t = T.INT;
            oValue = CmpType.T_GT;
        }
        // fall through
    case Opcodes.IF_ICMPLE:
        if (t == null) {
            t = T.INT;
            oValue = CmpType.T_LE;
        }
        // fall through
    case Opcodes.IF_ICMPLT:
        if (t == null) {
            t = T.INT;
            oValue = CmpType.T_LT;
        }
        // fall through
    case Opcodes.IF_ICMPNE:
        if (t == null) {
            t = T.AINT; // boolean too
            oValue = CmpType.T_NE;
        } {
        assert oValue instanceof CmpType;
        final JCMP op = new JCMP(this.ops.size(), opcode, this.line, t, (CmpType) oValue);
        add(op);
        op.setTargetPc(targetPc);
        if (targetPc < 0) {
            getUnresolved(label).add(op);
        }
    }
        break;
    /********
     * JCND *
     ********/
    case Opcodes.IFNULL:
        t = T.REF;
        oValue = CmpType.T_EQ;
        // fall through
    case Opcodes.IFNONNULL:
        if (t == null) {
            t = T.REF;
            oValue = CmpType.T_NE;
        }
        // fall through
    case Opcodes.IFEQ:
        if (t == null) {
            t = T.AINT; // boolean too
            oValue = CmpType.T_EQ;
        }
        // fall through
    case Opcodes.IFGE:
        if (t == null) {
            t = T.INT;
            oValue = CmpType.T_GE;
        }
        // fall through
    case Opcodes.IFGT:
        if (t == null) {
            t = T.INT;
            oValue = CmpType.T_GT;
        }
        // fall through
    case Opcodes.IFLE:
        if (t == null) {
            t = T.INT;
            oValue = CmpType.T_LE;
        }
        // fall through
    case Opcodes.IFLT:
        if (t == null) {
            t = T.INT;
            oValue = CmpType.T_LT;
        }
        // fall through
    case Opcodes.IFNE:
        if (t == null) {
            t = T.AINT; // boolean too
            oValue = CmpType.T_NE;
        } {
        assert oValue instanceof CmpType;
        final JCND op = new JCND(this.ops.size(), opcode, this.line, t, (CmpType) oValue);
        add(op);
        op.setTargetPc(targetPc);
        if (targetPc < 0) {
            getUnresolved(label).add(op);
        }
    }
        break;
    /*******
     * JSR *
     *******/
    case Opcodes.JSR: {
        final JSR op = new JSR(this.ops.size(), opcode, this.line);
        add(op);
        op.setTargetPc(targetPc);
        if (targetPc < 0) {
            getUnresolved(label).add(op);
        }
        break;
    }
    default:
        log.warn(getM() + ": Unknown jump insn opcode '" + opcode + "'!");
    }
}

From source file:org.eclipse.objectteams.otredyn.bytecode.asm.CreateFieldAccessAdapter.java

License:Open Source License

@Override
public boolean transform() {

    InsnList instructions = new InsnList();
    // put accessId on the stack
    instructions.add(new IntInsnNode(Opcodes.ILOAD, firstArgIndex + 1));
    // read or write access
    LabelNode writeAccess = new LabelNode();
    instructions.add(new JumpInsnNode(Opcodes.IFNE, writeAccess));
    // read access
    if (field.isStatic()) {
        // get value of field
        instructions.add(new FieldInsnNode(Opcodes.GETSTATIC, name, field.getName(), field.getSignature()));
    } else {// w  w  w . jav a2  s. c o  m
        // put "this" on the stack
        instructions.add(new IntInsnNode(Opcodes.ALOAD, 0));
        // get value of field
        instructions.add(new FieldInsnNode(Opcodes.GETFIELD, name, field.getName(), field.getSignature()));
    }

    //box value as "Object"
    Type type = Type.getType(field.getSignature());
    instructions.add(AsmTypeHelper.getBoxingInstructionForType(type));
    instructions.add(new InsnNode(Opcodes.ARETURN));

    //write access
    instructions.add(writeAccess);
    //put "args" on the stack 
    instructions.add(new IntInsnNode(Opcodes.ALOAD, firstArgIndex + 2));
    //get the first element of "args"
    instructions.add(new InsnNode(Opcodes.ICONST_0));
    instructions.add(new InsnNode(Opcodes.AALOAD));
    //unbox it
    if (type.getSort() != Type.ARRAY && type.getSort() != Type.OBJECT) {
        String objectType = AsmTypeHelper.getObjectType(type);
        instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, objectType));
        instructions.add(AsmTypeHelper.getUnboxingInstructionForType(type, objectType));
    } else {
        instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, type.getInternalName()));
    }

    if (field.isStatic()) {
        //save value in field
        instructions.add(new FieldInsnNode(Opcodes.PUTSTATIC, name, field.getName(), field.getSignature()));
    } else {
        //put "this" on the stack
        instructions.add(new IntInsnNode(Opcodes.ALOAD, 0));
        instructions.add(new InsnNode(Opcodes.SWAP));
        //save value in field
        instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, name, field.getName(), field.getSignature()));
    }

    //dummy return 
    instructions.add(new InsnNode(Opcodes.ACONST_NULL));
    instructions.add(new InsnNode(Opcodes.ARETURN));

    //add the instructions to a new label in the existing switch
    MethodNode method = getMethod(access);
    addNewLabelToSwitch(method.instructions, instructions, accessId);

    return true;
}

From source file:org.elasticsearch.painless.MethodWriter.java

License:Apache License

public void writeBranch(final Label tru, final Label fals) {
    if (tru != null) {
        visitJumpInsn(Opcodes.IFNE, tru);
    } else if (fals != null) {
        visitJumpInsn(Opcodes.IFEQ, fals);
    }/*from ww  w .jav a  2  s  .  c  om*/
}

From source file:org.elasticsearch.painless.node.EBool.java

License:Apache License

@Override
void write(MethodWriter writer, Globals globals) {
    if (operation == Operation.AND) {
        Label fals = new Label();
        Label end = new Label();

        left.write(writer, globals);/*from   w  w w  .  j a v  a2  s  .c o  m*/
        writer.ifZCmp(Opcodes.IFEQ, fals);
        right.write(writer, globals);
        writer.ifZCmp(Opcodes.IFEQ, fals);

        writer.push(true);
        writer.goTo(end);
        writer.mark(fals);
        writer.push(false);
        writer.mark(end);
    } else if (operation == Operation.OR) {
        Label tru = new Label();
        Label fals = new Label();
        Label end = new Label();

        left.write(writer, globals);
        writer.ifZCmp(Opcodes.IFNE, tru);
        right.write(writer, globals);
        writer.ifZCmp(Opcodes.IFEQ, fals);

        writer.mark(tru);
        writer.push(true);
        writer.goTo(end);
        writer.mark(fals);
        writer.push(false);
        writer.mark(end);
    } else {
        throw createError(new IllegalStateException("Illegal tree structure."));
    }
}

From source file:org.elasticsearch.painless.Writer.java

License:Apache License

void checkWriteBranch(final ParserRuleContext source) {
    final Branch branch = getBranch(source);

    if (branch != null) {
        if (branch.tru != null) {
            execute.visitJumpInsn(Opcodes.IFNE, branch.tru);
        } else if (branch.fals != null) {
            execute.visitJumpInsn(Opcodes.IFEQ, branch.fals);
        }//  w w  w .  j  a  v  a  2s.  co  m
    }
}

From source file:org.elasticsearch.plan.a.Adapter.java

License:Apache License

void checkWriteBranch(final MethodVisitor visitor, final ParserRuleContext source) {
    final Branch branch = getBranch(source);

    if (branch != null) {
        if (branch.tru != null) {
            visitor.visitJumpInsn(Opcodes.IFNE, branch.tru);
        } else if (branch.fals != null) {
            visitor.visitJumpInsn(Opcodes.IFEQ, branch.fals);
        }/*w ww .  ja v a 2  s.c o  m*/
    }
}

From source file:org.evosuite.graphs.cfg.BytecodeInstructionPool.java

License:Open Source License

/**
 * Determine how many bytes the current instruction occupies together with
 * its operands/*from   w  w w . j av a 2s.c  o  m*/
 * 
 * @return
 */
private int getBytecodeIncrement(AbstractInsnNode instructionNode) {
    int opcode = instructionNode.getOpcode();
    switch (opcode) {
    case Opcodes.ALOAD: // index
    case Opcodes.ASTORE: // index
    case Opcodes.DLOAD:
    case Opcodes.DSTORE:
    case Opcodes.FLOAD:
    case Opcodes.FSTORE:
    case Opcodes.ILOAD:
    case Opcodes.ISTORE:
    case Opcodes.LLOAD:
    case Opcodes.LSTORE:
        VarInsnNode varNode = (VarInsnNode) instructionNode;
        if (varNode.var > 3)
            return 1;
        else
            return 0;
    case Opcodes.BIPUSH: // byte
    case Opcodes.NEWARRAY:
    case Opcodes.RET:
        return 1;
    case Opcodes.LDC:
        LdcInsnNode ldcNode = (LdcInsnNode) instructionNode;
        if (ldcNode.cst instanceof Double || ldcNode.cst instanceof Long)
            return 2; // LDC2_W
        else
            return 1;
    case 19: //LDC_W
    case 20: //LDC2_W
        return 2;
    case Opcodes.ANEWARRAY: // indexbyte1, indexbyte2
    case Opcodes.CHECKCAST: // indexbyte1, indexbyte2
    case Opcodes.GETFIELD:
    case Opcodes.GETSTATIC:
    case Opcodes.GOTO:
    case Opcodes.IF_ACMPEQ:
    case Opcodes.IF_ACMPNE:
    case Opcodes.IF_ICMPEQ:
    case Opcodes.IF_ICMPNE:
    case Opcodes.IF_ICMPGE:
    case Opcodes.IF_ICMPGT:
    case Opcodes.IF_ICMPLE:
    case Opcodes.IF_ICMPLT:
    case Opcodes.IFLE:
    case Opcodes.IFLT:
    case Opcodes.IFGE:
    case Opcodes.IFGT:
    case Opcodes.IFNE:
    case Opcodes.IFEQ:
    case Opcodes.IFNONNULL:
    case Opcodes.IFNULL:
    case Opcodes.IINC:
    case Opcodes.INSTANCEOF:
    case Opcodes.INVOKESPECIAL:
    case Opcodes.INVOKESTATIC:
    case Opcodes.INVOKEVIRTUAL:
    case Opcodes.JSR:
    case Opcodes.NEW:
    case Opcodes.PUTFIELD:
    case Opcodes.PUTSTATIC:
    case Opcodes.SIPUSH:
        // case Opcodes.LDC_W
        // case Opcodes.LDC2_W

        return 2;
    case Opcodes.MULTIANEWARRAY:
        return 3;
    case Opcodes.INVOKEDYNAMIC:
    case Opcodes.INVOKEINTERFACE:
        return 4;

    case Opcodes.LOOKUPSWITCH:
    case Opcodes.TABLESWITCH:
        // TODO: Could be more
        return 4;
    // case Opcodes.GOTO_W 
    // case Opcodes.JSR_W
    }
    return 0;
}

From source file:org.evosuite.instrumentation.coverage.BranchInstrumentation.java

License:Open Source License

/**
 * <p>//from   w  w  w .ja  v a2  s .c om
 * getInstrumentation
 * </p>
 *
 * @param instruction
 *            a {@link org.evosuite.graphs.cfg.BytecodeInstruction} object.
 * @return a {@link org.objectweb.asm.tree.InsnList} object.
 */
protected InsnList getInstrumentation(BytecodeInstruction instruction) {
    if (instruction == null)
        throw new IllegalArgumentException("null given");
    if (!instruction.isActualBranch())
        throw new IllegalArgumentException("branch instruction expected");
    if (!BranchPool.getInstance(classLoader).isKnownAsNormalBranchInstruction(instruction))
        throw new IllegalArgumentException(
                "expect given instruction to be known by the BranchPool as a normal branch instruction");

    int opcode = instruction.getASMNode().getOpcode();
    int instructionId = instruction.getInstructionId();
    int branchId = BranchPool.getInstance(classLoader).getActualBranchIdForNormalBranchInstruction(instruction);
    if (branchId < 0)
        throw new IllegalStateException("expect BranchPool to know branchId for all branch instructions");

    InsnList instrumentation = new InsnList();

    switch (opcode) {
    case Opcodes.IFEQ:
    case Opcodes.IFNE:
    case Opcodes.IFLT:
    case Opcodes.IFGE:
    case Opcodes.IFGT:
    case Opcodes.IFLE:
        instrumentation.add(new InsnNode(Opcodes.DUP));
        instrumentation.add(new LdcInsnNode(opcode));
        // instrumentation.add(new LdcInsnNode(id));
        instrumentation.add(new LdcInsnNode(branchId));
        instrumentation.add(new LdcInsnNode(instructionId));
        instrumentation.add(
                new MethodInsnNode(Opcodes.INVOKESTATIC, EXECUTION_TRACER, "passedBranch", "(IIII)V", false));
        logger.debug("Adding passedBranch val=?, opcode=" + opcode + ", branch=" + branchId + ", bytecode_id="
                + instructionId);

        break;
    case Opcodes.IF_ICMPEQ:
    case Opcodes.IF_ICMPNE:
    case Opcodes.IF_ICMPLT:
    case Opcodes.IF_ICMPGE:
    case Opcodes.IF_ICMPGT:
    case Opcodes.IF_ICMPLE:
        instrumentation.add(new InsnNode(Opcodes.DUP2));
        instrumentation.add(new LdcInsnNode(opcode));
        // instrumentation.add(new LdcInsnNode(id));
        instrumentation.add(new LdcInsnNode(branchId));
        instrumentation.add(new LdcInsnNode(instructionId));
        instrumentation.add(
                new MethodInsnNode(Opcodes.INVOKESTATIC, EXECUTION_TRACER, "passedBranch", "(IIIII)V", false));
        break;
    case Opcodes.IF_ACMPEQ:
    case Opcodes.IF_ACMPNE:
        instrumentation.add(new InsnNode(Opcodes.DUP2));
        instrumentation.add(new LdcInsnNode(opcode));
        // instrumentation.add(new LdcInsnNode(id));
        instrumentation.add(new LdcInsnNode(branchId));
        instrumentation.add(new LdcInsnNode(instructionId));
        instrumentation.add(new MethodInsnNode(Opcodes.INVOKESTATIC, EXECUTION_TRACER, "passedBranch",
                "(Ljava/lang/Object;Ljava/lang/Object;III)V", false));
        break;
    case Opcodes.IFNULL:
    case Opcodes.IFNONNULL:
        instrumentation.add(new InsnNode(Opcodes.DUP));
        instrumentation.add(new LdcInsnNode(opcode));
        // instrumentation.add(new LdcInsnNode(id));
        instrumentation.add(new LdcInsnNode(branchId));
        instrumentation.add(new LdcInsnNode(instructionId));
        instrumentation.add(new MethodInsnNode(Opcodes.INVOKESTATIC, EXECUTION_TRACER, "passedBranch",
                "(Ljava/lang/Object;III)V", false));
        break;
    }
    return instrumentation;
}