List of usage examples for org.objectweb.asm.tree AbstractInsnNode FRAME
int FRAME
To view the source code for org.objectweb.asm.tree AbstractInsnNode FRAME.
Click Source Link
From source file:org.evosuite.instrumentation.NodeRegularExpression.java
License:Open Source License
/** * <p>matches</p>/* w ww .j a v a2s.co m*/ * * @param instructions a {@link org.objectweb.asm.tree.InsnList} object. * @return a boolean. */ public boolean matches(InsnList instructions) { int match = 0; AbstractInsnNode node = instructions.getFirst(); while (node != instructions.getLast()) { if (node.getType() == AbstractInsnNode.FRAME || node.getType() == AbstractInsnNode.LABEL || node.getType() == AbstractInsnNode.LINE) { node = node.getNext(); continue; } else { boolean found = false; for (int opcode : pattern[match]) { if (node.getOpcode() == opcode) { match++; found = true; break; } } if (!found) match = 0; } if (match == pattern.length) return true; node = node.getNext(); } return false; }
From source file:org.evosuite.instrumentation.NodeRegularExpression.java
License:Open Source License
/** * <p>getNextMatch</p>//from w w w .j a va2s . c o m * * @param start a {@link org.objectweb.asm.tree.AbstractInsnNode} object. * @param instructions a {@link org.objectweb.asm.tree.InsnList} object. * @return a {@link org.objectweb.asm.tree.AbstractInsnNode} object. */ public AbstractInsnNode getNextMatch(AbstractInsnNode start, InsnList instructions) { int match = 0; AbstractInsnNode node = start; AbstractInsnNode startNode = start; while (node != instructions.getLast()) { if (node.getType() == AbstractInsnNode.FRAME || node.getType() == AbstractInsnNode.LABEL || node.getType() == AbstractInsnNode.LINE) { node = node.getNext(); continue; } else { boolean found = false; for (int opcode : pattern[match]) { if (node.getOpcode() == opcode) { if (match == 0) startNode = node; match++; found = true; break; } } if (!found) match = 0; } if (match == pattern.length) { return startNode; } node = node.getNext(); } return null; }
From source file:org.jacoco.core.internal.analysis.filter.AbstractMatcher.java
License:Open Source License
/** * Returns first instruction from given and following it that is not * {@link AbstractInsnNode#FRAME}, {@link AbstractInsnNode#LABEL}, * {@link AbstractInsnNode#LINE}.// ww w. j a va 2s .c o m */ static AbstractInsnNode skipNonOpcodes(AbstractInsnNode cursor) { while (cursor != null && (cursor.getType() == AbstractInsnNode.FRAME || cursor.getType() == AbstractInsnNode.LABEL || cursor.getType() == AbstractInsnNode.LINE)) { cursor = cursor.getNext(); } return cursor; }
From source file:org.jacoco.core.internal.analysis.filter.FinallyFilter.java
License:Open Source License
private static void filter(final IFilterOutput output, final List<TryCatchBlockNode> tryCatchBlocks, final TryCatchBlockNode catchAnyBlock) { final AbstractInsnNode e = next(catchAnyBlock.handler); final int size = size(e); if (size <= 0) { return;/*from w w w . j ava2 s.c o m*/ } // Determine instructions inside regions final Set<AbstractInsnNode> inside = new HashSet<AbstractInsnNode>(); for (final TryCatchBlockNode t : tryCatchBlocks) { if (t.handler == catchAnyBlock.handler) { AbstractInsnNode i = t.start; while (i != t.end) { inside.add(i); i = i.getNext(); } } } // Find and merge duplicates at exits of regions for (final TryCatchBlockNode t : tryCatchBlocks) { if (t.handler == catchAnyBlock.handler) { boolean continues = false; AbstractInsnNode i = t.start; while (i != t.end) { switch (i.getType()) { case AbstractInsnNode.FRAME: case AbstractInsnNode.LINE: case AbstractInsnNode.LABEL: break; case AbstractInsnNode.JUMP_INSN: final AbstractInsnNode jumpTarget = next(((JumpInsnNode) i).label); if (!inside.contains(jumpTarget)) { merge(output, size, e, jumpTarget); } continues = i.getOpcode() != Opcodes.GOTO; break; default: switch (i.getOpcode()) { case Opcodes.IRETURN: case Opcodes.LRETURN: case Opcodes.FRETURN: case Opcodes.DRETURN: case Opcodes.ARETURN: case Opcodes.RETURN: case Opcodes.ATHROW: continues = false; break; default: continues = true; break; } break; } i = i.getNext(); } i = next(i); if (continues && !inside.contains(i)) { merge(output, size, e, i); } } if (t != catchAnyBlock && t.start == catchAnyBlock.start && t.end == catchAnyBlock.end) { final AbstractInsnNode i = next(next(t.handler)); if (!inside.contains(i)) { // javac's empty catch - merge after ASTORE merge(output, size, e, i); } } } }
From source file:org.jacoco.core.internal.analysis.filter.FinallyFilter.java
License:Open Source License
private static AbstractInsnNode next(AbstractInsnNode i) { do {//from ww w . java2 s. c o m i = i.getNext(); } while (i != null && (AbstractInsnNode.FRAME == i.getType() || AbstractInsnNode.LABEL == i.getType() || AbstractInsnNode.LINE == i.getType())); return i; }
From source file:org.spoofax.interpreter.adapter.asm.ASMFactory.java
License:LGPL
public static IStrategoTerm wrap(AbstractInsnNode node) { if (node == null) return None.INSTANCE; switch (node.getType()) { case AbstractInsnNode.FIELD_INSN: return wrap((FieldInsnNode) node); case AbstractInsnNode.FRAME: return wrap((FrameNode) node); case AbstractInsnNode.IINC_INSN: return wrap((IincInsnNode) node); case AbstractInsnNode.INSN: return wrap((InsnNode) node); case AbstractInsnNode.INT_INSN: return wrap((IntInsnNode) node); case AbstractInsnNode.INVOKE_DYNAMIC_INSN: throw new NotImplementedException(); case AbstractInsnNode.JUMP_INSN: return wrap((JumpInsnNode) node); case AbstractInsnNode.LABEL: return wrap((LabelNode) node); case AbstractInsnNode.LDC_INSN: return wrap((LdcInsnNode) node); case AbstractInsnNode.LINE: return wrap((LineNumberNode) node); case AbstractInsnNode.LOOKUPSWITCH_INSN: return wrap((LookupSwitchInsnNode) node); case AbstractInsnNode.METHOD_INSN: return wrap((MethodInsnNode) node); case AbstractInsnNode.MULTIANEWARRAY_INSN: return wrap((MultiANewArrayInsnNode) node); case AbstractInsnNode.TABLESWITCH_INSN: return wrap((TableSwitchInsnNode) node); case AbstractInsnNode.TYPE_INSN: return wrap((TypeInsnNode) node); case AbstractInsnNode.VAR_INSN: return wrap((VarInsnNode) node); case -1:/*from w w w . j a va 2 s.c om*/ System.err.println("Bogus " + node.getClass().getName()); return None.INSTANCE; default: throw new IllegalArgumentException( "Unknown type " + node.getOpcode() + " for " + node.getClass().getName()); } }
From source file:org.springsource.loaded.TypeDiffComputer.java
License:Apache License
private static boolean sameInstruction(AbstractInsnNode o, AbstractInsnNode n) { if (o.getType() != o.getType() || o.getOpcode() != n.getOpcode()) { return false; }/*from w ww . j a v a2 s . c o m*/ switch (o.getType()) { case (AbstractInsnNode.INSN): // 0 if (!sameInsnNode(o, n)) { return false; } break; case (AbstractInsnNode.INT_INSN): // 1 if (!sameIntInsnNode(o, n)) { return false; } break; case (AbstractInsnNode.VAR_INSN): // 2 if (!sameVarInsn(o, n)) { return false; } break; case (AbstractInsnNode.TYPE_INSN):// 3 if (!sameTypeInsn(o, n)) { return false; } break; case (AbstractInsnNode.FIELD_INSN): // 4 if (!sameFieldInsn(o, n)) { return false; } break; case (AbstractInsnNode.METHOD_INSN): // 5 if (!sameMethodInsnNode(o, n)) { return false; } break; case (AbstractInsnNode.JUMP_INSN): // 6 if (!sameJumpInsnNode(o, n)) { return false; } break; case (AbstractInsnNode.LABEL): // 7 if (!sameLabelNode(o, n)) { return false; } break; case (AbstractInsnNode.LDC_INSN): // 8 if (!sameLdcInsnNode(o, n)) { return false; } break; case (AbstractInsnNode.IINC_INSN): // 9 if (!sameIincInsn(o, n)) { return false; } break; case (AbstractInsnNode.TABLESWITCH_INSN): // 10 if (!sameTableSwitchInsn(o, n)) { return false; } break; case (AbstractInsnNode.LOOKUPSWITCH_INSN): // 11 if (!sameLookupSwitchInsn(o, n)) { return false; } break; case (AbstractInsnNode.MULTIANEWARRAY_INSN): // 12 if (!sameMultiANewArrayInsn(o, n)) { return false; } break; case (AbstractInsnNode.FRAME): // 13 if (!sameFrameInsn(o, n)) { return false; } break; case (AbstractInsnNode.LINE): // 14 if (!sameLineNumberNode(o, n)) { return false; } break; default: throw new IllegalStateException("nyi " + o.getType()); } return true; }
From source file:pku.sei.checkedcoverage.tracer.instrumentation.TracingMethodInstrumenter.java
License:Creative Commons License
@SuppressWarnings("unchecked") public void transform(final ListIterator<MethodNode> methodIt) { // do not modify abstract or native methods if ((this.methodNode.access & ACC_ABSTRACT) != 0 || (this.methodNode.access & ACC_NATIVE) != 0) return;/*from ww w . ja va 2 s . co m*/ // check out what labels are jump targets (only these have to be traced) analyze(this.methodNode); this.instructionIterator = new FixedInstructionIterator(this.methodNode.instructions); // in the old method, initialize the new local variable for the threadtracer this.instructionIterator.add(new MethodInsnNode(INVOKESTATIC, Type.getInternalName(Tracer.class), "getInstance", "()L" + Type.getInternalName(Tracer.class) + ";")); this.instructionIterator.add(new MethodInsnNode(INVOKEVIRTUAL, Type.getInternalName(Tracer.class), "getThreadTracer", "()L" + Type.getInternalName(ThreadTracer.class) + ";")); this.instructionIterator.add(new InsnNode(DUP)); this.instructionIterator.add(new VarInsnNode(ASTORE, this.tracerLocalVarIndex)); this.instructionIterator.add( new MethodInsnNode(INVOKEINTERFACE, Type.getInternalName(ThreadTracer.class), "isPaused", "()Z")); final LabelNode noTracingLabel = new LabelNode(); this.instructionIterator.add(new JumpInsnNode(IFNE, noTracingLabel)); // create a copy of the (uninstrumented) instructions (later, while iterating through the instructions) final InsnList oldInstructions = new InsnList(); final Map<LabelNode, LabelNode> labelCopies = LazyMap.decorate(new HashMap<LabelNode, LabelNode>(), new Factory() { @Override public Object create() { return new LabelNode(); } }); // copy the try-catch-blocks final Object[] oldTryCatchblockNodes = this.methodNode.tryCatchBlocks.toArray(); for (final Object o : oldTryCatchblockNodes) { final TryCatchBlockNode tcb = (TryCatchBlockNode) o; final TryCatchBlockNode newTcb = new TryCatchBlockNode(labelCopies.get(tcb.start), labelCopies.get(tcb.end), labelCopies.get(tcb.handler), tcb.type); this.methodNode.tryCatchBlocks.add(newTcb); } // increment number of local variables by one (for the threadtracer) ++this.methodNode.maxLocals; // and increment all local variable indexes after the new one by one for (final Object o : this.methodNode.localVariables) { final LocalVariableNode localVar = (LocalVariableNode) o; if (localVar.index >= this.tracerLocalVarIndex) ++localVar.index; } // store information about local variables in the ReadMethod object List<LocalVariable> localVariables = new ArrayList<LocalVariable>(); for (final Object o : this.methodNode.localVariables) { final LocalVariableNode localVar = (LocalVariableNode) o; while (localVariables.size() <= localVar.index) localVariables.add(null); localVariables.set(localVar.index, new LocalVariable(localVar.index, localVar.name, localVar.desc)); } this.readMethod.setLocalVariables(localVariables.toArray(new LocalVariable[localVariables.size()])); localVariables = null; // each method must start with a (dedicated) label: assert this.readMethod.getInstructions().isEmpty(); traceLabel(null, InstructionType.METHODENTRY); assert this.readMethod.getInstructions().size() == 1 && this.readMethod.getInstructions().get(0) instanceof LabelMarker && ((LabelMarker) this.readMethod.getInstructions().get(0)).isAdditionalLabel(); this.readMethod.setMethodEntryLabel((LabelMarker) this.readMethod.getInstructions().get(0)); // needed later: final LabelNode l0 = new LabelNode(); this.instructionIterator.add(l0); // then, visit the instructions that were in the method before while (this.instructionIterator.hasNext()) { final AbstractInsnNode insnNode = this.instructionIterator.next(); switch (insnNode.getType()) { case AbstractInsnNode.INSN: transformInsn((InsnNode) insnNode); break; case AbstractInsnNode.INT_INSN: transformIntInsn((IntInsnNode) insnNode); break; case AbstractInsnNode.VAR_INSN: transformVarInsn((VarInsnNode) insnNode); break; case AbstractInsnNode.TYPE_INSN: transformTypeInsn((TypeInsnNode) insnNode); break; case AbstractInsnNode.FIELD_INSN: transformFieldInsn((FieldInsnNode) insnNode); break; case AbstractInsnNode.METHOD_INSN: transformMethodInsn((MethodInsnNode) insnNode); break; case AbstractInsnNode.JUMP_INSN: transformJumpInsn((JumpInsnNode) insnNode); break; case AbstractInsnNode.LABEL: transformLabel((LabelNode) insnNode); break; case AbstractInsnNode.LDC_INSN: transformLdcInsn((LdcInsnNode) insnNode); break; case AbstractInsnNode.IINC_INSN: transformIincInsn((IincInsnNode) insnNode); break; case AbstractInsnNode.TABLESWITCH_INSN: transformTableSwitchInsn((TableSwitchInsnNode) insnNode); break; case AbstractInsnNode.LOOKUPSWITCH_INSN: transformLookupSwitchInsn((LookupSwitchInsnNode) insnNode); break; case AbstractInsnNode.MULTIANEWARRAY_INSN: transformMultiANewArrayInsn((MultiANewArrayInsnNode) insnNode); break; case AbstractInsnNode.FRAME: // ignore break; case AbstractInsnNode.LINE: // ignore break; default: throw new RuntimeException("Unknown instruction type " + insnNode.getType() + " (" + insnNode.getClass().getSimpleName() + ")"); } oldInstructions.add(insnNode.clone(labelCopies)); } assert this.outstandingInitializations == 0; // add the (old) try-catch blocks to the readMethods // (can only be done down here since we use the information in the // labels map) for (final Object o : oldTryCatchblockNodes) { final TryCatchBlockNode tcb = (TryCatchBlockNode) o; this.readMethod.addTryCatchBlock(new TryCatchBlock(this.labels.get(tcb.start), this.labels.get(tcb.end), this.labels.get(tcb.handler), tcb.type)); } final LabelNode l1 = new LabelNode(); this.instructionIterator.add(l1); final int newPos = this.readMethod.getInstructions().size(); traceLabel(null, InstructionType.METHODEXIT); assert this.readMethod.getInstructions().size() == newPos + 1; final AbstractInstruction abnormalTerminationLabel = this.readMethod.getInstructions().get(newPos); assert abnormalTerminationLabel instanceof LabelMarker; this.readMethod.setAbnormalTerminationLabel((LabelMarker) abnormalTerminationLabel); this.methodNode.instructions.add(new InsnNode(ATHROW)); // add a try catch block around the method so that we can trace when this method is left // a thrown exception this.methodNode.tryCatchBlocks.add(new TryCatchBlockNode(l0, l1, l1, null)); // now add the code that is executed if no tracing should be performed this.methodNode.instructions.add(noTracingLabel); if (this.firstLine != -1) this.methodNode.instructions.add(new LineNumberNode(this.firstLine, noTracingLabel)); this.methodNode.instructions.add(new InsnNode(ACONST_NULL)); this.methodNode.instructions.add(new VarInsnNode(ASTORE, this.tracerLocalVarIndex)); this.methodNode.instructions.add(oldInstructions); // finally: create a copy of the method that gets the ThreadTracer as argument // this is only necessary for private methods or "<init>" if (this.tracer.wasRedefined(this.readMethod.getReadClass().getName()) && (this.methodNode.access & ACC_PRIVATE) != 0) { final Type[] oldMethodArguments = Type.getArgumentTypes(this.methodNode.desc); final Type[] newMethodArguments = Arrays.copyOf(oldMethodArguments, oldMethodArguments.length + 1); newMethodArguments[oldMethodArguments.length] = Type.getType(ThreadTracer.class); final String newMethodDesc = Type.getMethodDescriptor(Type.getReturnType(this.methodNode.desc), newMethodArguments); final MethodNode newMethod = new MethodNode(this.methodNode.access, this.methodNode.name, newMethodDesc, this.methodNode.signature, (String[]) this.methodNode.exceptions.toArray(new String[this.methodNode.exceptions.size()])); methodIt.add(newMethod); int threadTracerParamPos = ((this.readMethod.getAccess() & Opcodes.ACC_STATIC) == 0 ? 1 : 0); for (final Type t : oldMethodArguments) threadTracerParamPos += t.getSize(); final Map<LabelNode, LabelNode> newMethodLabels = LazyMap.decorate(new HashMap<LabelNode, LabelNode>(), new Factory() { @Override public Object create() { return new LabelNode(); } }); // copy the local variables information to the new method for (final Object o : this.methodNode.localVariables) { final LocalVariableNode lv = (LocalVariableNode) o; newMethod.localVariables.add(new LocalVariableNode(lv.name, lv.desc, lv.signature, newMethodLabels.get(lv.start), newMethodLabels.get(lv.end), lv.index)); } newMethod.maxLocals = this.methodNode.maxLocals; newMethod.maxStack = this.methodNode.maxStack; // copy the try-catch-blocks for (final Object o : this.methodNode.tryCatchBlocks) { final TryCatchBlockNode tcb = (TryCatchBlockNode) o; newMethod.tryCatchBlocks.add(new TryCatchBlockNode(newMethodLabels.get(tcb.start), newMethodLabels.get(tcb.end), newMethodLabels.get(tcb.handler), tcb.type)); } // skip the first 6 instructions, replace them with these: newMethod.instructions.add(new VarInsnNode(ALOAD, threadTracerParamPos)); newMethod.instructions.add(new InsnNode(DUP)); newMethod.instructions.add(new VarInsnNode(ASTORE, this.tracerLocalVarIndex)); newMethod.instructions.add(new JumpInsnNode(IFNULL, newMethodLabels.get(noTracingLabel))); final Iterator<AbstractInsnNode> oldInsnIt = this.methodNode.instructions.iterator(6); // and add all the other instructions while (oldInsnIt.hasNext()) { final AbstractInsnNode insn = oldInsnIt.next(); newMethod.instructions.add(insn.clone(newMethodLabels)); } } ready(); }
From source file:pl.clareo.coroutines.core.MethodTransformer.java
License:Apache License
private static FrameNode findNextFrame(AbstractInsnNode insn) { AbstractInsnNode nextInsn = insn.getNext(); while (nextInsn != null) { if (nextInsn.getType() == AbstractInsnNode.FRAME) { return (FrameNode) nextInsn; }/*from www . jav a 2 s .c om*/ nextInsn = nextInsn.getNext(); } return null; }
From source file:pl.clareo.coroutines.core.MethodTransformer.java
License:Apache License
private static FrameNode findPreviousFrame(AbstractInsnNode insn) { AbstractInsnNode prevInsn = insn.getPrevious(); while (prevInsn != null) { if (prevInsn.getType() == AbstractInsnNode.FRAME) { return (FrameNode) prevInsn; }/*from w w w . ja va2 s. c o m*/ prevInsn = prevInsn.getPrevious(); } return null; }