Example usage for org.objectweb.asm Opcodes ISTORE

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

Introduction

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

Prototype

int ISTORE

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

Click Source Link

Usage

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  w  w w .java 2 s  .c om
    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.KotlinCoroutineFilterTest.java

License:Open Source License

@Test
public void should_filter_suspending_lambdas_generated_by_Kotlin_1_3_30() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "invokeSuspend",
            "(Ljava/lang/Object;)Ljava/lang/Object;", null, null);
    context.classAnnotations.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC);

    m.visitLabel(new Label());
    final Range range1 = new Range();
    range1.fromInclusive = m.instructions.getLast();
    m.visitMethodInsn(Opcodes.INVOKESTATIC, "kotlin/coroutines/intrinsics/IntrinsicsKt",
            "getCOROUTINE_SUSPENDED", "()Ljava/lang/Object;", false);
    m.visitVarInsn(Opcodes.ASTORE, 4);/* w w w  .  j  a  va 2 s  . c om*/

    m.visitVarInsn(Opcodes.ALOAD, 0);
    // line of "runBlocking"
    m.visitFieldInsn(Opcodes.GETFIELD, "Target", "label", "I");
    final Label dflt = new Label();
    final Label state0 = new Label();
    final Label state1 = new Label();
    m.visitTableSwitchInsn(0, 1, dflt, state0, state1);

    m.visitLabel(state0);

    {
        m.visitVarInsn(Opcodes.ALOAD, 1);
        m.visitMethodInsn(Opcodes.INVOKESTATIC, "kotlin/ResultKt", "throwOnFailure", "(Ljava/lang/Object;)V",
                false);
        range1.toInclusive = m.instructions.getLast();
    }

    // line before "suspendingFunction"
    m.visitInsn(Opcodes.NOP);

    // line of "suspendingFunction"
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "", "suspendingFunction",
            "(Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", false);

    m.visitInsn(Opcodes.DUP);
    final Range range2 = new Range();
    range2.fromInclusive = m.instructions.getLast();
    m.visitVarInsn(Opcodes.ALOAD, 4);
    final Label continuationLabelAfterLoadedResult = new Label();
    m.visitJumpInsn(Opcodes.IF_ACMPNE, continuationLabelAfterLoadedResult);
    // line of "runBlocking"
    m.visitVarInsn(Opcodes.ALOAD, 4);
    m.visitInsn(Opcodes.ARETURN);

    m.visitLabel(state1);

    m.visitVarInsn(Opcodes.ALOAD, 0);
    m.visitFieldInsn(Opcodes.GETFIELD, "Target", "I$0", "I");
    m.visitVarInsn(Opcodes.ISTORE, 3);

    {
        m.visitVarInsn(Opcodes.ALOAD, 1);
        m.visitMethodInsn(Opcodes.INVOKESTATIC, "kotlin/ResultKt", "throwOnFailure", "(Ljava/lang/Object;)V",
                false);
    }
    m.visitVarInsn(Opcodes.ALOAD, 1);
    range2.toInclusive = m.instructions.getLast();
    m.visitLabel(continuationLabelAfterLoadedResult);

    // line after "suspendingFunction"
    m.visitInsn(Opcodes.NOP);
    m.visitInsn(Opcodes.ARETURN);

    m.visitLabel(dflt);
    final Range range0 = new Range();
    range0.fromInclusive = m.instructions.getLast();
    m.visitTypeInsn(Opcodes.NEW, "java/lang/IllegalStateException");
    m.visitInsn(Opcodes.DUP);
    m.visitLdcInsn("call to 'resume' before 'invoke' with coroutine");
    m.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/IllegalStateException", "<init>",
            "(Ljava/lang/String;)V", false);
    m.visitInsn(Opcodes.ATHROW);
    range0.toInclusive = m.instructions.getLast();

    filter.filter(m, context, output);

    assertIgnored(range0, range1, range2);
}

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

License:Open Source License

/**
 * <pre>// ww w  .  j  av a  2  s. c o  m
 *     runBlocking {
 *         val x = 42
 *         nop(x)
 *         suspendingFunction()
 *         nop(x)
 *     }
 * </pre>
 */
