List of usage examples for org.objectweb.asm.tree AbstractInsnNode getNext
public AbstractInsnNode getNext()
From source file:de.tuberlin.uebb.jbop.optimizer.var.LocalVarInliner.java
License:Open Source License
private AbstractInsnNode hanldeLoad(final InsnList original, final AbstractInsnNode currentNode, final Map<Integer, Object> knownValues) { final int index = NodeHelper.getVarIndex(currentNode); if (knownValues.containsKey(index) && currentNode.getNext() != null && currentNode.getPrevious() != null) { final Object value = knownValues.get(index); final AbstractInsnNode replacement = NodeHelper.getInsnNodeFor(value); original.set(currentNode, replacement); optimized = true;/* w w w .j a va2 s .c om*/ return replacement; } return currentNode; }
From source file:de.tuberlin.uebb.jbop.optimizer.var.RemoveUnusedLocalVars.java
License:Open Source License
@Override public InsnList optimize(final InsnList original, final MethodNode methodNode) { optimized = false;//from w w w.j a v a 2 s.c o m final List<VarInsnNode> stores = new ArrayList<>(); final List<VarInsnNode> users = new ArrayList<>(); final List<IincInsnNode> iincs = new ArrayList<>(); findNodes(original, stores, users, iincs); final List<AbstractInsnNode> toBeRemoved = new ArrayList<>(); for (final VarInsnNode node : stores) { if (!usersContains(users, node)) { toBeRemoved.add(node); toBeRemoved.addAll(iincsContains(iincs, node)); } } // final InsnList newList = new InsnList(); final Iterator<AbstractInsnNode> iterator = original.iterator(); while (iterator.hasNext()) { final AbstractInsnNode currentNode = iterator.next(); if (toBeRemoved.contains(currentNode)) { if (currentNode.getOpcode() == Opcodes.IINC) { original.remove(currentNode); optimized = true; continue; } final AbstractInsnNode firstOfStack = NodeHelper.getFirstOfStack(currentNode); if (firstOfStack != null) { optimized = true; AbstractInsnNode remove = firstOfStack; while (remove != currentNode) { final AbstractInsnNode toRemove = remove; remove = remove.getNext(); original.remove(toRemove); } original.remove(currentNode); } } } return original; }
From source file:de.unisb.cs.st.javaslicer.tracer.instrumentation.TracingMethodInstrumenter.java
License:Open Source License
private void addLabelIfNecessary(final AbstractInsnNode insn) { AbstractInsnNode next = insn.getNext(); while (next != null) { if (next instanceof LabelNode && this.jumpTargetLabels.contains(next)) return; if (next instanceof FrameNode || next instanceof LineNumberNode) next = next.getNext();// www . j a va 2s .c o m else break; } traceLabel(null, InstructionType.SAFE); }
From source file:dodola.anole.lib.ConstructorDelegationDetector.java
License:Apache License
/** * Splits the constructor in two methods, the "set up" and the "body" parts (see above). *//* w ww. j a v a2s . co m*/ private static Constructor split(String owner, MethodNode method, VarInsnNode loadThis, MethodInsnNode delegation, int loadThisLine) { String[] exceptions = ((List<String>) method.exceptions).toArray(new String[method.exceptions.size()]); String newDesc = method.desc.replaceAll("\\((.*)\\)V", "([Ljava/lang/Object;$1)Ljava/lang/Object;"); MethodNode initArgs = new MethodNode(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "init$args", newDesc, null, exceptions); AbstractInsnNode insn = loadThis.getNext(); while (insn != delegation) { insn.accept(initArgs); insn = insn.getNext(); } LabelNode labelBefore = new LabelNode(); labelBefore.accept(initArgs); GeneratorAdapter mv = new GeneratorAdapter(initArgs, initArgs.access, initArgs.name, initArgs.desc); // Copy the arguments back to the argument array // The init_args part cannot access the "this" object and can have side effects on the // local variables. Because of this we use the first argument (which we want to keep // so all the other arguments remain unchanged) as a reference to the array where to // return the values of the modified local variables. Type[] types = Type.getArgumentTypes(initArgs.desc); int stack = 1; // Skip the first one which is a reference to the local array. for (int i = 1; i < types.length; i++) { Type type = types[i]; // This is not this, but the array of local arguments final values. mv.visitVarInsn(Opcodes.ALOAD, 0); mv.push(i); mv.visitVarInsn(type.getOpcode(Opcodes.ILOAD), stack); mv.box(type); mv.arrayStore(Type.getType(Object.class)); stack += type.getSize(); } // Create the args array with the values to send to the delegated constructor Type[] returnTypes = Type.getArgumentTypes(delegation.desc); // The extra element for the qualified name of the constructor. mv.push(returnTypes.length + 1); mv.newArray(Type.getType(Object.class)); int args = mv.newLocal(Type.getType("[Ljava/lang/Object;")); mv.storeLocal(args); for (int i = returnTypes.length - 1; i >= 0; i--) { Type type = returnTypes[i]; mv.loadLocal(args); mv.swap(type, Type.getType(Object.class)); mv.push(i + 1); mv.swap(type, Type.INT_TYPE); mv.box(type); mv.arrayStore(Type.getType(Object.class)); } // Store the qualified name of the constructor in the first element of the array. mv.loadLocal(args); mv.push(0); mv.push(delegation.owner + "." + delegation.desc); // Name of the constructor to be called. mv.arrayStore(Type.getType(Object.class)); mv.loadLocal(args); mv.returnValue(); newDesc = method.desc.replace("(", "(L" + owner + ";"); MethodNode body = new MethodNode(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "init$body", newDesc, null, exceptions); LabelNode labelAfter = new LabelNode(); labelAfter.accept(body); Set<LabelNode> bodyLabels = new HashSet<LabelNode>(); insn = delegation.getNext(); while (insn != null) { if (insn instanceof LabelNode) { bodyLabels.add((LabelNode) insn); } insn.accept(body); insn = insn.getNext(); } // manually transfer the exception table from the existing constructor to the new // "init$body" method. The labels were transferred just above so we can reuse them. //noinspection unchecked for (TryCatchBlockNode tryCatch : (List<TryCatchBlockNode>) method.tryCatchBlocks) { tryCatch.accept(body); } //noinspection unchecked for (LocalVariableNode variable : (List<LocalVariableNode>) method.localVariables) { boolean startsInBody = bodyLabels.contains(variable.start); boolean endsInBody = bodyLabels.contains(variable.end); if (!startsInBody && !endsInBody) { if (variable.index != 0) { // '#0' on init$args is not 'this' variable.accept(initArgs); } } else if (startsInBody && endsInBody) { variable.accept(body); } else if (!startsInBody && endsInBody) { // The variable spans from the args to the end of the method, create two: if (variable.index != 0) { // '#0' on init$args is not 'this' LocalVariableNode var0 = new LocalVariableNode(variable.name, variable.desc, variable.signature, variable.start, labelBefore, variable.index); var0.accept(initArgs); } LocalVariableNode var1 = new LocalVariableNode(variable.name, variable.desc, variable.signature, labelAfter, variable.end, variable.index); var1.accept(body); } else { throw new IllegalStateException("Local variable starts after it ends."); } } return new Constructor(loadThis, loadThisLine, initArgs, delegation, body); }
From source file:edu.mit.streamjit.util.bytecode.MethodResolver.java
License:Open Source License
private static AbstractInsnNode nextRealInstruction(AbstractInsnNode node) { assert node.getOpcode() == -1; while (node.getOpcode() == -1) node = node.getNext(); return node;/*from ww w . ja va 2s. c o m*/ }
From source file:edu.ubc.mirrors.holograms.FrameAnalyzer.java
License:Open Source License
public Frame<FrameValue>[] insertFrames() { Frame<FrameValue>[] frames = getFrames(); if (m == null || m.instructions == null) { return frames; }/*from w w w .j a v a2s. c o m*/ List<Frame<FrameValue>> newFrames = new ArrayList<Frame<FrameValue>>(); AbstractInsnNode insnNode = m.instructions.getFirst(); int n = m.instructions.size(); for (int i = 0; i < n; i++) { int insnType = insnNode.getType(); // Fetch the next node before possibly deleting this one, // since that will clear the links. AbstractInsnNode nextNode = insnNode.getNext(); if (insnType == AbstractInsnNode.LABEL || insnType == AbstractInsnNode.LINE || insnType == AbstractInsnNode.FRAME) { if (i + 1 < n) { jumpIn[i + 1] |= jumpIn[i]; stepIn[i + 1] = stepIn[i]; } if (insnType == AbstractInsnNode.FRAME) { m.instructions.remove(insnNode); } else { newFrames.add(frames[i]); } } else { if (jumpIn[i] || !stepIn[i]) { Frame<FrameValue> frame = frames[i]; // Unreachable code will have null frames if (frame != null) { FrameNode frameNode = toFrameNode(frame); m.instructions.insertBefore(insnNode, frameNode); newFrames.add(newFrame(frame)); } } newFrames.add(frames[i]); } insnNode = nextNode; } @SuppressWarnings("unchecked") Frame<FrameValue>[] result = (Frame<FrameValue>[]) newFrames.toArray(new Frame<?>[newFrames.size()]); return result; }
From source file:ivorius.ivtoolkit.asm.IvMultiNodeMatcherSimple.java
License:Apache License
@Override public boolean matchFromNodeInList(InsnList nodes, AbstractInsnNode node) { for (IvSingleNodeMatcher singleNodeMatcher : singleNodeMatchers) { if (!singleNodeMatcher.matchNode(node)) { return false; }// w ww . ja v a2 s. c om node = node.getNext(); } return true; }
From source file:jaspex.speculation.newspec.FlowFrame.java
License:Open Source License
/** Adiciona as frames geradas pelo Analyzer ao MethodNode, para serem usadas * pelo DelayGetFutureMethodVisitor./*from w ww. ja va2 s .c o m*/ **/ public static void injectFrames(MethodNode mn, Frame<BasicValue>[] frames) { InsnList insnList = mn.instructions; AbstractInsnNode node = insnList.getFirst(); int pos = 0; while (node != null) { Frame<BasicValue> currentFrame = frames[pos++]; if (currentFrame != null && !(node instanceof FrameNode)) { Object[] locals = locals(currentFrame); Object[] stack = stack(currentFrame); insnList.insertBefore(node, new FrameNode(F_NEW, locals.length, locals, stack.length, stack)); } node = node.getNext(); } }
From source file:jaspex.speculation.newspec.FlowFrame.java
License:Open Source License
/** Obtm prximo n que no seja uma Label ou um LineNumber **/ private static AbstractInsnNode getNextIgnoreLabelLineNop(AbstractInsnNode n) { while ((n != null) && (n instanceof LabelNode || n instanceof LineNumberNode || (n instanceof InsnNode && (((InsnNode) n).getOpcode() == NOP)))) { n = n.getNext(); }//from www . java 2 s. co m return n; }
From source file:jaspex.speculation.newspec.FlowFrame.java
License:Open Source License
/** Mtodo que detecta se o node1 est imediatamente antes do node2, ignorando LabelNodes * e LineNumberNodes que possam aparecer entre eles. * Nota: Diferente do nextIgnoreLabelLine pois node2 pode ser uma Label. **/// w w w. ja v a 2s.co m private static boolean directlyPrecedes(AbstractInsnNode node1, AbstractInsnNode node2) { AbstractInsnNode n = node1; while ((n = n.getNext()) != null) { if (n == node2) return true; if (!((n instanceof LabelNode) || (n instanceof LineNumberNode))) return false; } return false; }