Example usage for org.objectweb.asm Opcodes INVOKEINTERFACE

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

Introduction

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

Prototype

int INVOKEINTERFACE

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

Click Source Link

Usage

From source file:org.formulacompiler.compiler.internal.bytecode.SubSectionLazyGetterCompiler.java

License:Open Source License

@Override
protected void compileBody() throws CompilerException {
    final SubSectionCompiler sub = this.sub;
    final GeneratorAdapter mv = mv();

    // if (this.field == null) {
    final Label alreadySet = mv.newLabel();
    mv.loadThis();//w w w  .  j  a v a  2s  . co m
    mv.getField(section().classType(), sub.getterName(), sub.arrayType());
    mv.ifNonNull(alreadySet);

    // ~ final DetailInput[] ds = this.inputs.getarray();
    final CallFrame inputCall = sub.model().getCallChainToCall();
    final Class inputContainerClass = inputCall.getMethod().getReturnType();
    final Type inputContainerType = Type.getType(inputContainerClass);
    final int l_ds = mv.newLocal(inputContainerType);
    compileInputGetterCall(inputCall);
    mv.storeLocal(l_ds);

    // ~ if (ds != null) {
    final Label isNull = mv.newLabel();
    mv.loadLocal(l_ds);
    mv.ifNull(isNull);

    final int l_di;
    if (inputContainerClass.isArray()) {
        l_di = compileInitFromArray(sub, mv, l_ds);
    } else if (Collection.class.isAssignableFrom(inputContainerClass)) {
        l_di = compileInitFromCollection(sub, mv, l_ds);
    } else if (Iterable.class.isAssignableFrom(inputContainerClass)) {
        final int l_it = mv.newLocal(ITERATOR_INTF);
        mv.loadLocal(l_ds);
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, ITERABLE_INTF.getInternalName(), "iterator",
                "()" + ITERATOR_INTF.getDescriptor());
        mv.storeLocal(l_it);
        l_di = compileInitFromIterator(sub, mv, l_it);
    } else if (Iterator.class.isAssignableFrom(inputContainerClass)) {
        l_di = compileInitFromIterator(sub, mv, l_ds);
    } else {
        throw new CompilerException.UnsupportedDataType("The return type of '" + inputCall.getMethod()
                + "' is not supported as input to a repeating section.");
    }

    // ~ ~ this.field = di;
    mv.loadThis();
    mv.loadLocal(l_di);
    mv.putField(section().classType(), sub.getterName(), sub.arrayType());

    // ~ } else {
    mv.goTo(alreadySet);
    mv.mark(isNull);

    // ~ ~ this.field = new DetailPrototype[ 0 ];
    mv.loadThis();
    mv.push(0);
    mv.newArray(sub.classType());
    mv.putField(section().classType(), sub.getterName(), sub.arrayType());

    // ~ }
    // }
    mv.mark(alreadySet);

    // return this.field;
    mv.loadThis();
    mv.getField(section().classType(), sub.getterName(), sub.arrayType());
    mv.visitInsn(Opcodes.ARETURN);
}

From source file:org.formulacompiler.compiler.internal.bytecode.SubSectionLazyGetterCompiler.java

License:Open Source License

