Example usage for org.objectweb.asm Opcodes LRETURN

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

Introduction

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

Prototype

int LRETURN

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

Click Source Link

Usage

From source file:dyco4j.instrumentation.internals.InitTracingMethodVisitor.java

License:BSD License

@Override
public void visitInsn(final int opcode) {
    super.visitInsn(opcode);
    switch (opcode) {
    case Opcodes.IRETURN: // 1 before n/a after
    case Opcodes.FRETURN: // 1 before n/a after
    case Opcodes.ARETURN: // 1 before n/a after
    case Opcodes.ATHROW: // 1 before n/a after
        this.stackFrame.pop();
        break;/*from  ww w  .  j a v  a2 s .co m*/
    case Opcodes.LRETURN: // 2 before n/a after
    case Opcodes.DRETURN: // 2 before n/a after
        this.stackFrame.pop();
        this.stackFrame.pop();
        break;
    case Opcodes.NOP:
    case Opcodes.LALOAD: // remove 2 add 2
    case Opcodes.DALOAD: // remove 2 add 2
    case Opcodes.LNEG:
    case Opcodes.DNEG:
    case Opcodes.FNEG:
    case Opcodes.INEG:
    case Opcodes.L2D:
    case Opcodes.D2L:
    case Opcodes.F2I:
    case Opcodes.I2B:
    case Opcodes.I2C:
    case Opcodes.I2S:
    case Opcodes.I2F:
    case Opcodes.ARRAYLENGTH:
        break;
    case Opcodes.ACONST_NULL:
    case Opcodes.ICONST_M1:
    case Opcodes.ICONST_0:
    case Opcodes.ICONST_1:
    case Opcodes.ICONST_2:
    case Opcodes.ICONST_3:
    case Opcodes.ICONST_4:
    case Opcodes.ICONST_5:
    case Opcodes.FCONST_0:
    case Opcodes.FCONST_1:
    case Opcodes.FCONST_2:
    case Opcodes.F2L: // 1 before 2 after
    case Opcodes.F2D:
    case Opcodes.I2L:
    case Opcodes.I2D:
        this.stackFrame.push(OTHER);
        break;
    case Opcodes.LCONST_0:
    case Opcodes.LCONST_1:
    case Opcodes.DCONST_0:
    case Opcodes.DCONST_1:
        this.stackFrame.push(OTHER);
        this.stackFrame.push(OTHER);
        break;
    case Opcodes.IALOAD: // remove 2 add 1
    case Opcodes.FALOAD: // remove 2 add 1
    case Opcodes.AALOAD: // remove 2 add 1
    case Opcodes.BALOAD: // remove 2 add 1
    case Opcodes.CALOAD: // remove 2 add 1
    case Opcodes.SALOAD: // remove 2 add 1
    case Opcodes.POP:
    case Opcodes.IADD:
    case Opcodes.FADD:
    case Opcodes.ISUB:
    case Opcodes.LSHL: // 3 before 2 after
    case Opcodes.LSHR: // 3 before 2 after
    case Opcodes.LUSHR: // 3 before 2 after
    case Opcodes.L2I: // 2 before 1 after
    case Opcodes.L2F: // 2 before 1 after
    case Opcodes.D2I: // 2 before 1 after
    case Opcodes.D2F: // 2 before 1 after
    case Opcodes.FSUB:
    case Opcodes.FMUL:
    case Opcodes.FDIV:
    case Opcodes.FREM:
    case Opcodes.FCMPL: // 2 before 1 after
    case Opcodes.FCMPG: // 2 before 1 after
    case Opcodes.IMUL:
    case Opcodes.IDIV:
    case Opcodes.IREM:
    case Opcodes.ISHL:
    case Opcodes.ISHR:
    case Opcodes.IUSHR:
    case Opcodes.IAND:
    case Opcodes.IOR:
    case Opcodes.IXOR:
    case Opcodes.MONITORENTER:
    case Opcodes.MONITOREXIT:
        this.stackFrame.pop();
        break;
    case Opcodes.POP2:
    case Opcodes.LSUB:
    case Opcodes.LMUL:
    case Opcodes.LDIV:
    case Opcodes.LREM:
    case Opcodes.LADD:
    case Opcodes.LAND:
    case Opcodes.LOR:
    case Opcodes.LXOR:
    case Opcodes.DADD:
    case Opcodes.DMUL:
    case Opcodes.DSUB:
    case Opcodes.DDIV:
    case Opcodes.DREM:
        this.stackFrame.pop();
        this.stackFrame.pop();
        break;
    case Opcodes.IASTORE:
    case Opcodes.FASTORE:
    case Opcodes.AASTORE:
    case Opcodes.BASTORE:
    case Opcodes.CASTORE:
    case Opcodes.SASTORE:
    case Opcodes.LCMP: // 4 before 1 after
    case Opcodes.DCMPL:
    case Opcodes.DCMPG:
        this.stackFrame.pop();
        this.stackFrame.pop();
        this.stackFrame.pop();
        break;
    case Opcodes.LASTORE:
    case Opcodes.DASTORE:
        this.stackFrame.pop();
        this.stackFrame.pop();
        this.stackFrame.pop();
        this.stackFrame.pop();
        break;
    case Opcodes.DUP:
        this.stackFrame.push(this.stackFrame.peek());
        break;
    case Opcodes.DUP_X1: {
        final int _s = stackFrame.size();
        stackFrame.add(_s - 2, stackFrame.get(_s - 1));
        break;
    }
    case Opcodes.DUP_X2: {
        final int _s = stackFrame.size();
        stackFrame.add(_s - 3, stackFrame.get(_s - 1));
        break;
    }
    case Opcodes.DUP2: {
        final int _s = stackFrame.size();
        stackFrame.add(_s - 2, stackFrame.get(_s - 1));
        stackFrame.add(_s - 2, stackFrame.get(_s - 1));
        break;
    }
    case Opcodes.DUP2_X1: {
        final int _s = stackFrame.size();
        stackFrame.add(_s - 3, stackFrame.get(_s - 1));
        stackFrame.add(_s - 3, stackFrame.get(_s - 1));
        break;
    }
    case Opcodes.DUP2_X2: {
        final int _s = stackFrame.size();
        stackFrame.add(_s - 4, stackFrame.get(_s - 1));
        stackFrame.add(_s - 4, stackFrame.get(_s - 1));
        break;
    }
    case Opcodes.SWAP: {
        final int _s = stackFrame.size();
        stackFrame.add(_s - 2, stackFrame.get(_s - 1));
        stackFrame.remove(_s);
        break;
    }
    }
}

