Example usage for org.objectweb.asm Opcodes ACC_STATIC

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

Introduction

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

Prototype

int ACC_STATIC

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

Click Source Link

Usage

From source file:org.jacoco.core.internal.analysis.dua.DuaMethodAnalyzer.java

License:Open Source License

/**
 * New Method analyzer for the given probe data.
 * /*from  w  w w  . j  ava  2  s  . com*/
 * @param methodId
 * @param className
 * 
 * @param name
 *            method name
 * @param desc
 *            description of the method
 * @param signature
 *            optional parameterized signature
 * 
 * @param probes
 *            recorded probe date of the containing class or
 *            <code>null</code> if the class is not executed at all
 * @param methodProbeIndex
 */
public DuaMethodAnalyzer(final int methodId, final String className, final MethodNode methodNode,
        final boolean[] probes, final int methodProbeIndex) {
    super();
    this.className = className;
    this.methodNode = methodNode;
    this.probes = probes;
    this.methodProbeIndex = methodProbeIndex;
    this.coverage = new DuaMethodCoverage(methodId, methodNode.name, methodNode.desc, methodNode.signature,
            ((methodNode.access & Opcodes.ACC_STATIC) != 0));
}

From source file:org.jacoco.core.internal.analysis.dua.MethodAnalyzer.java

License:Open Source License

/**
 * New Method analyzer for the given probe data.
 * /*  w  w w .  j  a  v a  2 s .co m*/
 * @param methodId
 *            method Id
 * @param className
 *            class Name
 * @param methodNode
 *            method node
 * 
 * @param probes
 *            recorded probe date of the containing class or
 *            <code>null</code> if the class is not executed at all
 * @param methodProbeIndex
 */
public MethodAnalyzer(final int methodId, final String className, final MethodNode methodNode,
        final boolean[] probes, final int methodProbeIndex) {
    super();
    this.className = className;
    this.methodNode = methodNode;
    this.probes = probes;
    this.methodProbeIndex = methodProbeIndex;
    this.coverage = new DuaMethodCoverage(methodId, methodNode.name, methodNode.desc, methodNode.signature,
            ((methodNode.access & Opcodes.ACC_STATIC) != 0));
}

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

License:Open Source License

/**
 * <pre>/*from  w w  w  .  java  2s.  c o  m*/
 *     suspend fun example() {
 *         suspendingFunction()
 *         nop()
 *     }
 * </pre>
 */
@Test
public void should_filter_suspending_functions() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, Opcodes.ACC_STATIC, "example",
            "(Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", null, null);
    context.classAnnotations.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC);

    final int continuationArgumentIndex = 0;
    final int continuationIndex = 2;

    m.visitVarInsn(Opcodes.ALOAD, continuationArgumentIndex);
    final Range range1 = new Range();
    range1.fromInclusive = m.instructions.getLast();
    m.visitTypeInsn(Opcodes.INSTANCEOF, "ExampleKt$example$1");
    final Label createStateInstance = new Label();
    m.visitJumpInsn(Opcodes.IFEQ, createStateInstance);

    m.visitVarInsn(Opcodes.ALOAD, continuationArgumentIndex);
    m.visitTypeInsn(Opcodes.CHECKCAST, "ExampleKt$example$1");
    m.visitVarInsn(Opcodes.ASTORE, continuationIndex);

    m.visitVarInsn(Opcodes.ALOAD, continuationIndex);
    m.visitFieldInsn(Opcodes.GETFIELD, "ExampleKt$example$1", "label", "I");

    m.visitLdcInsn(Integer.valueOf(Integer.MIN_VALUE));
    m.visitInsn(Opcodes.IAND);
    m.visitJumpInsn(Opcodes.IFEQ, createStateInstance);

    m.visitVarInsn(Opcodes.ALOAD, continuationIndex);
    m.visitInsn(Opcodes.DUP);
    m.visitFieldInsn(Opcodes.GETFIELD, "ExampleKt$example$1", "label", "I");

    m.visitLdcInsn(Integer.valueOf(Integer.MIN_VALUE));
    m.visitInsn(Opcodes.ISUB);
    m.visitFieldInsn(Opcodes.PUTFIELD, "ExampleKt$example$1", "label", "I");

    final Label afterCoroutineStateCreated = new Label();
    m.visitJumpInsn(Opcodes.GOTO, afterCoroutineStateCreated);

    m.visitLabel(createStateInstance);

    m.visitTypeInsn(Opcodes.NEW, "ExampleKt$example$1");
    m.visitInsn(Opcodes.DUP);
    m.visitVarInsn(Opcodes.ALOAD, continuationArgumentIndex);
    m.visitMethodInsn(Opcodes.INVOKESPECIAL, "ExampleKt$example$1", "<init>",
            "(Lkotlin/coroutines/Continuation;)V", false);

    m.visitVarInsn(Opcodes.ASTORE, continuationIndex);

    m.visitLabel(afterCoroutineStateCreated);

    m.visitVarInsn(Opcodes.ALOAD, continuationIndex);
    m.visitFieldInsn(Opcodes.GETFIELD, "ExampleKt$example$1", "result", "Ljava/lang/Object;");
    m.visitVarInsn(Opcodes.ASTORE, 1);

    m.visitMethodInsn(Opcodes.INVOKESTATIC, "kotlin/coroutines/intrinsics/IntrinsicsKt",
            "getCOROUTINE_SUSPENDED", "()Ljava/lang/Object;", false);

    // line of "fun"
    m.visitVarInsn(Opcodes.ASTORE, 3);

    m.visitVarInsn(Opcodes.ALOAD, continuationIndex);
    m.visitFieldInsn(Opcodes.GETFIELD, "ExampleKt$example$1", "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 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, 3);
    final Label continuationLabelAfterLoadedResult = new Label();
    m.visitJumpInsn(Opcodes.IF_ACMPNE, continuationLabelAfterLoadedResult);
    // line of "fun"
    m.visitVarInsn(Opcodes.ALOAD, 3);
    m.visitInsn(Opcodes.ARETURN);

    m.visitLabel(state1);

    {
        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.SyntheticFilterTest.java

License:Open Source License

@Test
public void should_not_filter_synthetic_methods_whose_last_argument_is_kotlin_coroutine_continuation() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION,
            Opcodes.ACC_SYNTHETIC | Opcodes.ACC_STATIC, "example",
            "(Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", null, null);
    context.classAnnotations.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC);
    m.visitInsn(Opcodes.NOP);/*from   www. j ava 2s  . c om*/

    filter.filter(m, context, output);

    assertIgnored();
}

