List of usage examples for org.objectweb.asm Opcodes IRETURN
int IRETURN
To view the source code for org.objectweb.asm Opcodes IRETURN.
Click Source Link
From source file:de.zib.sfs.instrument.AbstractSfsAdapter.java
License:BSD License
@Override public void visitEnd() { // public void setInstrumentationActive(boolean instrumentationActive) { MethodVisitor setInstrumentationActiveMV = this.cv.visitMethod(Opcodes.ACC_PUBLIC, "setInstrumentationActive", Type.getMethodDescriptor(Type.VOID_TYPE, Type.BOOLEAN_TYPE), null, null);/* www . j a v a 2s.c om*/ setInstrumentationActiveMV.visitCode(); // this.instrumentationActive.setInstrumentationActive(instrumentationActive); setInstrumentationActiveMV.visitVarInsn(Opcodes.ALOAD, 0); setInstrumentationActiveMV.visitFieldInsn(Opcodes.GETFIELD, this.instrumentedTypeInternalName, "instrumentationActive", Type.getDescriptor(InstrumentationActive.class)); setInstrumentationActiveMV.visitVarInsn(Opcodes.ILOAD, 1); setInstrumentationActiveMV.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(InstrumentationActive.class), "setInstrumentationActive", Type.getMethodDescriptor(Type.VOID_TYPE, Type.BOOLEAN_TYPE), false); // } setInstrumentationActiveMV.visitInsn(Opcodes.RETURN); setInstrumentationActiveMV.visitMaxs(0, 0); setInstrumentationActiveMV.visitEnd(); // public boolean isInstrumentationActive() { MethodVisitor isInstrumentationActiveMV = this.cv.visitMethod(Opcodes.ACC_PUBLIC, "isInstrumentationActive", Type.getMethodDescriptor(Type.BOOLEAN_TYPE), null, null); isInstrumentationActiveMV.visitCode(); // return instrumentationActive.isInstrumentationActive(); // } isInstrumentationActiveMV.visitVarInsn(Opcodes.ALOAD, 0); isInstrumentationActiveMV.visitFieldInsn(Opcodes.GETFIELD, this.instrumentedTypeInternalName, "instrumentationActive", Type.getDescriptor(InstrumentationActive.class)); isInstrumentationActiveMV.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(InstrumentationActive.class), "isInstrumentationActive", Type.getMethodDescriptor(Type.BOOLEAN_TYPE), false); isInstrumentationActiveMV.visitInsn(Opcodes.IRETURN); isInstrumentationActiveMV.visitMaxs(0, 0); isInstrumentationActiveMV.visitEnd(); appendWrappedMethods(this.cv); this.cv.visitEnd(); }
From source file:de.zib.sfs.instrument.DirectByteBufferAdapter.java
License:BSD License
@Override protected void wrapMethod(int access, String name, Type returnType, Type[] argumentTypes, String signature, String[] exceptions, String callbackName, Type additionalCallbackArgumentType, ResultPasser resultPasser) {/*w ww.j a v a 2 s. c o m*/ argumentTypes = argumentTypes == null ? new Type[] {} : argumentTypes; String methodDescriptor = Type.getMethodDescriptor(returnType, argumentTypes); // <access> <returnType> <name>(<argumentTypes> arguments) throws // <exceptions> { MethodVisitor mv = this.cv.visitMethod(access, name, methodDescriptor, signature, exceptions); mv.visitCode(); // if (isInstrumentationActive() || !fromFileChannel) { isInstrumentationActive(mv); Label instrumentationActiveLabel = new Label(); mv.visitJumpInsn(Opcodes.IFNE, instrumentationActiveLabel); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, this.instrumentedTypeInternalName, "fromFileChannel", Type.getDescriptor(Boolean.TYPE)); Label fromFileChannelLabel = new Label(); mv.visitJumpInsn(Opcodes.IFNE, fromFileChannelLabel); mv.visitLabel(instrumentationActiveLabel); // return? methodPrefix<name>(arguments); mv.visitVarInsn(Opcodes.ALOAD, 0); int argumentIndex = 1; for (Type argument : argumentTypes) { mv.visitVarInsn(argument.getOpcode(Opcodes.ILOAD), argumentIndex); argumentIndex += argument.getSize(); } mv.visitMethodInsn(Opcodes.INVOKESPECIAL, this.instrumentedTypeInternalName, this.methodPrefix + name, methodDescriptor, false); if (!Type.VOID_TYPE.equals(returnType)) { mv.visitInsn(returnType.getOpcode(Opcodes.IRETURN)); } else { mv.visitInsn(Opcodes.RETURN); } // } mv.visitLabel(fromFileChannelLabel); // setInstrumentationActive(true); setInstrumentationActive(mv, true); // long startTime = System.nanoTime(); int startTimeIndex = 1; for (Type argument : argumentTypes) { startTimeIndex += argument.getSize(); } storeTime(mv, startTimeIndex); // <returnType> result =? methodPrefix<name>(arguments); mv.visitVarInsn(Opcodes.ALOAD, 0); argumentIndex = 1; for (Type argument : argumentTypes) { mv.visitVarInsn(argument.getOpcode(Opcodes.ILOAD), argumentIndex); argumentIndex += argument.getSize(); } mv.visitMethodInsn(Opcodes.INVOKESPECIAL, this.instrumentedTypeInternalName, this.methodPrefix + name, methodDescriptor, false); int endTimeIndex = startTimeIndex + 2; if (!Type.VOID_TYPE.equals(returnType)) { mv.visitVarInsn(returnType.getOpcode(Opcodes.ISTORE), startTimeIndex + 2); endTimeIndex += returnType.getSize(); } // long endTime = System.nanoTime(); storeTime(mv, endTimeIndex); // callback.<callbackMethod>(startTime, endTime, result?); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, this.instrumentedTypeInternalName, "callback", this.callbackTypeDescriptor); mv.visitVarInsn(Opcodes.LLOAD, startTimeIndex); mv.visitVarInsn(Opcodes.LLOAD, endTimeIndex); // -1 indicates no result should be passed int resultIndex = resultPasser.getResultIndex(); if (resultIndex != -1) { // result of the actual operation requested if (resultIndex == 0) { mv.visitVarInsn(returnType.getOpcode(Opcodes.ILOAD), startTimeIndex + 2); resultPasser.passResult(mv); } else { // some parameter requested mv.visitVarInsn(argumentTypes[resultIndex - 1].getOpcode(Opcodes.ILOAD), resultIndex); resultPasser.passResult(mv); } } Type[] callbackArgumentTypes; if (additionalCallbackArgumentType == null) { callbackArgumentTypes = new Type[] { Type.LONG_TYPE, Type.LONG_TYPE }; } else { callbackArgumentTypes = new Type[] { Type.LONG_TYPE, Type.LONG_TYPE, additionalCallbackArgumentType }; } mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, this.callbackTypeInternalName, callbackName, Type.getMethodDescriptor(Type.VOID_TYPE, callbackArgumentTypes), false); // setInstrumentationActive(false); setInstrumentationActive(mv, false); // return result;? // } if (!Type.VOID_TYPE.equals(returnType)) { mv.visitVarInsn(returnType.getOpcode(Opcodes.ILOAD), startTimeIndex + 2); mv.visitInsn(returnType.getOpcode(Opcodes.IRETURN)); } else { mv.visitInsn(Opcodes.RETURN); } mv.visitMaxs(0, 0); mv.visitEnd(); }
From source file:de.zib.sfs.instrument.FileChannelImplAdapter.java
License:BSD License
protected void wrapFileChannelImplMethod(int access, String name, Type returnType, Type[] argumentTypes, String signature, String[] exceptions, String callbackName, String oppositeCallbackName, Type additionalCallbackArgumentType, int bufferArgumentTypeIndex, boolean isTransferMethod) { String methodDescriptor = Type.getMethodDescriptor(returnType, argumentTypes); // <access> <returnType> <name>(<argumentTypes> arguments) throws // <exceptions> { MethodVisitor mv = this.cv.visitMethod(access, name, methodDescriptor, signature, exceptions); mv.visitCode();/*from w ww .j a va 2 s.c om*/ // if (isInstrumentationActive()) { isInstrumentationActive(mv); Label instrumentationActiveLabel = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, instrumentationActiveLabel); // return methodPrefix<name>(arguments); mv.visitVarInsn(Opcodes.ALOAD, 0); int argumentIndex = 1; for (Type argument : argumentTypes) { mv.visitVarInsn(argument.getOpcode(Opcodes.ILOAD), argumentIndex); argumentIndex += argument.getSize(); } mv.visitMethodInsn(Opcodes.INVOKESPECIAL, this.instrumentedTypeInternalName, this.methodPrefix + name, methodDescriptor, false); mv.visitInsn(returnType.getOpcode(Opcodes.IRETURN)); // } mv.visitLabel(instrumentationActiveLabel); // setInstrumentationActive(true); setInstrumentationActive(mv, true); // we need to set the instrumentation flag for the source/destination // buffer(s) as well // boolean bufferInstrumentationActive = false; int bufferInstrumentationActiveIndex = 1; for (Type argument : argumentTypes) { bufferInstrumentationActiveIndex += argument.getSize(); } mv.visitInsn(Opcodes.ICONST_0); mv.visitVarInsn(Opcodes.ISTORE, bufferInstrumentationActiveIndex); // obtain actual index of the buffer(s) in the argument list int bufferArgumentIndex = 1; for (int i = 0; i < bufferArgumentTypeIndex; ++i) { bufferArgumentIndex += argumentTypes[i].getSize(); } if (argumentTypes[bufferArgumentTypeIndex].getSort() == Type.ARRAY) { // If the first buffer in the array is a MappedByteBuffer, assume // they all are. If not, this will crash the users' program. // if (<buffers>[0] instanceof MappedByteBuffer) { mv.visitVarInsn(Opcodes.ALOAD, bufferArgumentIndex); mv.visitInsn(Opcodes.ICONST_0); mv.visitInsn(Opcodes.AALOAD); mv.visitTypeInsn(Opcodes.INSTANCEOF, Type.getInternalName(MappedByteBuffer.class)); Label bufferInstanceofMappedByteBufferLabel = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, bufferInstanceofMappedByteBufferLabel); // only trace mmapped file channels if desired if (this.traceMmap) { // if (<buffers>[0].isFromFileChannel()) { mv.visitVarInsn(Opcodes.ALOAD, bufferArgumentIndex); mv.visitInsn(Opcodes.ICONST_0); mv.visitInsn(Opcodes.AALOAD); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(MappedByteBuffer.class), "isFromFileChannel", Type.getMethodDescriptor(Type.BOOLEAN_TYPE), false); Label fromFileChannelLabel = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, fromFileChannelLabel); int iIndex = bufferInstrumentationActiveIndex + 1; // for (int i = 0; i < <buffers>.length; ++i) { // <buffers>[i].setInstrumentationActive(true); // } mv.visitInsn(Opcodes.ICONST_0); mv.visitVarInsn(Opcodes.ISTORE, iIndex); Label loopConditionLabel = new Label(); mv.visitJumpInsn(Opcodes.GOTO, loopConditionLabel); Label loopStartLabel = new Label(); mv.visitLabel(loopStartLabel); mv.visitVarInsn(Opcodes.ALOAD, bufferArgumentIndex); mv.visitVarInsn(Opcodes.ILOAD, iIndex); mv.visitInsn(Opcodes.AALOAD); mv.visitInsn(Opcodes.ICONST_1); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(MappedByteBuffer.class), "setInstrumentationActive", Type.getMethodDescriptor(Type.VOID_TYPE, Type.BOOLEAN_TYPE), false); mv.visitIincInsn(iIndex, 1); mv.visitLabel(loopConditionLabel); mv.visitVarInsn(Opcodes.ILOAD, iIndex); mv.visitVarInsn(Opcodes.ALOAD, bufferArgumentIndex); mv.visitInsn(Opcodes.ARRAYLENGTH); mv.visitJumpInsn(Opcodes.IF_ICMPLT, loopStartLabel); // bufferInstrumentationActive = true; mv.visitInsn(Opcodes.ICONST_1); mv.visitVarInsn(Opcodes.ISTORE, bufferInstrumentationActiveIndex); // } mv.visitLabel(fromFileChannelLabel); } // } mv.visitLabel(bufferInstanceofMappedByteBufferLabel); } else { // We need to handle the transferFrom/transferTo methods a little // differently. Their "buffers" only need to be FileChannelImpls, // the rest remains the same. // if (buffer instanceof MappedByteBuffer) { // if (buffer instanceof FileChannelImpl) { mv.visitVarInsn(Opcodes.ALOAD, bufferArgumentIndex); if (!isTransferMethod) { mv.visitTypeInsn(Opcodes.INSTANCEOF, Type.getInternalName(MappedByteBuffer.class)); } else { mv.visitTypeInsn(Opcodes.INSTANCEOF, Type.getInternalName(FileChannelImpl.class)); } Label bufferInstanceofMappedByteBufferLabel = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, bufferInstanceofMappedByteBufferLabel); // additional check required if the buffer is a MappedByteBuffer, // and we want to trace those Label fromFileChannelLabel = new Label(); if (!isTransferMethod && this.traceMmap) { // if (buffer.isFromFileChannel()) { mv.visitVarInsn(Opcodes.ALOAD, bufferArgumentIndex); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(MappedByteBuffer.class), "isFromFileChannel", Type.getMethodDescriptor(Type.BOOLEAN_TYPE), false); mv.visitJumpInsn(Opcodes.IFEQ, fromFileChannelLabel); } // either we're dealing with a FileChannelImpl (in a // transferTo/transferFrom method), or this is a regular read or // write and we want to count in mmapped buffers if (isTransferMethod || this.traceMmap) { // buffer.setInstrumentationActive(true); mv.visitVarInsn(Opcodes.ALOAD, bufferArgumentIndex); mv.visitInsn(Opcodes.ICONST_1); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, !isTransferMethod ? Type.getInternalName(MappedByteBuffer.class) : Type.getInternalName(FileChannelImpl.class), "setInstrumentationActive", Type.getMethodDescriptor(Type.VOID_TYPE, Type.BOOLEAN_TYPE), false); // bufferInstrumentationActive = true; mv.visitInsn(Opcodes.ICONST_1); mv.visitVarInsn(Opcodes.ISTORE, bufferInstrumentationActiveIndex); } if (!isTransferMethod && this.traceMmap) { // } mv.visitLabel(fromFileChannelLabel); } // } mv.visitLabel(bufferInstanceofMappedByteBufferLabel); } // long startTime = System.nanoTime(); int startTimeIndex = bufferInstrumentationActiveIndex + 1; storeTime(mv, startTimeIndex); // <returnType> result = methodPrefix<name>(arguments); mv.visitVarInsn(Opcodes.ALOAD, 0); argumentIndex = 1; for (Type argument : argumentTypes) { mv.visitVarInsn(argument.getOpcode(Opcodes.ILOAD), argumentIndex); argumentIndex += argument.getSize(); } mv.visitMethodInsn(Opcodes.INVOKESPECIAL, this.instrumentedTypeInternalName, this.methodPrefix + name, methodDescriptor, false); int resultIndex = startTimeIndex + 2; mv.visitVarInsn(returnType.getOpcode(Opcodes.ISTORE), resultIndex); int endTimeIndex = resultIndex + returnType.getSize(); // long endTime = System.nanoTime(); storeTime(mv, endTimeIndex); // if map(...) was involved in this, then it may have reset the // instrumentationActive flag if we don't trace mmap calls, so we need // to check again whether instrumentation is still active, and only // report the data then // if (isInstrumentationActive()) { isInstrumentationActive(mv); Label instrumentationStillActiveLabel = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, instrumentationStillActiveLabel); // callback.<callbackName>(startTime, endTime, result); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, this.instrumentedTypeInternalName, "callback", this.callbackTypeDescriptor); mv.visitVarInsn(Opcodes.LLOAD, startTimeIndex); mv.visitVarInsn(Opcodes.LLOAD, endTimeIndex); mv.visitVarInsn(returnType.getOpcode(Opcodes.ILOAD), resultIndex); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, this.callbackTypeInternalName, callbackName, Type.getMethodDescriptor(Type.VOID_TYPE, Type.LONG_TYPE, Type.LONG_TYPE, additionalCallbackArgumentType), false); // } mv.visitLabel(instrumentationStillActiveLabel); // same for the buffer if (argumentTypes[bufferArgumentTypeIndex].getSort() != Type.ARRAY) { // if (buffer instanceof MappedByteBuffer) { // if (buffer instanceof FileChannelImpl) { mv.visitVarInsn(Opcodes.ALOAD, bufferArgumentIndex); if (!isTransferMethod) { mv.visitTypeInsn(Opcodes.INSTANCEOF, Type.getInternalName(MappedByteBuffer.class)); } else { mv.visitTypeInsn(Opcodes.INSTANCEOF, Type.getInternalName(FileChannelImpl.class)); } Label bufferInstanceofMappedByteBufferLabel = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, bufferInstanceofMappedByteBufferLabel); // additional check required if the buffer is a MappedByteBuffer, // and we want to trace those Label fromFileChannelLabel = new Label(); if (!isTransferMethod && this.traceMmap) { // if (buffer.isFromFileChannel()) { mv.visitVarInsn(Opcodes.ALOAD, bufferArgumentIndex); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(MappedByteBuffer.class), "isFromFileChannel", Type.getMethodDescriptor(Type.BOOLEAN_TYPE), false); mv.visitJumpInsn(Opcodes.IFEQ, fromFileChannelLabel); } // either we're dealing with a FileChannelImpl (in a // transferTo/transferFrom method), which might have flipped its // instrumentationActive flag because mmap was used, or this is a // regular read or write and we want to count in mmapped buffers if (isTransferMethod || this.traceMmap) { // if traceMmap is true, then we could actually just set // bufferInstrumentationActive to true // bufferInstrumentationActive = // buffer.isInstrumentationActive(); mv.visitVarInsn(Opcodes.ALOAD, bufferArgumentIndex); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, !isTransferMethod ? Type.getInternalName(MappedByteBuffer.class) : Type.getInternalName(FileChannelImpl.class), "isInstrumentationActive", Type.getMethodDescriptor(Type.BOOLEAN_TYPE), false); mv.visitVarInsn(Opcodes.ISTORE, bufferInstrumentationActiveIndex); } if (!isTransferMethod && this.traceMmap) { // } mv.visitLabel(fromFileChannelLabel); } // } mv.visitLabel(bufferInstanceofMappedByteBufferLabel); } // if (bufferInstrumentationActive) { mv.visitVarInsn(Opcodes.ILOAD, bufferInstrumentationActiveIndex); Label bufferInstrumentationActiveLabel = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, bufferInstrumentationActiveLabel); // callback.<oppositeCallbackName>(buffer.getFileDescriptor(), // startTime, endTime, result); if (!isTransferMethod) { if (argumentTypes[bufferArgumentTypeIndex].getSort() == Type.ARRAY) { // TODO this calls the opposite callback only on the first // element in the buffer array, but there is not really a way to // tell which buffer has received how many bytes, and thus which // file mv.visitVarInsn(Opcodes.ALOAD, bufferArgumentIndex); mv.visitInsn(Opcodes.ICONST_0); mv.visitInsn(Opcodes.AALOAD); } else { mv.visitVarInsn(Opcodes.ALOAD, bufferArgumentIndex); } mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(MappedByteBuffer.class), "getFileDescriptor", Type.getMethodDescriptor(Type.getType(FileDescriptor.class)), false); } else { mv.visitVarInsn(Opcodes.ALOAD, bufferArgumentIndex); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(FileChannelImpl.class), "getFileDescriptor", Type.getMethodDescriptor(Type.getType(FileDescriptor.class)), false); } mv.visitVarInsn(Opcodes.LLOAD, startTimeIndex); mv.visitVarInsn(Opcodes.LLOAD, endTimeIndex); mv.visitVarInsn(returnType.getOpcode(Opcodes.ILOAD), resultIndex); mv.visitMethodInsn(Opcodes.INVOKESTATIC, this.callbackTypeInternalName, oppositeCallbackName, Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(FileDescriptor.class), Type.LONG_TYPE, Type.LONG_TYPE, additionalCallbackArgumentType), false); // revert the active instrumentation flag for the buffer if (argumentTypes[bufferArgumentTypeIndex].getSort() == Type.ARRAY) { int iIndex = bufferInstrumentationActiveIndex + 1; // for (int i = 0; i < <buffers>.length; ++i) { // <buffers>[i].setInstrumentationActive(false); // } mv.visitInsn(Opcodes.ICONST_0); mv.visitVarInsn(Opcodes.ISTORE, iIndex); Label loopConditionLabel = new Label(); mv.visitJumpInsn(Opcodes.GOTO, loopConditionLabel); Label loopStartLabel = new Label(); mv.visitLabel(loopStartLabel); mv.visitVarInsn(Opcodes.ALOAD, bufferArgumentIndex); mv.visitVarInsn(Opcodes.ILOAD, iIndex); mv.visitInsn(Opcodes.AALOAD); mv.visitInsn(Opcodes.ICONST_0); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(MappedByteBuffer.class), "setInstrumentationActive", Type.getMethodDescriptor(Type.VOID_TYPE, Type.BOOLEAN_TYPE), false); mv.visitIincInsn(iIndex, 1); mv.visitLabel(loopConditionLabel); mv.visitVarInsn(Opcodes.ILOAD, iIndex); mv.visitVarInsn(Opcodes.ALOAD, bufferArgumentIndex); mv.visitInsn(Opcodes.ARRAYLENGTH); mv.visitJumpInsn(Opcodes.IF_ICMPLT, loopStartLabel); } else { // buffer.setInstrumentationActive(false); mv.visitVarInsn(Opcodes.ALOAD, bufferArgumentIndex); mv.visitInsn(Opcodes.ICONST_0); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, !isTransferMethod ? Type.getInternalName(MappedByteBuffer.class) : Type.getInternalName(FileChannelImpl.class), "setInstrumentationActive", Type.getMethodDescriptor(Type.VOID_TYPE, Type.BOOLEAN_TYPE), false); } // } mv.visitLabel(bufferInstrumentationActiveLabel); // setInstrumentationActive(false); setInstrumentationActive(mv, false); // return result; // } mv.visitVarInsn(returnType.getOpcode(Opcodes.ILOAD), resultIndex); mv.visitInsn(returnType.getOpcode(Opcodes.IRETURN)); mv.visitMaxs(0, 0); mv.visitEnd(); }
From source file:de.zib.sfs.instrument.MappedByteBufferAdapter.java
License:BSD License
@Override protected void appendWrappedMethods(ClassVisitor visitor) { // public void setFromFileChannel(boolean fromFileChannel) { MethodVisitor setFromFileChannelMV = visitor.visitMethod(Opcodes.ACC_PUBLIC, "setFromFileChannel", Type.getMethodDescriptor(Type.VOID_TYPE, Type.BOOLEAN_TYPE), null, null); setFromFileChannelMV.visitCode();// w w w. j av a 2 s . co m // this.fromFileChannel = fromFileChannel; setFromFileChannelMV.visitVarInsn(Opcodes.ALOAD, 0); setFromFileChannelMV.visitVarInsn(Opcodes.ILOAD, 1); setFromFileChannelMV.visitFieldInsn(Opcodes.PUTFIELD, Type.getInternalName(MappedByteBuffer.class), "fromFileChannel", Type.getDescriptor(Boolean.TYPE)); // } setFromFileChannelMV.visitInsn(Opcodes.RETURN); setFromFileChannelMV.visitMaxs(0, 0); setFromFileChannelMV.visitEnd(); // public boolean isFromFileChannel() { MethodVisitor isFromFileChannelMV = visitor.visitMethod(Opcodes.ACC_PUBLIC, "isFromFileChannel", Type.getMethodDescriptor(Type.BOOLEAN_TYPE), null, null); isFromFileChannelMV.visitCode(); // return fromFileChannel; // } isFromFileChannelMV.visitVarInsn(Opcodes.ALOAD, 0); isFromFileChannelMV.visitFieldInsn(Opcodes.GETFIELD, Type.getInternalName(MappedByteBuffer.class), "fromFileChannel", Type.getDescriptor(Boolean.TYPE)); isFromFileChannelMV.visitInsn(Opcodes.IRETURN); isFromFileChannelMV.visitMaxs(0, 0); isFromFileChannelMV.visitEnd(); // public void setFileDescriptor(FileDescriptor fileDescriptor) { MethodVisitor settFileDescriptorMV = visitor.visitMethod(Opcodes.ACC_PUBLIC, "setFileDescriptor", Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(FileDescriptor.class)), null, null); settFileDescriptorMV.visitCode(); // this.fileDescriptor = fileDescriptor; settFileDescriptorMV.visitVarInsn(Opcodes.ALOAD, 0); settFileDescriptorMV.visitVarInsn(Opcodes.ALOAD, 1); settFileDescriptorMV.visitFieldInsn(Opcodes.PUTFIELD, Type.getInternalName(MappedByteBuffer.class), "fileDescriptor", Type.getDescriptor(FileDescriptor.class)); // } settFileDescriptorMV.visitInsn(Opcodes.RETURN); settFileDescriptorMV.visitMaxs(0, 0); settFileDescriptorMV.visitEnd(); // public FileDescriptor getFileDescriptor() { MethodVisitor getFileDescriptorMV = visitor.visitMethod(Opcodes.ACC_PUBLIC, "getFileDescriptor", Type.getMethodDescriptor(Type.getType(FileDescriptor.class)), null, null); getFileDescriptorMV.visitCode(); // return getFileDescriptorImpl(); // } getFileDescriptorMV.visitVarInsn(Opcodes.ALOAD, 0); getFileDescriptorMV.visitMethodInsn(Opcodes.INVOKESPECIAL, this.instrumentedTypeInternalName, "getFileDescriptorImpl", Type.getMethodDescriptor(Type.getType(FileDescriptor.class)), false); getFileDescriptorMV.visitInsn(Opcodes.ARETURN); getFileDescriptorMV.visitMaxs(0, 0); getFileDescriptorMV.visitEnd(); // protected FileDescriptor getFileDescriptorImpl() { MethodVisitor getFileDescriptorImplMV = visitor.visitMethod(Opcodes.ACC_PROTECTED, "getFileDescriptorImpl", Type.getMethodDescriptor(Type.getType(FileDescriptor.class)), null, null); getFileDescriptorImplMV.visitCode(); // return fileDescriptor; // } getFileDescriptorImplMV.visitVarInsn(Opcodes.ALOAD, 0); getFileDescriptorImplMV.visitFieldInsn(Opcodes.GETFIELD, Type.getInternalName(MappedByteBuffer.class), "fileDescriptor", Type.getDescriptor(FileDescriptor.class)); getFileDescriptorImplMV.visitInsn(Opcodes.ARETURN); getFileDescriptorImplMV.visitMaxs(0, 0); getFileDescriptorImplMV.visitEnd(); visitor.visitEnd(); }
From source file:dyco4j.instrumentation.internals.InitTracingMethodVisitor.java
License:BSD License
@Override public void visitInsn(final int opcode) { super.visitInsn(opcode); switch (opcode) { case Opcodes.IRETURN: // 1 before n/a after case Opcodes.FRETURN: // 1 before n/a after case Opcodes.ARETURN: // 1 before n/a after case Opcodes.ATHROW: // 1 before n/a after this.stackFrame.pop(); break;/*ww w . j av a 2s . c o m*/ case Opcodes.LRETURN: // 2 before n/a after case Opcodes.DRETURN: // 2 before n/a after this.stackFrame.pop(); this.stackFrame.pop(); break; case Opcodes.NOP: case Opcodes.LALOAD: // remove 2 add 2 case Opcodes.DALOAD: // remove 2 add 2 case Opcodes.LNEG: case Opcodes.DNEG: case Opcodes.FNEG: case Opcodes.INEG: case Opcodes.L2D: case Opcodes.D2L: case Opcodes.F2I: case Opcodes.I2B: case Opcodes.I2C: case Opcodes.I2S: case Opcodes.I2F: case Opcodes.ARRAYLENGTH: break; case Opcodes.ACONST_NULL: case Opcodes.ICONST_M1: case Opcodes.ICONST_0: case Opcodes.ICONST_1: case Opcodes.ICONST_2: case Opcodes.ICONST_3: case Opcodes.ICONST_4: case Opcodes.ICONST_5: case Opcodes.FCONST_0: case Opcodes.FCONST_1: case Opcodes.FCONST_2: case Opcodes.F2L: // 1 before 2 after case Opcodes.F2D: case Opcodes.I2L: case Opcodes.I2D: this.stackFrame.push(OTHER); break; case Opcodes.LCONST_0: case Opcodes.LCONST_1: case Opcodes.DCONST_0: case Opcodes.DCONST_1: this.stackFrame.push(OTHER); this.stackFrame.push(OTHER); break; case Opcodes.IALOAD: // remove 2 add 1 case Opcodes.FALOAD: // remove 2 add 1 case Opcodes.AALOAD: // remove 2 add 1 case Opcodes.BALOAD: // remove 2 add 1 case Opcodes.CALOAD: // remove 2 add 1 case Opcodes.SALOAD: // remove 2 add 1 case Opcodes.POP: case Opcodes.IADD: case Opcodes.FADD: case Opcodes.ISUB: case Opcodes.LSHL: // 3 before 2 after case Opcodes.LSHR: // 3 before 2 after case Opcodes.LUSHR: // 3 before 2 after case Opcodes.L2I: // 2 before 1 after case Opcodes.L2F: // 2 before 1 after case Opcodes.D2I: // 2 before 1 after case Opcodes.D2F: // 2 before 1 after case Opcodes.FSUB: case Opcodes.FMUL: case Opcodes.FDIV: case Opcodes.FREM: case Opcodes.FCMPL: // 2 before 1 after case Opcodes.FCMPG: // 2 before 1 after case Opcodes.IMUL: case Opcodes.IDIV: case Opcodes.IREM: case Opcodes.ISHL: case Opcodes.ISHR: case Opcodes.IUSHR: case Opcodes.IAND: case Opcodes.IOR: case Opcodes.IXOR: case Opcodes.MONITORENTER: case Opcodes.MONITOREXIT: this.stackFrame.pop(); break; case Opcodes.POP2: case Opcodes.LSUB: case Opcodes.LMUL: case Opcodes.LDIV: case Opcodes.LREM: case Opcodes.LADD: case Opcodes.LAND: case Opcodes.LOR: case Opcodes.LXOR: case Opcodes.DADD: case Opcodes.DMUL: case Opcodes.DSUB: case Opcodes.DDIV: case Opcodes.DREM: this.stackFrame.pop(); this.stackFrame.pop(); break; case Opcodes.IASTORE: case Opcodes.FASTORE: case Opcodes.AASTORE: case Opcodes.BASTORE: case Opcodes.CASTORE: case Opcodes.SASTORE: case Opcodes.LCMP: // 4 before 1 after case Opcodes.DCMPL: case Opcodes.DCMPG: this.stackFrame.pop(); this.stackFrame.pop(); this.stackFrame.pop(); break; case Opcodes.LASTORE: case Opcodes.DASTORE: this.stackFrame.pop(); this.stackFrame.pop(); this.stackFrame.pop(); this.stackFrame.pop(); break; case Opcodes.DUP: this.stackFrame.push(this.stackFrame.peek()); break; case Opcodes.DUP_X1: { final int _s = stackFrame.size(); stackFrame.add(_s - 2, stackFrame.get(_s - 1)); break; } case Opcodes.DUP_X2: { final int _s = stackFrame.size(); stackFrame.add(_s - 3, stackFrame.get(_s - 1)); break; } case Opcodes.DUP2: { final int _s = stackFrame.size(); stackFrame.add(_s - 2, stackFrame.get(_s - 1)); stackFrame.add(_s - 2, stackFrame.get(_s - 1)); break; } case Opcodes.DUP2_X1: { final int _s = stackFrame.size(); stackFrame.add(_s - 3, stackFrame.get(_s - 1)); stackFrame.add(_s - 3, stackFrame.get(_s - 1)); break; } case Opcodes.DUP2_X2: { final int _s = stackFrame.size(); stackFrame.add(_s - 4, stackFrame.get(_s - 1)); stackFrame.add(_s - 4, stackFrame.get(_s - 1)); break; } case Opcodes.SWAP: { final int _s = stackFrame.size(); stackFrame.add(_s - 2, stackFrame.get(_s - 1)); stackFrame.remove(_s); break; } } }
From source file:dyco4j.instrumentation.internals.TracingMethodVisitor.java
License:BSD License
@Override public final void visitInsn(final int opcode) { if (opcode == Opcodes.IRETURN || opcode == Opcodes.LRETURN || opcode == Opcodes.FRETURN || opcode == Opcodes.DRETURN || opcode == Opcodes.ARETURN || opcode == Opcodes.RETURN) { if (this.cv.cmdLineOptions.traceMethodRetValue) LoggingHelper.emitLogReturn(this.mv, method.getReturnType()); LoggingHelper.emitLogMethodExit(this.mv, this.methodId, LoggingHelper.ExitKind.NORMAL); super.visitInsn(opcode); } else if (opcode == Opcodes.AASTORE || opcode == Opcodes.BASTORE || opcode == Opcodes.CASTORE || opcode == Opcodes.DASTORE || opcode == Opcodes.FASTORE || opcode == Opcodes.IASTORE || opcode == Opcodes.LASTORE || opcode == Opcodes.SASTORE) { if (this.cv.cmdLineOptions.traceArrayAccess) visitArrayStoreInsn(opcode); else/* w w w . j av a 2 s .co m*/ super.visitInsn(opcode); } else if (opcode == Opcodes.AALOAD || opcode == Opcodes.BALOAD || opcode == Opcodes.CALOAD || opcode == Opcodes.DALOAD || opcode == Opcodes.FALOAD || opcode == Opcodes.IALOAD || opcode == Opcodes.LALOAD || opcode == Opcodes.SALOAD) { if (this.cv.cmdLineOptions.traceArrayAccess) visitArrayLoadInsn(opcode); else super.visitInsn(opcode); } else super.visitInsn(opcode); }
From source file:edu.illinois.nondex.instr.HashMapShufflingAdder.java
License:Open Source License
public void addHasNext() { MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, "hasNext", "()Z", null, null); mv.visitCode();//from w w w.ja v a2 s. c o m mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/HashMap$HashIterator", "shuffler", "Ljava/util/HashMap$HashIterator$HashIteratorShuffler;"); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/HashMap$HashIterator$HashIteratorShuffler", "hasNext", "()Z", false); mv.visitInsn(Opcodes.IRETURN); mv.visitMaxs(1, 1); mv.visitEnd(); }
From source file:edu.illinois.nondex.instr.IdentityHashMapShufflingAdder.java
License:Open Source License
public void addNextIndex() { MethodVisitor mv = super.visitMethod(Opcodes.ACC_PROTECTED, "nextIndex", "()I", null, null); mv.visitCode();/*w w w.j av a2s. c o m*/ mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "this$0", "Ljava/util/IdentityHashMap;"); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap", "modCount", "I"); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "expectedModCount", "I"); Label l0 = new Label(); mv.visitJumpInsn(Opcodes.IF_ICMPEQ, l0); mv.visitTypeInsn(Opcodes.NEW, "java/util/ConcurrentModificationException"); mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/ConcurrentModificationException", "<init>", "()V", false); mv.visitInsn(Opcodes.ATHROW); mv.visitLabel(l0); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/IdentityHashMap$IdentityHashMapIterator", "hasNext", "()Z", false); Label l1 = new Label(); mv.visitJumpInsn(Opcodes.IFNE, l1); mv.visitTypeInsn(Opcodes.NEW, "java/util/NoSuchElementException"); mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/NoSuchElementException", "<init>", "()V", false); mv.visitInsn(Opcodes.ATHROW); mv.visitLabel(l1); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "keys", "Ljava/util/List;"); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitInsn(Opcodes.DUP); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "idx", "I"); mv.visitInsn(Opcodes.DUP_X1); mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.IADD); mv.visitFieldInsn(Opcodes.PUTFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "idx", "I"); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "get", "(I)Ljava/lang/Object;", true); mv.visitVarInsn(Opcodes.ASTORE, 1); mv.visitInsn(Opcodes.ICONST_0); mv.visitVarInsn(Opcodes.ISTORE, 2); Label l2 = new Label(); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_APPEND, 2, new Object[] { "java/lang/Object", Opcodes.INTEGER }, 0, null); mv.visitVarInsn(Opcodes.ILOAD, 2); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "this$0", "Ljava/util/IdentityHashMap;"); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap", "table", "[Ljava/lang/Object;"); mv.visitInsn(Opcodes.ARRAYLENGTH); Label l3 = new Label(); mv.visitJumpInsn(Opcodes.IF_ICMPGE, l3); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "this$0", "Ljava/util/IdentityHashMap;"); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap", "table", "[Ljava/lang/Object;"); mv.visitVarInsn(Opcodes.ILOAD, 2); mv.visitInsn(Opcodes.AALOAD); mv.visitVarInsn(Opcodes.ALOAD, 1); Label l4 = new Label(); mv.visitJumpInsn(Opcodes.IF_ACMPNE, l4); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ILOAD, 2); mv.visitFieldInsn(Opcodes.PUTFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "lastReturnedIndex", "I"); mv.visitJumpInsn(Opcodes.GOTO, l3); mv.visitLabel(l4); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitIincInsn(2, 2); mv.visitJumpInsn(Opcodes.GOTO, l2); mv.visitLabel(l3); mv.visitFrame(Opcodes.F_CHOP, 1, null, 0, null); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "lastReturnedIndex", "I"); mv.visitInsn(Opcodes.IRETURN); mv.visitMaxs(5, 3); mv.visitEnd(); }
From source file:edu.illinois.nondex.instr.IdentityHashMapShufflingAdder.java
License:Open Source License
public void addHasNext() { MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC, "hasNext", "()Z", null, null); mv.visitCode();//w w w . j a v a 2 s .c o m mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "idx", "I"); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "order", "Ljava/util/List;"); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "size", "()I", true); Label l0 = new Label(); mv.visitJumpInsn(Opcodes.IF_ICMPGE, l0); mv.visitInsn(Opcodes.ICONST_1); Label l1 = new Label(); mv.visitJumpInsn(Opcodes.GOTO, l1); mv.visitLabel(l0); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(Opcodes.ICONST_0); mv.visitLabel(l1); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { Opcodes.INTEGER }); mv.visitInsn(Opcodes.IRETURN); mv.visitMaxs(2, 1); mv.visitEnd(); }
From source file:edu.illinois.nondex.instr.PriorityQueueShufflingAdder.java
License:Open Source License
public void addHasNext() { MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC, "hasNext", "()Z", null, null); mv.visitCode();//from www . j ava 2 s.c o m mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/PriorityQueue$Itr", "iter", "Ljava/util/Iterator;"); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Iterator", "hasNext", "()Z", true); mv.visitInsn(Opcodes.IRETURN); mv.visitMaxs(1, 1); mv.visitEnd(); }