From source file:dyco4j.instrumentation.internals.TracingMethodVisitor.java

License:BSD License

@Override
public final void visitInsn(final int opcode) {
    if (opcode == Opcodes.IRETURN || opcode == Opcodes.LRETURN || opcode == Opcodes.FRETURN
            || opcode == Opcodes.DRETURN || opcode == Opcodes.ARETURN || opcode == Opcodes.RETURN) {
        if (this.cv.cmdLineOptions.traceMethodRetValue)
            LoggingHelper.emitLogReturn(this.mv, method.getReturnType());
        LoggingHelper.emitLogMethodExit(this.mv, this.methodId, LoggingHelper.ExitKind.NORMAL);
        super.visitInsn(opcode);
    } else if (opcode == Opcodes.AASTORE || opcode == Opcodes.BASTORE || opcode == Opcodes.CASTORE
            || opcode == Opcodes.DASTORE || opcode == Opcodes.FASTORE || opcode == Opcodes.IASTORE
            || opcode == Opcodes.LASTORE || opcode == Opcodes.SASTORE) {
        if (this.cv.cmdLineOptions.traceArrayAccess)
            visitArrayStoreInsn(opcode);
        else//from w ww  .  ja v a2  s  .  c o  m
            super.visitInsn(opcode);
    } else if (opcode == Opcodes.AALOAD || opcode == Opcodes.BALOAD || opcode == Opcodes.CALOAD
            || opcode == Opcodes.DALOAD || opcode == Opcodes.FALOAD || opcode == Opcodes.IALOAD
            || opcode == Opcodes.LALOAD || opcode == Opcodes.SALOAD) {
        if (this.cv.cmdLineOptions.traceArrayAccess)
            visitArrayLoadInsn(opcode);
        else
            super.visitInsn(opcode);
    } else
        super.visitInsn(opcode);
}

From source file:edu.mit.streamjit.util.bytecode.MethodResolver.java

License:Open Source License