@Test
public void should_filter_suspending_lambdas() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "invokeSuspend",
            "(Ljava/lang/Object;)Ljava/lang/Object;", null, null);
    context.classAnnotations.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC);

    m.visitLabel(new Label());
    final Range range1 = new Range();
    range1.fromInclusive = m.instructions.getLast();
    m.visitMethodInsn(Opcodes.INVOKESTATIC, "kotlin/coroutines/intrinsics/IntrinsicsKt",
            "getCOROUTINE_SUSPENDED", "()Ljava/lang/Object;", false);
    m.visitVarInsn(Opcodes.ASTORE, 4);

    m.visitVarInsn(Opcodes.ALOAD, 0);
    // line of "runBlocking"
    m.visitFieldInsn(Opcodes.GETFIELD, "Target", "label", "I");
    final Label dflt = new Label();
    final Label state0 = new Label();
    final Label state1 = new Label();
    m.visitTableSwitchInsn(0, 1, dflt, state0, state1);

    m.visitLabel(state0);

    {
        m.visitVarInsn(Opcodes.ALOAD, 1);
        m.visitInsn(Opcodes.DUP);
        m.visitTypeInsn(Opcodes.INSTANCEOF, "kotlin/Result$Failure");
        Label label = new Label();
        m.visitJumpInsn(Opcodes.IFEQ, label);
        m.visitTypeInsn(Opcodes.CHECKCAST, "kotlin/Result$Failure");
        m.visitFieldInsn(Opcodes.GETFIELD, "kotlin/Result$Failure", "exception", "Ljava/lang/Throwable");
        m.visitInsn(Opcodes.ATHROW);
        m.visitInsn(Opcodes.POP);
        range1.toInclusive = m.instructions.getLast();
        m.visitLabel(label);
    }

    // line before "suspendingFunction"
    m.visitInsn(Opcodes.NOP);

    // line of "suspendingFunction"
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "", "suspendingFunction",
            "(Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", false);

    m.visitInsn(Opcodes.DUP);
    final Range range2 = new Range();
    range2.fromInclusive = m.instructions.getLast();
    m.visitVarInsn(Opcodes.ALOAD, 4);
    final Label continuationLabelAfterLoadedResult = new Label();
    m.visitJumpInsn(Opcodes.IF_ACMPNE, continuationLabelAfterLoadedResult);
    // line of "runBlocking"
    m.visitVarInsn(Opcodes.ALOAD, 4);
    m.visitInsn(Opcodes.ARETURN);

    m.visitLabel(state1);

    m.visitVarInsn(Opcodes.ALOAD, 0);
    m.visitFieldInsn(Opcodes.GETFIELD, "Target", "I$0", "I");
    m.visitVarInsn(Opcodes.ISTORE, 3);

    {
        m.visitVarInsn(Opcodes.ALOAD, 1);
        m.visitInsn(Opcodes.DUP);
        m.visitTypeInsn(Opcodes.INSTANCEOF, "kotlin/Result$Failure");
        final Label label = new Label();
        m.visitJumpInsn(Opcodes.IFEQ, label);
        m.visitTypeInsn(Opcodes.CHECKCAST, "kotlin/Result$Failure");
        m.visitFieldInsn(Opcodes.GETFIELD, "kotlin/Result$Failure", "exception", "Ljava/lang/Throwable");
        m.visitInsn(Opcodes.ATHROW);
        m.visitInsn(Opcodes.POP);
        m.visitLabel(label);
    }
    m.visitVarInsn(Opcodes.ALOAD, 1);
    range2.toInclusive = m.instructions.getLast();
    m.visitLabel(continuationLabelAfterLoadedResult);

    // line after "suspendingFunction"
    m.visitInsn(Opcodes.NOP);
    m.visitInsn(Opcodes.ARETURN);

    m.visitLabel(dflt);
    final Range range0 = new Range();
    range0.fromInclusive = m.instructions.getLast();
    m.visitTypeInsn(Opcodes.NEW, "java/lang/IllegalStateException");
    m.visitInsn(Opcodes.DUP);
    m.visitLdcInsn("call to 'resume' before 'invoke' with coroutine");
    m.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/IllegalStateException", "<init>",
            "(Ljava/lang/String;)V", false);
    m.visitInsn(Opcodes.ATHROW);
    range0.toInclusive = m.instructions.getLast();

    filter.filter(m, context, output);

    assertIgnored(range0, range1, range2);
}

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

License:Open Source License

private static MethodNode createMethod(final int access, final String name, final String descriptor) {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, access, name, descriptor, null, null);

    m.visitVarInsn(Opcodes.ILOAD, 2);/*from  w w w .j  a va  2  s. c  o m*/
    m.visitInsn(Opcodes.ICONST_1);
    m.visitInsn(Opcodes.IAND);
    final Label label = new Label();
    m.visitJumpInsn(Opcodes.IFEQ, label);
    // default argument
    m.visitLdcInsn(Integer.valueOf(42));
    m.visitVarInsn(Opcodes.ISTORE, 1);
    m.visitLabel(label);

    m.visitVarInsn(Opcodes.ALOAD, 0);
    m.visitVarInsn(Opcodes.ILOAD, 1);
    m.visitMethodInsn(Opcodes.INVOKESPECIAL, "Target", "origin", "(I)V", false);
    m.visitInsn(Opcodes.RETURN);

    return m;
}

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