private int compileInitFromCollection(final SubSectionCompiler sub, final GeneratorAdapter mv, final int l_dc) {
    final String n_iter = ITERATOR_INTF.getInternalName();
    final String n_coll = COLLECTION_INTF.getInternalName();

    // final int dl = dc.size();
    final int l_dl = mv.newLocal(Type.INT_TYPE);
    mv.loadLocal(l_dc);/*w ww. ja v  a2s  . c o  m*/
    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, n_coll, "size", "()I");
    mv.storeLocal(l_dl);

    // final Iterator<DetailInput> ds = dc.iterator();
    final int l_ds = mv.newLocal(ITERATOR_INTF);
    mv.loadLocal(l_dc);
    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, n_coll, "iterator", "()" + ITERATOR_INTF.getDescriptor());
    mv.storeLocal(l_ds);

    // DetailImpl[] di = new DetailPrototype[ dl ];
    final int l_di = mv.newLocal(sub.arrayType());
    mv.loadLocal(l_dl);
    mv.newArray(sub.classType());
    mv.storeLocal(l_di);

    // for (int i = 0; i < dl; i++) {
    final int l_i = mv.newLocal(Type.INT_TYPE);
    final Label next = mv.newLabel();
    mv.push(0);
    mv.storeLocal(l_i);
    mv.goTo(next);
    final Label again = mv.mark();

    // ~ di[ i ] = new DetailPrototype( ds.next(), this );
    mv.loadLocal(l_di);
    mv.loadLocal(l_i);
    mv.newInstance(sub.classType());
    mv.dup();
    mv.loadLocal(l_ds);
    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, n_iter, "next", "()Ljava/lang/Object;");
    mv.checkCast(sub.inputType());
    final IndexCompiler ic = sub.isComputationListenerEnabled() ? new IndexCompiler(l_i) : null;
    compileInit(mv, sub, ic);
    mv.arrayStore(sub.classType());

    // }
    mv.iinc(l_i, 1);
    mv.mark(next);
    mv.loadLocal(l_i);
    mv.loadLocal(l_dl);
    mv.ifCmp(Type.INT_TYPE, mv.LT, again);

    return l_di;
}

From source file:org.formulacompiler.compiler.internal.bytecode.SubSectionLazyGetterCompiler.java

License:Open Source License

private int compileInitFromIterator(final SubSectionCompiler sub, final GeneratorAdapter mv, final int l_ds) {
    final String n_iter = ITERATOR_INTF.getInternalName();
    final String n_coll = COLLECTION_INTF.getInternalName();
    final String n_arraylist = ARRAYLIST_CLASS.getInternalName();

    // final Collection<DetailPrototype> coll = new ArrayList<DetailPrototype>();
    final int l_coll = mv.newLocal(ARRAYLIST_CLASS);
    mv.newInstance(ARRAYLIST_CLASS);//w  w w . j a v a 2s . c  o  m
    mv.dup();
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, n_arraylist, "<init>", "()V");
    mv.storeLocal(l_coll);

    final IndexCompiler ic;
    if (sub.isComputationListenerEnabled()) {
        final int l_i = mv.newLocal(Type.INT_TYPE);
        mv.push(0);
        mv.storeLocal(l_i);
        ic = new IndexCompiler(l_i);
    } else
        ic = null;

    // while (ds.hasNext()) {
    final Label next = mv.newLabel();
    mv.goTo(next);
    final Label again = mv.mark();

    // ~ coll.add( new DetailPrototype( ds.next(), this ) );
    mv.loadLocal(l_coll);
    mv.newInstance(sub.classType());
    mv.dup();
    mv.loadLocal(l_ds);
    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, n_iter, "next", "()Ljava/lang/Object;");
    mv.checkCast(sub.inputType());
    compileInit(mv, sub, ic);
    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, n_coll, "add", "(Ljava/lang/Object;)Z");
    mv.pop();

    // index++;
    if (ic != null)
        ic.compileInc(mv);

    // }
    mv.mark(next);
    mv.loadLocal(l_ds);
    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, n_iter, "hasNext", "()Z");
    mv.ifZCmp(mv.NE, again);

    // final DetailPrototype[] di = coll.toArray( new DetailPrototype[ coll.size() ] );
    final int l_di = mv.newLocal(sub.arrayType());
    mv.loadLocal(l_coll);
    mv.loadLocal(l_coll);
    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, n_coll, "size", "()I");
    mv.newArray(sub.classType());
    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, n_coll, "toArray", "([Ljava/lang/Object;)[Ljava/lang/Object;");
    mv.checkCast(sub.arrayType());
    mv.storeLocal(l_di);

    return l_di;
}

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

License:Open Source License