private void findBlockBoundaries() {
    InsnList insns = methodNode.instructions;
    //We find the indices of any block-ending instruction and of any jump
    //target, sort, remove duplicates, then use pairs to define blocks. Note
    //these are end-exclusive indices, thus one after the block-enders, but
    //right on the jump targets (they're one-past-the-end of the preceding
    //block)./*from w w  w  .  j a v  a2s  .c  o m*/
    List<Integer> indices = new ArrayList<>();
    indices.add(0);
    for (int i = 0; i < insns.size(); ++i) {
        AbstractInsnNode insn = insns.get(i);
        int opcode = insn.getOpcode();
        //Terminator opcodes end blocks.
        if (insn instanceof JumpInsnNode || insn instanceof LookupSwitchInsnNode
                || insn instanceof TableSwitchInsnNode || opcode == Opcodes.ATHROW || opcode == Opcodes.IRETURN
                || opcode == Opcodes.LRETURN || opcode == Opcodes.FRETURN || opcode == Opcodes.DRETURN
                || opcode == Opcodes.ARETURN || opcode == Opcodes.RETURN) {
            indices.add(i + 1);
        }
        //Jump targets of this instruction end blocks.
        if (insn instanceof JumpInsnNode)
            indices.add(insns.indexOf(((JumpInsnNode) insn).label));
        else if (insn instanceof LookupSwitchInsnNode) {
            indices.add(insns.indexOf(((LookupSwitchInsnNode) insn).dflt));
            for (Object label : ((LookupSwitchInsnNode) insn).labels)
                indices.add(insns.indexOf((LabelNode) label));
        } else if (insn instanceof TableSwitchInsnNode) {
            indices.add(insns.indexOf(((TableSwitchInsnNode) insn).dflt));
            for (Object label : ((TableSwitchInsnNode) insn).labels)
                indices.add(insns.indexOf((LabelNode) label));
        }

        //While we're scanning the instructions, make the UninitializedValue
        //values for 'new' opcodes.
        if (opcode == Opcodes.NEW) {
            Klass k = getKlassByInternalName(((TypeInsnNode) insn).desc);
            ReferenceType t = typeFactory.getReferenceType(k);
            newValues.put(insn, new UninitializedValue(t, "new" + (counter++)));
        }
    }

    //Remove duplicates and sort via TreeSet.
    indices = new ArrayList<>(new TreeSet<>(indices));
    for (int i = 1; i < indices.size(); ++i)
        blocks.add(new BBInfo(indices.get(i - 1), indices.get(i), i - 1));
}

From source file:edu.mit.streamjit.util.bytecode.MethodResolver.java

License:Open Source License

