List of usage examples for org.objectweb.asm.tree AbstractInsnNode getNext
public AbstractInsnNode getNext()
From source file:de.tuberlin.uebb.jbop.optimizer.utils.LoopMatcher.java
License:Open Source License
/** * Checks if node is store of loop.//from w w w . java2 s . co m * * @param node * the node * @return true if node is store of loop */ public static boolean isStoreOfLoop(final AbstractInsnNode node) { if (node == null) { return false; } final int opcode = node.getOpcode(); if (opcode != ISTORE) { return false; } final AbstractInsnNode next = node.getNext(); if (NodeHelper.isGoto(next)) { return getTypeOneLoop(node, next) != null; } if (next instanceof LabelNode) { return getTypeTwoLoop(node, next) != null; } return false; }
From source file:de.tuberlin.uebb.jbop.optimizer.utils.LoopMatcher.java
License:Open Source License
private static Loop getTypeOneLoop(final AbstractInsnNode counter, final AbstractInsnNode jump) { final LabelNode labelOfJump = ((JumpInsnNode) jump).label; final AbstractInsnNode target = labelOfJump.getNext(); final AbstractInsnNode label = jump.getNext(); if (!(label instanceof LabelNode)) { return null; }//from w ww . j a v a 2s . c om final AbstractInsnNode ifNode = findIf(target, label); if (ifNode == null) { return null; } AbstractInsnNode previous = NodeHelper.getPrevious(ifNode); AbstractInsnNode endValue = previous.getPrevious(); final int varIndex = NodeHelper.getVarIndex(counter); int varIndex2 = NodeHelper.getVarIndex(previous); if (varIndex2 == -1) { previous = target; endValue = previous.getNext(); varIndex2 = NodeHelper.getVarIndex(counter); } if (varIndex != varIndex2) { return null; } final AbstractInsnNode iinc = labelOfJump.getPrevious(); if (endValue instanceof LabelNode) { endValue = NodeHelper.getInsnNodeFor(0); } final AbstractInsnNode startValue = counter.getPrevious(); final AbstractInsnNode firstOfBody = ((JumpInsnNode) ifNode).label.getNext(); return new Loop(ifNode, startValue, endValue, iinc, firstOfBody, ifNode, counter); }
From source file:de.tuberlin.uebb.jbop.optimizer.utils.LoopMatcher.java
License:Open Source License
/** * Find if.// w w w .j ava 2 s . com * * @param target * the target * @param desiredLabel * the desired label * @return the abstract insn node */ public static AbstractInsnNode findIf(final AbstractInsnNode target, final AbstractInsnNode desiredLabel) { if (target == null) { return null; } AbstractInsnNode maybeIf = target.getNext(); while (maybeIf != null) { if (NodeHelper.isIf(maybeIf)) { if (((JumpInsnNode) maybeIf).label == desiredLabel) { return maybeIf; } } maybeIf = maybeIf.getNext(); } return null; }
From source file:de.tuberlin.uebb.jbop.optimizer.utils.LoopMatcher.java
License:Open Source License
private static AbstractInsnNode findGotoForLabel(final AbstractInsnNode label, final boolean up) { AbstractInsnNode currentNode;/*from ww w. ja v a 2 s .co m*/ if (up) { currentNode = label.getPrevious(); } else { currentNode = label.getNext(); } while (currentNode != null) { if (NodeHelper.isGoto(currentNode) && ((JumpInsnNode) currentNode).label == label) { return currentNode; } if (up) { currentNode = currentNode.getPrevious(); } else { currentNode = currentNode.getNext(); } } return null; }
From source file:de.tuberlin.uebb.jbop.optimizer.utils.LoopMatcher.java
License:Open Source License
private static Loop getTypeTwoLoop(final AbstractInsnNode counter, final AbstractInsnNode label) { final AbstractInsnNode gotoNode = findGotoForLabel(label, false); if (gotoNode == null) { return null; }// w w w .java 2 s. c o m final AbstractInsnNode ifNode = findIf(counter.getNext(), gotoNode.getNext()); if (ifNode == null) { return null; } AbstractInsnNode previous = ifNode.getPrevious(); AbstractInsnNode endValue = previous.getPrevious(); int varIndex2 = NodeHelper.getVarIndex(previous); if (varIndex2 == -1) { previous = label.getNext(); varIndex2 = NodeHelper.getVarIndex(previous); endValue = previous.getNext(); } final int varIndex = NodeHelper.getVarIndex(counter); if (varIndex != varIndex2) { return null; } final AbstractInsnNode startValue = counter.getPrevious(); if (endValue instanceof LabelNode) { endValue = NodeHelper.getInsnNodeFor(0); } final AbstractInsnNode iinc = gotoNode.getPrevious(); final AbstractInsnNode firstOfBody = ((JumpInsnNode) ifNode).getNext(); return new Loop(reverse((JumpInsnNode) ifNode), startValue, endValue, iinc, firstOfBody, gotoNode.getNext(), counter); }
From source file:de.tuberlin.uebb.jbop.optimizer.utils.NodeHelper.java
License:Open Source License
/** * Gets the next node skipping {@link LineNumberNode}s and {@link LabelNode}s. * //from www . j av a 2 s . com * @param node * the node * @return the next node */ public static AbstractInsnNode getNext(final AbstractInsnNode node) { if (node == null) { return null; } AbstractInsnNode current = node; do { current = current.getNext(); if (current != null && !(current instanceof LineNumberNode || current instanceof LabelNode)) { break; } } while (current != null); return current; }
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 2s.c o 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)); }/*from w ww . j ava 2 s . c om*/ current = current.getNext(); } return vars; }
From source file:de.tuberlin.uebb.jbop.optimizer.var.LocalVarInliner.java
License:Open Source License
private AbstractInsnNode handleIf(final AbstractInsnNode currentNode, final Map<Integer, Object> knownValues, final InsnList original, final MethodNode methodNode) { if (LoopMatcher.isIfOfLoop(currentNode)) { return skipVars(currentNode, knownValues); }/* ww w. j ava 2s.c o m*/ final LabelNode endIf = ((JumpInsnNode) currentNode).label; final AbstractInsnNode end1 = endIf.getNext(); handleNodes(currentNode.getNext(), endIf, original, new HashMap<>(knownValues), methodNode); AbstractInsnNode end2 = null; final List<Integer> stores = getStores(currentNode.getNext(), end1); if (endIf.getPrevious() instanceof JumpInsnNode) { end2 = ((JumpInsnNode) endIf.getPrevious()).label.getNext(); handleNodes(end1, end2, original, new HashMap<>(knownValues), methodNode); stores.addAll(getStores(endIf, end2)); } for (final Integer var : stores) { knownValues.remove(var); } if (end2 != null) { return end2; } return end1; }
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 w w . j a v a 2s. com*/ } tmpNode = tmpNode.getNext(); } return stores; }