@Override
public void visitCode() {
    if (SHORT_FORM) {
        super.visitCode();
        mv.visitLdcInsn(Type.getType("L" + ecd.getClassName() + ";"));
        Type mmrType = Type.getType(MethodMonitorRegistry.class);
        String mdesc = "(Ljava/lang/Class;)V";
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, mmrType.getInternalName(), "registerClass", mdesc);
    } else {/*from   www .  ja v  a2s . co  m*/
        int line = 1;
        util.info(2, "StaticInitVisitor.visitCode");
        super.visitCode();

        Label start = new Label();
        Label end = new Label();

        mv.visitLabel(start);

        LocalVariableNode thisClass = defineLocal(mv, "thisClass", Class.class, start, end);
        LocalVariableNode mnameList = defineLocal(mv, "mnameList", List.class, start, end);
        LocalVariableNode holderMap = defineLocal(mv, "holderMap", Map.class, start, end);

        generateTraceMsg(mv, "initialize the holders", line++);
        for (String str : ecd.getAnnotationToHolderName().values()) {
            generateTraceMsg(mv, "Generating to initialize holder " + str, line++);
            util.info(2, "Generating code to initialize holder " + str);
            util.newWithSimpleConstructor(mv, SynchronizedHolder.class);
            mv.visitFieldInsn(Opcodes.PUTSTATIC, ecd.getClassName(), str,
                    Type.getDescriptor(SynchronizedHolder.class));
        }

        generateTraceMsg(mv, "Store the Class of this class", line++);
        mv.visitLdcInsn(Type.getType("L" + ecd.getClassName() + ";"));
        mv.visitVarInsn(Opcodes.ASTORE, thisClass.index);

        generateTraceMsg(mv, "Create list of method names", line++);
        util.newWithSimpleConstructor(mv, ArrayList.class);
        mv.visitVarInsn(Opcodes.ASTORE, mnameList.index);

        for (String str : ecd.getMethodNames()) {
            util.info(2, "Generating code to add " + str + " to methodNames");
            mv.visitVarInsn(Opcodes.ALOAD, mnameList.index);
            mv.visitLdcInsn(str);
            mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z");
            mv.visitInsn(Opcodes.POP);
        }

        generateTraceMsg(mv, "create map from MM annotation class to Holder and init", line++);
        util.newWithSimpleConstructor(mv, HashMap.class);
        mv.visitVarInsn(Opcodes.ASTORE, holderMap.index);

        for (Map.Entry<String, String> entry : ecd.getAnnotationToHolderName().entrySet()) {

            util.info(2,
                    "Generating code to put " + entry.getKey() + "=>" + entry.getValue() + " into holderMap");

            mv.visitVarInsn(Opcodes.ALOAD, holderMap.index);

            Type annoType = Type.getType("L" + entry.getKey() + ";");
            mv.visitLdcInsn(annoType);

            mv.visitFieldInsn(Opcodes.GETSTATIC, ecd.getClassName(), entry.getValue(),
                    Type.getDescriptor(SynchronizedHolder.class));

            mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Map", "put",
                    "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");

            mv.visitInsn(Opcodes.POP);
        }

        generateTraceMsg(mv, "register with MethodMonitorRegistry", line++);
        util.info(2, "Generating code call MethodMonitorRegistry.registerClass");
        mv.visitVarInsn(Opcodes.ALOAD, thisClass.index);
        mv.visitVarInsn(Opcodes.ALOAD, mnameList.index);
        mv.visitVarInsn(Opcodes.ALOAD, holderMap.index);

        Type mmrType = Type.getType(MethodMonitorRegistry.class);
        String mdesc = "(Ljava/lang/Class;Ljava/util/List;Ljava/util/Map;)V";
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, mmrType.getInternalName(), "registerClass", mdesc);

        mv.visitLabel(end);

        thisClass.accept(mv);
        mnameList.accept(mv);
        holderMap.accept(mv);
    }
}

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

License:Open Source License

/**
 * <pre>/* w  ww  . j  a  v a 2  s  . com*/
 *   try (r = new ...) {
 *     ...
 *   }
 * </pre>
 */