private void interpret(InsnNode insn, FrameState frame, BBInfo block) {
    ReturnType returnType = block.block.getParent().getType().getReturnType();
    switch (insn.getOpcode()) {
    case Opcodes.NOP:
        break;//from ww  w .j  av  a 2 s. c om
    //<editor-fold defaultstate="collapsed" desc="Stack manipulation opcodes (pop, dup, swap)">
    case Opcodes.POP:
        assert frame.stack.peek().getType().getCategory() == 1;
        frame.stack.pop();
        break;
    case Opcodes.POP2:
        final int[][][] pop2Permutations = { { { 1, 1 }, {} }, { { 2 }, {} } };
        conditionallyPermute(frame, pop2Permutations);
        break;
    case Opcodes.DUP:
        final int[][][] dupPermutations = { { { 1 }, { 1, 1 } } };
        conditionallyPermute(frame, dupPermutations);
        break;
    case Opcodes.DUP_X1:
        final int[][][] dup_x1Permutations = { { { 1, 1 }, { 1, 2, 1 } } };
        conditionallyPermute(frame, dup_x1Permutations);
        break;
    case Opcodes.DUP_X2:
        final int[][][] dup_x2Permutations = { { { 1, 1, 1 }, { 1, 3, 2, 1 } }, { { 1, 2 }, { 1, 2, 1 } } };
        conditionallyPermute(frame, dup_x2Permutations);
        break;
    case Opcodes.DUP2:
        final int[][][] dup2Permutations = { { { 1, 1 }, { 2, 1, 2, 1 } }, { { 2 }, { 1, 1 } } };
        conditionallyPermute(frame, dup2Permutations);
        break;
    case Opcodes.DUP2_X1:
        final int[][][] dup2_x1Permutations = { { { 1, 1, 1 }, { 2, 1, 3, 2, 1 } }, { { 2, 1 }, { 1, 2, 1 } } };
        conditionallyPermute(frame, dup2_x1Permutations);
        break;
    case Opcodes.DUP2_X2:
        final int[][][] dup2_x2Permutations = { { { 1, 1, 1, 1 }, { 2, 1, 4, 3, 2, 1 } },
                { { 2, 1, 1 }, { 1, 3, 2, 1 } }, { { 3, 2, 1 }, { 2, 1, 3, 2, 1 } },
                { { 2, 2 }, { 1, 2, 1 } } };
        conditionallyPermute(frame, dup2_x2Permutations);
        break;
    case Opcodes.SWAP:
        final int[][][] swapPermutations = { { { 1, 1 }, { 1, 2 } } };
        conditionallyPermute(frame, swapPermutations);
        break;
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Constant-stacking opcodes (iconst_0, etc.; see also bipush, sipush)">
    case Opcodes.ACONST_NULL:
        frame.stack.push(module.constants().getNullConstant());
        break;
    case Opcodes.ICONST_M1:
        frame.stack.push(module.constants().getSmallestIntConstant(-1));
        break;
    case Opcodes.ICONST_0:
        frame.stack.push(module.constants().getSmallestIntConstant(0));
        break;
    case Opcodes.ICONST_1:
        frame.stack.push(module.constants().getSmallestIntConstant(1));
        break;
    case Opcodes.ICONST_2:
        frame.stack.push(module.constants().getSmallestIntConstant(2));
        break;
    case Opcodes.ICONST_3:
        frame.stack.push(module.constants().getSmallestIntConstant(3));
        break;
    case Opcodes.ICONST_4:
        frame.stack.push(module.constants().getSmallestIntConstant(4));
        break;
    case Opcodes.ICONST_5:
        frame.stack.push(module.constants().getSmallestIntConstant(5));
        break;
    case Opcodes.LCONST_0:
        frame.stack.push(module.constants().getConstant(0L));
        break;
    case Opcodes.LCONST_1:
        frame.stack.push(module.constants().getConstant(1L));
        break;
    case Opcodes.FCONST_0:
        frame.stack.push(module.constants().getConstant(0f));
        break;
    case Opcodes.FCONST_1:
        frame.stack.push(module.constants().getConstant(1f));
        break;
    case Opcodes.FCONST_2:
        frame.stack.push(module.constants().getConstant(2f));
        break;
    case Opcodes.DCONST_0:
        frame.stack.push(module.constants().getConstant(0d));
        break;
    case Opcodes.DCONST_1:
        frame.stack.push(module.constants().getConstant(1d));
        break;
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Return opcodes">
    case Opcodes.IRETURN:
        assert returnType.isSubtypeOf(typeFactory.getType(int.class));
        assert frame.stack.peek().getType().isSubtypeOf(returnType);
        block.block.instructions().add(new ReturnInst(returnType, frame.stack.pop()));
        break;
    case Opcodes.LRETURN:
        assert returnType.isSubtypeOf(typeFactory.getType(long.class));
        assert frame.stack.peek().getType().isSubtypeOf(returnType);
        block.block.instructions().add(new ReturnInst(returnType, frame.stack.pop()));
        break;
    case Opcodes.FRETURN:
        assert returnType.isSubtypeOf(typeFactory.getType(float.class));
        assert frame.stack.peek().getType().isSubtypeOf(returnType);
        block.block.instructions().add(new ReturnInst(returnType, frame.stack.pop()));
        break;
    case Opcodes.DRETURN:
        assert returnType.isSubtypeOf(typeFactory.getType(double.class));
        assert frame.stack.peek().getType().isSubtypeOf(returnType);
        block.block.instructions().add(new ReturnInst(returnType, frame.stack.pop()));
        break;
    case Opcodes.ARETURN:
        assert returnType.isSubtypeOf(typeFactory.getType(Object.class));
        assert frame.stack.peek().getType().isSubtypeOf(returnType);
        block.block.instructions().add(new ReturnInst(returnType, frame.stack.pop()));
        break;
    case Opcodes.RETURN:
        assert returnType instanceof VoidType || method.isConstructor();
        block.block.instructions().add(new ReturnInst(typeFactory.getVoidType()));
        break;
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Unary math opcodes (negation)">
    //Unary minus is rendered as a multiplication by -1.  (The obvious
    //other choice, subtraction from 0, is not equivalent for floats and
    //doubles due to negative zero.)
    case Opcodes.INEG:
        frame.stack.push(module.constants().getSmallestIntConstant(-1));
        binary(BinaryInst.Operation.MUL, frame, block);
        break;
    case Opcodes.LNEG:
        frame.stack.push(module.constants().getConstant(-1L));
        binary(BinaryInst.Operation.MUL, frame, block);
        break;
    case Opcodes.FNEG:
        frame.stack.push(module.constants().getConstant(-1f));
        binary(BinaryInst.Operation.MUL, frame, block);
        break;
    case Opcodes.DNEG:
        frame.stack.push(module.constants().getConstant(-1d));
        binary(BinaryInst.Operation.MUL, frame, block);
        break;
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Binary math opcodes">
    case Opcodes.IADD:
    case Opcodes.LADD:
    case Opcodes.FADD:
    case Opcodes.DADD:
        binary(BinaryInst.Operation.ADD, frame, block);
        break;
    case Opcodes.ISUB:
    case Opcodes.LSUB:
    case Opcodes.FSUB:
    case Opcodes.DSUB:
        binary(BinaryInst.Operation.SUB, frame, block);
        break;
    case Opcodes.IMUL:
    case Opcodes.LMUL:
    case Opcodes.FMUL:
    case Opcodes.DMUL:
        binary(BinaryInst.Operation.MUL, frame, block);
        break;
    case Opcodes.IDIV:
    case Opcodes.LDIV:
    case Opcodes.FDIV:
    case Opcodes.DDIV:
        binary(BinaryInst.Operation.DIV, frame, block);
        break;
    case Opcodes.IREM:
    case Opcodes.LREM:
    case Opcodes.FREM:
    case Opcodes.DREM:
        binary(BinaryInst.Operation.REM, frame, block);
        break;
    case Opcodes.ISHL:
    case Opcodes.LSHL:
        binary(BinaryInst.Operation.SHL, frame, block);
        break;
    case Opcodes.ISHR:
    case Opcodes.LSHR:
        binary(BinaryInst.Operation.SHR, frame, block);
        break;
    case Opcodes.IUSHR:
    case Opcodes.LUSHR:
        binary(BinaryInst.Operation.USHR, frame, block);
        break;
    case Opcodes.IAND:
    case Opcodes.LAND:
        binary(BinaryInst.Operation.AND, frame, block);
        break;
    case Opcodes.IOR:
    case Opcodes.LOR:
        binary(BinaryInst.Operation.OR, frame, block);
        break;
    case Opcodes.IXOR:
    case Opcodes.LXOR:
        binary(BinaryInst.Operation.XOR, frame, block);
        break;
    case Opcodes.LCMP:
    case Opcodes.FCMPL:
    case Opcodes.DCMPL:
        binary(BinaryInst.Operation.CMP, frame, block);
        break;
    case Opcodes.FCMPG:
    case Opcodes.DCMPG:
        binary(BinaryInst.Operation.CMPG, frame, block);
        break;
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Primitive casts">
    case Opcodes.I2L:
        cast(int.class, long.class, frame, block);
        break;
    case Opcodes.I2F:
        cast(int.class, float.class, frame, block);
        break;
    case Opcodes.I2D:
        cast(int.class, double.class, frame, block);
        break;
    case Opcodes.L2I:
        cast(long.class, int.class, frame, block);
        break;
    case Opcodes.L2F:
        cast(long.class, float.class, frame, block);
        break;
    case Opcodes.L2D:
        cast(long.class, double.class, frame, block);
        break;
    case Opcodes.F2I:
        cast(float.class, int.class, frame, block);
        break;
    case Opcodes.F2L:
        cast(float.class, long.class, frame, block);
        break;
    case Opcodes.F2D:
        cast(float.class, double.class, frame, block);
        break;
    case Opcodes.D2I:
        cast(double.class, int.class, frame, block);
        break;
    case Opcodes.D2L:
        cast(double.class, long.class, frame, block);
        break;
    case Opcodes.D2F:
        cast(double.class, float.class, frame, block);
        break;
    case Opcodes.I2B:
        cast(int.class, byte.class, frame, block);
        break;
    case Opcodes.I2C:
        cast(int.class, char.class, frame, block);
        break;
    case Opcodes.I2S:
        cast(int.class, short.class, frame, block);
        break;
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Array store opcodes">
    case Opcodes.IASTORE:
    case Opcodes.LASTORE:
    case Opcodes.FASTORE:
    case Opcodes.DASTORE:
    case Opcodes.AASTORE:
    case Opcodes.BASTORE:
    case Opcodes.CASTORE:
    case Opcodes.SASTORE:
        Value data = frame.stack.pop();
        Value index = frame.stack.pop();
        Value array = frame.stack.pop();
        ArrayStoreInst asi = new ArrayStoreInst(array, index, data);
        block.block.instructions().add(asi);
        break;
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Array load opcodes">
    case Opcodes.IALOAD:
    case Opcodes.LALOAD:
    case Opcodes.FALOAD:
    case Opcodes.DALOAD:
    case Opcodes.AALOAD:
    case Opcodes.BALOAD:
    case Opcodes.CALOAD:
    case Opcodes.SALOAD:
        Value index2 = frame.stack.pop();
        Value array2 = frame.stack.pop();
        ArrayLoadInst ali = new ArrayLoadInst(array2, index2);
        block.block.instructions().add(ali);
        frame.stack.push(ali);
        break;
    //</editor-fold>
    case Opcodes.ARRAYLENGTH:
        ArrayLengthInst lengthInst = new ArrayLengthInst(frame.stack.pop());
        block.block.instructions().add(lengthInst);
        frame.stack.push(lengthInst);
        break;
    case Opcodes.ATHROW:
        block.block.instructions().add(new ThrowInst(frame.stack.pop()));
        break;
    default:
        throw new UnsupportedOperationException("" + insn.getOpcode());
    }
}

