Example usage for org.objectweb.asm Opcodes INVOKEVIRTUAL

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

Introduction

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

Prototype

int INVOKEVIRTUAL

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

Click Source Link

Usage

From source file:org.glassfish.pfl.tf.tools.enhancer.StaticInitVisitor.java

License:Open Source License

private void generateTraceMsg(MethodVisitor mv, String msg, int num) {
    if (ENABLED && util.getDebug()) {
        final Label start = new Label();
        mv.visitLabel(start);//from   w w  w .ja  v a 2  s. c o m
        mv.visitLineNumber(num, start);
        mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
        mv.visitLdcInsn(msg);
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V");
    }
}

From source file:org.gradle.initialization.ExceptionDecoratingClassGenerator.java

License:Apache License

private <T> Class<? extends T> doGenerate(Class<T> type) {
    ClassWriter visitor = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    String typeName = StringUtils.substringBeforeLast(type.getName(), ".") + ".LocationAware"
            + type.getSimpleName();//from ww w  .j  ava  2 s.  co  m
    Type generatedType = Type.getType("L" + typeName.replaceAll("\\.", "/") + ";");
    Type superclassType = Type.getType(type);

    visitor.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, generatedType.getInternalName(), null,
            superclassType.getInternalName(),
            new String[] { Type.getType(LocationAwareException.class).getInternalName() });

    Type helperType = Type.getType(ExceptionHelper.class);
    Type throwableType = Type.getType(Throwable.class);
    Type scriptSourceType = Type.getType(ScriptSource.class);
    Type integerType = Type.getType(Integer.class);

    // GENERATE private ExceptionHelper helper;
    visitor.visitField(Opcodes.ACC_PRIVATE, "helper", helperType.getDescriptor(), null, null);

    // GENERATE <init>(<type> target, ScriptSource source, Integer lineNumber)

    String methodDescriptor = Type.getMethodDescriptor(Type.VOID_TYPE,
            new Type[] { superclassType, scriptSourceType, integerType });
    MethodVisitor methodVisitor = visitor.visitMethod(Opcodes.ACC_PUBLIC, "<init>", methodDescriptor, null,
            new String[0]);
    methodVisitor.visitCode();

    boolean noArgsConstructor;
    try {
        type.getConstructor(type);
        noArgsConstructor = false;
    } catch (NoSuchMethodException e) {
        try {
            type.getConstructor();
            noArgsConstructor = true;
        } catch (NoSuchMethodException e1) {
            throw new IllegalArgumentException(String.format(
                    "Cannot create subtype for exception '%s'. It needs a zero-args or copy constructor.",
                    type.getName()));
        }
    }

    if (noArgsConstructor) {
        // GENERATE super()
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
        methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, superclassType.getInternalName(), "<init>",
                Type.getMethodDescriptor(Type.VOID_TYPE, new Type[0]));
        // END super()
    } else {
        // GENERATE super(target)
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 1);
        methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, superclassType.getInternalName(), "<init>",
                Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { superclassType }));
        // END super(target)
    }

    // GENERATE helper = new ExceptionHelper(this, target, source, lineNumber)
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);

    methodVisitor.visitTypeInsn(Opcodes.NEW, helperType.getInternalName());
    methodVisitor.visitInsn(Opcodes.DUP);
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 1);
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 2);
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 3);
    methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, helperType.getInternalName(), "<init>",
            Type.getMethodDescriptor(Type.VOID_TYPE,
                    new Type[] { throwableType, throwableType, scriptSourceType, integerType }));

    methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, generatedType.getInternalName(), "helper",
            helperType.getDescriptor());

    // END helper = new ExceptionHelper(target)

    methodVisitor.visitInsn(Opcodes.RETURN);
    methodVisitor.visitMaxs(0, 0);
    methodVisitor.visitEnd();

    // END <init>(<type> target, ScriptSource source, Integer lineNumber)

    for (Method method : ExceptionHelper.class.getDeclaredMethods()) {
        // GENERATE public <type> <method>() { return helper.<method>(); }
        methodDescriptor = Type.getMethodDescriptor(Type.getType(method.getReturnType()), new Type[0]);
        methodVisitor = visitor.visitMethod(Opcodes.ACC_PUBLIC, method.getName(), methodDescriptor, null,
                new String[0]);
        methodVisitor.visitCode();

        methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
        methodVisitor.visitFieldInsn(Opcodes.GETFIELD, generatedType.getInternalName(), "helper",
                helperType.getDescriptor());
        methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, helperType.getInternalName(), method.getName(),
                methodDescriptor);

        methodVisitor.visitInsn(Opcodes.ARETURN);
        methodVisitor.visitMaxs(0, 0);
        methodVisitor.visitEnd();
        // END public <type> <method>() { return helper.<method>(); }
    }

    visitor.visitEnd();

    byte[] bytecode = visitor.toByteArray();
    return (Class<T>) ReflectionUtil.invoke(type.getClassLoader(), "defineClass",
            new Object[] { typeName, bytecode, 0, bytecode.length });
}

