Example usage for org.objectweb.asm Opcodes RETURN

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

Introduction

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

Prototype

int RETURN

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

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.
 * //from ww w  .  j a  v a  2  s  . c  o  m
 * Input is
 * 
 * <pre>
 * if(2>1)
 * ...
 * </pre>
 * 
 * @throws JBOPClassException
 *           the jBOP class exception
 */

@Test
public void testConstantIfInlinerIF_ICMPLE() throws JBOPClassException {
    // INIT
    final LabelNode label = 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(label).//
            addInsn(new InsnNode(Opcodes.RETURN));

    // RUN
    assertEquals(6, 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 . ja v  a 2s .co m
 * Input is
 * 
 * <pre>
 * if(2>=1)
 * ...
 * </pre>
 * 
 * @throws JBOPClassException
 *           the jBOP class exception
 */

@Test
public void testConstantIfInlinerIF_ICMPLT() throws JBOPClassException {
    // INIT
    final LabelNode label = new LabelNode();
    builder.addInsn(new InsnNode(Opcodes.ICONST_2)).//
            addInsn(new InsnNode(Opcodes.ICONST_1)).//
            addInsn(new JumpInsnNode(Opcodes.IF_ICMPLT, label)).//
            addInsn(new InsnNode(Opcodes.NOP)).//
            addInsn(label).//
            addInsn(new InsnNode(Opcodes.RETURN));

    // RUN
    assertEquals(6, 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 ww.  jav  a  2  s.c  o m*/
 * Input is
 * 
 * <pre>
 * if(1==1)
 * ...
 * </pre>
 * 
 * @throws JBOPClassException
 *           the jBOP class exception
 */
@Test
public void testConstantIfInlinerIF_ICMPNE() throws JBOPClassException {
    // INIT
    final LabelNode label = new LabelNode();
    builder.addInsn(new InsnNode(Opcodes.ICONST_1)).//
            addInsn(new InsnNode(Opcodes.ICONST_1)).//
            addInsn(new JumpInsnNode(Opcodes.IF_ICMPNE, label)).//
            addInsn(new InsnNode(Opcodes.NOP)).//
            addInsn(label).//
            addInsn(new InsnNode(Opcodes.RETURN));

    // RUN
    assertEquals(6, 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.
 * //  w  ww.  ja v  a2  s .c  om
 * Input is
 * 
 * <pre>
 * if(1!=2)
 * ...
 * </pre>
 * 
 * @throws JBOPClassException
 *           the jBOP class exception
 */
@Test
public void testConstantIfInlinerIF_ICMPEQ() throws JBOPClassException {
    // INIT
    final LabelNode label = new LabelNode();
    builder.addInsn(new InsnNode(Opcodes.ICONST_1)).//
            addInsn(new InsnNode(Opcodes.ICONST_2)).//
            addInsn(new JumpInsnNode(Opcodes.IF_ICMPEQ, label)).//
            addInsn(new InsnNode(Opcodes.NOP)).//
            addInsn(label).//
            addInsn(new InsnNode(Opcodes.RETURN));

    // RUN
    assertEquals(6, 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.
 * /*w  ww.  j  a  va2s  . c o m*/
 * 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 v  a 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  w  w w  .j av  a  2  s  .c om*/
 * 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 w  w w .j  a  v  a  2 s.  co  m
 * 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 w ww  . ja v a 2  s.com*/
 * 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.
 * //from   ww  w. ja  va2s .c  om
 * 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());
}