Example usage for org.objectweb.asm.tree AbstractInsnNode getOpcode

List of usage examples for org.objectweb.asm.tree AbstractInsnNode getOpcode

Introduction

In this page you can find the example usage for org.objectweb.asm.tree AbstractInsnNode getOpcode.

Prototype

public int getOpcode() 

Source Link

Document

Returns the opcode of this instruction.

Usage

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

License:Open Source License

/**
 * Returns true if node is an two-param-if-Statement.
 * /*from w w w. j a va2s  . c  o  m*/
 * @param node
 *          the node
 * @return true if node is two value if
 */
public static boolean isTwoValueIf(final AbstractInsnNode node) {
    if (node == null) {
        return false;
    }
    return node.getOpcode() >= Opcodes.IF_ICMPEQ && node.getOpcode() <= Opcodes.IF_ACMPNE;
}

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

License:Open Source License

/**
 * returns the first Element of the "Stack" that produces the value, that is stored
 * by this node./*from  w  w w  . j  a v  a 2 s  .c  o m*/
 * 
 * returns null if node is null.
 * returns null if node is not a store.
 * 
 * @param node
 *          the node
 * @return the first of stack
 */
public static AbstractInsnNode getFirstOfStack(final AbstractInsnNode node) {
    if (node == null) {
        return null;
    }
    int opcode = node.getOpcode();
    if (opcode < ISTORE || opcode > ASTORE) {
        return null;
    }

    int stackCounter = 1;
    AbstractInsnNode prev = getPrevious(node);
    while (prev != null) {
        opcode = prev.getOpcode();
        stackCounter = getStackCounter(opcode, stackCounter, prev);

        if (stackCounter == 0) {
            return prev;
        }
        prev = prev.getPrevious();
    }
    return null;
}

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

License:Open Source License

@Override
public boolean evaluate(final AbstractInsnNode object) {
    if (object == null) {
        return false;
    }//from w  w w.  j av a 2  s.  com
    return object.getOpcode() == Opcodes.FALOAD;
}

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

License:Open Source License

@Override
public boolean evaluate(final AbstractInsnNode object) {
    if (object == null) {
        return false;
    }/*from  w  w w .j av  a  2s  .  com*/
    return object.getOpcode() == Opcodes.IALOAD;
}

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

License:Open Source License

@Override
public boolean evaluate(final AbstractInsnNode object) {
    if (object == null) {
        return false;
    }/* w  w w.j a v a 2s  .  c o  m*/
    return object.getOpcode() == Opcodes.LALOAD;
}

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

License:Open Source License

@Override
public InsnList optimize(final InsnList original, final MethodNode methodNode) throws JBOPClassException {
    optimized = false;//www  . j ava2s.c om
    final ListIterator<AbstractInsnNode> localIterator = original.iterator(iterator.nextIndex());
    Object object = input;
    Object lastObject = null;
    final List<AbstractInsnNode> nodes = new ArrayList<>();
    String fieldname = null;
    while (localIterator.hasNext()) {
        final AbstractInsnNode next = localIterator.next();
        if (next.getOpcode() == GETFIELD) {
            fieldname = NodeHelper.getFieldname(next);
            if (!ClassAccessor.isFinal(object, fieldname)) {
                correctIterator(localIterator);
                return original;
            }
            nodes.add(next);
            lastObject = object;
            object = ClassAccessor.getCurrentValue(object, fieldname);

        } else {
            if (object == input) {
                correctIterator(localIterator);
                return original;
            }
            final Type type = Type.getType(object.getClass());
            final String descriptor = type.getDescriptor();

            if (handleBuiltIn(descriptor, original, next, object, nodes, localIterator)) {
                optimized = true;
                return original;
            }
            object = handleArray(type, nodes, object, lastObject, next, fieldname, localIterator);
            if (object == null) {
                correctIterator(localIterator);
                return original;
            }
        }
    }
    return original;
}

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

License:Open Source License