License:Open Source License

/**
 * <pre>/*from   w w  w  . ja v  a 2s .c om*/
 * open class Open {
 *     open fun foo(a: Int = 42) {
 *     }
 * }
 * </pre>
 */
@Test
public void should_filter_open_functions() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, Opcodes.ACC_SYNTHETIC, "foo$default",
            "(LOpen;IILjava/lang/Object;)V", null, null);
    context.classAnnotations.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC);
    {
        m.visitVarInsn(Opcodes.ALOAD, 3);
        final Label label = new Label();
        m.visitJumpInsn(Opcodes.IFNULL, label);
        m.visitTypeInsn(Opcodes.NEW, "java/lang/UnsupportedOperationException");
        m.visitInsn(Opcodes.DUP);
        m.visitLdcInsn("Super calls with default arguments not supported in this target, function: foo");
        m.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/UnsupportedOperationException", "<init>",
                "(Ljava/lang/String;)V", false);
        m.visitInsn(Opcodes.ATHROW);
        m.visitLabel(label);
    }
    {
        m.visitVarInsn(Opcodes.ILOAD, 2);
        m.visitInsn(Opcodes.ICONST_1);
        m.visitInsn(Opcodes.IAND);
        final Label label = new Label();
        m.visitJumpInsn(Opcodes.IFEQ, label);
        // default argument
        m.visitLdcInsn(Integer.valueOf(42));
        m.visitVarInsn(Opcodes.ISTORE, 1);
        m.visitLabel(label);

        m.visitVarInsn(Opcodes.ALOAD, 0);
        m.visitVarInsn(Opcodes.ILOAD, 1);
        m.visitMethodInsn(Opcodes.INVOKESPECIAL, "Open", "foo", "(I)V", false);
        m.visitInsn(Opcodes.RETURN);
    }

    filter.filter(m, context, output);

    assertIgnored(new Range(m.instructions.getFirst(), m.instructions.get(6)),
            new Range(m.instructions.get(11), m.instructions.get(11)));
}

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

License:Open Source License

/**
 * <pre>//from  w w w  .  ja v a 2  s .c  o  m
 * class C(a: Int = 42)
 * </pre>
 */
@Test
public void should_filter_constructors() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, Opcodes.ACC_SYNTHETIC, "<init>",
            "(IILkotlin/jvm/internal/DefaultConstructorMarker;)V", null, null);
    context.classAnnotations.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC);

    m.visitVarInsn(Opcodes.ILOAD, 2);
    m.visitInsn(Opcodes.ICONST_1);
    m.visitInsn(Opcodes.IAND);
    Label label = new Label();
    m.visitJumpInsn(Opcodes.IFEQ, label);
    // default argument
    m.visitLdcInsn(Integer.valueOf(42));
    m.visitVarInsn(Opcodes.ISTORE, 1);
    m.visitLabel(label);
    m.visitVarInsn(Opcodes.ALOAD, 0);
    m.visitVarInsn(Opcodes.ILOAD, 1);
    m.visitMethodInsn(Opcodes.INVOKESPECIAL, "Owner", "<init>", "(I)V", false);
    m.visitInsn(Opcodes.RETURN);

    filter.filter(m, context, output);

    assertIgnored(new Range(m.instructions.get(3), m.instructions.get(3)));
}

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

License:Open Source License

/**
 * <pre>/*from  w w w .  j av  a  2s.  c  o m*/
 * data class C(val x: Long = 42)
 * </pre>
 */
@Test
public void should_filter_methods_with_parameters_that_consume_two_slots() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, Opcodes.ACC_SYNTHETIC, "<init>",
            "(JILkotlin/jvm/internal/DefaultConstructorMarker;)V", null, null);
    context.classAnnotations.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC);

    m.visitVarInsn(Opcodes.ILOAD, 3);
    m.visitInsn(Opcodes.ICONST_1);
    m.visitInsn(Opcodes.IAND);
    final Label label = new Label();
    m.visitJumpInsn(Opcodes.IFEQ, label);
    // default argument
    m.visitLdcInsn(Integer.valueOf(42));
    m.visitVarInsn(Opcodes.ISTORE, 1);
    m.visitLabel(label);
    m.visitVarInsn(Opcodes.ALOAD, 0);
    m.visitVarInsn(Opcodes.ILOAD, 1);
    m.visitMethodInsn(Opcodes.INVOKESPECIAL, "Owner", "<init>", "(J)V", false);
    m.visitInsn(Opcodes.RETURN);

    filter.filter(m, context, output);

    assertIgnored(new Range(m.instructions.get(3), m.instructions.get(3)));
}

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

License:Open Source License

