Example usage for org.objectweb.asm Opcodes RETURN

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

Introduction

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

Prototype

int RETURN

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

Click Source Link

Usage

From source file:org.jacoco.core.internal.analysis.AC_MethodAnalyzerTest.java

License:Open Source License

private void createLinearSequence() {
    final Label l0 = new Label();
    method.visitLabel(l0);/*from   w  w w .j a v  a  2s . c o m*/
    method.visitLineNumber(1001, l0);
    method.visitInsn(Opcodes.NOP);
    final Label l1 = new Label();
    method.visitLabel(l1);
    method.visitLineNumber(1002, l1);
    method.visitInsn(Opcodes.RETURN);
}

From source file:org.jacoco.core.internal.analysis.AC_MethodAnalyzerTest.java

License:Open Source License

private void createIfBranchMerge() {
    final Label l0 = new Label();
    method.visitLabel(l0);// ww  w  . ja  v a 2s  . c o m
    method.visitLineNumber(1001, l0);
    method.visitVarInsn(Opcodes.ILOAD, 1);
    Label l1 = new Label();
    method.visitJumpInsn(Opcodes.IFEQ, l1);
    final Label l2 = new Label();
    method.visitLabel(l2);
    method.visitLineNumber(1002, l2);
    method.visitInsn(Opcodes.NOP);
    method.visitLabel(l1);
    method.visitLineNumber(1003, l1);
    method.visitInsn(Opcodes.RETURN);
}

From source file:org.jacoco.core.internal.analysis.AC_MethodAnalyzerTest.java

License:Open Source License

private void createJumpBackwards() {
    final Label l0 = new Label();
    method.visitLabel(l0);//  w  ww. jav a2 s  . c  o m
    method.visitLineNumber(1001, l0);
    final Label l1 = new Label();
    method.visitJumpInsn(Opcodes.GOTO, l1);
    final Label l2 = new Label();
    method.visitLabel(l2);
    method.visitLineNumber(1002, l2);
    method.visitInsn(Opcodes.RETURN);
    method.visitLabel(l1);
    method.visitLineNumber(1003, l1);
    method.visitJumpInsn(Opcodes.GOTO, l2);
}

From source file:org.jacoco.core.internal.analysis.AC_MethodAnalyzerTest.java

License:Open Source License

private void createLoop() {
    final Label l0 = new Label();
    method.visitLabel(l0);/*from   ww  w .  j  a  v  a 2 s. c  o  m*/
    method.visitLineNumber(1001, l0);
    method.visitInsn(Opcodes.ICONST_0);
    method.visitVarInsn(Opcodes.ISTORE, 1);
    final Label l1 = new Label();
    method.visitLabel(l1);
    method.visitLineNumber(1002, l1);
    method.visitVarInsn(Opcodes.ILOAD, 1);
    method.visitInsn(Opcodes.ICONST_5);
    final Label l2 = new Label();
    method.visitJumpInsn(Opcodes.IF_ICMPGE, l2);
    method.visitIincInsn(1, 1);
    method.visitJumpInsn(Opcodes.GOTO, l1);
    method.visitLabel(l2);
    method.visitLineNumber(1003, l2);
    method.visitInsn(Opcodes.RETURN);
}

From source file:org.jacoco.core.internal.analysis.filter.EnumEmptyConstructorFilterTest.java

License:Open Source License

@Test
public void should_filter() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, Opcodes.ACC_PRIVATE, "<init>",
            "(Ljava/lang/String;I)V", null, null);
    m.visitVarInsn(Opcodes.ALOAD, 0);//from   w ww. j a  va2 s . c  o  m
    m.visitVarInsn(Opcodes.ALOAD, 1);
    m.visitVarInsn(Opcodes.ILOAD, 2);
    m.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Enum", "<init>", "(Ljava/lang/String;I)V", false);
    m.visitInsn(Opcodes.RETURN);
    context.superClassName = "java/lang/Enum";

    filter.filter(m, context, output);

    assertIgnored(new Range(m.instructions.getFirst(), m.instructions.getLast()));
}

From source file:org.jacoco.core.internal.analysis.filter.EnumEmptyConstructorFilterTest.java

License:Open Source License

/**
 * <code><pre>/*from   ww w . j  a va  2 s  .  c o m*/
 * enum E {
 *   ;
 *   private E() {
 *     ...
 *   }
 * }
 * </pre></code>
 */
@Test
public void should_not_filter_non_empty_constructor() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, Opcodes.ACC_PRIVATE, "<init>",
            "(Ljava/lang/String;I)V", null, null);
    m.visitVarInsn(Opcodes.ALOAD, 0);
    m.visitVarInsn(Opcodes.ALOAD, 1);
    m.visitVarInsn(Opcodes.ILOAD, 2);
    m.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Enum", "<init>", "(Ljava/lang/String;I)V", false);
    m.visitInsn(Opcodes.NOP);
    m.visitInsn(Opcodes.RETURN);
    context.superClassName = "java/lang/Enum";

    filter.filter(m, context, output);

    assertIgnored();
}

From source file:org.jacoco.core.internal.analysis.filter.EnumEmptyConstructorFilterTest.java

License:Open Source License

/**
 * <code><pre>//from w  ww.  j  a  v  a  2  s  . c o m
 * enum E {
 *   ;
 *   private E(long p) {
 *   }
 * }
 * </pre></code>
 */