From source file:edu.mit.streamjit.util.bytecode.MethodUnresolver.java

License:Open Source License

private void emit(ReturnInst i, InsnList insns) {
    ReturnType rt = i.getReturnType();//from w w w  . ja  va2s  .  com
    if (rt instanceof VoidType)
        insns.add(new InsnNode(Opcodes.RETURN));
    else {
        load(i.getOperand(0), insns);
        if (rt instanceof ReferenceType)
            insns.add(new InsnNode(Opcodes.ARETURN));
        else if (rt.isSubtypeOf(intType))
            insns.add(new InsnNode(Opcodes.IRETURN));
        else if (rt.equals(longType))
            insns.add(new InsnNode(Opcodes.LRETURN));
        else if (rt.equals(floatType))
            insns.add(new InsnNode(Opcodes.FRETURN));
        else if (rt.equals(doubleType))
            insns.add(new InsnNode(Opcodes.DRETURN));
        else
            throw new AssertionError(i);
    }
}

From source file:gemlite.core.internal.asm.AsmHelper.java

License:Apache License

public final static int getReturnCodeByType(String typeDesc) {
    switch (typeDesc) {
    case "I":
        return Opcodes.IRETURN;
    case "J":
        return Opcodes.LRETURN;
    case "D":
        return Opcodes.DRETURN;
    case "F":
        return Opcodes.FRETURN;
    }//from  ww  w .ja v  a  2 s .  c o m

    return Opcodes.ARETURN;
}

