Example usage for org.objectweb.asm Opcodes NOP

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

Introduction

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

Prototype

int NOP

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

Click Source Link

Usage

From source file:de.tuberlin.uebb.jbop.optimizer.controlflow.ConstantIfInlinerTest.java

License:Open Source License

/**
 * Tests that constantIfInliner is working correctly.
 * // w w  w. j  a v  a2s . c  om
 * Input is
 * 
 * <pre>
 * if(a)
 * ...
 * </pre>
 * 
 * where a is true
 * 
 * @throws JBOPClassException
 *           the jBOP class exception
 */
@Test
public void testConstantIfInlinerIFEQ() throws JBOPClassException {
    // INIT
    final LabelNode label = new LabelNode();
    builder.addInsn(new InsnNode(Opcodes.ICONST_1)).//
            addInsn(new JumpInsnNode(Opcodes.IFEQ, label)).//
            addInsn(new InsnNode(Opcodes.NOP)).//
            addInsn(label).//
            addInsn(new InsnNode(Opcodes.RETURN));

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

    // ASSERT
    assertEquals(3, optimized.size());
    assertEquals(Opcodes.NOP, optimized.get(0).getOpcode());
}

From source file:de.tuberlin.uebb.jbop.optimizer.controlflow.ConstantIfInlinerTest.java

License:Open Source License

/**
 * Tests that constantIfInliner is working correctly.
 * /*from w  w  w.j a  va 2 s.c  o m*/
 * Input is
 * 
 * <pre>
 * if(!a)
 * ...
 * </pre>
 * 
 * where a is false
 * 
 * @throws JBOPClassException
 *           the jBOP class exception
 */
@Test
public void testConstantIfInlinerIFNE() throws JBOPClassException {
    // INIT
    final LabelNode label = new LabelNode();
    builder.addInsn(new InsnNode(Opcodes.ICONST_0)).//
            addInsn(new JumpInsnNode(Opcodes.IFNE, label)).//
            addInsn(new InsnNode(Opcodes.NOP)).//
            addInsn(label).//
            addInsn(new InsnNode(Opcodes.RETURN));

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

    // ASSERT
    assertEquals(3, optimized.size());
    assertEquals(Opcodes.NOP, optimized.get(0).getOpcode());
}

From source file:de.tuberlin.uebb.jbop.optimizer.controlflow.ConstantIfInlinerTest.java

License:Open Source License

/**
 * Tests that constantIfInliner is working correctly.
 * /*from   www  . j a v a  2  s . c o m*/
 * Input is
 * 
 * <pre>
 * if(a==null)
 * ...
 * </pre>
 * 
 * where a is not null
 * 
 * @throws JBOPClassException
 *           the jBOP class exception
 */
@Test
public void testConstantIfInlinerIFNULL() throws JBOPClassException {
    // INIT
    when(nonNullValue.is(Matchers.<AbstractInsnNode>any(), Matchers.<AbstractInsnNode>any(),
            Matchers.<List<AbstractInsnNode>>any(), Matchers.<List<AbstractInsnNode>>any()))
                    .thenReturn(Boolean.valueOf(true));
    final LabelNode label = new LabelNode();
    builder.addInsn(new TypeInsnNode(Opcodes.NEW, Type.getDescriptor(Object.class))).//
            addInsn(new JumpInsnNode(Opcodes.IFNULL, label)).//
            addInsn(new InsnNode(Opcodes.NOP)).//
            addInsn(label).//
            addInsn(new InsnNode(Opcodes.RETURN));

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

    // ASSERT
    assertEquals(3, optimized.size());
    assertEquals(Opcodes.NOP, optimized.get(0).getOpcode());
}

From source file:de.tuberlin.uebb.jbop.optimizer.controlflow.ConstantIfInlinerTest.java

License:Open Source License

/**
 * Tests that constantIfInliner is working correctly.
 * /*from  www.ja v a2 s  . com*/
 * Input is
 * 
 * <pre>
 * if(a==null)
 * ...
 * </pre>
 * 
 * where a is null
 * 
 * @throws JBOPClassException
 *           the jBOP class exception
 */
@Test
public void testConstantIfInlinerIFNONNULL() throws JBOPClassException {
    // INIT
    final LabelNode label = new LabelNode();
    builder.addInsn(new InsnNode(Opcodes.ACONST_NULL)).//
            addInsn(new JumpInsnNode(Opcodes.IFNONNULL, label)).//
            addInsn(new InsnNode(Opcodes.NOP)).//
            addInsn(label).//
            addInsn(new InsnNode(Opcodes.RETURN));

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

    // ASSERT
    assertEquals(3, optimized.size());
    assertEquals(Opcodes.NOP, optimized.get(0).getOpcode());
}

