Example usage for org.objectweb.asm.tree InsnList size

List of usage examples for org.objectweb.asm.tree InsnList size

Introduction

In this page you can find the example usage for org.objectweb.asm.tree InsnList size.

Prototype

int size

To view the source code for org.objectweb.asm.tree InsnList size.

Click Source Link

Document

The number of instructions in this list.

Usage

From source file:de.tuberlin.uebb.jbop.optimizer.loop.ForLoopUnrollerTest.java

License:Open Source License

/**
 * Tests that ForLoopUnroller is working correctly.
 * //from   ww w .j a  va2  s.c  om
 * Used is a loop of the kind:
 * 
 * for(int i=6; i> 0; i=i-2)
 */
@Test
public void testForLoopUnrollerBackward() {
    // INIT
    final LabelNode label1 = new LabelNode();
    final LabelNode label2 = new LabelNode();
    builder.addInsn(NodeHelper.getInsnNodeFor(6)).//
            addInsn(new VarInsnNode(Opcodes.ISTORE, 1)).//
            addInsn(new JumpInsnNode(Opcodes.GOTO, label1)).//
            addInsn(label2).//
            addInsn(new VarInsnNode(Opcodes.ILOAD, 1)).//
            addInsn(new VarInsnNode(Opcodes.ILOAD, 1)).//
            addInsn(new InsnNode(Opcodes.IADD)).//
            addInsn(new IincInsnNode(1, -2)).//
            addInsn(label1).//
            addInsn(new VarInsnNode(Opcodes.ILOAD, 1)).//
            addInsn(new JumpInsnNode(Opcodes.IFGT, label2)).//
            addInsn(new InsnNode(Opcodes.RETURN));

    // RUN
    assertEquals(12, method.instructions.size());
    final InsnList optimized = optimizer.optimize(method.instructions, method);

    // ASSERT
    assertEquals(19, optimized.size());

    int node = 0;
    for (int i = 6; i > 0; i -= 2) {
        assertEquals(i, NodeHelper.getNumberValue(optimized.get(node)).intValue());
        node++;
        assertEquals(Opcodes.ISTORE, optimized.get(node).getOpcode());
        node++;
        assertEquals(Opcodes.ILOAD, optimized.get(node).getOpcode());
        node++;
        assertEquals(Opcodes.ILOAD, optimized.get(node).getOpcode());
        node++;
        assertEquals(Opcodes.IADD, optimized.get(node).getOpcode());
        node++;
        assertEquals(Opcodes.NOP, optimized.get(node).getOpcode());
        node++;
    }
}

From source file:de.tuberlin.uebb.jbop.optimizer.loop.ForLoopUnrollerTest.java

License:Open Source License

/**
 * Tests the LoopUnroller for an empty loop.
 *///from w  w w .j  a  v a 2  s. c  om
@Test
public void testForLoopUnrollerEmptyLoop() {
    // INIT
    final LabelNode label1 = new LabelNode();
    final LabelNode label2 = new LabelNode();
    builder.add(ICONST_0).//
            add(ISTORE, 1).//
            add(GOTO, label1).//
            addInsn(label2).//
            add(IINC, 1, 1).//
            addInsn(label1).//
            add(ICONST_5).//
            add(ILOAD, 1).//
            add(IF_ICMPLT, label2).//
            addReturn();

    // RUN
    assertEquals(10, method.instructions.size());
    final InsnList optimized = optimizer.optimize(method.instructions, method);

    // ASSERT
    assertEquals(1, optimized.size()); //
}

From source file:de.tuberlin.uebb.jbop.optimizer.loop.ForLoopUnrollerTest.java

License:Open Source License

/**
 * Tests the Loopunroller for a loop with the test-instructions at the beginning.
 *//*from w  ww.j a va  2s  .com*/
@Test
public void testForLoopTypeTwo() {
    // INIT
    final LabelNode check = new LabelNode();
    final LabelNode ende = new LabelNode();
    builder.add(ICONST_0)//
            .add(ISTORE, 1)//
            .addInsn(check)//
            .add(ICONST_5)//
            .add(ILOAD, 1)//
            .add(IF_ICMPGT, ende)//
            .add(NOP)//
            .add(NOP)//
            .add(NOP)//
            .add(IINC, 1, 1)//
            .add(GOTO, check)//
            .addInsn(ende)//
            .add(NOP)//
            .addReturn();

    // RUN
    assertEquals(14, method.instructions.size());
    final InsnList optimized = optimizer.optimize(method.instructions, method);

    // ASSERT
    assertEquals(38, optimized.size()); //
    int node = 0;
    for (int i = 0; i < 6; ++i) {
        assertEquals(i, NodeHelper.getNumberValue(optimized.get(node)).intValue());
        node++;
        assertEquals(Opcodes.ISTORE, optimized.get(node).getOpcode());
        node++;
        assertEquals(Opcodes.NOP, optimized.get(node).getOpcode());
        node++;
        assertEquals(Opcodes.NOP, optimized.get(node).getOpcode());
        node++;
        assertEquals(Opcodes.NOP, optimized.get(node).getOpcode());
        node++;
        assertEquals(Opcodes.NOP, optimized.get(node).getOpcode());
        node++;
    }
    assertEquals(Opcodes.NOP, optimized.get(node).getOpcode());
    node++;
    assertEquals(Opcodes.RETURN, optimized.get(node).getOpcode());
    node++;
}