From source file:gemlite.core.internal.measurement.MeasureHelper.java

License:Apache License

public final static void instrumentCheckPoint(String className, MethodNode mn) {
    if (LogUtil.getCoreLog().isTraceEnabled())
        LogUtil.getCoreLog().trace("Found check point, class:" + className + " method:" + mn.name);

    InsnList insn = mn.instructions;//from   w w w  . j a v a 2s.c  o  m
    List<AbstractInsnNode> returnIndex = new ArrayList<>();
    // return
    int localVarCount = mn.localVariables.size();
    for (int i = 0; i < insn.size(); i++) {
        AbstractInsnNode insnNode = (AbstractInsnNode) insn.get(i);
        switch (insnNode.getOpcode()) {
        case Opcodes.ARETURN:
        case Opcodes.IRETURN:
        case Opcodes.DRETURN:
        case Opcodes.LRETURN:
        case Opcodes.FRETURN:
            returnIndex.add(insnNode.getPrevious());
            break;
        case Opcodes.RETURN:
            returnIndex.add(insnNode);
            break;
        }
    }
    // 
    insn.insert(new VarInsnNode(Opcodes.LSTORE, localVarCount + 2));
    insn.insert(
            new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/System", "currentTimeMillis", "()J", false));
    // ?
    for (AbstractInsnNode insnNode : returnIndex) {
        insn.insertBefore(insnNode, new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/System",
                "currentTimeMillis", "()J", false));
        insn.insertBefore(insnNode, new VarInsnNode(Opcodes.LSTORE, localVarCount + 4));

        insn.insertBefore(insnNode, new LdcInsnNode(className));
        insn.insertBefore(insnNode, new LdcInsnNode(mn.name));
        insn.insertBefore(insnNode, new VarInsnNode(Opcodes.LLOAD, localVarCount + 2));
        insn.insertBefore(insnNode, new VarInsnNode(Opcodes.LLOAD, localVarCount + 4));
        insn.insertBefore(insnNode,
                new MethodInsnNode(Opcodes.INVOKESTATIC, "gemlite/core/internal/measurement/MeasureHelper",
                        "recordCheckPoint", "(Ljava/lang/String;Ljava/lang/String;JJ)V", false));
    }
}