@Test
public void without_null_check() {
    final Range range1 = new Range();
    final Range range2 = new Range();

    final Label e = new Label();
    final Label t = new Label();

    final Label handler = new Label();
    m.visitTryCatchBlock(handler, handler, handler, "java/lang/Throwable");

    m.visitInsn(Opcodes.NOP);

    m.visitVarInsn(Opcodes.ALOAD, 0);
    range1.fromInclusive = m.instructions.getLast();
    m.visitMethodInsn(Opcodes.INVOKEINTERFACE, "Resource", "close", "()V", false);
    m.visitJumpInsn(Opcodes.GOTO, e);
    range1.toInclusive = m.instructions.getLast();

    m.visitLabel(handler);
    range2.fromInclusive = m.instructions.getLast();
    m.visitVarInsn(Opcodes.ASTORE, 1);
    m.visitVarInsn(Opcodes.ALOAD, 0);
    m.visitMethodInsn(Opcodes.INVOKEINTERFACE, "Resource", "close", "()V", false);
    m.visitJumpInsn(Opcodes.GOTO, t);

    m.visitVarInsn(Opcodes.ASTORE, 2);
    m.visitVarInsn(Opcodes.ALOAD, 1);
    m.visitVarInsn(Opcodes.ALOAD, 2);
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Throwable", "addSuppressed", "(Ljava/lang/Throwable;)V",
            false);
    m.visitLabel(t);
    m.visitVarInsn(Opcodes.ALOAD, 1);
    m.visitInsn(Opcodes.ATHROW);
    range2.toInclusive = m.instructions.getLast();

    m.visitLabel(e);

    filter.filter(m, context, output);

    assertIgnored(range1, range2);
}

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

License:Open Source License

/**
 * <pre>//from  ww w. j ava 2 s  .  c o  m
 *   try (r = open()) {
 *     ...
 *   }
 * </pre>
 */
@Test
public void with_null_check() {
    final Range range1 = new Range();
    final Range range2 = new Range();

    final Label e = new Label();
    final Label t = new Label();

    final Label handler = new Label();
    m.visitTryCatchBlock(handler, handler, handler, "java/lang/Throwable");

    m.visitInsn(Opcodes.NOP);

    m.visitVarInsn(Opcodes.ALOAD, 0);
    range1.fromInclusive = m.instructions.getLast();
    m.visitJumpInsn(Opcodes.IFNULL, e);
    m.visitVarInsn(Opcodes.ALOAD, 0);
    m.visitMethodInsn(Opcodes.INVOKEINTERFACE, "Resource", "close", "()V", false);
    m.visitJumpInsn(Opcodes.GOTO, e);
    range1.toInclusive = m.instructions.getLast();

    m.visitLabel(handler);
    range2.fromInclusive = m.instructions.getLast();
    m.visitVarInsn(Opcodes.ASTORE, 1);
    m.visitVarInsn(Opcodes.ALOAD, 0);
    m.visitJumpInsn(Opcodes.IFNULL, t);
    m.visitVarInsn(Opcodes.ALOAD, 0);
    m.visitMethodInsn(Opcodes.INVOKEINTERFACE, "Resource", "close", "()V", false);
    m.visitJumpInsn(Opcodes.GOTO, t);

    m.visitVarInsn(Opcodes.ASTORE, 2);
    m.visitVarInsn(Opcodes.ALOAD, 1);
    m.visitVarInsn(Opcodes.ALOAD, 2);
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Throwable", "addSuppressed", "(Ljava/lang/Throwable;)V",
            false);
    m.visitLabel(t);
    m.visitVarInsn(Opcodes.ALOAD, 1);
    m.visitInsn(Opcodes.ATHROW);
    range2.toInclusive = m.instructions.getLast();

    m.visitLabel(e);

    filter.filter(m, context, output);

    assertIgnored(range1, range2);
}

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

License:Open Source License

