Example usage for org.objectweb.asm Opcodes ILOAD

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

Introduction

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

Prototype

int ILOAD

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

Click Source Link

Usage

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  o  m
 * 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.
 * /*from www .j  a v  a 2 s  .c  o m*/
 * 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.methodsplitter.Block.java

License:Open Source License

private int getOpcode(final Type type) {
    if (Type.BOOLEAN_TYPE.equals(type)) {
        return Opcodes.ILOAD;
    }/*from ww w.  j a va  2s. co  m*/
    if (Type.INT_TYPE.equals(type)) {
        return Opcodes.ILOAD;
    }
    if (Type.FLOAT_TYPE.equals(type)) {
        return Opcodes.FLOAD;
    }
    if (Type.LONG_TYPE.equals(type)) {
        return Opcodes.LLOAD;
    }
    if (Type.DOUBLE_TYPE.equals(type)) {
        return Opcodes.DLOAD;
    }
    if (Type.CHAR_TYPE.equals(type)) {
        return Opcodes.ILOAD;
    }
    return Opcodes.ALOAD;
}

From source file:de.tuberlin.uebb.jbop.optimizer.methodsplitter.Block.java

License:Open Source License

private Type getTypeIfSimpleType(final AbstractInsnNode node) {
    final int opcode = node.getOpcode();
    if ((opcode == Opcodes.ILOAD) || (opcode == Opcodes.ISTORE) || (opcode == Opcodes.IRETURN)) {
        return Type.INT_TYPE;
    }/*from  w  w w.j  a  v a  2s .  com*/
    if ((opcode == Opcodes.FLOAD) || (opcode == Opcodes.FSTORE) || (opcode == Opcodes.FRETURN)) {
        return Type.FLOAT_TYPE;
    }
    if ((opcode == Opcodes.LLOAD) || (opcode == Opcodes.LSTORE) || (opcode == Opcodes.LRETURN)) {
        return Type.LONG_TYPE;
    }
    if ((opcode == Opcodes.DLOAD) || (opcode == Opcodes.DSTORE) || (opcode == Opcodes.DRETURN)) {
        return Type.DOUBLE_TYPE;
    }
    return null;
}

From source file:de.tuberlin.uebb.jbop.optimizer.methodsplitter.Block.java

License:Open Source License

private static boolean isLoad(final AbstractInsnNode currentNode) {
    if (currentNode == null) {
        return false;
    }//from  ww  w  .  j av a  2 s . co m
    if ((currentNode.getOpcode() >= Opcodes.ILOAD) && (currentNode.getOpcode() <= Opcodes.ALOAD)) {
        return true;
    }
    return false;
}

From source file:de.tuberlin.uebb.jbop.optimizer.methodsplitter.BlockTest.java

License:Open Source License

/**
 * Tests the type erasure./* w  ww  .  j av a2 s . co  m*/
 */
@Test
public void testTypeErasure() {
    final InsnList list = new InsnList();
    list.add(new InsnNode(Opcodes.ICONST_5));
    list.add(new IntInsnNode(Opcodes.NEWARRAY, Opcodes.T_INT));
    list.add(new VarInsnNode(Opcodes.ASTORE, 3));
    list.add(new VarInsnNode(Opcodes.ILOAD, 1));
    list.add(new VarInsnNode(Opcodes.ILOAD, 2));
    list.add(new InsnNode(Opcodes.IADD));
    list.add(new InsnNode(Opcodes.ICONST_0));
    list.add(new VarInsnNode(Opcodes.ALOAD, 3));
    list.add(new InsnNode(Opcodes.IASTORE));
    list.add(new InsnNode(Opcodes.ICONST_5));
    list.add(new IntInsnNode(Opcodes.NEWARRAY, Opcodes.T_INT));
    list.add(new VarInsnNode(Opcodes.ASTORE, 4));
    list.add(new VarInsnNode(Opcodes.ILOAD, 1));
    list.add(new VarInsnNode(Opcodes.ILOAD, 2));
    list.add(new InsnNode(Opcodes.IADD));
    list.add(new InsnNode(Opcodes.ICONST_1));
    final VarInsnNode insn = new VarInsnNode(Opcodes.ALOAD, 3);
    list.add(insn);
    list.add(new InsnNode(Opcodes.IASTORE));
    list.add(new InsnNode(Opcodes.RETURN));

    final ListIterator<AbstractInsnNode> iterator = list.iterator();

    final Block block = new Block(1, new Type[] { Type.INT_TYPE, Type.INT_TYPE }, Type.INT_TYPE);
    while (iterator.hasNext()) {
        block.addInsn(iterator.next(), true);
    }

    final Type findType = block.findType(insn);
    assertEquals(Type.getType("[I"), findType);
}

