Example usage for org.objectweb.asm Opcodes F_NEW

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

Introduction

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

Prototype

int F_NEW

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

Click Source Link

Document

An expanded frame.

Usage

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

License:Open Source License

@Override
public final void visitFrame(final int type, final int nLocal, final Object[] local, final int nStack,
        final Object[] stack) {

    if (type != Opcodes.F_NEW) { // uncompressed frame
        throw new IllegalArgumentException("ClassReader.accept() should be called with EXPAND_FRAMES flag");
    }//from w  w w  .java 2  s .c  o  m

    final Object[] newLocal = new Object[Math.max(nLocal, variable) + 1];
    int idx = 0; // Arrays index for existing locals
    int newIdx = 0; // Array index for new locals
    int pos = 0; // Current variable position
    while (idx < nLocal || pos <= variable) {
        if (pos == variable) {
            newLocal[newIdx++] = InstrSupport.DATAFIELD_DESC;
            pos++;
        } else {
            if (idx < nLocal) {
                final Object t = local[idx++];
                newLocal[newIdx++] = t;
                pos++;
                if (t == Opcodes.LONG || t == Opcodes.DOUBLE) {
                    pos++;
                }
            } else {
                // Fill unused slots with TOP
                newLocal[newIdx++] = Opcodes.TOP;
                pos++;
            }
        }
    }
    mv.visitFrame(type, newIdx, newLocal, nStack, stack);
}

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

License:Open Source License

@Test
public void testVisitFrame() {
    ProbeInserter pi = new ProbeInserter(0, "(J)V", actualVisitor, arrayStrategy);

    pi.visitFrame(Opcodes.F_NEW, 3, new Object[] { "Foo", Opcodes.LONG, "java/lang/String" }, 0, new Object[0]);

    expectedVisitor.visitFrame(Opcodes.F_NEW, 4, new Object[] { "Foo", Opcodes.LONG, "[Z", "java/lang/String" },
            0, new Object[0]);
}

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

License:Open Source License

@Test
public void testVisitFrameNoLocals() {
    ProbeInserter pi = new ProbeInserter(Opcodes.ACC_STATIC, "()V", actualVisitor, arrayStrategy);

    pi.visitFrame(Opcodes.F_NEW, 0, new Object[] {}, 0, new Object[0]);

    expectedVisitor.visitFrame(Opcodes.F_NEW, 1, new Object[] { "[Z" }, 0, new Object[0]);
}

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

License:Open Source License

@Test
public void testVisitFrameProbeAt0() {
    ProbeInserter pi = new ProbeInserter(Opcodes.ACC_STATIC, "()V", actualVisitor, arrayStrategy);

    pi.visitFrame(Opcodes.F_NEW, 2, new Object[] { Opcodes.DOUBLE, "Foo" }, 0, new Object[0]);

    expectedVisitor.visitFrame(Opcodes.F_NEW, 3, new Object[] { "[Z", Opcodes.DOUBLE, "Foo" }, 0,
            new Object[0]);
}

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

License:Open Source License

@Test
public void testFillOneWord() {
    ProbeInserter pi = new ProbeInserter(Opcodes.ACC_STATIC, "(I)V", actualVisitor, arrayStrategy);

    pi.visitFrame(Opcodes.F_NEW, 0, new Object[] {}, 0, new Object[] {});

    // The locals in this frame are filled with TOP up to the probe variable
    expectedVisitor.visitFrame(Opcodes.F_NEW, 2, new Object[] { Opcodes.TOP, "[Z", }, 0, new Object[] {});
}

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

License:Open Source License

@Test
public void testFillTwoWord() {
    ProbeInserter pi = new ProbeInserter(Opcodes.ACC_STATIC, "(J)V", actualVisitor, arrayStrategy);

    pi.visitFrame(Opcodes.F_NEW, 0, new Object[] {}, 0, new Object[] {});

    // The locals in this frame are filled with TOP up to the probe variable
    expectedVisitor.visitFrame(Opcodes.F_NEW, 3, new Object[] { Opcodes.TOP, Opcodes.TOP, "[Z", }, 0,
            new Object[] {});
}

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

License:Open Source License

