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.jboss.byteman.agent.adapter.cfg.BBlock.java

License:Open Source License

/**
 * write a string represenattion of this block to the buffer
 * @param buf the buffer to be written to
 * @return//from   w w  w . j a v a  2 s .  co m
 */
void printTo(StringBuffer buf) {
    int blockIdx = this.getBlockIdx();
    buf.append(this.getLabel().getOffset());
    buf.append(": BB ");
    buf.append(blockIdx);
    buf.append("\n");
    FanOut containsFanOut = cfg.getContains(this);
    Iterator<Label> containsIter;
    Label containedLabel;
    int containedPosition;
    if (containsFanOut != null) {
        containsIter = containsFanOut.iterator();
        if (containsIter.hasNext()) {
            containedLabel = containsIter.next();
            containedPosition = cfg.getBlockInstructionIdx(containedLabel);
        } else {
            containedLabel = null;
            containedPosition = -1;
        }
    } else {
        containsIter = null;
        containedLabel = null;
        containedPosition = -1;
    }

    int instructionCount = this.getInstructionCount();
    for (int i = 0; i < instructionCount; i++) {
        // we will never enter this if containedPosition is -1 which safeguards us when containsIter
        // is null or containedLabel is null
        while (containedPosition == i) {
            buf.append(containedLabel.getOffset());
            buf.append(": ");
            buf.append(containedLabel);
            buf.append(" +");
            buf.append(containedPosition);
            if (cfg.tryCatchStart(containedLabel)) {
                List<TryCatchDetails> detailsList = cfg.tryCatchStartDetails(containedLabel);
                int detailsCount = detailsList.size();
                for (int j = 0; j < detailsCount; j++) {
                    TryCatchDetails details = detailsList.get(j);
                    Label handlerLabel = details.getHandler();
                    CodeLocation handlerLocation = cfg.getLocation(handlerLabel);
                    buf.append(" try ");
                    buf.append(details.getType());
                    buf.append(" ");
                    if (handlerLocation != null) {
                        buf.append(handlerLabel.getOffset());
                    } else {
                        buf.append("??");
                    }
                    buf.append(" ");
                    buf.append(handlerLabel);
                }
            }
            if (cfg.tryCatchEnd(containedLabel)) {
                List<TryCatchDetails> detailsList = cfg.tryCatchEndDetails(containedLabel);
                int detailsCount = detailsList.size();
                for (int j = 0; j < detailsCount; j++) {
                    TryCatchDetails details = detailsList.get(j);
                    Label handlerLabel = details.getHandler();
                    CodeLocation handlerLocation = cfg.getLocation(handlerLabel);
                    buf.append(" catch ");
                    buf.append(details.getType());
                    buf.append(" ");
                    if (handlerLocation != null) {
                        buf.append(handlerLabel.getOffset());
                    } else {
                        buf.append("??");
                    }
                    buf.append(" ");
                    buf.append(handlerLabel);
                }
            }
            if (cfg.tryCatchHandlerStart(containedLabel)) {
                List<TryCatchDetails> detailsList = cfg.tryCatchHandlerStartDetails(containedLabel);
                int detailsCount = detailsList.size();
                for (int j = 0; j < detailsCount; j++) {
                    TryCatchDetails details = detailsList.get(j);
                    buf.append(" handle ");
                    buf.append(details.getType());
                    buf.append(" ");
                    buf.append(details.getStart().getOffset());
                    buf.append(" ");
                    buf.append(details.getEnd().getOffset());
                }
            }
            if (cfg.triggerStart(containedLabel)) {
                buf.append(" trigger start");
                TriggerDetails details = cfg.triggerStartDetails(containedLabel);
            }
            if (cfg.triggerEnd(containedLabel)) {
                buf.append(" trigger end");
            }
            buf.append("\n");
            List<CodeLocation> openEnters = cfg.getOpenMonitorEnters(containedLabel);
            if (openEnters != null) {
                int openCount = openEnters.size();
                if (openCount > 0) {
                    buf.append("open monitors: ");
                    for (int j = 0; j < openCount; j++) {
                        CodeLocation l = openEnters.get(j);
                        buf.append(" BB");
                        buf.append(l.getBlock().getBlockIdx());
                        buf.append(".");
                        buf.append(l.getInstructionIdx());
                    }
                    buf.append('\n');
                }
            }
            containedLabel = (containsIter.hasNext() ? containsIter.next() : null);
            containedPosition = (containedLabel != null ? cfg.getBlockInstructionIdx(containedLabel) : -1);
        }
        // buf.append("   ");
        buf.append(blockIdx);
        buf.append(".");
        buf.append(i);
        buf.append(": ");
        int opcode = this.getInstruction(i);
        switch (OpcodesHelper.insnType(opcode)) {
        case OpcodesHelper.INSN_NONE: {
            // print the instruction name
            buf.append(OpcodesHelper.insnName(opcode));
            if (opcode == Opcodes.MONITOREXIT) {
                CodeLocation exit = new CodeLocation(this, i);
                CodeLocation enter = cfg.getPairedEnter(exit);
                // print the corresponding open instruction
                buf.append(" (enter: ");
                buf.append(enter);
                buf.append(")");
            }
            buf.append("\n");
        }
            break;
        case OpcodesHelper.INSN_INT: {
            // just print the instruction name and one integer argument
            int intValue = this.getInstructionArg(i, 0);
            buf.append(OpcodesHelper.insnName(opcode));
            buf.append(" ");
            buf.append(intValue);
            buf.append("\n");
        }
            break;
        case OpcodesHelper.INSN_LDC: {
            // print the instruction and one constant argument
            int nameIdx = this.getInstructionArg(i, 0);
            String name = cfg.getName(nameIdx);
            buf.append(OpcodesHelper.insnName(opcode));
            buf.append(" ");
            buf.append(name);
            buf.append("\n");
        }
            break;
        case OpcodesHelper.INSN_VAR: {
            // print the instruction and the var idx
            int varIdx = this.getInstructionArg(i, 0);
            buf.append(OpcodesHelper.insnName(opcode));
            buf.append(" ");
            buf.append(varIdx);
            buf.append("\n");
        }
            break;
        case OpcodesHelper.INSN_IINC: {
            // print the instruction and the var idx
            int increment = this.getInstructionArg(i, 0);
            buf.append(OpcodesHelper.insnName(opcode));
            buf.append(" ");
            buf.append(increment);
            buf.append("\n");
        }
            break;
        case OpcodesHelper.INSN_JUMP: {
            // note that we may not have generated the code for the jump target yet
            Label targetLabel = this.firstOut();
            CodeLocation targetLocation = cfg.getLocation(targetLabel);
            int targetPos = (targetLocation != null ? targetLabel.getOffset() : -1);
            switch (opcode) {
            case Opcodes.IFEQ:
                buf.append("IFEQ ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.IFNE:
                buf.append("IFNE ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.IFLT:
                buf.append("IFLT ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.IFGE:
                buf.append("IFGE ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.IFGT:
                buf.append("IFGT ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.IFLE:
                buf.append("IFLE ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.IF_ICMPEQ:
                buf.append("IF_ICMPEQ ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.IF_ICMPNE:
                buf.append("IF_ICMPNE ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.IF_ICMPLT:
                buf.append("IF_ICMPLT ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.IF_ICMPGE:
                buf.append("IF_ICMPGE ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.IF_ICMPGT:
                buf.append("IF_ICMPGT ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.IF_ICMPLE:
                buf.append("IF_ICMPLE ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.IF_ACMPEQ:
                buf.append("IF_ACMPEQ ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.IF_ACMPNE:
                buf.append("IF_ACMPNE ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.GOTO:
                buf.append("GOTO ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.JSR:
                buf.append("JSR ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.IFNULL:
                buf.append("IFNULL ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.IFNONNULL:
                buf.append("IFNONNULL ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            }
        }
            break;
        case OpcodesHelper.INSN_TSWITCH: {
            Label targetLabel;
            CodeLocation targetLocation;
            int targetPos;
            // print the instruction followed by the jump table discriminant min and max and then
            // the jump labels
            int min = this.getInstructionArg(i, 0);
            int max = this.getInstructionArg(i, 1);
            int count = (max + 1 - min);
            buf.append(OpcodesHelper.insnName(opcode));
            buf.append(" ");
            buf.append(min);
            buf.append(" ");
            buf.append(max);
            buf.append("\n");
            for (int j = 1; j <= count; j++) {
                // note that we may not have generated the code for the jump target yet
                targetLabel = this.nthOut(j);
                targetLocation = cfg.getLocation(targetLabel);
                targetPos = (targetLocation != null ? targetLabel.getOffset() : -1);
                buf.append("    ");
                buf.append(min + j);
                buf.append(" : ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
            }
            targetLabel = this.firstOut();
            targetLocation = cfg.getLocation(targetLabel);
            targetPos = (targetLocation != null ? targetLabel.getOffset() : -1);
            buf.append("    dflt : ");
            if (targetPos >= 0) {
                buf.append(targetPos);
                buf.append(" BB ");
                buf.append(targetLocation.getBlock().getBlockIdx());
                buf.append(" ");
                buf.append(targetLabel);
            } else {
                buf.append("??  ");
                buf.append(targetLabel);
            }
        }
            break;
        case OpcodesHelper.INSN_LOOKUP: {
            Label targetLabel;
            CodeLocation targetLocation;
            int targetPos;
            // print the instruction followed by each jump table discriminant and label
            int count = this.getInstructionArg(i, 0);
            buf.append(OpcodesHelper.insnName(opcode));
            buf.append("\n");
            for (int j = 1; j <= count; j++) {
                // note that we may not have generated the code for the jump target yet
                targetLabel = this.nthOut(j);
                targetLocation = cfg.getLocation(targetLabel);
                targetPos = (targetLocation != null ? targetLabel.getOffset() : -1);
                buf.append("    ");
                buf.append(this.getInstructionArg(i, j));
                buf.append(" : ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
            }
            targetLabel = this.firstOut();
            targetLocation = cfg.getLocation(targetLabel);
            targetPos = (targetLocation != null ? targetLabel.getOffset() : -1);
            buf.append("    dflt : ");
            if (targetPos >= 0) {
                buf.append(targetPos);
                buf.append(" BB ");
                buf.append(targetLocation.getBlock().getBlockIdx());
                buf.append(" ");
                buf.append(targetLabel);
            } else {
                buf.append("??  ");
                buf.append(targetLabel);
            }
        }
            break;
        case OpcodesHelper.INSN_FIELD:
        case OpcodesHelper.INSN_METHOD: {
            // print the instruction with the owner, name and descriptor
            int idx1 = this.getInstructionArg(i, 0);
            int idx2 = this.getInstructionArg(i, 1);
            int idx3 = this.getInstructionArg(i, 2);
            String owner = cfg.getName(idx1);
            String name = cfg.getName(idx2);
            String desc = cfg.getName(idx3);
            buf.append(OpcodesHelper.insnName(opcode));
            buf.append(" ");
            buf.append(owner);
            buf.append(" ");
            buf.append(name);
            buf.append(" ");
            buf.append(desc);
            buf.append("\n");
        }
            break;
        case OpcodesHelper.INSN_TYPE: {
            // print the instruction with the type name
            int idx = this.getInstructionArg(i, 0);
            String name = cfg.getName(idx);
            buf.append(OpcodesHelper.insnName(opcode));
            buf.append(" ");
            buf.append(name);
            buf.append("\n");
        }
            break;
        case OpcodesHelper.INSN_MULTIANEWARRAY: {
            // print the instruction with the typename and the dimension count
            int idx = this.getInstructionArg(i, 0);
            int dims = this.getInstructionArg(i, 1);
            String name = cfg.getName(idx);
            buf.append(OpcodesHelper.insnName(opcode));
            buf.append(" ");
            buf.append(name);
            buf.append(" ");
            buf.append(dims);
            buf.append("\n");
        }
            break;
        case OpcodesHelper.INSN_UNUSED: {
            // print the instruction
            buf.append(OpcodesHelper.insnName(opcode));
            buf.append("!!!\n");
        }
            break;
        }
    }
    // print the active starts for this block
    if (activeTryStarts != null) {
        Iterator<TryCatchDetails> activeStartsIter = activeTryStarts.iterator();
        while (activeStartsIter.hasNext()) {
            TryCatchDetails details = activeStartsIter.next();
            Label label = details.getStart();
            BBlock block = cfg.getBlock(label);
            buf.append("try: ");
            if (block != null) {
                buf.append(label.getOffset());
                buf.append(" ");
                buf.append(block.getBlockIdx());
                buf.append(".");
                buf.append(cfg.getBlockInstructionIdx(label));
            } else {
                buf.append(label);
            }
            buf.append(" catch: ");
            label = details.getEnd();
            block = cfg.getBlock(label);
            if (block != null) {
                buf.append(label.getOffset());
                buf.append(" ");
                buf.append(block.getBlockIdx());
                buf.append(".");
                buf.append(cfg.getBlockInstructionIdx(label));
            } else {
                buf.append(label);
            }
            buf.append(" handle: ");
            label = details.getHandler();
            block = cfg.getBlock(label);
            if (block != null) {
                buf.append(label.getOffset());
                buf.append(" ");
                buf.append(block.getBlockIdx());
                buf.append(".");
                buf.append(cfg.getBlockInstructionIdx(label));
            } else {
                buf.append(label);
            }
            buf.append(" ");
            buf.append(details.getType());
            buf.append("\n");
        }
    }
}

From source file:org.jboss.byteman.agent.adapter.RuleTriggerMethodAdapter.java

License:Open Source License

@Override
public void visitJumpInsn(int opcode, Label label) {
    super.visitJumpInsn(opcode, label);
    switch (opcode) {
    case Opcodes.IFEQ:
    case Opcodes.IFNE:
    case Opcodes.IFLT:
    case Opcodes.IFGE:
    case Opcodes.IFGT:
    case Opcodes.IFLE:
    case Opcodes.IF_ICMPEQ:
    case Opcodes.IF_ICMPNE:
    case Opcodes.IF_ICMPLT:
    case Opcodes.IF_ICMPGE:
    case Opcodes.IF_ICMPGT:
    case Opcodes.IF_ICMPLE:
    case Opcodes.IF_ACMPEQ:
    case Opcodes.IF_ACMPNE: {
        // create a new current block and add the label supplied in the call as the
        // first out of the old current block and the label of the new current block as
        // the second out
        cfg.add(opcode);/*from   w ww  . j a va 2  s . c  o m*/
        Label newStart = super.newLabel();
        // must call split before visiting the label
        cfg.split(newStart, label, newStart);
        visitLabel(newStart);
    }
        break;
    case Opcodes.GOTO: {
        // create a new current block and  add the label supplied in the call as the
        // first out of the old current block
        cfg.add(opcode);
        Label newStart = super.newLabel();
        // must call split before visiting the label
        cfg.split(newStart, label);
        visitLabel(newStart);
    }
        break;
    case Opcodes.JSR: {
        // create a new current block and add the label supplied in the call as the first out
        // of the current block -- the new current block is a potential return point from the
        // JSR but we cannot represent that statically
        cfg.add(opcode);
        Label newStart = super.newLabel();
        // must call split before visiting the label
        cfg.split(newStart, label, newStart);
        visitLabel(newStart);
    }
        break;
    case Opcodes.IFNULL:
    case Opcodes.IFNONNULL: {
        // create a new current block and add the label supplied in the call as the
        // first out of the old current block and the label of the new current block as
        // the second out
        cfg.add(opcode);
        Label newStart = super.newLabel();
        // must call split before visiting the label
        cfg.split(newStart, label, newStart);
        visitLabel(newStart);
    }
        break;
    }
}

From source file:org.jboss.byteman.rule.expression.ComparisonExpression.java

License:Open Source License

public void compile(MethodVisitor mv, CompileContext compileContext) throws CompileException {
    // make sure we are at the right source line
    compileContext.notifySourceLine(line);

    Expression oper0 = getOperand(0);
    Expression oper1 = getOperand(1);

    int removed = 0;

    // evaluate the operands and ensure the reuslt is of the correct type for comparison adds 2
    oper0.compile(mv, compileContext);//from w  ww .j av  a 2s . c o  m
    compileTypeConversion(oper0.getType(), comparisonType, mv, compileContext);
    oper1.compile(mv, compileContext);
    compileTypeConversion(oper1.getType(), comparisonType, mv, compileContext);

    // now do the appropriate type of comparison
    if (comparisonType == type.B || comparisonType == type.S || comparisonType == type.S
            || comparisonType == type.I) {
        Label elsetarget = new Label();
        Label endtarget = new Label();
        // we remove 2 words from the stack and then add 1 back
        removed = 2;
        switch (oper) {
        case LT:
            mv.visitJumpInsn(Opcodes.IF_ICMPGE, elsetarget);
            mv.visitLdcInsn(true);
            mv.visitJumpInsn(Opcodes.GOTO, endtarget);
            mv.visitLabel(elsetarget);
            mv.visitLdcInsn(false);
            mv.visitLabel(endtarget);
            break;
        case LE:
            mv.visitJumpInsn(Opcodes.IF_ICMPGT, elsetarget);
            mv.visitLdcInsn(true);
            mv.visitJumpInsn(Opcodes.GOTO, endtarget);
            mv.visitLabel(elsetarget);
            mv.visitLdcInsn(false);
            mv.visitLabel(endtarget);
            break;
        case GT:
            mv.visitJumpInsn(Opcodes.IF_ICMPLE, elsetarget);
            mv.visitLdcInsn(true);
            mv.visitJumpInsn(Opcodes.GOTO, endtarget);
            mv.visitLabel(elsetarget);
            mv.visitLdcInsn(false);
            mv.visitLabel(endtarget);
            break;
        case GE:
            mv.visitJumpInsn(Opcodes.IF_ICMPLT, elsetarget);
            mv.visitLdcInsn(true);
            mv.visitJumpInsn(Opcodes.GOTO, endtarget);
            mv.visitLabel(elsetarget);
            mv.visitLdcInsn(false);
            mv.visitLabel(endtarget);
            break;
        case EQ:
            mv.visitJumpInsn(Opcodes.IF_ICMPNE, elsetarget);
            mv.visitLdcInsn(true);
            mv.visitJumpInsn(Opcodes.GOTO, endtarget);
            mv.visitLabel(elsetarget);
            mv.visitLdcInsn(false);
            mv.visitLabel(endtarget);
            break;
        case NE:
            mv.visitJumpInsn(Opcodes.IF_ICMPEQ, elsetarget);
            mv.visitLdcInsn(true);
            mv.visitJumpInsn(Opcodes.GOTO, endtarget);
            mv.visitLabel(elsetarget);
            mv.visitLdcInsn(false);
            mv.visitLabel(endtarget);
            break;
        }
    } else if (comparisonType == type.J || comparisonType == type.F || comparisonType == type.D) {
        if (comparisonType == type.J) {
            mv.visitInsn(Opcodes.LCMP);
            // we remove four words from the stack and add 1 back
            removed = 4;
        } else if (comparisonType == type.F) {
            // we remove two words from the stack and add 1 back
            removed = 2;
            mv.visitInsn(Opcodes.FCMPG);
        } else if (comparisonType == type.D) {
            // we remove four words from the stack and add 1 back
            removed = 4;
            mv.visitInsn(Opcodes.DCMPG);
        }
        Label elsetarget = new Label();
        Label endtarget = new Label();
        switch (oper) {
        case LT:
            mv.visitJumpInsn(Opcodes.IFGE, elsetarget);
            mv.visitLdcInsn(true);
            mv.visitJumpInsn(Opcodes.GOTO, endtarget);
            mv.visitLabel(elsetarget);
            mv.visitLdcInsn(false);
            mv.visitLabel(endtarget);
            break;
        case LE:
            mv.visitJumpInsn(Opcodes.IFGT, elsetarget);
            mv.visitLdcInsn(true);
            mv.visitJumpInsn(Opcodes.GOTO, endtarget);
            mv.visitLabel(elsetarget);
            mv.visitLdcInsn(false);
            mv.visitLabel(endtarget);
            break;
        case GT:
            mv.visitJumpInsn(Opcodes.IFLE, elsetarget);
            mv.visitLdcInsn(true);
            mv.visitJumpInsn(Opcodes.GOTO, endtarget);
            mv.visitLabel(elsetarget);
            mv.visitLdcInsn(false);
            mv.visitLabel(endtarget);
            break;
        case GE:
            mv.visitJumpInsn(Opcodes.IFLT, elsetarget);
            mv.visitLdcInsn(true);
            mv.visitJumpInsn(Opcodes.GOTO, endtarget);
            mv.visitLabel(elsetarget);
            mv.visitLdcInsn(false);
            mv.visitLabel(endtarget);
            break;
        case EQ:
            mv.visitJumpInsn(Opcodes.IFNE, elsetarget);
            mv.visitLdcInsn(true);
            mv.visitJumpInsn(Opcodes.GOTO, endtarget);
            mv.visitLabel(elsetarget);
            mv.visitLdcInsn(false);
            mv.visitLabel(endtarget);
            break;
        case NE:
            mv.visitJumpInsn(Opcodes.IFEQ, elsetarget);
            mv.visitLdcInsn(true);
            mv.visitJumpInsn(Opcodes.GOTO, endtarget);
            mv.visitLabel(elsetarget);
            mv.visitLdcInsn(false);
            mv.visitLabel(endtarget);
            break;
        }
    } else if (comparable) {
        // we add a further two words setting up the relevant test then remove them
        // and also remove the original two words replacing them with a single word
        removed = 4;
        compileContext.addStackCount(2);
        // we need to deal with null values correctly
        // if op1 == null || op2 == null
        // then
        //   EQ:
        //   push value1 == value2
        //   NE:
        //   push value1 != value2
        //   ow:
        //   push false
        // else
        //   execute compareTo or equals and test for the desired outcome
        // end if
        Label splittarget = new Label(); // else
        Label jointarget = new Label(); // end if
        mv.visitInsn(Opcodes.DUP2); // [... op1, op2 ] ==> [... op1, op2, op1,  op2]
        mv.visitInsn(Opcodes.POP); // [... op1, op2, op1, op2 ] ==> [... op1, op2, op1]
        // if op1 == null
        mv.visitJumpInsn(Opcodes.IFNULL, splittarget); // [... op1, op2, op1] ==> [... op1, op2]
        mv.visitInsn(Opcodes.DUP); // [... op1, op2 ] ==> [... op1, op2, op2]
        // || op2 == null
        mv.visitJumpInsn(Opcodes.IFNULL, splittarget); // [... op1, op2, op2] ==> [... op1, op2]
        // so, it is ok to call compareTo leaving an int or equals leaving a boolean
        if (oper != EQ && oper != NE) {
            mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/lang/Comparable", "compareTo",
                    "(Ljava/lang/Object;)I");
        } else {
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "equals", "(Ljava/lang/Object;)Z");
        }
        // now if we did a compareTo we need to generate the required boolean
        Label elsetarget = new Label();
        Label endtarget = new Label();
        // if needed the convert the compareTo result to the required boolean outcome
        switch (oper) {
        case LT:
            mv.visitJumpInsn(Opcodes.IFGE, elsetarget);
            mv.visitLdcInsn(true);
            mv.visitJumpInsn(Opcodes.GOTO, endtarget);
            mv.visitLabel(elsetarget);
            mv.visitLdcInsn(false);
            mv.visitLabel(endtarget);
            break;
        case LE:
            mv.visitJumpInsn(Opcodes.IFGT, elsetarget);
            mv.visitLdcInsn(true);
            mv.visitJumpInsn(Opcodes.GOTO, endtarget);
            mv.visitLabel(elsetarget);
            mv.visitLdcInsn(false);
            mv.visitLabel(endtarget);
            break;
        case GT:
            mv.visitJumpInsn(Opcodes.IFLE, elsetarget);
            mv.visitLdcInsn(true);
            mv.visitJumpInsn(Opcodes.GOTO, endtarget);
            mv.visitLabel(elsetarget);
            mv.visitLdcInsn(false);
            mv.visitLabel(endtarget);
            break;
        case GE:
            mv.visitJumpInsn(Opcodes.IFLT, elsetarget);
            mv.visitLdcInsn(true);
            mv.visitJumpInsn(Opcodes.GOTO, endtarget);
            mv.visitLabel(elsetarget);
            mv.visitLdcInsn(false);
            mv.visitLabel(endtarget);
            break;
        case NE:
            mv.visitJumpInsn(Opcodes.IFEQ, elsetarget);
            mv.visitLdcInsn(false);
            mv.visitJumpInsn(Opcodes.GOTO, endtarget);
            mv.visitLabel(elsetarget);
            mv.visitLdcInsn(true);
            mv.visitLabel(endtarget);
            break;
        }
        // skip to the join point
        mv.visitJumpInsn(Opcodes.GOTO, jointarget);
        // label the split point
        mv.visitLabel(splittarget);
        if (oper == EQ) {
            elsetarget = new Label();
            endtarget = new Label();
            mv.visitJumpInsn(Opcodes.IF_ACMPEQ, elsetarget);
            mv.visitLdcInsn(false);
            mv.visitJumpInsn(Opcodes.GOTO, endtarget);
            mv.visitLabel(elsetarget);
            mv.visitLdcInsn(true);
            mv.visitLabel(endtarget);
        } else if (oper == NE) {
            elsetarget = new Label();
            endtarget = new Label();
            mv.visitJumpInsn(Opcodes.IF_ACMPNE, elsetarget);
            mv.visitLdcInsn(false);
            mv.visitJumpInsn(Opcodes.GOTO, endtarget);
            mv.visitLabel(elsetarget);
            mv.visitLdcInsn(true);
            mv.visitLabel(endtarget);
        } else {
            // pop the operands and stack false
            mv.visitInsn(Opcodes.POP2);
            mv.visitLdcInsn(false);
        }
        // label the join point
        mv.visitLabel(jointarget);
    } else if (comparisonType == Type.Z) {
        // unboxed booleans need special treatment
        // we remove two words replacing them with a single word
        removed = 2;
        Label elsetarget = new Label();
        Label endtarget = new Label();
        mv.visitJumpInsn(Opcodes.IFEQ, elsetarget);
        // on this branch for EQ the stacked value is what we need and for NE
        // the stacked value needs flipping
        if (oper == NE) {
            Label elsetarget2 = new Label();
            mv.visitJumpInsn(Opcodes.IFEQ, elsetarget2);
            mv.visitLdcInsn(false);
            mv.visitJumpInsn(Opcodes.GOTO, endtarget);
            mv.visitLabel(elsetarget2);
            mv.visitLdcInsn(true);
        }
        mv.visitJumpInsn(Opcodes.GOTO, endtarget);
        mv.visitLabel(elsetarget);
        // on this branch for NE the stacked value is what we need and for EQ
        // the stacked value needs flipping
        if (oper == EQ) {
            Label elsetarget2 = new Label();
            mv.visitJumpInsn(Opcodes.IFEQ, elsetarget2);
            mv.visitLdcInsn(false);
            mv.visitJumpInsn(Opcodes.GOTO, endtarget);
            mv.visitLabel(elsetarget2);
            mv.visitLdcInsn(true);
        }
        mv.visitLabel(endtarget);

    } else if (comparisonType == Type.BOOLEAN) {
        // boxed booleans need special treatment
        // we remove two words replacing them with a single word
        removed = 2;
        Label elsetarget = new Label();
        Label endtarget = new Label();
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java.lang.Boolean", "equals", "(Ljava/lang/Boolean;)Z");
        if (oper == NE) {
            mv.visitJumpInsn(Opcodes.IFEQ, elsetarget);
            mv.visitLdcInsn(true);
            mv.visitJumpInsn(Opcodes.GOTO, endtarget);
            mv.visitLabel(elsetarget);
            mv.visitLdcInsn(false);
            mv.visitLabel(endtarget);
        }
    } else {
        // we remove two words replacing them with a single word
        removed = 2;
        Label elsetarget = new Label();
        Label endtarget = new Label();
        if (oper == EQ) {
            mv.visitJumpInsn(Opcodes.IF_ACMPNE, elsetarget);
            mv.visitLdcInsn(true);
            mv.visitJumpInsn(Opcodes.GOTO, endtarget);
            mv.visitLabel(elsetarget);
            mv.visitLdcInsn(false);
            mv.visitLabel(endtarget);
        } else {
            mv.visitJumpInsn(Opcodes.IF_ACMPEQ, elsetarget);
            mv.visitLdcInsn(true);
            mv.visitJumpInsn(Opcodes.GOTO, endtarget);
            mv.visitLabel(elsetarget);
            mv.visitLdcInsn(false);
            mv.visitLabel(endtarget);
        }
    }
    compileContext.addStackCount(1 - removed);
}

From source file:org.jboss.byteman.rule.expression.LogicalExpression.java

License:Open Source License

public void compile(MethodVisitor mv, CompileContext compileContext) throws CompileException {
    // make sure we are at the right source line
    compileContext.notifySourceLine(line);

    Expression oper0 = getOperand(0);
    Expression oper1 = getOperand(1);

    int currentStack = compileContext.getStackCount();

    // compile the first expression and make sure it is a boolean -- adds 1 to stack height
    oper0.compile(mv, compileContext);/*from www  .  j ava  2  s.  com*/
    if (oper0.getType() == Type.BOOLEAN) {
        compileBooleanConversion(Type.BOOLEAN, type.Z, mv, compileContext);
    }
    // plant a test and branch
    Label nextLabel = new Label();
    Label endLabel = new Label();
    if (oper == AND) {
        // only try next if we got true here
        mv.visitJumpInsn(Opcodes.IFNE, nextLabel);
        // ok, the first branch was false so stack a false for the result and skip to the end
        mv.visitLdcInsn(false);
        mv.visitJumpInsn(Opcodes.GOTO, endLabel);
    } else {
        // only try next if we got false here
        mv.visitJumpInsn(Opcodes.IFEQ, nextLabel);
        // ok, the first branch was true so stack a true for the result and skip to the end
        mv.visitLdcInsn(true);
        mv.visitJumpInsn(Opcodes.GOTO, endLabel);
    }
    // in either case if we get here the if test removed 1 from the stack
    compileContext.addStackCount(-1);
    // the else branch -- adds 1 to stack height
    mv.visitLabel(nextLabel);
    oper1.compile(mv, compileContext);
    if (oper0.getType() == Type.BOOLEAN) {
        compileBooleanConversion(Type.BOOLEAN, type.Z, mv, compileContext);
    }
    // the final result is the result of the second oper which is on the stack already
    // This is the end, my beau-tiful friend
    mv.visitLabel(endLabel);
    // in either case if we get here we should have one extra value on the stack
    // check stack height
    if (compileContext.getStackCount() != currentStack + 1) {
        throw new CompileException("LogicalExpression.compile : invalid stack height "
                + compileContext.getStackCount() + " expecting " + (currentStack + 1));
    }
}

From source file:org.kantega.dogmaticmvc.mutation.MutationMethodVisitor.java

License:Apache License

private int getMutatedJumpInsn(int i) {
    switch (i) {//from www.j a v a 2 s .c o  m
    case Opcodes.IFEQ:
        return Opcodes.IFNE;
    case Opcodes.IFNE:
        return Opcodes.IFEQ;
    case Opcodes.IFLT:
        return Opcodes.IFGE;
    case Opcodes.IFGE:
        return Opcodes.IFLT;
    case Opcodes.IFGT:
        return Opcodes.IFLE;
    case Opcodes.IFLE:
        return Opcodes.IFGT;
    case Opcodes.IF_ICMPEQ:
        return Opcodes.IF_ICMPNE;
    case Opcodes.IF_ICMPNE:
        return Opcodes.IF_ICMPEQ;
    case Opcodes.IF_ICMPLT:
        return Opcodes.IF_ICMPGE;
    case Opcodes.IF_ICMPGE:
        return Opcodes.IF_ICMPLT;
    case Opcodes.IF_ICMPGT:
        return Opcodes.IF_ICMPLE;
    case Opcodes.IF_ICMPLE:
        return Opcodes.IF_ICMPGT;
    case Opcodes.IF_ACMPEQ:
        return Opcodes.IF_ACMPNE;
    case Opcodes.IF_ACMPNE:
        return Opcodes.IF_ACMPEQ;
    case Opcodes.IFNULL:
        return Opcodes.IFNONNULL;
    case Opcodes.IFNONNULL:
        return Opcodes.IFNULL;

    default:
        return i;
    }
}

From source file:org.lambdamatic.analyzer.ast.LambdaExpressionReader.java

License:Open Source License

/**
 * Extracts the comparison {@link CompoundExpressionOperator} from the given {@link JumpInsnNode}.
 * /*from www . ja v a 2  s  . c  o  m*/
 * @param currentInstruction the comparison instruction
 * @return the corresponding {@link CompoundExpressionOperator}
 */
private static CompoundExpressionOperator extractComparisonOperator(final AbstractInsnNode currentInstruction) {
    switch (currentInstruction.getOpcode()) {
    case Opcodes.IF_ACMPNE:
    case Opcodes.IF_ICMPNE:
    case Opcodes.IFNE:
        return CompoundExpressionOperator.NOT_EQUALS;
    case Opcodes.IF_ACMPEQ:
    case Opcodes.IF_ICMPEQ:
    case Opcodes.IFEQ:
        return CompoundExpressionOperator.EQUALS;
    case Opcodes.IF_ICMPLE:
    case Opcodes.IFLE:
        return CompoundExpressionOperator.LESS_EQUALS;
    case Opcodes.IF_ICMPLT:
    case Opcodes.IFLT:
        return CompoundExpressionOperator.LESS;
    case Opcodes.IF_ICMPGE:
    case Opcodes.IFGE:
        return CompoundExpressionOperator.GREATER_EQUALS;
    case Opcodes.IF_ICMPGT:
    case Opcodes.IFGT:
        return CompoundExpressionOperator.GREATER;
    default:
        throw new AnalyzeException(
                "Failed to retrieve the operator for the current comparison instruction (opcode: "
                        + currentInstruction.getOpcode() + ")");
    }
}

From source file:org.lambdamatic.analyzer.ast.LambdaExpressionReader.java

License:Open Source License

/**
 * The {@link AbstractInsnNode#getOpcode()} value should be one of {@code IFEQ}, {@code IFNE},
 * {@code IFLT}, {@code IFGE}, {@code IFGT}, {@code IFLE}, {@code IFLT}, {@code IFGE},
 * {@code IFGT},{@code IF_ICMPEQ}, {@code IF_ICMPNE}, {@code IF_ICMPLT}, {@code IF_ICMPGE},
 * {@code IF_ICMPGT}, {@code IF_ICMPLE}, {@code IF_ACMPEQ}, {@code IF_ACMPNE}, {@code GOTO},
 * {@code JSR}, {@code IFNULL} or {@code IFNONNULL}.
 * /*w  w w  . ja  v  a  2 s  .c om*/
 * 
 * @param instructionCursor the cursor for the current instruction to read
 * @param expressionStack the stack of Expressions
 * @param capturedArguments the captured arguments
 * @param localVariables the local variables
 * @return the list of statements read from the jump instruction
 */
private List<Statement> readJumpInstruction(final InsnCursor instructionCursor,
        final Stack<Expression> expressionStack, final List<CapturedArgument> capturedArguments,
        final LocalVariables localVariables) {
    final JumpInsnNode jumpInsnNode = (JumpInsnNode) instructionCursor.getCurrent();
    final LabelNode jumpLabel = jumpInsnNode.label;
    // FIXME: add support for LCMP:
    // Takes two two-word long integers off the stack and compares them. If
    // the two integers are the same, the int 0 is pushed onto the stack. If
    // value2 is greater than value1, the int 1 is pushed onto the stack. If
    // value1 is greater than value2, the int -1 is pushed onto the stack.
    switch (jumpInsnNode.getOpcode()) {
    case Opcodes.IFEQ:
    case Opcodes.IFNE:
    case Opcodes.IFLE:
    case Opcodes.IFLT:
    case Opcodes.IFGE:
    case Opcodes.IFGT:
    case Opcodes.IF_ICMPEQ:
    case Opcodes.IF_ICMPNE:
    case Opcodes.IF_ICMPLE:
    case Opcodes.IF_ICMPLT:
    case Opcodes.IF_ICMPGE:
    case Opcodes.IF_ICMPGT:
    case Opcodes.IF_ACMPEQ:
    case Opcodes.IF_ACMPNE:
        return Arrays.asList(buildControlFlowStatement(instructionCursor, expressionStack, capturedArguments,
                localVariables));
    case Opcodes.GOTO:
        final InsnCursor jumpInstructionCursor = instructionCursor.duplicate();
        jumpInstructionCursor.move(jumpLabel.getLabel());
        return readStatements(jumpInstructionCursor, expressionStack, capturedArguments, localVariables);
    default:
        throw new AnalyzeException("Unexpected JumpInsnNode OpCode: " + jumpInsnNode.getOpcode());
    }
}

From source file:org.lanternpowered.server.event.filter.delegate.IncludeSubtypeFilterDelegate.java

License:MIT License

@Override
public int write(String name, ClassWriter cw, MethodVisitor mv, Method method, int locals) {
    // TODO could do an optimization here to inline a single instanceof if
    // the set would contain only a single member

    Label successLabel = new Label();

    mv.visitVarInsn(ALOAD, 0);/*  ww w. j a va  2 s . com*/
    mv.visitFieldInsn(GETFIELD, name, "classes", "Ljava/util/Set;");
    // Loop through the classes set's members
    mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Set", "iterator", "()Ljava/util/Iterator;", true);
    mv.visitVarInsn(ASTORE, locals);
    Label continueLabel = new Label();
    mv.visitJumpInsn(GOTO, continueLabel);
    Label loopStart = new Label();
    mv.visitLabel(loopStart);
    mv.visitVarInsn(ALOAD, locals);
    mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Iterator", "next", "()Ljava/lang/Object;", true);
    mv.visitTypeInsn(CHECKCAST, "java/lang/Class");
    mv.visitVarInsn(ALOAD, 1);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "isInstance", "(Ljava/lang/Object;)Z", false);

    // If isInstance returns true, jump to success (jump over return)
    mv.visitJumpInsn(Opcodes.IFNE, successLabel);
    mv.visitLabel(continueLabel);
    mv.visitVarInsn(ALOAD, locals);
    mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Iterator", "hasNext", "()Z", true);

    // If there are any classes left, continue looping. Otherwise, fail and return out (no @Include matches were found)
    mv.visitJumpInsn(IFNE, loopStart);

    mv.visitInsn(ACONST_NULL);
    mv.visitInsn(ARETURN);

    mv.visitLabel(successLabel);

    return locals + 1;
}

From source file:org.mbte.groovypp.compiler.bytecode.BytecodeExpr.java

License:Apache License

/**
 * negate a boolean on stack. true->false, false->true
 * @param mv/*from   ww  w  .  j a v  a  2s.c  o  m*/
 */
public void negateBoolean(MethodVisitor mv) {
    // code to negate the primitive boolean
    Label endLabel = new Label();
    Label falseLabel = new Label();
    mv.visitJumpInsn(Opcodes.IFNE, falseLabel);
    mv.visitInsn(Opcodes.ICONST_1);
    mv.visitJumpInsn(Opcodes.GOTO, endLabel);
    mv.visitLabel(falseLabel);
    mv.visitInsn(Opcodes.ICONST_0);
    mv.visitLabel(endLabel);
}

From source file:org.openquark.cal.internal.javamodel.AsmJavaBytecodeGenerator.java

License:Open Source License

/**
 * Add the <clinit> method. This initializes the static fields that have initializers.
 * @param classRep/* w ww .  j  a v  a  2  s  .c  om*/
 * @param cv
 * @param initializeForAsserts
 * @throws JavaGenerationException
 */
private static void encodeClassInitializer(JavaClassRep classRep, ClassVisitor cv, boolean initializeForAsserts)
        throws JavaGenerationException {

    // Add initializers for the statically-initialized fields.
    final int nFields = classRep.getNFieldDeclarations();

    if (!classRep.hasInitializedStaticField() && !initializeForAsserts) {
        //we don't need to bother adding a static initializer if there are no static fields to initialize.
        //note that javac also has this optimization.
        return;
    }

    MethodVisitor mv = cv.visitMethod(Opcodes.ACC_STATIC, "<clinit>", "()V", null, null);

    // Start the method's code.
    mv.visitCode();

    final JavaTypeName classRepTypeName = classRep.getClassName();

    /*
     * If this class contains assert statements we need to initialize the static final synthetic boolean field
     * '$assertionsDisabled'.
     * This is done by loading the Class constant for the top level class. The method 'desiredAssertionStatus()'
     * is then invoked on this Class object and the returned value is used to initialize $assertionsDisabled. 
     */
    if (initializeForAsserts) {
        // Get the fully-qualified internal class  name.    
        final String className = classRepTypeName.getJVMInternalName();

        // Get the top level class name.
        String topLevelClassName = getTopLevelClassJVMInternalName(className);

        // Load the Class constant for the top level class
        mv.visitLdcInsn(Type.getType("L" + topLevelClassName + ";"));

        // Now that we have the Class constant for the top level class we invoke the method
        // desiredAssertionStatus on it and use the resulting value to initialize the static field $assertionsDisabled in this class.
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Class", "desiredAssertionStatus", "()Z");
        Label l0 = new Label();
        mv.visitJumpInsn(Opcodes.IFNE, l0);
        mv.visitInsn(Opcodes.ICONST_1);
        Label l1 = new Label();
        mv.visitJumpInsn(Opcodes.GOTO, l1);
        mv.visitLabel(l0);
        mv.visitInsn(Opcodes.ICONST_0);
        mv.visitLabel(l1);
        mv.visitFieldInsn(Opcodes.PUTSTATIC, className, "$assertionsDisabled", "Z");
    }

    for (int i = 0; i < nFields; ++i) {

        JavaFieldDeclaration fieldDecl = classRep.getFieldDeclaration(i);
        JavaExpression initializer = fieldDecl.getInitializer();

        if (initializer != null && Modifier.isStatic(fieldDecl.getModifiers())) {

            GenerationContext context = new GenerationContext(new HashMap<String, JavaTypeName>(),
                    new HashMap<String, Integer>(), 0, mv, classRepTypeName);

            //evaluate the initializer
            encodeExpr(initializer, context);

            //do the assignment
            mv.visitFieldInsn(Opcodes.PUTSTATIC, classRep.getClassName().getJVMInternalName(),
                    fieldDecl.getFieldName(), fieldDecl.getFieldType().getJVMDescriptor());
        }
    }

    // return.
    mv.visitInsn(Opcodes.RETURN);

    //mark the end of the method with a call to visitMaxs
    mv.visitMaxs(0, 0);

    // End the method.
    mv.visitEnd();
}