private Object handleArray(final Type type, final List<AbstractInsnNode> nodes, final Object object,
        final Object lastObject, final AbstractInsnNode currentNode, final String fieldName,
        final ListIterator<AbstractInsnNode> localIterator) {
    if (!type.getDescriptor().startsWith("[")) {
        return null;
    }//from w ww .  ja v  a  2 s  .  c om

    Object localObject = object;
    AbstractInsnNode next = currentNode;
    final boolean isFinal = ClassAccessor.isFinal(lastObject, fieldName);
    final boolean hasAnnotation = ClassAccessor.hasAnnotation(lastObject, fieldName, ImmutableArray.class);

    for (int i = 0; i < type.getDimensions(); ++i) {
        if (!localIterator.hasNext()) {
            return null;
        }
        final boolean isArrayLength = next.getOpcode() == ARRAYLENGTH;
        if (isArrayLength) {
            if (!isFinal) {
                return null;
            }
            localObject = Array.getLength(localObject);
        } else {

            if (!NodeHelper.isNumberNode(next)) {
                return null;
            }
            final int index = NodeHelper.getNumberValue(next).intValue();
            nodes.add(next);
            if (!localIterator.hasNext()) {
                return null;
            }
            next = localIterator.next();
            final boolean isArrayLoad = next.getOpcode() >= IALOAD && next.getOpcode() <= SALOAD;
            if (isArrayLoad) {
                if (!hasAnnotation) {
                    return null;
                }
                localObject = Array.get(localObject, index);
            }
        }
        nodes.add(next);
        if (isArrayLength) {
            break;
        }
        if (i < type.getDimensions() - 1) {
            next = localIterator.next();
        }
    }
    return localObject;
}

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

License:Open Source License

private AbstractInsnNode handleNode(final InsnList original, final AbstractInsnNode currentNode,
        final Map<Integer, Object> knownValues, final MethodNode methodNode) {
    final int opcode = currentNode.getOpcode();
    if (opcode >= ISTORE && opcode <= ASTORE) {
        handleStore(currentNode, knownValues);
    } else if (opcode >= ILOAD && opcode <= ALOAD) {
        return hanldeLoad(original, currentNode, knownValues).getNext();
    } else if (opcode == IINC) {
        handleIInc(currentNode, knownValues);
    } else if (NodeHelper.isIf(currentNode)) {
        return handleIf(currentNode, knownValues, original, methodNode);
    } else if (opcode == GOTO) {
        if (LoopMatcher.isGotoOfLoop(currentNode)) {
            final AbstractInsnNode skipVars = skipVars(currentNode, knownValues);
            final Pair<AbstractInsnNode, AbstractInsnNode> bodyBounds = LoopMatcher.getBodyBounds(currentNode);
            if (bodyBounds != null) {
                handleNodes(bodyBounds.getLeft(), bodyBounds.getRight(), original, new HashMap<>(knownValues),
                        methodNode);// w ww. j  ava  2 s  .co  m
            }
            return skipVars;
        }
        return currentNode.getNext();
    }
    return currentNode.getNext();
}

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

License:Open Source License

private Collection<Integer> getVarsInRange(final AbstractInsnNode start, final AbstractInsnNode end) {
    final Set<Integer> vars = new HashSet<>();
    AbstractInsnNode current = start;
    while (current != null && current != end) {
        final int opcode = current.getOpcode();
        if (opcode >= ISTORE && opcode <= ASTORE || opcode == IINC) {
            vars.add(NodeHelper.getVarIndex(current));
        }/* w  w  w .java  2 s . c  o  m*/
        current = current.getNext();
    }
    return vars;
}

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

License:Open Source License

private List<Integer> getStores(final AbstractInsnNode start, final AbstractInsnNode end) {
    AbstractInsnNode tmpNode = start;
    final List<Integer> stores = new ArrayList<>();
    while (tmpNode != null && tmpNode != end) {
        if (tmpNode.getOpcode() >= ISTORE && tmpNode.getOpcode() <= ASTORE) {
            stores.add(NodeHelper.getVarIndex(tmpNode));
        } else if (tmpNode.getOpcode() == IINC) {
            final IincInsnNode iinc = (IincInsnNode) tmpNode;
            final int index = iinc.var;
            stores.add(index);//from w ww  . j ava2 s .  c om
        }
        tmpNode = tmpNode.getNext();
    }
    return stores;
}