From source file:org.jacoco.core.internal.instr.CondyProbeArrayStrategyTest.java

License:Open Source License

@Test
public void should_add_bootstrap_method() {
    final ClassNode c = new ClassNode();
    strategy.addMembers(c, 1);/*www  . j  a  va  2 s  .  co  m*/

    assertEquals(1, c.methods.size());

    final MethodNode m = c.methods.get(0);
    assertEquals(Opcodes.ACC_SYNTHETIC | Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, m.access);
    assertEquals("$jacocoInit", m.name);
    assertEquals("(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;)[Z", m.desc);

    assertEquals(4, m.maxStack);
    assertEquals(3, m.maxLocals);
}

From source file:org.jacoco.core.internal.instr.FrameTracker.java

License:Open Source License

public FrameTracker(final String owner, final int access, final String name, final String desc,
        final MethodVisitor mv) {
    super(Opcodes.ASM4, mv);
    this.owner = owner;
    local = new Object[8];
    localSize = 0;//ww  w .j a v a2s .  c  o  m
    stack = new Object[8];
    stackSize = 0;

    if ((access & Opcodes.ACC_STATIC) == 0) {
        if ("<init>".equals(name)) {
            set(localSize, Opcodes.UNINITIALIZED_THIS);
        } else {
            set(localSize, owner);
        }
    }
    for (final Type t : Type.getArgumentTypes(desc)) {
        set(localSize, t);
    }

}

From source file:org.jacoco.core.internal.instr.FrameTrackerTest.java

License:Open Source License

@Test
public void testArgumentsStatic() {
    FrameBuilder expectedFrame = new FrameBuilder();
    testArguments(Opcodes.ACC_STATIC, "test", "()V", expectedFrame);
}

From source file:org.jacoco.core.internal.instr.FrameTrackerTest.java

License:Open Source License

@Test
public void testArgumentsStaticIJZ() {
    FrameBuilder expectedFrame = new FrameBuilder();
    expectedFrame.locals(INTEGER, LONG, INTEGER);
    testArguments(Opcodes.ACC_STATIC, "test", "(IJZ)V", expectedFrame);
}

From source file:org.jacoco.core.internal.instr.FrameTrackerTest.java

License:Open Source License

@Test
public void testArgumentsStaticLArr() {
    FrameBuilder expectedFrame = new FrameBuilder();
    expectedFrame.locals("Foo", "[[S");
    testArguments(Opcodes.ACC_STATIC, "test", "(LFoo;[[S)V", expectedFrame);
}

From source file:org.jacoco.core.internal.instr.ProbeArrayStrategyFactoryTest.java

License:Open Source License

private IProbeArrayStrategy test(int version, int access, boolean clinit, boolean method,
        boolean abstractMethod) {
    final ClassWriter writer = new ClassWriter(0);
    writer.visit(version, access, "Foo", "java/lang/Object", null, null);
    if (clinit) {
        final MethodVisitor mv = writer.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "<clinit>", "()V",
                null, null);//from  w  w  w. j  ava2s  . co m
        mv.visitCode();
        mv.visitInsn(Opcodes.RETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    if (method) {
        final MethodVisitor mv = writer.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "doit", "()V",
                null, null);
        mv.visitCode();
        mv.visitInsn(Opcodes.RETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    if (abstractMethod) {
        final MethodVisitor mv = writer.visitMethod(Opcodes.ACC_ABSTRACT, "foo", "()V", null, null);
        mv.visitEnd();
    }
    writer.visitEnd();

    final IProbeArrayStrategy strategy = ProbeArrayStrategyFactory.createFor(0,
            new ClassReader(writer.toByteArray()), generator);

    strategy.addMembers(cv, 123);
    return strategy;
}