From source file:gnu.classpath.tools.rmic.ClassRmicCompiler.java

License:Open Source License

private static int returnOpcode(Class cls) {
    int returncode;
    if (cls.equals(Boolean.TYPE))
        returncode = Opcodes.IRETURN;//from w w  w. j  av  a 2  s . c  om
    else if (cls.equals(Byte.TYPE))
        returncode = Opcodes.IRETURN;
    else if (cls.equals(Character.TYPE))
        returncode = Opcodes.IRETURN;
    else if (cls.equals(Short.TYPE))
        returncode = Opcodes.IRETURN;
    else if (cls.equals(Integer.TYPE))
        returncode = Opcodes.IRETURN;
    else if (cls.equals(Long.TYPE))
        returncode = Opcodes.LRETURN;
    else if (cls.equals(Float.TYPE))
        returncode = Opcodes.FRETURN;
    else if (cls.equals(Double.TYPE))
        returncode = Opcodes.DRETURN;
    else if (cls.equals(Void.TYPE))
        returncode = Opcodes.RETURN;
    else
        returncode = Opcodes.ARETURN;

    return returncode;
}

From source file:instrumentation.InstrumentationMethodAdapter.java

License:Open Source License

public void visitInsn(int opcode) {

    switch (opcode) {
    case Opcodes.MONITORENTER:
        insertCode(opcode, "MonitorEnterBefore");
        mv.visitInsn(Opcodes.DUP);// w  w  w .j  a va  2  s.com
        mv.visitInsn(opcode);
        insertCode(opcode, "MonitorEnterAfter");
        mv.visitInsn(Opcodes.POP);
        break;
    case Opcodes.MONITOREXIT:
        insertCode(opcode, "MonitorExitBefore");
        mv.visitInsn(opcode);
        break;
    case Opcodes.ATHROW:
    case Opcodes.RETURN:
    case Opcodes.IRETURN:
    case Opcodes.LRETURN:
    case Opcodes.FRETURN:
    case Opcodes.DRETURN:
    case Opcodes.ARETURN:
        addMonitorExitBeforeReturn();
        mv.visitInsn(opcode);
        break;
    default:
        mv.visitInsn(opcode);
    }

}

From source file:io.awacs.plugin.springmvc.ServiceWrapper.java

License:Apache License

/**
 * origin method: (XXX)X//  www.ja  va2s. c  om
 * <p>
 * proxy method: (XXXLjavax/servlet/http/HttpServletRequest;)X
 * req -> localIndex - 1
 *
 * @param cn
 * @param origin
 * @return
 */