/**
 * javac 7 and 8 for/*w w  w.j a v a 2  s.  com*/
 *
 * <pre>
 *     try (r0 = ...; r1 = ...) {
 *         return ...
 *     } finally {
 *         ...
 *     }
 * </pre>
 *
 * generate
 *
 * <pre>
 *     ...
 *     ASTORE r0
 *     ACONST_NULL
 *     ASTORE primaryExc0
 *
 *     ...
 *     ASTORE r1
 *     ACONST_NULL
 *     ASTORE primaryExc1
 *
 *     ... // body
 *
 *     ALOAD r1
 *     IFNULL n
 *     ALOAD primaryExc1
 *     IFNULL c
 *     ALOAD r1
 *     INVOKEINTERFACE close:()V
 *     GOTO n
 *     ASTORE t
 *     ALOAD primaryExc1
 *     ALOAD t
 *     INVOKEVIRTUAL java/lang/Throwable.addSuppressed:(Ljava/lang/Throwable;)V
 *     GOTO n
 *     c:
 *     ALOAD r1
 *     INVOKEINTERFACE close:()V
 *     n:
 *
 *     ALOAD r0
 *     IFNULL n
 *     ALOAD primaryExc0
 *     IFNULL c
 *     ALOAD r0
 *     INVOKEVIRTUAL close:()V
 *     GOTO n
 *     ASTORE t
 *     ALOAD primaryExc0
 *     ALOAD t
 *     INVOKEVIRTUAL java/lang/Throwable.addSuppressed:(Ljava/lang/Throwable;)V
 *     GOTO n
 *     c:
 *     ALOAD r0
 *     INVOKEVIRTUAL close:()V
 *     n:
 *
 *     ... // finally on normal path
 *     ARETURN
 *
 *     ASTORE t
 *     ALOAD t
 *     ASTORE primaryExc1
 *     ALOAD t
 *     ATHROW
 *
 *     ASTORE t1
 *     ALOAD r1
 *     IFNULL e
 *     ALOAD primaryExc1
 *     IFNULL c
 *     ALOAD r1
 *     INVOKEINTERFACE close:()V
 *     GOTO e
 *     ASTORE t2
 *     ALOAD primaryExc1
 *     ALOAD t2
 *     INVOKEVIRTUAL java/lang/Throwable.addSuppressed:(Ljava/lang/Throwable;)V
 *     GOTO e
 *     c:
 *     ALOAD r1
 *     INVOKEINTERFACE close:()V
 *     e:
 *     ALOAD t1
 *     ATHROW
 *
 *     ASTORE t
 *     ALOAD t
 *     ASTORE primaryExc0
 *     ALOAD t
 *     ATHROW
 *
 *     ASTORE t1
 *     ALOAD r0
 *     IFNULL e
 *     ALOAD primaryExc0
 *     IFNULL c
 *     ALOAD r0
 *     INVOKEVIRTUAL close:()V
 *     GOTO e
 *     ASTORE t2
 *     ALOAD primaryExc0
 *     ALOAD t2
 *     INVOKEVIRTUAL java/lang/Throwable.addSuppressed:(Ljava/lang/Throwable;)V
 *     GOTO e
 *     c:
 *     ALOAD r0
 *     INVOKEVIRTUAL close:()V
 *     e:
 *     ALOAD t1
 *     ATHROW
 *
 *     ... // additional handlers for catch blocks and finally on exceptional path
 * </pre>
 */