@Test
public void should_not_filter_constructor_with_additional_parameters() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, Opcodes.ACC_PRIVATE, "<init>",
            "(Ljava/lang/String;IJ)V", null, null);
    m.visitVarInsn(Opcodes.ALOAD, 0);
    m.visitVarInsn(Opcodes.ALOAD, 1);
    m.visitVarInsn(Opcodes.ILOAD, 2);
    m.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Enum", "<init>", "(Ljava/lang/String;I)V", false);
    m.visitInsn(Opcodes.RETURN);
    context.superClassName = "java/lang/Enum";

    filter.filter(m, context, output);

    assertIgnored();
}

From source file:org.jacoco.core.internal.analysis.filter.FinallyFilter.java

License:Open Source License

private static void filter(final IFilterOutput output, final List<TryCatchBlockNode> tryCatchBlocks,
        final TryCatchBlockNode catchAnyBlock) {
    final AbstractInsnNode e = next(catchAnyBlock.handler);
    final int size = size(e);
    if (size <= 0) {
        return;//from   w w  w.ja  v  a  2  s  . c  o m
    }

    // Determine instructions inside regions
    final Set<AbstractInsnNode> inside = new HashSet<AbstractInsnNode>();
    for (final TryCatchBlockNode t : tryCatchBlocks) {
        if (t.handler == catchAnyBlock.handler) {
            AbstractInsnNode i = t.start;
            while (i != t.end) {
                inside.add(i);
                i = i.getNext();
            }
        }
    }

    // Find and merge duplicates at exits of regions
    for (final TryCatchBlockNode t : tryCatchBlocks) {
        if (t.handler == catchAnyBlock.handler) {
            boolean continues = false;
            AbstractInsnNode i = t.start;

            while (i != t.end) {
                switch (i.getType()) {
                case AbstractInsnNode.FRAME:
                case AbstractInsnNode.LINE:
                case AbstractInsnNode.LABEL:
                    break;
                case AbstractInsnNode.JUMP_INSN:
                    final AbstractInsnNode jumpTarget = next(((JumpInsnNode) i).label);
                    if (!inside.contains(jumpTarget)) {
                        merge(output, size, e, jumpTarget);
                    }
                    continues = i.getOpcode() != Opcodes.GOTO;
                    break;
                default:
                    switch (i.getOpcode()) {
                    case Opcodes.IRETURN:
                    case Opcodes.LRETURN:
                    case Opcodes.FRETURN:
                    case Opcodes.DRETURN:
                    case Opcodes.ARETURN:
                    case Opcodes.RETURN:
                    case Opcodes.ATHROW:
                        continues = false;
                        break;
                    default:
                        continues = true;
                        break;
                    }
                    break;
                }
                i = i.getNext();
            }

            i = next(i);
            if (continues && !inside.contains(i)) {
                merge(output, size, e, i);
            }
        }

        if (t != catchAnyBlock && t.start == catchAnyBlock.start && t.end == catchAnyBlock.end) {
            final AbstractInsnNode i = next(next(t.handler));
            if (!inside.contains(i)) {
                // javac's empty catch - merge after ASTORE
                merge(output, size, e, i);
            }
        }
    }
}

From source file:org.jacoco.core.internal.analysis.filter.FinallyFilterTest.java

License:Open Source License

/**
 * <pre>//  ww  w  .j  av  a 2  s. c o  m
 *   try {
 *     ...
 *     if (...) {
 *       ...
 *       return;
 *     } else {
 *       ...
 *       return;
 *     }
 *   } finally {
 *     ...
 *   }
 * </pre>
 */
@Test
public void should_analyze_control_flow() {
    final Label start1 = new Label();
    final Label end1 = new Label();
    final Label start2 = new Label();
    final Label end2 = new Label();
    final Label finallyStart = new Label();

    m.visitTryCatchBlock(start1, end1, finallyStart, null);
    m.visitTryCatchBlock(start2, end2, finallyStart, null);

    m.visitLabel(start1);
    // jump to another region associated with same handler:
    m.visitJumpInsn(Opcodes.IFEQ, start2);
    m.visitInsn(Opcodes.NOP);
    m.visitLabel(end1);

    m.visitInsn(Opcodes.NOP); // finally block
    shouldMergeLast();
    m.visitInsn(Opcodes.RETURN);

    m.visitLabel(start2);
    m.visitInsn(Opcodes.NOP);
    m.visitLabel(end2);
    m.visitInsn(Opcodes.NOP); // finally block
    shouldMergeLast();
    m.visitInsn(Opcodes.RETURN);

    m.visitLabel(finallyStart);
    m.visitVarInsn(Opcodes.ASTORE, 1);
    shouldIgnoreLast();
    m.visitInsn(Opcodes.NOP); // finally block
    shouldMergeLast();
    m.visitVarInsn(Opcodes.ALOAD, 1);
    shouldIgnoreLast();
    m.visitInsn(Opcodes.ATHROW);
    shouldIgnoreLast();

    execute();
}

From source file:org.jacoco.core.internal.analysis.filter.FinallyFilterTest.java

License:Open Source License

@Test
public void javac_always_completes_abruptly() {
    final Label tryStart = new Label();
    final Label tryEnd = new Label();
    final Label finallyStart = new Label();

    m.visitTryCatchBlock(tryStart, tryEnd, finallyStart, null);

    m.visitLabel(tryStart);/* w  w w .j a v  a  2s  .c  om*/
    m.visitInsn(Opcodes.NOP); // try body
    m.visitLabel(tryEnd);
    m.visitInsn(Opcodes.RETURN); // finally body

    m.visitLabel(finallyStart);
    m.visitVarInsn(Opcodes.ASTORE, 1);
    m.visitInsn(Opcodes.RETURN); // finally body

    execute();
}