From source file:de.tuberlin.uebb.jbop.optimizer.var.FinalFieldInlinerTest.java

License:Open Source License

/**
 * Tests that FinalFieldInliner is working correctly for int-Fields.
 * // ww w  .jav a  2 s .  c om
 * @throws Exception
 *           the exception
 */
@Test
public void testFinalFieldInlinerIntField() throws Exception {
    // INIT
    initTestMethod("I", 42, 1);

    // RUN
    final InsnList optimized = inliner.optimize(method.instructions, method);

    // ASSERT
    assertEquals(2, optimized.size());
    assertEquals(42, NodeHelper.getNumberValue(optimized.get(0)).intValue());
}

From source file:de.tuberlin.uebb.jbop.optimizer.var.FinalFieldInlinerTest.java

License:Open Source License

/**
 * Tests that FinalFieldInliner is working correctly for double-Fields.
 * /*from   w ww. ja  va  2 s.c om*/
 * @throws Exception
 *           the exception
 */
@Test
public void testFinalFieldInlinerDoubleField() throws Exception {
    // INIT
    initTestMethod("D", 23.0, 2);

    // RUN
    final InsnList optimized = inliner.optimize(method.instructions, method);

    // ASSERT
    assertEquals(2, optimized.size());
    assertEquals(23.0, NodeHelper.getNumberValue(optimized.get(0)).doubleValue(), .0001);
}

From source file:de.tuberlin.uebb.jbop.optimizer.var.FinalFieldInlinerTest.java

License:Open Source License

/**
 * Tests that FinalFieldInliner is working correctly for long-Fields.
 * /*from  w w  w.  ja  v a 2 s.  com*/
 * @throws Exception
 *           the exception
 */
@Test
public void testFinalFieldInlinerLongField() throws Exception {
    // INIT
    initTestMethod("J", 12L, 3);

    // RUN
    final InsnList optimized = inliner.optimize(method.instructions, method);

    // ASSERT
    assertEquals(2, optimized.size());
    assertEquals(12L, NodeHelper.getNumberValue(optimized.get(0)).longValue());
}

From source file:de.tuberlin.uebb.jbop.optimizer.var.FinalFieldInlinerTest.java

License:Open Source License

/**
 * Tests that FinalFieldInliner is working correctly for float-Fields.
 * //from   www.  j a  va 2  s.  com
 * @throws Exception
 *           the exception
 */
@Test
public void testFinalFieldInlinerFloatField() throws Exception {
    // INIT
    initTestMethod("F", 13.13F, 4);

    // RUN
    final InsnList optimized = inliner.optimize(method.instructions, method);

    // ASSERT
    assertEquals(2, optimized.size());
    assertEquals(13.13F, NodeHelper.getNumberValue(optimized.get(0)).floatValue(), .0001);
}

From source file:de.tuberlin.uebb.jbop.optimizer.var.FinalFieldInlinerTest.java

License:Open Source License

/**
 * Tests that FinalFieldInliner is working correctly for byte-Fields.
 * //from w ww. j av a 2  s. com
 * @throws Exception
 *           the exception
 */
@Test
public void testFinalFieldInlinerByteField() throws Exception {
    // INIT
    initTestMethod("B", (byte) 1, 5);

    // RUN
    final InsnList optimized = inliner.optimize(method.instructions, method);

    // ASSERT
    assertEquals(2, optimized.size());
    assertEquals((byte) 1, NodeHelper.getNumberValue(optimized.get(0)).byteValue());
}

From source file:de.tuberlin.uebb.jbop.optimizer.var.FinalFieldInlinerTest.java

License:Open Source License

/**
 * Tests that FinalFieldInliner is working correctly for short-Fields.
 * /*from w w w.j av a  2 s .  com*/
 * @throws Exception
 *           the exception
 */
@Test
public void testFinalFieldInlinerShortField() throws Exception {
    // INIT
    initTestMethod("S", (short) 3, 6);

    // RUN
    final InsnList optimized = inliner.optimize(method.instructions, method);

    // ASSERT
    assertEquals(2, optimized.size());
    assertEquals((short) 3, NodeHelper.getNumberValue(optimized.get(0)).byteValue());
}

From source file:de.tuberlin.uebb.jbop.optimizer.var.FinalFieldInlinerTest.java

License:Open Source License

/**
 * Tests that FinalFieldInliner is working correctly for boolean-Fields.
 * /*from ww w . java2  s . c  o  m*/
 * @throws Exception
 *           the exception
 */
@Test
public void testFinalFieldInlinerBooleanField() throws Exception {
    // INIT
    initTestMethod("Z", true, 7);

    // RUN
    final InsnList optimized = inliner.optimize(method.instructions, method);

    // ASSERT
    assertEquals(2, optimized.size());
    assertTrue(NodeHelper.getBooleanValue(optimized.get(0)));
}