List of usage examples for org.objectweb.asm.tree InsnList add
public void add(final InsnList insnList)
From source file:com.navercorp.pinpoint.profiler.instrument.ASMMethodVariables.java
License:Apache License
void box(final InsnList instructions, Type type) { if (type.getSort() == Type.OBJECT || type.getSort() == Type.ARRAY) { return;//from www . j a v a 2s . c om } if (type == Type.VOID_TYPE) { // push null instructions.add(new InsnNode(Opcodes.ACONST_NULL)); } else { Type boxed = getBoxedType(type); // new instance. newInstance(instructions, boxed); if (type.getSize() == 2) { // Pp -> Ppo -> oPpo -> ooPpo -> ooPp -> o // dupX2 dupX2(instructions); // dupX2 dupX2(instructions); // pop pop(instructions); } else { // p -> po -> opo -> oop -> o // dupX1 dupX1(instructions); // swap swap(instructions); } invokeConstructor(instructions, boxed, new Method("<init>", Type.VOID_TYPE, new Type[] { type })); } }
From source file:com.navercorp.pinpoint.profiler.instrument.ASMMethodVariables.java
License:Apache License
void arrayStore(final InsnList instructions, final Type type) { instructions.add(new InsnNode(type.getOpcode(Opcodes.IASTORE))); }
From source file:com.navercorp.pinpoint.profiler.instrument.ASMMethodVariables.java
License:Apache License
void newInstance(final InsnList instructions, final Type type) { instructions.add(new TypeInsnNode(Opcodes.NEW, type.getInternalName())); }
From source file:com.navercorp.pinpoint.profiler.instrument.ASMMethodVariables.java
License:Apache License
void invokeConstructor(final InsnList instructions, final Type type, final Method method) { String owner = type.getSort() == Type.ARRAY ? type.getDescriptor() : type.getInternalName(); instructions.add( new MethodInsnNode(Opcodes.INVOKESPECIAL, owner, method.getName(), method.getDescriptor(), false)); }
From source file:com.navercorp.pinpoint.profiler.instrument.ASMMethodVariables.java
License:Apache License
public void returnValue(final InsnList instructions) { instructions.add(new InsnNode(this.returnType.getOpcode(Opcodes.IRETURN))); }
From source file:com.offbynull.coroutines.instrumenter.asm.InstructionUtils.java
License:Open Source License
/** * Clones an invokevirtual/invokespecial/invokeinterface/invokedynamic node and returns it as an instruction list. * @param insnNode instruction to clone/*from w ww . j a va 2 s . com*/ * @throws NullPointerException if any argument is {@code null} * @throws IllegalArgumentException if node isn't of invoke type * @return instruction list with cloned instruction */ public static InsnList cloneInvokeNode(AbstractInsnNode insnNode) { Validate.notNull(insnNode); Validate.isTrue(insnNode instanceof MethodInsnNode || insnNode instanceof InvokeDynamicInsnNode); InsnList ret = new InsnList(); ret.add(insnNode.clone(new HashMap<>())); return ret; }
From source file:com.offbynull.coroutines.instrumenter.asm.InstructionUtils.java
License:Open Source License
/** * Clones a monitorenter/monitorexit node and returns it as an instruction list. * @param insnNode instruction to clone/*from www . ja va 2 s. com*/ * @throws NullPointerException if any argument is {@code null} * @throws IllegalArgumentException if node isn't of invoke type * @return instruction list with cloned instruction */ public static InsnList cloneMonitorNode(AbstractInsnNode insnNode) { Validate.notNull(insnNode); Validate.isTrue(insnNode instanceof InsnNode); Validate.isTrue( insnNode.getOpcode() == Opcodes.MONITORENTER || insnNode.getOpcode() == Opcodes.MONITOREXIT); InsnList ret = new InsnList(); ret.add(insnNode.clone(new HashMap<>())); return ret; }
From source file:com.offbynull.coroutines.instrumenter.asm.InstructionUtils.java
License:Open Source License
/** * Clones an instruction list. All labels are remapped unless otherwise specified in {@code globalLabels}. * @param insnList instruction list to clone * @param globalLabels set of labels that should not be remapped * @throws NullPointerException if any argument is {@code null} * @return instruction list with cloned instructions *//*from www.ja v a 2 s . c om*/ public static InsnList cloneInsnList(InsnList insnList, Set<LabelNode> globalLabels) { Validate.notNull(insnList); // remap all labelnodes Map<LabelNode, LabelNode> labelNodeMapping = new HashMap<>(); ListIterator<AbstractInsnNode> it = insnList.iterator(); while (it.hasNext()) { AbstractInsnNode abstractInsnNode = it.next(); if (abstractInsnNode instanceof LabelNode) { LabelNode existingLabelNode = (LabelNode) abstractInsnNode; labelNodeMapping.put(existingLabelNode, new LabelNode()); } } // override remapping such that global labels stay the same for (LabelNode globalLabel : globalLabels) { labelNodeMapping.put(globalLabel, globalLabel); } // clone InsnList ret = new InsnList(); it = insnList.iterator(); while (it.hasNext()) { AbstractInsnNode abstractInsnNode = it.next(); ret.add(abstractInsnNode.clone(labelNodeMapping)); } return ret; }
From source file:com.offbynull.coroutines.instrumenter.asm.InstructionUtils.java
License:Open Source License
/** * Combines multiple instruction lists in to a single instruction list. * @param insnLists instruction lists to merge * @throws NullPointerException if any argument is {@code null} or contains {@code null} * @return merged instructions/*w w w . j a v a2s. c om*/ */ public static InsnList merge(InsnList... insnLists) { Validate.notNull(insnLists); Validate.noNullElements(insnLists); InsnList ret = new InsnList(); for (InsnList insnList : insnLists) { ret.add(insnList); } return ret; }
From source file:com.offbynull.coroutines.instrumenter.asm.InstructionUtils.java
License:Open Source License
/** * Generates instructions for an unconditional jump to a label. * @param labelNode label to jump to/* w ww. j a v a2s .com*/ * @throws NullPointerException if any argument is {@code null} * @return instructions for an unconditional jump to {@code labelNode} */ public static InsnList jumpTo(LabelNode labelNode) { Validate.notNull(labelNode); InsnList ret = new InsnList(); ret.add(new JumpInsnNode(Opcodes.GOTO, labelNode)); return ret; }