public void add(Object o) { if (next != null) { InsnList.this.insertBefore(next, (AbstractInsnNode) o); } else if (prev != null) { InsnList.this.insert(prev, (AbstractInsnNode) o); } else { InsnList.this.add((AbstractInsnNode) o); } prev = (AbstractInsnNode) o; remove = null; }
@Override protected void doMethodFilter(MethodSource methodSource) { InsnList instructions = methodSource.getInstructions(); for (AbstractInsnNode abstractInsnNode = instructions.getFirst(); abstractInsnNode != null; abstractInsnNode = abstractInsnNode.getNext()) { methodInsnNode.owner.equals(ASM.getInternalName(PersistenceXmlParser.class))) { AbstractInsnNode nextInsnNode = abstractInsnNode.getNext(); instructions.remove(methodInsnNode.getPrevious()); instructions.remove(methodInsnNode); InsnList tmpInstructions = new InsnList(); tmpInstructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); tmpInstructions.add( new FieldInsnNode( Opcodes.GETFIELD, abstractInsnNode = tmpInstructions.getLast(); instructions.insertBefore(nextInsnNode, tmpInstructions); } else if (methodInsnNode.name.equals("isProvider") && methodInsnNode.owner.equals(ASM.getInternalName(ProviderChecker.class))) {
methodNode.tryCatchBlocks = cloneTryCatchBlocks(parseSource.getOldTryCatchBlocks()); InsnList instructions = cloneInsnList(parseSource.getOldInstructions()); for (AbstractInsnNode abstractInsnNode = instructions.getFirst(); abstractInsnNode != null; abstractInsnNode = abstractInsnNode.getNext()) { if (abstractInsnNode.getOpcode() == Opcodes.ARETURN) { InsnList tmpInstructions = new InsnList(); tmpInstructions.add(new InsnNode(Opcodes.DUP)); tmpInstructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); tmpInstructions.add(new InsnNode(Opcodes.SWAP)); tmpInstructions.add( new MethodInsnNode( Opcodes.INVOKEVIRTUAL, "()" + ASM.getDescriptor(AST.class), false)); tmpInstructions.add( new MethodInsnNode( Opcodes.INVOKEVIRTUAL, ")V", false)); instructions.insertBefore(abstractInsnNode, tmpInstructions);
@Override public void visitInvokeDynamicInsn(String name, String desc, Handle bsm, Object... bsmArgs) { instructions.add(new InvokeDynamicInsnNode(name, desc, bsm, bsmArgs)); }
protected static InsnList cloneInsnList(InsnList insnList) { InsnList newInsnList = new InsnList(); for (AbstractInsnNode abstractInsnNode = insnList.getFirst(); abstractInsnNode != null; abstractInsnNode = abstractInsnNode.getNext()) { newInsnList.add(cloneInsnNode(abstractInsnNode)); } return newInsnList; }
for (MethodEntry invokingMethodEntry : invokingClassEntry.methodEntries.values()) { InsnList instructions = invokingMethodEntry.instructions; for (AbstractInsnNode abstractInsnNode = instructions.getFirst(); abstractInsnNode != null; abstractInsnNode = abstractInsnNode.getNext()) { invokedClassEntry.clazz, methodInsnNode); instructions.insert(methodInsnNode, replacedMethodInsnNode); instructions.remove(methodInsnNode);
for (MethodEntry methodEntry : classEntry.methodEntries.values()) { if ((methodEntry.methodNode.access & Opcodes.ACC_BRIDGE) != 0) { if (methodEntry.instructions.size() < 3) { throw new AssertionError("illegal bridge method"); AbstractInsnNode firstInsnNode = methodEntry.methodNode.instructions.getFirst(); AbstractInsnNode lastInsnNode = methodEntry.methodNode.instructions.getLast(); AbstractInsnNode previousOfLastInsnNode = lastInsnNode.getPrevious(); if (firstInsnNode.getOpcode() != Opcodes.ALOAD ||
newMethodNode.signature = methodNode.signature; newMethodNode.exceptions = methodNode.exceptions; InsnList instractions = new InsnList(); instractions.add(new VarInsnNode(Opcodes.ALOAD, 0)); int slotIndex = 1; for (Class<?> parameterType : methodEntry.constructor.getParameterTypes()) { instractions.add(new VarInsnNode(ASM.getLoadCode(parameterType), slotIndex)); slotIndex += ASM.getSlotCount(parameterType); instractions.add(new MethodInsnNode( Opcodes.INVOKESPECIAL, lastEntry.clazz.getName().replace('.', '/'), InsnList moreInstructions = ClassEnhancer.this.getMoreConstructorInstructions(methodEntry.constructor); if (moreInstructions != null && moreInstructions.size() != 0) { instractions.add(moreInstructions); retval = true; instractions.add(new InsnNode(Opcodes.RETURN)); newMethodNode.instructions = instractions; newClassNode.methods.add(newMethodNode); retval = true; } else { instructions = new InsnList();
for (AbstractInsnNode abstractInsnNode = instructions.getLast(); abstractInsnNode != null; abstractInsnNode = abstractInsnNode.getPrevious()) { this.ancestorObjectModelContractDescriptor ); instructions.insert(abstractInsnNode, objectModelFieldInsnNode); if (this.metadataClass.getSuperClass() != null) { instructions.insert( objectModelFieldInsnNode, new TypeInsnNode(Opcodes.CHECKCAST, this.objectModelContractInternalName)
/** * Detects a JSR instruction and sets a flag to indicate we will need to do * inlining. */ @Override public void visitJumpInsn(final int opcode, final Label lbl) { super.visitJumpInsn(opcode, lbl); LabelNode ln = ((JumpInsnNode) instructions.getLast()).label; if (opcode == JSR && !subroutineHeads.containsKey(ln)) { subroutineHeads.put(ln, new BitSet()); } }
for (int i = 0, c = instructions.size(); i < c; i++) { AbstractInsnNode insn = instructions.get(i); Instantiation owner = instant.findOwner(i); newInstructions.add(remap); duplbl = remap; + " is a RET not owned by any subroutine"); newInstructions.add(new JumpInsnNode(GOTO, retlabel)); } else if (insn.getOpcode() == JSR) { LabelNode lbl = ((JumpInsnNode) insn).label; newInstructions.add(new InsnNode(ACONST_NULL)); newInstructions.add(new JumpInsnNode(GOTO, startlbl)); newInstructions.add(newinst.returnLabel); newInstructions.add(insn.clone(instant));
final BitSet anyvisited) { while (true) { AbstractInsnNode node = instructions.get(index); int destidx = instructions.indexOf(jnode.label); markSubroutineWalkDFS(sub, destidx, anyvisited); int destidx = instructions.indexOf(tsnode.dflt); markSubroutineWalkDFS(sub, destidx, anyvisited); for (int i = tsnode.labels.size() - 1; i >= 0; --i) { LabelNode l = tsnode.labels.get(i); destidx = instructions.indexOf(l); markSubroutineWalkDFS(sub, destidx, anyvisited); int destidx = instructions.indexOf(lsnode.dflt); markSubroutineWalkDFS(sub, destidx, anyvisited); for (int i = lsnode.labels.size() - 1; i >= 0; --i) { LabelNode l = lsnode.labels.get(i); destidx = instructions.indexOf(l); markSubroutineWalkDFS(sub, destidx, anyvisited); switch (instructions.get(index).getOpcode()) { case GOTO: case RET: if (index >= instructions.size()) { return;
/** * Constructs an uninitialized {@link MethodNode}. * * @param api * the ASM API version implemented by this visitor. Must be one * of {@link Opcodes#ASM4}, {@link Opcodes#ASM5} or {@link Opcodes#ASM6}. */ public MethodNode(final int api) { super(api); this.instructions = new InsnList(); }
instructions.resetLabels(); if (instructions.size() > 0) { mv.visitCode(); instructions.accept(mv);
public void remove() { if (remove != null) { if (remove == next) { next = next.next; } else { prev = prev.prev; } InsnList.this.remove(remove); remove = null; } else { throw new IllegalStateException(); } }