@Test
public void testFillPartly() {
    ProbeInserter pi = new ProbeInserter(Opcodes.ACC_STATIC, "(DIJ)V", actualVisitor, arrayStrategy);

    pi.visitFrame(Opcodes.F_NEW, 1, new Object[] { Opcodes.DOUBLE }, 0, new Object[] {});

    // The locals in this frame are filled with TOP up to the probe variable
    expectedVisitor.visitFrame(Opcodes.F_NEW, 5,
            new Object[] { Opcodes.DOUBLE, Opcodes.TOP, Opcodes.TOP, Opcodes.TOP, "[Z", }, 0, new Object[] {});
}

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

License:Open Source License

@Override
public void visitFrame(final int type, final int nLocal, final Object[] local, final int nStack,
        final Object[] stack) {

    if (type != Opcodes.F_NEW) { // uncompressed frame
        throw new IllegalStateException("ClassReader.accept() should be called with EXPAND_FRAMES flag");
    }/*  ww w.  ja v  a  2s. c o m*/

    final Object[] newLocal = new Object[nLocal + 1];
    for (int i = 0; i <= local.length; i++) {
        if (i < variableIdx) {
            newLocal[i] = local[i];
            continue;
        }
        if (i > variableIdx) {
            newLocal[i] = local[i - 1];
            continue;
        }
        newLocal[i] = InstrSupport.DATAFIELD_DESC;
    }

    if (lastLabel != null) {
        if (LabelInfo.isMultiTarget(lastLabel)) {
            // Create map instance only if required:
            if (probeFrames == null) {
                probeFrames = new HashMap<Label, FrameNode>();
            }
            probeFrames.put(lastLabel, new FrameNode(type, nLocal + 1, newLocal, nStack, stack));
        }
        lastLabel = null;
    }

    if (firstFrame) {
        // The first frame is generated by ASM and represents the implicit
        // frame derived from the method signature only. This frame must not
        // yet be modified.
        mv.visitFrame(type, nLocal, local, nStack, stack);
        firstFrame = false;
    } else {
        mv.visitFrame(type, nLocal + 1, newLocal, nStack, stack);
    }
}

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

License:Open Source License

@Test
public void testVisitFrame() {
    final FrameRecorder rec = new FrameRecorder();
    ProbeVariableInserter i = new ProbeVariableInserter(0, "(J)V", rec);

    // The first (implicit) frame must not be modified:
    i.visitFrame(Opcodes.F_NEW, 2, new Object[] { "LFoo;", Opcodes.LONG }, 0, new Object[0]);
    assertEquals(Arrays.asList((Object) "LFoo;", Opcodes.LONG), rec.frame.local);

    // Starting from the second frame on the probe variable is inserted:
    i.visitFrame(Opcodes.F_NEW, 3, new Object[] { "LFoo;", Opcodes.LONG, "Ljava/lang/String;" }, 0,
            new Object[0]);
    assertEquals(Arrays.asList((Object) "LFoo;", Opcodes.LONG, "[Z", "Ljava/lang/String;"), rec.frame.local);
}

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

License:Open Source License

@Test
public void testInsertProbeFrame() {
    final FrameRecorder rec = new FrameRecorder();
    ProbeVariableInserter i = new ProbeVariableInserter(0, "(J)V", rec);

    // The first (implicit) frame:
    i.visitFrame(Opcodes.F_NEW, 2, new Object[] { "LFoo;", Opcodes.LONG }, 0, new Object[0]);

    // There must be a label which is a multi-jump target:
    Label label = new Label();
    LabelInfo.setTarget(label);//w w w  . j  av a 2s .com
    LabelInfo.setTarget(label);
    i.visitLabel(label);

    // Insert a frame for this label:
    i.visitFrame(Opcodes.F_NEW, 3, new Object[] { "LFoo;", Opcodes.LONG, "Ljava/lang/String;" }, 0,
            new Object[0]);

    // Insert this frame again:
    rec.frame = null;
    i.insertProbeFrame(label);

    assertEquals(Arrays.asList((Object) "LFoo;", Opcodes.LONG, "[Z", "Ljava/lang/String;"), rec.frame.local);
}