From source file:org.hua.ast.visitors.BytecodeGeneratorASTVisitor.java

private void handleBooleanOperator(Expression node, Operator op, Type type) throws ASTVisitorException {
    List<JumpInsnNode> trueList = new ArrayList<JumpInsnNode>();
    System.out.println("***** handle boolean " + op);
    if (type.equals(TypeUtils.STRING_TYPE)) {
        mn.instructions.add(new InsnNode(Opcodes.SWAP));
        JumpInsnNode jmp = null;//from  w w  w. j av  a 2 s. c om
        mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals",
                "(Ljava/lang/Object;)Z", false));
        switch (op) {
        case EQUAL:
            jmp = new JumpInsnNode(Opcodes.IFNE, null);
            break;
        case NOT_EQUAL:
            jmp = new JumpInsnNode(Opcodes.IFEQ, null);
            break;
        default:
            ASTUtils.error(node, "Operator not supported on strings");
            break;
        }
        mn.instructions.add(jmp);
        trueList.add(jmp);
    } else if (type.equals(Type.DOUBLE_TYPE)) {

        // FIXME: add DCMPG instruction
        // FIXME: add a JumpInsnNode with null label based on the operation
        //        IFEQ, IFNE, IFGT, IFGE, IFLT, IFLE
        // FIXME: add the jmp instruction into trueList
        mn.instructions.add(new InsnNode(Opcodes.DCMPG));
        JumpInsnNode jmp = null;
        switch (op) {
        case EQUAL:
            jmp = new JumpInsnNode(Opcodes.IFEQ, null);
            mn.instructions.add(jmp);
            break;
        case NOT_EQUAL:
            jmp = new JumpInsnNode(Opcodes.IFNE, null);
            mn.instructions.add(jmp);
            break;
        case GREATER:
            jmp = new JumpInsnNode(Opcodes.IFGT, null);
            mn.instructions.add(jmp);
            break;
        case GREATER_EQUAL:
            jmp = new JumpInsnNode(Opcodes.IFGE, null);
            mn.instructions.add(jmp);
            break;
        case LESS:
            jmp = new JumpInsnNode(Opcodes.IFLT, null);
            mn.instructions.add(jmp);
            break;
        case LESS_EQUAL:
            jmp = new JumpInsnNode(Opcodes.IFLE, null);
            mn.instructions.add(jmp);
            break;
        }
        trueList.add(jmp);

    } else {
        System.out.println("here");
        JumpInsnNode jmp = null;
        switch (op) {
        case EQUAL:
            jmp = new JumpInsnNode(Opcodes.IF_ICMPEQ, null);
            mn.instructions.add(jmp);
            break;
        case NOT_EQUAL:
            jmp = new JumpInsnNode(Opcodes.IF_ICMPNE, null);
            mn.instructions.add(jmp);
            break;
        case GREATER:
            System.out.println("----- greater");
            jmp = new JumpInsnNode(Opcodes.IF_ICMPGT, null);
            mn.instructions.add(jmp);
            break;
        case GREATER_EQUAL:
            jmp = new JumpInsnNode(Opcodes.IF_ICMPGE, null);
            mn.instructions.add(jmp);
            break;
        case LESS:
            jmp = new JumpInsnNode(Opcodes.IF_ICMPLT, null);
            mn.instructions.add(jmp);
            break;
        case LESS_EQUAL:
            jmp = new JumpInsnNode(Opcodes.IF_ICMPLE, null);
            mn.instructions.add(jmp);
            break;
        default:
            ASTUtils.error(node, "Operator not supported");
            break;
        }
        trueList.add(jmp);
    }
    ASTUtils.setTrueList(node, trueList);
    List<JumpInsnNode> falseList = new ArrayList<JumpInsnNode>();
    JumpInsnNode jmp = new JumpInsnNode(Opcodes.GOTO, null);
    mn.instructions.add(jmp);
    falseList.add(jmp);
    ASTUtils.setFalseList(node, falseList);
}