private void createFirstSwitch() {
    final Label h1 = new Label();
    final Label h1_2 = new Label();
    final Label h2 = new Label();
    final Label secondSwitch = new Label();

    m.visitInsn(Opcodes.ICONST_M1);//  w w w .  j  a v a2 s. co  m
    m.visitVarInsn(Opcodes.ISTORE, 2);

    m.visitVarInsn(Opcodes.ALOAD, 1);
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "hashCode", "()I", false);
    m.visitLookupSwitchInsn(secondSwitch, new int[] { 97, 98 }, new Label[] { h1, h2 });
    expectedFromInclusive = m.instructions.getLast();

    m.visitLabel(h1);
    m.visitVarInsn(Opcodes.ALOAD, 1);
    m.visitLdcInsn("a");
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false);
    // if not equal "a", then goto next comparison
    m.visitJumpInsn(Opcodes.IFEQ, h1_2);
    m.visitInsn(Opcodes.ICONST_0);
    m.visitVarInsn(Opcodes.ISTORE, 2);

    // goto secondSwitch
    m.visitJumpInsn(Opcodes.GOTO, secondSwitch);

    m.visitLabel(h1_2);
    m.visitVarInsn(Opcodes.ALOAD, 1);
    m.visitLdcInsn("\0a");
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false);
    // if not equal "\0a", then goto second switch
    m.visitJumpInsn(Opcodes.IFEQ, secondSwitch);
    m.visitInsn(Opcodes.ICONST_1);
    m.visitVarInsn(Opcodes.ISTORE, 2);

    // goto secondSwitch
    m.visitJumpInsn(Opcodes.GOTO, secondSwitch);

    m.visitLabel(h2);
    m.visitVarInsn(Opcodes.ALOAD, 1);
    m.visitLdcInsn("b");
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false);
    // if not equal "b", then goto second switch
    m.visitJumpInsn(Opcodes.IFEQ, secondSwitch);
    m.visitInsn(Opcodes.ICONST_2);
    m.visitVarInsn(Opcodes.ISTORE, 2);

    m.visitLabel(secondSwitch);
    expectedToInclusive = m.instructions.getLast();
    m.visitVarInsn(Opcodes.ILOAD, 2);
}

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

License:Open Source License

private void createTableSwitch() {
    method.visitLineNumber(1001, new Label());
    method.visitVarInsn(Opcodes.ILOAD, 1);
    Label l1 = new Label();
    Label l2 = new Label();
    Label l3 = new Label();
    method.visitTableSwitchInsn(1, 3, l3, new Label[] { l1, l2, l1 });
    method.visitLabel(l1);// w  w w  . j  a  v a2 s .com
    method.visitLineNumber(1002, l1);
    method.visitIntInsn(Opcodes.BIPUSH, 11);
    method.visitVarInsn(Opcodes.ISTORE, 2);
    method.visitLineNumber(1003, new Label());
    Label l5 = new Label();
    method.visitJumpInsn(Opcodes.GOTO, l5);
    method.visitLabel(l2);
    method.visitLineNumber(1004, l2);
    method.visitIntInsn(Opcodes.BIPUSH, 22);
    method.visitVarInsn(Opcodes.ISTORE, 2);
    method.visitLineNumber(1005, new Label());
    method.visitJumpInsn(Opcodes.GOTO, l5);
    method.visitLabel(l3);
    method.visitLineNumber(1006, l3);
    method.visitInsn(Opcodes.ICONST_0);
    method.visitVarInsn(Opcodes.ISTORE, 2);
    method.visitLabel(l5);
    method.visitLineNumber(1007, l5);
    method.visitVarInsn(Opcodes.ILOAD, 2);
    method.visitInsn(Opcodes.IRETURN);
}

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

License:Open Source License

private void createTableSwitchMerge() {
    method.visitLineNumber(1001, new Label());
    method.visitInsn(Opcodes.ICONST_0);// w  w w.j  a  v a 2s.c  om
    method.visitVarInsn(Opcodes.ISTORE, 2);
    method.visitLineNumber(1002, new Label());
    method.visitVarInsn(Opcodes.ILOAD, 1);
    Label l2 = new Label();
    Label l3 = new Label();
    Label l4 = new Label();
    method.visitTableSwitchInsn(1, 3, l4, new Label[] { l2, l3, l2 });
    method.visitLabel(l2);
    method.visitLineNumber(1003, l2);
    method.visitIincInsn(2, 1);
    method.visitLabel(l3);
    method.visitLineNumber(1004, l3);
    method.visitIincInsn(2, 1);
    method.visitLabel(l4);
    method.visitLineNumber(1005, l4);
    method.visitVarInsn(Opcodes.ILOAD, 2);
    method.visitInsn(Opcodes.IRETURN);
}