From source file:de.tuberlin.uebb.jbop.optimizer.controlflow.ConstantIfInlinerTest.java

License:Open Source License

/**
 * Tests that constantIfInliner is working correctly.
 * //from ww w  .j a  v  a 2 s .  c o  m
 * Input is
 * 
 * <pre>
 * if(1>2)
 * ...
 * else
 * ...
 * </pre>
 * 
 * @throws JBOPClassException
 *           the jBOP class exception
 */
@Test
public void testConstantIfInlinerIF_ICMPLEWithElseChooseIf() throws JBOPClassException {
    // INIT
    final LabelNode label = new LabelNode();
    final LabelNode label2 = new LabelNode();
    builder.addInsn(new InsnNode(Opcodes.ICONST_2)).//
            addInsn(new InsnNode(Opcodes.ICONST_1)).//
            addInsn(new JumpInsnNode(Opcodes.IF_ICMPLE, label)).//
            addInsn(new InsnNode(Opcodes.NOP)).//
            addInsn(new InsnNode(Opcodes.NOP)).//
            addInsn(new JumpInsnNode(Opcodes.GOTO, label2)).//
            addInsn(label).//
            addInsn(new InsnNode(Opcodes.NOP)).//
            addInsn(label2).//
            addInsn(new InsnNode(Opcodes.RETURN));

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

    // ASSERT
    assertEquals(4, optimized.size());
    assertEquals(Opcodes.NOP, optimized.get(0).getOpcode());
    assertEquals(Opcodes.NOP, optimized.get(1).getOpcode());
}

From source file:de.tuberlin.uebb.jbop.optimizer.controlflow.ConstantIfInlinerTest.java

License:Open Source License

/**
 * Tests that constantIfInliner is working correctly.
 * /*  w ww  .j av  a 2s  .c  o  m*/
 * Input is
 * 
 * <pre>
 * if(2>1)
 * ...
 * else
 * ...
 * </pre>
 * 
 * @throws JBOPClassException
 *           the jBOP class exception
 */
@Test
public void testConstantIfInlinerIF_ICMPLEWithElseChooseElse() throws JBOPClassException {
    // INIT
    final LabelNode label = new LabelNode();
    final LabelNode label2 = new LabelNode();
    builder.addInsn(new InsnNode(Opcodes.ICONST_2)).//
            addInsn(new InsnNode(Opcodes.ICONST_1)).//
            addInsn(new JumpInsnNode(Opcodes.IF_ICMPLE, label)).//
            addInsn(new InsnNode(Opcodes.NOP)).//
            addInsn(new JumpInsnNode(Opcodes.GOTO, label2)).//
            addInsn(label).//
            addInsn(new InsnNode(Opcodes.NOP)).//
            addInsn(new InsnNode(Opcodes.NOP)).//
            addInsn(label2).//
            addInsn(new InsnNode(Opcodes.RETURN));

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

    // ASSERT
    assertEquals(3, optimized.size());
    assertEquals(Opcodes.NOP, optimized.get(0).getOpcode());
    assertEquals(-1, optimized.get(1).getOpcode());
}

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

License:Open Source License

/**
 * Tests that ForLoopUnroller is working correctly.
 * //from ww  w. java 2s.  c om
 * Used is a loop of the kind:
 * 
 * for(int i=0; i< 3; ++i)
 */
@Test
public void testForLoopUnrollerStrictForward() {
    // INIT
    final LabelNode label1 = new LabelNode();
    final LabelNode label2 = new LabelNode();
    builder.addInsn(new InsnNode(Opcodes.ICONST_0)).//
            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, 1)).//
            addInsn(label1).//
            addInsn(NodeHelper.getInsnNodeFor(3)).//
            addInsn(new VarInsnNode(Opcodes.ILOAD, 1)).//
            addInsn(new JumpInsnNode(Opcodes.IF_ICMPLT, label2)).//
            addInsn(new InsnNode(Opcodes.RETURN));

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

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

    int node = 0;
    for (int i = 0; i < 3; ++i) {
        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()); // this is the SkipMarkNode
        node++;
    }
}

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

License:Open Source License

/**
 * Tests that ForLoopUnroller is working correctly.
 * //  w  w w .j a v  a 2  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 a loop with the test-instructions at the beginning.
 *//*from   w ww . ja v a 2 s . c o m*/
@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.loop.SplitMarkNode.java

License:Open Source License

/**
 * Instantiates a new split mark node.
 */
public SplitMarkNode() {
    super(Opcodes.NOP);
}