From source file:de.tuberlin.uebb.jbop.optimizer.utils.NodeHelper.java

License:Open Source License

/**
 * Checks if node is iload_i.//from   ww w  .  j  a  va2 s.co  m
 * 
 * @param node
 *          the node
 * @param i
 *          the i
 * @return true, if is iload_i (-1 for any I_LOAD)
 */
public static boolean isIload(final AbstractInsnNode node, final int i) {
    if (node == null) {
        return false;
    }
    if (node instanceof VarInsnNode) {
        final boolean isIload = node.getOpcode() == Opcodes.ILOAD;
        return isIload && ((VarInsnNode) node).var == i || i == CONST_M1;
    }
    return false;
}

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

License:Open Source License

private void findNodes(final InsnList original, final List<VarInsnNode> stores, final List<VarInsnNode> users, //
        final List<IincInsnNode> iincs) {
    final Iterator<AbstractInsnNode> iterator = original.iterator();
    while (iterator.hasNext()) {
        final AbstractInsnNode node = iterator.next();
        if ((node.getOpcode() >= Opcodes.ISTORE) && (node.getOpcode() <= Opcodes.ASTORE)) {
            stores.add((VarInsnNode) node);
        } else if ((node.getOpcode() >= Opcodes.ILOAD) && (node.getOpcode() <= Opcodes.ALOAD)) {
            users.add((VarInsnNode) node);
        } else if (node.getOpcode() == Opcodes.IINC) {
            iincs.add((IincInsnNode) node);
        }/*from  w  ww .j a va2 s  .c o m*/
    }
}

From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.VarInstruction.java

License:Open Source License

public VarInstruction(final ReadMethod readMethod, final int opcode, final int lineNumber,
        final int localVarIndex) {
    super(readMethod, opcode, lineNumber);
    assert opcode == Opcodes.ILOAD || opcode == Opcodes.LLOAD || opcode == Opcodes.FLOAD
            || opcode == Opcodes.DLOAD || opcode == Opcodes.ALOAD || opcode == Opcodes.ISTORE
            || opcode == Opcodes.LSTORE || opcode == Opcodes.FSTORE || opcode == Opcodes.DSTORE
            || opcode == Opcodes.ASTORE || opcode == Opcodes.RET;
    this.localVarIndex = localVarIndex;
}

From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.VarInstruction.java

License:Open Source License

private VarInstruction(final ReadMethod readMethod, final int lineNumber, final int opcode,
        final int localVarIndex, final int index) {
    super(readMethod, opcode, lineNumber, index);
    assert opcode == Opcodes.ILOAD || opcode == Opcodes.LLOAD || opcode == Opcodes.FLOAD
            || opcode == Opcodes.DLOAD || opcode == Opcodes.ALOAD || opcode == Opcodes.ISTORE
            || opcode == Opcodes.LSTORE || opcode == Opcodes.FSTORE || opcode == Opcodes.DSTORE
            || opcode == Opcodes.ASTORE || opcode == Opcodes.RET;
    this.localVarIndex = localVarIndex;
}