private MethodNode doProxy(ClassNode cn, MethodNode origin) {

    MethodNode newNode = copyMethod(origin);
    //move annotations
    hideAnnotations(origin);

    LabelNode l0 = new LabelNode();
    LabelNode l1 = new LabelNode();
    LabelNode l2 = new LabelNode();

    String returnType = origin.desc.substring(origin.desc.indexOf(')') + 1);

    int localIndex = copyParameters(origin, newNode, l0, l2);

    newNode.tryCatchBlocks.add(new TryCatchBlockNode(l0, l1, l2, "java/lang/Exception"));

    //localIndex -> elapsedTime
    newNode.localVariables.add(new LocalVariableNode("elapsedTime", "J", null, l0, l1, localIndex));

    //
    newNode.instructions.add(l0);

    // long elapsedTime = System.currentTimeMillis();
    newNode.instructions
            .add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/System", "currentTimeMillis", "()J"));
    newNode.instructions.add(new VarInsnNode(Opcodes.LSTORE, localIndex));

    int paramCount = getParamCount(origin.desc, origin.access);

    //load?
    for (int i = 0; i < paramCount; i++) {
        LocalVariableNode node = (LocalVariableNode) newNode.localVariables.get(i);
        switch (node.desc) {
        case "J":
            newNode.instructions.add(new VarInsnNode(Opcodes.LLOAD, node.index));
            break;
        case "D":
            newNode.instructions.add(new VarInsnNode(Opcodes.DLOAD, node.index));
            break;
        case "F":
            newNode.instructions.add(new VarInsnNode(Opcodes.FLOAD, node.index));
            break;
        case "I":
            newNode.instructions.add(new VarInsnNode(Opcodes.ILOAD, node.index));
            break;
        case "S":
            newNode.instructions.add(new VarInsnNode(Opcodes.ILOAD, node.index));
            break;
        case "Z":
            newNode.instructions.add(new VarInsnNode(Opcodes.ILOAD, node.index));
            break;
        case "B":
            newNode.instructions.add(new VarInsnNode(Opcodes.ILOAD, node.index));
            break;
        case "C":
            newNode.instructions.add(new VarInsnNode(Opcodes.ILOAD, node.index));
            break;
        default:
            newNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, node.index));
            break;
        }
    }
    //
    newNode.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, cn.name, origin.name, origin.desc));

    //
    newNode.instructions
            .add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/System", "currentTimeMillis", "()J"));
    newNode.instructions.add(new VarInsnNode(Opcodes.LLOAD, localIndex));
    newNode.instructions.add(new InsnNode(Opcodes.LSUB));
    newNode.instructions.add(new VarInsnNode(Opcodes.LSTORE, localIndex));

    newNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, localIndex - 1));
    newNode.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE,
            "javax/servlet/http/HttpServletRequest", "getRequestURI", "()Ljava/lang/String;"));

    //?
    newNode.instructions.add(new VarInsnNode(Opcodes.LLOAD, localIndex));
    //SpringmvcPlugin.incrAccess(uri, elapsedTime);
    newNode.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC,
            "io/awacs/plugin/springmvc/SpringmvcPlugin", "incrAccess", "(Ljava/lang/String;J)V"));
    //
    newNode.instructions.add(l1);
    switch (returnType) {
    case "J":
        newNode.instructions.add(new InsnNode(Opcodes.LRETURN));
        break;
    case "D":
        newNode.instructions.add(new InsnNode(Opcodes.DRETURN));
        break;
    case "F":
        newNode.instructions.add(new InsnNode(Opcodes.FRETURN));
        break;
    case "I":
        newNode.instructions.add(new InsnNode(Opcodes.IRETURN));
        break;
    case "S":
        newNode.instructions.add(new InsnNode(Opcodes.IRETURN));
        break;
    case "C":
        newNode.instructions.add(new InsnNode(Opcodes.IRETURN));
        break;
    case "B":
        newNode.instructions.add(new InsnNode(Opcodes.IRETURN));
        break;
    case "Z":
        newNode.instructions.add(new InsnNode(Opcodes.IRETURN));
        break;
    default:
        newNode.instructions.add(new InsnNode(Opcodes.ARETURN));
        break;
    }

    newNode.instructions.add(l2);
    newNode.instructions
            .add(new FrameNode(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Exception" }));
    newNode.instructions.add(new VarInsnNode(Opcodes.ASTORE, localIndex));

    newNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, localIndex - 1));
    newNode.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE,
            "javax/servlet/http/HttpServletRequest", "getRequestURI", "()Ljava/lang/String;"));

    newNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, localIndex));
    newNode.instructions
            .add(new MethodInsnNode(Opcodes.INVOKESTATIC, "io/awacs/plugin/springmvc/SpringmvcPlugin",
                    "incrFailure", "(Ljava/lang/String;Ljava/lang/Throwable;)V"));

    newNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, localIndex));
    newNode.instructions.add(new InsnNode(Opcodes.ATHROW));
    newNode.maxLocals = origin.maxLocals + 3;
    newNode.maxStack = Math.max(localIndex + 2, 6);
    return newNode;
}