From source file:org.hua.ast.visitors.BytecodeGeneratorASTVisitor.java

/**
 * Assumes top of stack contains two strings
 *//*from w w  w.j av  a 2 s .  c  o  m*/
private void handleStringOperator(ASTNode node, Operator op) throws ASTVisitorException {
    if (op.equals(Operator.PLUS)) {
        mn.instructions.add(new TypeInsnNode(Opcodes.NEW, "java/lang/StringBuilder"));
        mn.instructions.add(new InsnNode(Opcodes.DUP));
        mn.instructions.add(
                new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "()V", false));
        mn.instructions.add(new InsnNode(Opcodes.SWAP));
        mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
                "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false));
        mn.instructions.add(new InsnNode(Opcodes.SWAP));
        mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
                "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false));
        mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "toString",
                "()Ljava/lang/String;", false));
    } else if (op.isRelational()) {
        LabelNode trueLabelNode = new LabelNode();
        switch (op) {
        case EQUAL:
            mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals",
                    "(Ljava/lang/Object;)Z", false));
            mn.instructions.add(new JumpInsnNode(Opcodes.IFNE, trueLabelNode));
            break;
        case NOT_EQUAL:
            mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals",
                    "(Ljava/lang/Object;)Z", false));
            mn.instructions.add(new JumpInsnNode(Opcodes.IFEQ, trueLabelNode));
            break;
        default:
            ASTUtils.error(node, "Operator not supported on strings");
            break;
        }
        mn.instructions.add(new InsnNode(Opcodes.ICONST_0));
        LabelNode endLabelNode = new LabelNode();
        mn.instructions.add(new JumpInsnNode(Opcodes.GOTO, endLabelNode));
        mn.instructions.add(trueLabelNode);
        mn.instructions.add(new InsnNode(Opcodes.ICONST_1));
        mn.instructions.add(endLabelNode);
    } else {
        ASTUtils.error(node, "Operator not recognized");
    }
}

From source file:org.hua.ast.visitors.BytecodeGeneratorASTVisitor.java

@Override
public void visit(AccessorExpression node) throws ASTVisitorException {
    node.getExpression().accept(this);
    //function access
    if (node.getExpressions() != null) {

        node.getExpressions().accept(this);

        //if expressionS length is 0, no args privided
        Type returnType;//from  w  w  w.  j  a v a  2  s  . c o m
        Type exprClass = ASTUtils.getSafeType(node.getExpression());
        SymTable<SymTableEntry> sTable = ASTUtils.getSafeEnv(node);
        SymTableEntry lookup = sTable.lookup(node.getIdentifier());
        System.out.println(
                "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$4 " + node.getIdentifier());
        if (lookup != null) {
            mn.instructions.add(
                    new MethodInsnNode(Opcodes.INVOKEVIRTUAL, exprClass.getInternalName(), node.getIdentifier(),
                            Type.getMethodDescriptor(lookup.getType(), lookup.getParametersTypes()), false));
        } else {
            Map<Type, SymTable<SymTableEntry>> classes = Registry.getInstance().getClasses();
            Iterator<Map.Entry<Type, SymTable<SymTableEntry>>> entries = classes.entrySet().iterator();
            while (entries.hasNext()) {
                Map.Entry<Type, SymTable<SymTableEntry>> entry = entries.next();
                if (entry.getValue().lookup(node.getIdentifier()) != null) {
                    SymTableEntry lookup1 = entry.getValue().lookup(node.getIdentifier());
                    System.out.println("entry key: " + entry.getKey().getDescriptor());
                    mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL,
                            entry.getKey().getInternalName(), node.getIdentifier(),
                            Type.getMethodDescriptor(lookup1.getType(), lookup1.getParametersTypes()), false));
                    break;
                }
            }
        }
    }
    //field access
    else {
        System.out.println("+++++++++++++++++++++++++> HEY " + node.getIdentifier());
        if (node.getExpression().getClass() != IdentifierExpression.class && previousIsIdentifier) {
            System.out.println("+++++++++++++++++++++++++++++++++++++++++++---> " + node.getIdentifier());
            mn.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, cn.name, node.getIdentifier(),
                    ASTUtils.getSafeType(node).getDescriptor()));
        } else {
            mn.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, cn.name, node.getIdentifier(),
                    ASTUtils.getSafeType(node).getDescriptor()));
        }

    }
}

