List of usage examples for org.objectweb.asm.tree AbstractInsnNode getNext
public AbstractInsnNode getNext()
From source file:org.jacoco.playground.filter.InsnSequenceMatcher.java
License:Open Source License
private AbstractInsnNode getNext(final AbstractInsnNode node) { return skipIgnoredForward(node.getNext()); }
From source file:org.jacoco.playground.filter.InsnSubList.java
License:Open Source License
public Iterator<AbstractInsnNode> iterator() { return new Iterator<AbstractInsnNode>() { private AbstractInsnNode next = first; public boolean hasNext() { return next != null; }/*from w w w . j a v a 2s. c o m*/ public AbstractInsnNode next() { final AbstractInsnNode n = next; if (n == null) { throw new NoSuchElementException(); } next = n == last ? null : n.getNext(); return n; } public void remove() { throw new UnsupportedOperationException(); } }; }
From source file:org.jboss.byteman.agent.adapter.BMInsnList.java
License:Open Source License
public void accept(final MethodVisitor mv) { // this method visitor must implement LocalScopeMethodVisitor or else we woudl not be here LocalScopeMethodVisitor lsmv = (LocalScopeMethodVisitor) mv; // first index all local vars by start and end label HashMap<Label, LinkedList<LocalVariableNode>> localStarts = new HashMap<Label, LinkedList<LocalVariableNode>>(); HashMap<Label, LinkedList<LocalVariableNode>> localEnds = new HashMap<Label, LinkedList<LocalVariableNode>>(); Iterator iterator = localvariables.iterator(); while (iterator.hasNext()) { LocalVariableNode local = (LocalVariableNode) iterator.next(); Label label = local.start.getLabel(); LinkedList<LocalVariableNode> locals = localStarts.get(label); if (locals == null) { locals = new LinkedList<LocalVariableNode>(); localStarts.put(label, locals); }//from w w w.j a v a 2 s.co m locals.addLast(local); label = local.end.getLabel(); locals = localEnds.get(label); if (locals == null) { locals = new LinkedList<LocalVariableNode>(); localEnds.put(label, locals); } locals.addLast(local); } // now visit the instructions intercepting labels AbstractInsnNode insn = getFirst(); while (insn != null) { insn.accept(mv); if (insn.getType() == AbstractInsnNode.LABEL) { LabelNode labelNode = (LabelNode) insn; Label label = labelNode.getLabel(); List<LocalVariableNode> localStart = localStarts.get(label); List<LocalVariableNode> localEnd = localEnds.get(label); if (localStart != null) { for (LocalVariableNode local : localStart) { lsmv.visitLocalScopeStart(local.name, local.desc, local.signature, local.index, label.getOffset()); } } if (localEnd != null) { for (LocalVariableNode local : localEnd) { lsmv.visitLocalScopeEnd(local.name, local.desc, local.signature, local.index, label.getOffset()); } } } insn = insn.getNext(); } }
From source file:org.jephyr.easyflow.instrument.AnalyzingMethodNode.java
License:Open Source License
private static Object[] convertValues(Collection<?> values) { Object[] values1 = new Object[values.size()]; int i = 0;/* w ww . j ava2 s . co m*/ for (Object value : values) { if (value instanceof Label) { AbstractInsnNode next = ((AbstractInsnNode) ((Label) value).info).getNext(); while (next.getOpcode() != NEW) { next = next.getNext(); } values1[i] = next; } else { values1[i] = value; } i++; } return values1; }
From source file:org.jephyr.easyflow.instrument.ContinuationMethodAdapter.java
License:Open Source License
private void updateFrames(int implVarIndex) { AbstractInsnNode next = instructions.getFirst(); while (next != null) { AbstractInsnNode node = next;//from www. ja v a 2 s . co m next = next.getNext(); if (node instanceof FrameNode) { FrameNode frameNode = (FrameNode) node; Collection<Object> locals = new ArrayList<>(); for (Object value : frameNode.local) { locals.add(value); if (isLong(value)) { locals.add(TOP); } } Object[] locals1 = convertValues(appendValue(ensureSize(locals.toArray(), implVarIndex), "org/jephyr/continuation/easyflow/ContinuationImpl")); List<Object> stack = frameNode.stack; instructions.set(node, new FrameNode(F_NEW, locals1.length, locals1, stack.size(), stack.toArray())); } } }
From source file:org.jephyr.easyflow.instrument.ContinuationMethodAdapter.java
License:Open Source License
private void addMonitorHooks(int implVarIndex) { AbstractInsnNode next = instructions.getFirst(); while (next != null) { AbstractInsnNode node = next;/*w w w.j a v a 2s . c om*/ next = next.getNext(); int opcode = node.getOpcode(); if (opcode == MONITORENTER || opcode == MONITOREXIT) { LabelNode labelNode = newLabelNode(); instructions.insert(node, labelNode); Frame frame = findNextFrame(frames, node); Object[] stack = frame.stack; if (!isNextFrameNode(labelNode)) { instructions.insert(labelNode, newFrameNode(appendValue(ensureSize(frame.locals, implVarIndex), "org/jephyr/continuation/easyflow/ContinuationImpl"), stack)); } instructions.insertBefore(labelNode, new VarInsnNode(ALOAD, implVarIndex)); instructions.insertBefore(labelNode, new JumpInsnNode(IFNULL, labelNode)); instructions.insertBefore(labelNode, new VarInsnNode(ALOAD, implVarIndex)); instructions.insertBefore(labelNode, new MethodInsnNode(INVOKEVIRTUAL, "org/jephyr/continuation/easyflow/ContinuationImpl", opcode == MONITORENTER ? "monitorEntered" : "monitorExited", "()V", false)); updateMaxStack(stack.length + 1); } } }
From source file:org.jephyr.easyflow.instrument.ContinuationMethodAdapter.java
License:Open Source License
private static boolean isNextFrameNode(AbstractInsnNode node) { for (AbstractInsnNode next = node.getNext(); next != null && next.getOpcode() == -1; next = next.getNext()) { if (next instanceof FrameNode) { return true; }/*from w w w. j a v a 2 s . c o m*/ } return false; }
From source file:org.jephyr.easyflow.instrument.ContinuationMethodAdapter.java
License:Open Source License
private static Frame findNextFrame(Map<AbstractInsnNode, Frame> frames, AbstractInsnNode node) { AbstractInsnNode next = node.getNext(); while (true) { Frame frame = frames.get(next); if (frame != null) { return frame; }// www .j av a2 s. com next = next.getNext(); } }
From source file:org.jephyr.easyflow.instrument.NewRelocatorMethodAdapter.java
License:Open Source License
@Override public void visitEnd() { AbstractInsnNode next = instructions.getFirst(); boolean removeFrame = false; int stackSize = 0; while (next != null) { AbstractInsnNode node = next;//from w w w. j av a 2 s .c o m next = next.getNext(); Object[] stack; switch (node.getOpcode()) { case -1: if (node instanceof FrameNode) { if (removeFrame) { instructions.remove(node); } else { stackSize = handleFrame((FrameNode) node); removeFrame = true; } } break; case NOP: case LALOAD: case DALOAD: case INEG: case LNEG: case FNEG: case DNEG: case IINC: case I2F: case L2D: case F2I: case D2L: case I2B: case I2C: case I2S: case GOTO: case RET: case NEWARRAY: case ANEWARRAY: case ARRAYLENGTH: case CHECKCAST: case INSTANCEOF: removeFrame = false; break; case ACONST_NULL: case ICONST_M1: case ICONST_0: case ICONST_1: case ICONST_2: case ICONST_3: case ICONST_4: case ICONST_5: case FCONST_0: case FCONST_1: case FCONST_2: case BIPUSH: case SIPUSH: case ILOAD: case FLOAD: case I2L: case I2D: case F2L: case F2D: case JSR: stackSize += 1; updateMaxStack(stackSize); removeFrame = false; break; case LCONST_0: case LCONST_1: case DCONST_0: case DCONST_1: case LLOAD: case DLOAD: stackSize += 2; updateMaxStack(stackSize); removeFrame = false; break; case LDC: Object cst = ((LdcInsnNode) node).cst; stackSize += cst instanceof Long || cst instanceof Double ? 2 : 1; updateMaxStack(stackSize); removeFrame = false; break; case ALOAD: if (frames.get(node).locals[((VarInsnNode) node).var] instanceof AbstractInsnNode) { instructions.remove(node); } else { stackSize += 1; updateMaxStack(stackSize); removeFrame = false; } break; case IALOAD: case FALOAD: case AALOAD: case BALOAD: case CALOAD: case SALOAD: case ISTORE: case FSTORE: case IADD: case FADD: case ISUB: case FSUB: case IMUL: case FMUL: case IDIV: case FDIV: case IREM: case FREM: case ISHL: case ISHR: case IUSHR: case IAND: case IOR: case IXOR: case L2I: case L2F: case D2I: case D2F: case IFEQ: case IFNE: case IFLT: case IFGE: case IFGT: case IFLE: case TABLESWITCH: case LOOKUPSWITCH: case MONITORENTER: case MONITOREXIT: stackSize -= 1; removeFrame = false; break; case LSTORE: case DSTORE: case LADD: case DADD: case LSUB: case DSUB: case LMUL: case DMUL: case LDIV: case DDIV: case LREM: case DREM: case LSHL: case LSHR: case LUSHR: case LAND: case LOR: case LXOR: case FCMPL: case FCMPG: case IF_ICMPEQ: case IF_ICMPNE: case IF_ICMPLT: case IF_ICMPGE: case IF_ICMPGT: case IF_ICMPLE: stackSize -= 2; removeFrame = false; break; case ASTORE: stack = frames.get(node).stack; if (stack[stack.length - 1] instanceof AbstractInsnNode) { instructions.remove(node); } else { stackSize -= 1; removeFrame = false; } break; case IASTORE: case FASTORE: case AASTORE: case BASTORE: case CASTORE: case SASTORE: case LCMP: case DCMPL: case DCMPG: stackSize -= 3; removeFrame = false; break; case LASTORE: case DASTORE: stackSize -= 4; removeFrame = false; break; case POP: stack = frames.get(node).stack; if (stack[stack.length - 1] instanceof AbstractInsnNode) { instructions.remove(node); } else { stackSize -= 1; removeFrame = false; } break; case POP2: stack = frames.get(node).stack; if (stack[stack.length - 1] instanceof AbstractInsnNode) { if (stack[stack.length - 2] instanceof AbstractInsnNode) { instructions.remove(node); } else { instructions.set(node, new InsnNode(POP)); stackSize -= 1; removeFrame = false; } } else { if (stack[stack.length - 2] instanceof AbstractInsnNode) { instructions.set(node, new InsnNode(POP)); stackSize -= 1; } else { stackSize -= 2; } removeFrame = false; } break; case DUP: stack = frames.get(node).stack; if (stack[stack.length - 1] instanceof AbstractInsnNode) { instructions.remove(node); } else { stackSize += 1; updateMaxStack(stackSize); removeFrame = false; } break; case DUP_X1: stack = frames.get(node).stack; if (stack[stack.length - 1] instanceof AbstractInsnNode) { instructions.remove(node); } else { if (stack[stack.length - 2] instanceof AbstractInsnNode) { instructions.set(node, new InsnNode(DUP)); } stackSize += 1; updateMaxStack(stackSize); removeFrame = false; } break; case DUP_X2: stack = frames.get(node).stack; if (stack[stack.length - 1] instanceof AbstractInsnNode) { instructions.remove(node); } else { if (stack[stack.length - 2] instanceof AbstractInsnNode) { if (stack[stack.length - 3] instanceof AbstractInsnNode) { instructions.set(node, new InsnNode(DUP)); } else { instructions.set(node, new InsnNode(DUP_X1)); } } else { if (stack[stack.length - 3] instanceof AbstractInsnNode) { instructions.set(node, new InsnNode(DUP_X1)); } } stackSize += 1; updateMaxStack(stackSize); removeFrame = false; } break; case DUP2: stack = frames.get(node).stack; if (stack[stack.length - 1] instanceof AbstractInsnNode) { if (stack[stack.length - 2] instanceof AbstractInsnNode) { instructions.remove(node); } else { instructions.set(node, new InsnNode(DUP)); stackSize += 1; updateMaxStack(stackSize); removeFrame = false; } } else { if (stack[stack.length - 2] instanceof AbstractInsnNode) { instructions.set(node, new InsnNode(DUP)); stackSize += 1; } else { stackSize += 2; } updateMaxStack(stackSize); removeFrame = false; } break; case DUP2_X1: stack = frames.get(node).stack; if (stack[stack.length - 1] instanceof AbstractInsnNode) { if (stack[stack.length - 2] instanceof AbstractInsnNode) { instructions.remove(node); } else { if (stack[stack.length - 3] instanceof AbstractInsnNode) { instructions.set(node, new InsnNode(DUP)); } else { instructions.set(node, new InsnNode(DUP_X1)); } stackSize += 1; updateMaxStack(stackSize); removeFrame = false; } } else { if (stack[stack.length - 2] instanceof AbstractInsnNode) { if (stack[stack.length - 3] instanceof AbstractInsnNode) { instructions.set(node, new InsnNode(DUP)); } else { instructions.set(node, new InsnNode(DUP_X1)); } stackSize += 1; } else { if (stack[stack.length - 3] instanceof AbstractInsnNode) { instructions.set(node, new InsnNode(DUP2)); } stackSize += 2; } updateMaxStack(stackSize); removeFrame = false; } break; case DUP2_X2: stack = frames.get(node).stack; if (stack[stack.length - 1] instanceof AbstractInsnNode) { if (stack[stack.length - 2] instanceof AbstractInsnNode) { instructions.remove(node); } else { if (stack[stack.length - 3] instanceof AbstractInsnNode) { if (stack[stack.length - 4] instanceof AbstractInsnNode) { instructions.set(node, new InsnNode(DUP)); } else { instructions.set(node, new InsnNode(DUP_X1)); } } else { if (stack[stack.length - 3] instanceof AbstractInsnNode) { instructions.set(node, new InsnNode(DUP_X1)); } else { instructions.set(node, new InsnNode(DUP_X2)); } } stackSize += 1; updateMaxStack(stackSize); removeFrame = false; } } else { if (stack[stack.length - 2] instanceof AbstractInsnNode) { if (stack[stack.length - 3] instanceof AbstractInsnNode) { if (stack[stack.length - 4] instanceof AbstractInsnNode) { instructions.set(node, new InsnNode(DUP)); } else { instructions.set(node, new InsnNode(DUP_X1)); } } else { if (stack[stack.length - 4] instanceof AbstractInsnNode) { instructions.set(node, new InsnNode(DUP_X1)); } else { instructions.set(node, new InsnNode(DUP_X2)); } } stackSize += 1; } else { if (stack[stack.length - 3] instanceof AbstractInsnNode) { if (stack[stack.length - 4] instanceof AbstractInsnNode) { instructions.set(node, new InsnNode(DUP2)); } else { instructions.set(node, new InsnNode(DUP2_X1)); } } else { if (stack[stack.length - 4] instanceof AbstractInsnNode) { instructions.set(node, new InsnNode(DUP2_X1)); } } stackSize += 2; } updateMaxStack(stackSize); removeFrame = false; } break; case SWAP: stack = frames.get(node).stack; if (stack[stack.length - 1] instanceof AbstractInsnNode || stack[stack.length - 2] instanceof AbstractInsnNode) { instructions.remove(node); } else { removeFrame = false; } break; case IF_ACMPEQ: stack = frames.get(node).stack; if (stack[stack.length - 1] instanceof AbstractInsnNode) { if (stack[stack.length - 2] instanceof AbstractInsnNode) { if (stack[stack.length - 1] == stack[stack.length - 2]) { instructions.set(node, new JumpInsnNode(GOTO, ((JumpInsnNode) node).label)); removeFrame = false; } else { instructions.remove(node); } } else { instructions.set(node, new InsnNode(POP)); stackSize -= 1; removeFrame = false; } } else { if (stack[stack.length - 2] instanceof AbstractInsnNode) { instructions.set(node, new InsnNode(POP)); stackSize -= 1; } else { stackSize -= 2; } removeFrame = false; } break; case IF_ACMPNE: stack = frames.get(node).stack; if (stack[stack.length - 1] instanceof AbstractInsnNode) { if (stack[stack.length - 2] instanceof AbstractInsnNode) { if (stack[stack.length - 1] == stack[stack.length - 2]) { instructions.remove(node); } else { instructions.set(node, new JumpInsnNode(GOTO, ((JumpInsnNode) node).label)); removeFrame = false; } } else { instructions.insertBefore(node, new InsnNode(POP)); stackSize -= 1; instructions.set(node, new JumpInsnNode(GOTO, ((JumpInsnNode) node).label)); removeFrame = false; } } else { if (stack[stack.length - 2] instanceof AbstractInsnNode) { instructions.insertBefore(node, new InsnNode(POP)); stackSize -= 1; instructions.set(node, new JumpInsnNode(GOTO, ((JumpInsnNode) node).label)); } else { stackSize -= 2; } removeFrame = false; } break; case IRETURN: case LRETURN: case FRETURN: case DRETURN: case ARETURN: case RETURN: stackSize = 0; removeFrame = false; break; case GETSTATIC: stackSize += getTypeSize(((FieldInsnNode) node).desc); updateMaxStack(stackSize); removeFrame = false; break; case PUTSTATIC: stackSize -= getTypeSize(((FieldInsnNode) node).desc); removeFrame = false; break; case GETFIELD: stackSize += getTypeSize(((FieldInsnNode) node).desc) - 1; updateMaxStack(stackSize); removeFrame = false; break; case PUTFIELD: stackSize -= getTypeSize(((FieldInsnNode) node).desc) + 1; removeFrame = false; break; case INVOKEVIRTUAL: case INVOKEINTERFACE: stackSize += getInvokeDelta(((MethodInsnNode) node).desc); updateMaxStack(stackSize); removeFrame = false; break; case INVOKESPECIAL: stackSize = handleInvokeSpecial((MethodInsnNode) node, stackSize); removeFrame = false; break; case INVOKESTATIC: stackSize += getInvokeDelta(((MethodInsnNode) node).desc) + 1; updateMaxStack(stackSize); removeFrame = false; break; case INVOKEDYNAMIC: stackSize += getInvokeDelta(((InvokeDynamicInsnNode) node).desc) + 1; updateMaxStack(stackSize); removeFrame = false; break; case NEW: instructions.remove(node); break; case ATHROW: stackSize += 1 - stackSize; updateMaxStack(stackSize); removeFrame = false; break; case MULTIANEWARRAY: stackSize += 1 - ((MultiANewArrayInsnNode) node).dims; updateMaxStack(stackSize); removeFrame = false; break; case IFNULL: stack = frames.get(node).stack; if (!(stack[stack.length - 1] instanceof AbstractInsnNode)) { stackSize -= 1; removeFrame = false; } break; default: // IFNONNULL: stack = frames.get(node).stack; if (stack[stack.length - 1] instanceof AbstractInsnNode) { instructions.set(node, new JumpInsnNode(GOTO, ((JumpInsnNode) node).label)); } else { stackSize -= 1; } removeFrame = false; } } accept(mv); }
From source file:org.jooby.internal.apitool.BytecodeRouteParser.java
License:Apache License
private List<RouteParameter> params(final ClassLoader loader, final ClassNode owner, final String pattern, final MethodNode lambda) { List<RouteParameter> result = new ArrayList<>(); new Insns(lambda).on(param(loader), it -> { String name = parameterName(it.node).orElse("arg" + result.size()); AbstractInsnNode next = it.node.getNext(); Object value = paramValue(loader, owner, lambda, next); if (value != next) { // there is a default value, move next next = next.getNext(); } else {/*from w ww. j a v a2 s . co m*/ value = null; } java.lang.reflect.Type parameterType = parameterType(loader, next); // boolean are ICONST_0 or ICONST_1 if (boolean.class.equals(parameterType) && Integer.class.isInstance(value)) { value = (((Integer) value)).intValue() == 1; } result.add(new RouteParameter(name, kind(pattern, it.node.name, name), simplifyType(parameterType), value)); }).forEach(); return result; }