@Test
public void javac_7_8() {
    final Range range0 = new Range();
    final Range range1 = new Range();
    final Range range2 = new Range();
    final Range range3 = new Range();

    final Label handler1 = new Label();
    m.visitTryCatchBlock(handler1, handler1, handler1, "java/lang/Throwable");
    final Label handler2 = new Label();
    m.visitTryCatchBlock(handler2, handler2, handler2, "java/lang/Throwable");

    // r1 = ...
    m.visitVarInsn(Opcodes.ASTORE, 1);

    // primaryExc1 = null
    m.visitInsn(Opcodes.ACONST_NULL);
    m.visitVarInsn(Opcodes.ASTORE, 2);

    // r2 = ...
    m.visitVarInsn(Opcodes.ASTORE, 3);
    // primaryExc2 = null
    m.visitInsn(Opcodes.ACONST_NULL);
    m.visitVarInsn(Opcodes.ASTORE, 4);

    // body
    m.visitInsn(Opcodes.NOP);

    m.visitInsn(Opcodes.ACONST_NULL);
    m.visitVarInsn(Opcodes.ASTORE, 5);

    final Label l15 = new Label();
    // if (r2 != null)
    m.visitVarInsn(Opcodes.ALOAD, 3);
    range0.fromInclusive = m.instructions.getLast();
    m.visitJumpInsn(Opcodes.IFNULL, l15);
    // if (primaryExc2 != null)
    m.visitVarInsn(Opcodes.ALOAD, 4);
    final Label l26 = new Label();
    m.visitJumpInsn(Opcodes.IFNULL, l26);
    // r2.close
    m.visitVarInsn(Opcodes.ALOAD, 3);
    m.visitMethodInsn(Opcodes.INVOKEINTERFACE, "Fun$Resource2", "close", "()V", false);
    m.visitJumpInsn(Opcodes.GOTO, l15);

    m.visitVarInsn(Opcodes.ASTORE, 6);
    m.visitVarInsn(Opcodes.ALOAD, 4);
    m.visitVarInsn(Opcodes.ALOAD, 6);
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Throwable", "addSuppressed", "(Ljava/lang/Throwable;)V",
            false);
    m.visitJumpInsn(Opcodes.GOTO, l15);

    m.visitLabel(l26);

    // r2.close
    m.visitVarInsn(Opcodes.ALOAD, 3);
    m.visitMethodInsn(Opcodes.INVOKEINTERFACE, "Fun$Resource2", "close", "()V", false);
    range0.toInclusive = m.instructions.getLast();
    m.visitLabel(l15);

    // if (r1 != null)
    m.visitVarInsn(Opcodes.ALOAD, 1);
    range2.fromInclusive = m.instructions.getLast();
    final Label l23 = new Label();
    m.visitJumpInsn(Opcodes.IFNULL, l23);
    // if (primaryExc1 != null)
    m.visitVarInsn(Opcodes.ALOAD, 2);
    final Label l27 = new Label();
    m.visitJumpInsn(Opcodes.IFNULL, l27);
    // r1.close
    m.visitVarInsn(Opcodes.ALOAD, 1);
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "Fun$Resource1", "close", "()V", false);
    m.visitJumpInsn(Opcodes.GOTO, l23);

    m.visitVarInsn(Opcodes.ASTORE, 6);
    m.visitVarInsn(Opcodes.ALOAD, 2);
    m.visitVarInsn(Opcodes.ALOAD, 6);
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Throwable", "addSuppressed", "(Ljava/lang/Throwable;)V",
            false);
    m.visitJumpInsn(Opcodes.GOTO, l23);

    m.visitLabel(l27);
    // r1.close
    m.visitVarInsn(Opcodes.ALOAD, 1);
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "Fun$Resource1", "close", "()V", false);
    range2.toInclusive = m.instructions.getLast();
    m.visitLabel(l23);

    // finally
    m.visitInsn(Opcodes.NOP);
    m.visitInsn(Opcodes.ARETURN);

    // catch (Throwable t)
    m.visitLabel(handler1);
    range1.fromInclusive = m.instructions.getLast();
    m.visitVarInsn(Opcodes.ASTORE, 5);
    // primaryExc2 = t
    m.visitVarInsn(Opcodes.ALOAD, 5);
    m.visitVarInsn(Opcodes.ASTORE, 4);
    // throw t
    m.visitVarInsn(Opcodes.ALOAD, 5);
    m.visitInsn(Opcodes.ATHROW);

    // catch (any t)
    m.visitVarInsn(Opcodes.ASTORE, 7);
    // if (r2 != null)
    m.visitVarInsn(Opcodes.ALOAD, 3);
    final Label l28 = new Label();
    m.visitJumpInsn(Opcodes.IFNULL, l28);
    // if (primaryExc2 != null)
    m.visitVarInsn(Opcodes.ALOAD, 4);
    final Label l29 = new Label();
    m.visitJumpInsn(Opcodes.IFNULL, l29);
    // r2.close
    m.visitVarInsn(Opcodes.ALOAD, 3);
    m.visitMethodInsn(Opcodes.INVOKEINTERFACE, "Fun$Resource2", "close", "()V", false);
    m.visitJumpInsn(Opcodes.GOTO, l28);

    m.visitVarInsn(Opcodes.ASTORE, 8);
    m.visitVarInsn(Opcodes.ALOAD, 4);
    m.visitVarInsn(Opcodes.ALOAD, 8);
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Throwable", "addSuppressed", "(Ljava/lang/Throwable;)V",
            false);
    m.visitJumpInsn(Opcodes.GOTO, l28);

    m.visitLabel(l29);
    // r2.close
    m.visitVarInsn(Opcodes.ALOAD, 3);
    m.visitMethodInsn(Opcodes.INVOKEINTERFACE, "Fun$Resource2", "close", "()V", false);
    m.visitLabel(l28);
    // throw t
    m.visitVarInsn(Opcodes.ALOAD, 7);
    m.visitInsn(Opcodes.ATHROW);
    range1.toInclusive = m.instructions.getLast();

    // catch (Throwable t)
    m.visitLabel(handler2);
    range3.fromInclusive = m.instructions.getLast();
    m.visitVarInsn(Opcodes.ASTORE, 3);
    // primaryExc2 = t
    m.visitVarInsn(Opcodes.ALOAD, 3);
    m.visitVarInsn(Opcodes.ASTORE, 2);
    // throw t
    m.visitVarInsn(Opcodes.ALOAD, 3);
    m.visitInsn(Opcodes.ATHROW);

    // catch (any t)
    m.visitVarInsn(Opcodes.ASTORE, 9);
    // if (r1 != null)
    m.visitVarInsn(Opcodes.ALOAD, 1);
    final Label l30 = new Label();
    m.visitJumpInsn(Opcodes.IFNULL, l30);
    // if (primaryExc1 != null)
    m.visitVarInsn(Opcodes.ALOAD, 2);
    final Label l31 = new Label();
    m.visitJumpInsn(Opcodes.IFNULL, l31);
    // r1.close
    m.visitVarInsn(Opcodes.ALOAD, 1);
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "Fun$Resource1", "close", "()V", false);
    m.visitJumpInsn(Opcodes.GOTO, l30);

    m.visitVarInsn(Opcodes.ASTORE, 10);
    m.visitVarInsn(Opcodes.ALOAD, 2);
    m.visitVarInsn(Opcodes.ALOAD, 10);
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Throwable", "addSuppressed", "(Ljava/lang/Throwable;)V",
            false);
    m.visitJumpInsn(Opcodes.GOTO, l30);

    m.visitLabel(l31);
    // r1.close
    m.visitVarInsn(Opcodes.ALOAD, 1);
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "Fun$Resource1", "close", "()V", false);
    m.visitLabel(l30);
    // throw t
    m.visitVarInsn(Opcodes.ALOAD, 9);
    m.visitInsn(Opcodes.ATHROW);
    range3.toInclusive = m.instructions.getLast();

    m.visitVarInsn(Opcodes.ASTORE, 11);
    // finally
    m.visitInsn(Opcodes.NOP);
    m.visitVarInsn(Opcodes.ALOAD, 11);
    m.visitInsn(Opcodes.ATHROW);

    filter.filter(m, context, output);

    assertIgnored(range0, range1, range2, range3);
}