From source file:org.hua.ast.visitors.BytecodeGeneratorASTVisitor.java

@Override
public void visit(IdentifierExpression node) throws ASTVisitorException {
    previousIsIdentifier = false;//from w  w  w .j av a  2 s  . c o m
    if (node.getExpressions() != null) {
        node.getExpressions().accept(this);
        SymTable<SymTableEntry> symbols = Registry.getInstance()
                .getExistingClass(Type.getType("Lorg/hua/customclasses/" + cn.name + ";"));
        SymTableEntry sEntry = symbols.lookup(node.getIdentifier());
        if (sEntry != null) {
            mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL,
                    Type.getType("Lorg/hua/customclasses/" + cn.name + ";").getInternalName(),
                    node.getIdentifier(), Type.getMethodDescriptor(Type.VOID_TYPE, Type.INT_TYPE), false));
        } else {
            //search all classes
            //if the function is static and defined in another class, ok
            //else error
            String nodeId = node.getIdentifier();
            boolean foundStaticOtherClass = false;
            String classFound;
            Map<Type, SymTable<SymTableEntry>> classes = Registry.getInstance().getClasses();
            Iterator<Map.Entry<Type, SymTable<SymTableEntry>>> entries = classes.entrySet().iterator();
            while (entries.hasNext()) {
                Map.Entry<Type, SymTable<SymTableEntry>> entry = entries.next();
                if (entry.getValue().lookup(nodeId) != null) {
                    if (entry.getValue().lookup(nodeId).isIsStatic()) {
                        foundStaticOtherClass = true;
                        classFound = entry.getKey().toString();
                        break;
                    }
                }
            }
            if (!foundStaticOtherClass) {
                ASTUtils.error(node, "This static(?) method could not be found");
            }
        }
    } else {

        Type type = ASTUtils.getSafeType(node);
        SymTable<SymTableEntry> symbols = Registry.getInstance()
                .getExistingClass(Type.getType("Lorg/hua/customclasses/" + cn.name + ";"));
        SymTableEntry csEntry = symbols.lookup(node.getIdentifier());
        //i think this is useless, because fields are not seperate identifier, but string ids in accessorExpressions
        if (csEntry != null) {

            mn.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, cn.name, node.getIdentifier(),
                    csEntry.getType().getDescriptor()));
            return;
        }
        SymTable<SymTableEntry> sTable = ASTUtils.getSafeEnv(node);
        SymTableEntry sEntry = sTable.lookup(node.getIdentifier());

        previousIsIdentifier = true;
        mn.instructions.add(new VarInsnNode(type.getOpcode(Opcodes.ILOAD), sEntry.getIndex()));
        System.out.println(
                "&&&&&&&&&&&&&&&&&&&&&&&&&&&& INDEX: " + sEntry.getIndex() + " id: " + node.getIdentifier());
    }
}

From source file:org.hua.ast.visitors.BytecodeGeneratorASTVisitor.java

@Override
public void visit(WriteStatement node) throws ASTVisitorException {

    Type type = ASTUtils.getSafeType(node.getExpression());
    LocalIndexPool lip = ASTUtils.getSafeLocalIndexPool(node);
    int li = lip.getLocalIndex(type);
    mn.instructions//from  w w w . j ava2 s.  c  om
            .add(new FieldInsnNode(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"));
    System.out.println(
            "***************************************************************-------------------------------------------------------------- "
                    + li);
    mn.instructions.add(new VarInsnNode(type.getOpcode(Opcodes.ILOAD), 0));
    node.getExpression().accept(this);
    mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "print",
            Type.getMethodType(Type.VOID_TYPE, type).toString(), false));
    lip.freeLocalIndex(li, type);
}

