List of usage examples for org.objectweb.asm.tree.analysis BasicValue getSize
@Override
public int getSize()
From source file:co.paralleluniverse.fibers.instrument.InstrumentMethod.java
License:Open Source License
private void emitNewAndDup(MethodVisitor mv, Frame frame, int stackIndex, MethodInsnNode min) { int arguments = frame.getStackSize() - stackIndex - 1; int neededLocals = 0; for (int i = arguments; i >= 1; i--) { BasicValue v = (BasicValue) frame.getStack(stackIndex + i); mv.visitVarInsn(v.getType().getOpcode(Opcodes.ISTORE), lvarStack + NUM_LOCALS + neededLocals); neededLocals += v.getSize(); }/*from ww w .j a va 2 s .co m*/ db.log(LogLevel.DEBUG, "Inserting NEW & DUP for constructor call %s%s with %d arguments (%d locals)", min.owner, min.desc, arguments, neededLocals); if (additionalLocals < neededLocals) { additionalLocals = neededLocals; } ((NewValue) frame.getStack(stackIndex - 1)).insn.accept(mv); ((NewValue) frame.getStack(stackIndex)).insn.accept(mv); for (int i = 1; i <= arguments; i++) { BasicValue v = (BasicValue) frame.getStack(stackIndex + i); neededLocals -= v.getSize(); mv.visitVarInsn(v.getType().getOpcode(Opcodes.ILOAD), lvarStack + NUM_LOCALS + neededLocals); } }
From source file:co.paralleluniverse.fibers.instrument.InstrumentMethod.java
License:Open Source License
private void emitStoreState(MethodVisitor mv, int idx, FrameInfo fi, int numArgsToPreserve) { Frame f = frames[fi.endInstruction]; if (fi.lBefore != null) fi.lBefore.accept(mv);/*from w w w . j a va2s. co m*/ mv.visitVarInsn(Opcodes.ALOAD, lvarStack); emitConst(mv, idx); emitConst(mv, fi.numSlots); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, STACK_NAME, "pushMethod", "(II)V"); // store operand stack for (int i = f.getStackSize(); i-- > 0;) { BasicValue v = (BasicValue) f.getStack(i); if (!isOmitted(v)) { if (!isNullType(v)) { int slotIdx = fi.stackSlotIndices[i]; assert slotIdx >= 0 && slotIdx < fi.numSlots; emitStoreValue(mv, v, lvarStack, slotIdx, -1); } else { db.log(LogLevel.DEBUG, "NULL stack entry: type=%s size=%d", v.getType(), v.getSize()); mv.visitInsn(Opcodes.POP); } } } // store local vars for (int i = firstLocal; i < f.getLocals(); i++) { BasicValue v = (BasicValue) f.getLocal(i); if (!isNullType(v)) { mv.visitVarInsn(v.getType().getOpcode(Opcodes.ILOAD), i); int slotIdx = fi.localSlotIndices[i]; assert slotIdx >= 0 && slotIdx < fi.numSlots; emitStoreValue(mv, v, lvarStack, slotIdx, i); } } // restore last numArgsToPreserve operands for (int i = f.getStackSize() - numArgsToPreserve; i < f.getStackSize(); i++) { BasicValue v = (BasicValue) f.getStack(i); if (!isOmitted(v)) { if (!isNullType(v)) { int slotIdx = fi.stackSlotIndices[i]; assert slotIdx >= 0 && slotIdx < fi.numSlots; emitRestoreValue(mv, v, lvarStack, slotIdx, -1); } else { mv.visitInsn(Opcodes.ACONST_NULL); } } } }