From source file:org.jboss.as.hibernate.MethodAdapter.java

License:Open Source License

@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
    if (rewriteSessionImplementor && hasSessionImplementor(desc)
            && (opcode == Opcodes.INVOKESPECIAL || opcode == Opcodes.INVOKEVIRTUAL)) {
        // if we have a user type calling a method from org.hibernate, we rewrite it to use SharedSessionContractImplementor
        logger.debugf("Deprecated Hibernate51CompatibilityTransformer transformed application classes in '%s', "
                + "class '%s' is calling method %s.%s, which must be changed to use SharedSessionContractImplementor as parameter.",
                moduleName, className, owner, name);
        mv.visitMethodInsn(opcode, owner, name, replaceSessionImplementor(desc), itf);
        transformedState.setClassTransformed(true);
    } else if (opcode == Opcodes.INVOKEINTERFACE
            && (owner.equals("org/hibernate/Session") || owner.equals("org/hibernate/BasicQueryContract"))
            && name.equals("getFlushMode") && desc.equals("()Lorg/hibernate/FlushMode;")) {
        logger.debugf("Deprecated Hibernate51CompatibilityTransformer transformed application classes in '%s', "
                + "class '%s' is calling %s.getFlushMode, which must be changed to call getHibernateFlushMode().",
                moduleName, className, owner);
        name = "getHibernateFlushMode";
        mv.visitMethodInsn(opcode, owner, name, desc, itf);
        transformedState.setClassTransformed(true);
    } else if (opcode == Opcodes.INVOKEINTERFACE && owner.equals("org/hibernate/Query")
            && name.equals("getFirstResult") && desc.equals("()Ljava/lang/Integer;")) {
        logger.debugf("Deprecated Hibernate51CompatibilityTransformer transformed application classes in '%s', "
                + "class '%s', is calling org.hibernate.Query.getFirstResult, which must be changed to call getHibernateFirstResult() "
                + "so null can be returned when the value is uninitialized. Please note that if a negative value was set using "
                + "org.hibernate.Query.setFirstResult, then getHibernateFirstResult() will return 0.",
                moduleName, className);/* w  w  w  . ja  va2 s  . c om*/
        name = "getHibernateFirstResult";
        mv.visitMethodInsn(opcode, owner, name, desc, itf);
        transformedState.setClassTransformed(true);
    } else if (opcode == Opcodes.INVOKEINTERFACE && owner.equals("org/hibernate/Query")
            && name.equals("getMaxResults") && desc.equals("()Ljava/lang/Integer;")) {
        logger.debugf("Deprecated Hibernate51CompatibilityTransformer transformed application classes in '%s', "
                + "class '%s', is calling org.hibernate.Query.getMaxResults, which must be changed to call getHibernateMaxResults() "
                + "so that null will be returned when the value is uninitialized or ORM 5.1 org.hibernate.Query#setMaxResults was "
                + "used to set a value <= 0", moduleName, className);
        name = "getHibernateMaxResults";
        mv.visitMethodInsn(opcode, owner, name, desc, itf);
        transformedState.setClassTransformed(true);
    } else if (!disableAmbiguousChanges && opcode == Opcodes.INVOKEINTERFACE
            && owner.equals("org/hibernate/Query") && name.equals("setFirstResult")
            && desc.equals("(I)Lorg/hibernate/Query;")) {
        logger.debugf("Deprecated Hibernate51CompatibilityTransformer transformed application classes in '%s', "
                + "class '%s', is calling org.hibernate.Query.setFirstResult, which must be changed to call setHibernateFirstResult() "
                + "so setting a value < 0 results in pagination starting with the 0th row as was done in Hibernate ORM 5.1 "
                + "(instead of throwing IllegalArgumentException as specified by JPA).", moduleName, className);
        name = "setHibernateFirstResult";
        mv.visitMethodInsn(opcode, owner, name, desc, itf);
        transformedState.setClassTransformed(true);
    } else if (!disableAmbiguousChanges && opcode == Opcodes.INVOKEINTERFACE
            && owner.equals("org/hibernate/Query") && name.equals("setMaxResults")
            && desc.equals("(I)Lorg/hibernate/Query;")) {
        logger.debugf("Deprecated Hibernate51CompatibilityTransformer transformed application classes in '%s', "
                + "class '%s', is calling org.hibernate.Query.setMaxResults, which must be changed to call setHibernateMaxResults() "
                + "so that values <= 0 are treated the same as uninitialized.  Review Hibernate ORM migration doc ",
                moduleName, className);
        name = "setHibernateMaxResults";
        mv.visitMethodInsn(opcode, owner, name, desc, itf);
        transformedState.setClassTransformed(true);
    } else {
        mv.visitMethodInsn(opcode, owner, name, desc, itf);
    }

}