From source file:org.hua.ast.visitors.BytecodeGeneratorASTVisitor.java

@Override
public void visit(NewIdentifierExpression node) throws ASTVisitorException {
    if (node.getExpressions() != null) {
        node.getExpressions().accept(this);
    }/*from w w w.  j  av  a  2s . c  o m*/
    mn.instructions.add(new TypeInsnNode(Opcodes.NEW, node.getIdentifier()));
    mn.instructions.add(new InsnNode(Opcodes.DUP));
    //@TODO: fix calling parameters
    if (node.getExpressions() != null) {
        if (node.getExpressions().getExpressions().isEmpty() && Registry.getInstance()
                .classExists(Type.getType("Lorg/hua/customclasses/" + node.getIdentifier() + ";"))) {
            System.out.println("222222222222222222222222222222222222222222 "
                    + ASTUtils.getSafeType(node).getInternalName());
            mn.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL,
                    ASTUtils.getSafeType(node).getInternalName(), "<init>", "()V", false));
        } else //get parameter types and then give that as the signature
        if (Registry.getInstance()
                .classExists(Type.getType("Lorg/hua/customclasses/" + node.getIdentifier() + ";"))) {
            SymTable<SymTableEntry> existingClass = Registry.getInstance()
                    .getExistingClass(Type.getType("Lorg/hua/customclasses/" + node.getIdentifier() + ";"));
            SymTableEntry lookup = existingClass.lookup(node.getIdentifier());
            if (lookup != null) {
                Type[] types = lookup.getParametersTypes();
                mn.instructions.add(
                        new MethodInsnNode(Opcodes.INVOKEVIRTUAL, ASTUtils.getSafeType(node).getInternalName(),
                                node.getIdentifier(), Type.getMethodDescriptor(Type.VOID_TYPE, types), false));
            } else {
                ASTUtils.error(node, "Constructor not found");
            }
        } else {
            ASTUtils.error(node, "Problem with called constructor");
        }
    }
    LocalIndexPool pool = ASTUtils.getSafeLocalIndexPool(fd);
    int localIndex = pool.getLocalIndex();
    System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
            + localIndex);
    mn.instructions.add(new VarInsnNode(Opcodes.ASTORE, localIndex));
}

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

License:Open Source License

@Test
public void nextIsInvoke() {
    m.visitInsn(Opcodes.NOP);/* w w  w.  j  a  v a  2s  .  c om*/
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "owner", "name", "()V", false);

    // should set cursor to null when opcode mismatch
    matcher.cursor = m.instructions.getFirst();
    matcher.nextIsInvoke(Opcodes.INVOKESTATIC, "owner", "name", "()V");
    assertNull(matcher.cursor);

    // should set cursor to null when owner mismatch
    matcher.cursor = m.instructions.getFirst();
    matcher.nextIsInvoke(Opcodes.INVOKEVIRTUAL, "another_owner", "name", "()V");
    assertNull(matcher.cursor);

    // should set cursor to null when name mismatch
    matcher.cursor = m.instructions.getFirst();
    matcher.nextIsInvoke(Opcodes.INVOKEVIRTUAL, "owner", "another_name", "()V");
    assertNull(matcher.cursor);

    // should set cursor to null when descriptor mismatch
    matcher.cursor = m.instructions.getFirst();
    matcher.nextIsInvoke(Opcodes.INVOKEVIRTUAL, "owner", "name", "(Lanother_descriptor;)V");
    assertNull(matcher.cursor);

    // should set cursor to next instruction when match
    matcher.cursor = m.instructions.getFirst();
    matcher.nextIsInvoke(Opcodes.INVOKEVIRTUAL, "owner", "name", "()V");
    assertSame(m.instructions.getLast(), matcher.cursor);

    // should not do anything when cursor is null
    matcher.cursor = null;
    matcher.nextIsInvoke(Opcodes.INVOKEVIRTUAL, "owner", "name", "()V");
}

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);//from  w  ww .j  a va2 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);
}