From source file:org.jboss.byteman.agent.adapter.RuleGeneratorAdapter.java

License:Open Source License

/**
 * Generates the instruction to invoke an interface method.
 *
 * @param owner the class in which the method is defined.
 * @param method the method to be invoked.
 *//* w ww .j  a v a  2s .  c o  m*/
public void invokeInterface(final Type owner, final Method method) {
    invokeInsn(Opcodes.INVOKEINTERFACE, owner, method);
}

From source file:org.jboss.byteman.rule.binding.Binding.java

License:Open Source License

public void compile(MethodVisitor mv, CompileContext compileContext) throws CompileException {
    if (alias != null) {
        alias.compile(mv, compileContext);
    } else if (isBindVar()) {
        // push the current helper instance i.e. this -- adds 1 to stack height
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        // push the variable name -- adds 1 to stack height
        mv.visitLdcInsn(name);//  w w  w . j av a  2  s .c o m
        // increment stack count
        compileContext.addStackCount(2);
        // compile the rhs expression for the binding -- adds 1 to stack height
        value.compile(mv, compileContext);
        // make sure value is boxed if necessary
        if (type.isPrimitive()) {
            compileBox(Type.boxType(type), mv, compileContext);
        } else if (doCheckCast) {
            mv.visitTypeInsn(Opcodes.CHECKCAST, type.getInternalName());
        }
        // compile a setBinding call pops 3 from stack height
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.internalName(HelperAdapter.class), "setBinding",
                "(Ljava/lang/String;Ljava/lang/Object;)V");
        compileContext.addStackCount(-3);
    }
}