List of usage examples for org.objectweb.asm Opcodes INVOKESTATIC
int INVOKESTATIC
To view the source code for org.objectweb.asm Opcodes INVOKESTATIC.
Click Source Link
From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.MethodInvocationInstruction.java
License:Open Source License
private MethodInvocationInstruction(final ReadMethod readMethod, final int lineNumber, final int opcode, final String internalClassName, final String methodName, final String methodDesc, final int index) { super(readMethod, opcode, lineNumber, index); assert opcode == Opcodes.INVOKEVIRTUAL || opcode == Opcodes.INVOKESPECIAL || opcode == Opcodes.INVOKESTATIC || opcode == Opcodes.INVOKEINTERFACE; this.internalClassName = internalClassName; this.methodName = methodName; this.methodDesc = methodDesc; final org.objectweb.asm.Type[] parameterTypes = org.objectweb.asm.Type.getArgumentTypes(methodDesc); this.parameterIsLong = new boolean[parameterTypes.length]; for (int i = 0; i < parameterTypes.length; ++i) { this.parameterIsLong[i] = parameterTypes[i].getSize() == 2; }/* w w w .jav a 2 s . c om*/ org.objectweb.asm.Type returnType = org.objectweb.asm.Type.getReturnType(methodDesc); this.returnedSize = returnType == org.objectweb.asm.Type.VOID_TYPE ? 0 : (byte) returnType.getSize(); }
From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.MethodInvocationInstruction.java
License:Open Source License
@Override public String toString() { String type;/*from ww w . j a v a 2 s .c o m*/ switch (getOpcode()) { case Opcodes.INVOKEVIRTUAL: type = "INVOKEVIRTUAL"; break; case Opcodes.INVOKESPECIAL: type = "INVOKESPECIAL"; break; case Opcodes.INVOKESTATIC: type = "INVOKESTATIC"; break; case Opcodes.INVOKEINTERFACE: type = "INVOKEINTERFACE"; break; default: assert false; type = "--ERROR--"; } final StringBuilder sb = new StringBuilder(type.length() + this.internalClassName.length() + this.methodName.length() + this.methodDesc.length() + 2); sb.append(type).append(' ').append(this.internalClassName).append('.').append(this.methodName) .append(this.methodDesc); return sb.toString(); }
From source file:de.unisb.cs.st.javaslicer.jung.ShowJungGraph.java
License:Open Source License
protected static String getShortInstructionText(Instruction inst) { if (inst.getType() == InstructionType.METHODINVOCATION) { MethodInvocationInstruction mtdInv = (MethodInvocationInstruction) inst; String type;//from w ww . j ava2s . c o m switch (mtdInv.getOpcode()) { case Opcodes.INVOKEVIRTUAL: type = "INVOKEVIRTUAL"; break; case Opcodes.INVOKESPECIAL: type = "INVOKESPECIAL"; break; case Opcodes.INVOKESTATIC: type = "INVOKESTATIC"; break; case Opcodes.INVOKEINTERFACE: type = "INVOKEINTERFACE"; break; default: assert false; type = "--ERROR--"; } return type + ' ' + getSimpleClassName(mtdInv.getInvokedInternalClassName()) + '.' + mtdInv.getInvokedMethodName(); } return inst.toString(); }
From source file:de.unisb.cs.st.javaslicer.slicing.Slicer.java
License:Open Source License
public void process(ThreadId threadId, final List<SlicingCriterion> sc, boolean multithreaded) throws InterruptedException { DependencesExtractor<SlicerInstance> depExtractor = DependencesExtractor.forTrace(this.trace, SlicerInstanceFactory.instance); for (ProgressMonitor mon : this.progressMonitors) depExtractor.addProgressMonitor(mon); VisitorCapability[] capabilities = { VisitorCapability.CONTROL_DEPENDENCES, VisitorCapability.DATA_DEPENDENCES_READ_AFTER_WRITE, VisitorCapability.INSTRUCTION_EXECUTIONS, VisitorCapability.METHOD_ENTRY_LEAVE, VisitorCapability.CONTROL_DEPENDENCES }; if (this.untracedCallVisitors.size() > 0) capabilities[capabilities.length - 1] = VisitorCapability.UNTRACED_METHOD_CALLS; final List<SliceVisitor> sliceVisitors0 = Slicer.this.sliceVisitors; final List<UntracedCallVisitor> untracedCallVisitors0 = Slicer.this.untracedCallVisitors; depExtractor.registerVisitor(new DependencesVisitorAdapter<SlicerInstance>() { private final List<SlicingCriterionInstance> slicingCritInst = instantiateSlicingCriteria(sc); @SuppressWarnings("unchecked") private IntegerMap<Object>[] interestingLocalVariables = (IntegerMap<Object>[]) new IntegerMap<?>[0]; private long[] critOccurenceNumbers = new long[2]; // 0 if not in a criterion private final SliceVisitor[] sliceVisitorsArray = sliceVisitors0 .toArray(new SliceVisitor[sliceVisitors0.size()]); private final UntracedCallVisitor[] untracedCallsVisitorsArray = untracedCallVisitors0 .toArray(new UntracedCallVisitor[untracedCallVisitors0.size()]); private ReadMethod enteredMethod; private List<SlicingCriterionInstance> instantiateSlicingCriteria(List<SlicingCriterion> criteria) { if (criteria.isEmpty()) return Collections.emptyList(); else if (criteria.size() == 1) return Collections.singletonList(criteria.get(0).getInstance()); else { List<SlicingCriterionInstance> instances = new ArrayList<SlicingCriterionInstance>( criteria.size()); for (SlicingCriterion crit : criteria) instances.add(crit.getInstance()); return instances; }/*from ww w . j a va 2 s . c o m*/ } @Override public void visitInstructionExecution(SlicerInstance instance) { int stackDepth = instance.getStackDepth(); if (this.critOccurenceNumbers.length <= stackDepth) { long[] newCritOccurenceNumbers = new long[2 * Math.max(this.critOccurenceNumbers.length, stackDepth)]; System.arraycopy(this.critOccurenceNumbers, 0, newCritOccurenceNumbers, 0, this.critOccurenceNumbers.length); this.critOccurenceNumbers = newCritOccurenceNumbers; } Instruction instruction = instance.getInstruction(); for (SlicingCriterionInstance crit : this.slicingCritInst) { if (crit.matches(instance)) { this.critOccurenceNumbers[stackDepth] = crit.getOccurenceNumber(); assert this.critOccurenceNumbers[stackDepth] > 0; // for each criterion, there are three cases: // - track all data and control dependences of the instruction // - track a given set of local variables // - track the control dependences of this instruction // only in the first case, the instruction itself is added to the dynamic slice instance.fullTransitiveClosure = crit.computeTransitiveClosure(); if (instance.fullTransitiveClosure) { // first case if (instruction.getType() != InstructionType.LABEL && instruction.getOpcode() != Opcodes.GOTO) for (SliceVisitor vis : this.sliceVisitorsArray) vis.visitMatchedInstance(instance); instance.onDynamicSlice = true; instance.criterionDistance = 0; } else if (crit.hasLocalVariables()) { // second case if (this.interestingLocalVariables.length <= stackDepth) { @SuppressWarnings("unchecked") IntegerMap<Object>[] newInterestingLocalVariables = (IntegerMap<Object>[]) new IntegerMap<?>[Math .max(stackDepth + 1, this.interestingLocalVariables.length * 3 / 2)]; System.arraycopy(this.interestingLocalVariables, 0, newInterestingLocalVariables, 0, this.interestingLocalVariables.length); this.interestingLocalVariables = newInterestingLocalVariables; } List<LocalVariable> localVariables = crit.getLocalVariables(); if (this.interestingLocalVariables[stackDepth] == null) this.interestingLocalVariables[stackDepth] = new IntegerMap<Object>( localVariables.size() * 4 / 3 + 1); for (LocalVariable i : localVariables) this.interestingLocalVariables[stackDepth].put(i.getIndex(), null); } else { // third case instance.onDynamicSlice = true; instance.criterionDistance = 0; } } else if (this.critOccurenceNumbers[stackDepth] != 0) { this.critOccurenceNumbers[stackDepth] = 0; } } if (this.interestingLocalVariables.length > stackDepth && this.interestingLocalVariables[stackDepth] != null) { switch (instruction.getOpcode()) { case Opcodes.ISTORE: case Opcodes.ASTORE: case Opcodes.LSTORE: case Opcodes.FSTORE: case Opcodes.DSTORE: VarInstruction varInsn = (VarInstruction) instruction; if (this.interestingLocalVariables[stackDepth].containsKey(varInsn.getLocalVarIndex())) { this.interestingLocalVariables[stackDepth].remove(varInsn.getLocalVarIndex()); if (this.interestingLocalVariables[stackDepth].isEmpty()) this.interestingLocalVariables[stackDepth] = null; for (SliceVisitor vis : this.sliceVisitorsArray) vis.visitMatchedInstance(instance); instance.onDynamicSlice = true; // and we want to know where the data comes from... instance.fullTransitiveClosure = true; instance.criterionDistance = 0; } break; case Opcodes.INVOKEINTERFACE: case Opcodes.INVOKESPECIAL: case Opcodes.INVOKESTATIC: case Opcodes.INVOKEVIRTUAL: if (this.enteredMethod != null) { MethodInvocationInstruction mtdInvInsn = (MethodInvocationInstruction) instruction; int paramCount = instruction.getOpcode() == INVOKESTATIC ? 0 : 1; for (int param = mtdInvInsn.getParameterCount() - 1; param >= 0; --param) paramCount += mtdInvInsn.parameterIsLong(param) ? 2 : 1; boolean enteredMethodMatches = this.enteredMethod.getName() .equals(mtdInvInsn.getInvokedMethodName()) && this.enteredMethod.getDesc().equals(mtdInvInsn.getInvokedMethodDesc()); if (enteredMethodMatches) { boolean localVarsMatched = false; for (int varNr = 0; varNr < paramCount; ++varNr) { if (this.interestingLocalVariables[stackDepth].containsKey(varNr)) { this.interestingLocalVariables[stackDepth].remove(varNr); if (this.interestingLocalVariables[stackDepth].isEmpty()) this.interestingLocalVariables[stackDepth] = null; localVarsMatched = true; instance.onDynamicSlice = true; // and we want to know where the data comes from... // TODO instance.fullTransitiveClosure = true; instance.criterionDistance = 0; } } if (localVarsMatched) for (SliceVisitor vis : this.sliceVisitorsArray) vis.visitMatchedInstance(instance); } } } } this.enteredMethod = null; } @Override public void visitControlDependence(SlicerInstance from, SlicerInstance to) { if (from.onDynamicSlice) { Instruction insn = to.getInstruction(); if (insn.getType() == InstructionType.LABEL || insn.getOpcode() == Opcodes.GOTO) { if (to.predecessors == null) to.predecessors = Collections.singleton(from); else { if (to.predecessors.size() == 1) to.predecessors = new HashSet<SlicerInstance>(to.predecessors); to.predecessors.add(from); } if (from.criterionDistance < to.criterionDistance) to.criterionDistance = from.criterionDistance; } else if (from.predecessors != null) { assert (!from.predecessors.isEmpty()); for (SlicerInstance pred : from.predecessors) { int distance = pred.criterionDistance + 1; delegateControlSliceDependence(pred, to, distance); if (distance < to.criterionDistance) to.criterionDistance = distance; } } else { int distance = from.criterionDistance + 1; delegateControlSliceDependence(from, to, distance); if (distance < to.criterionDistance) to.criterionDistance = distance; } to.onDynamicSlice = true; } } private void delegateControlSliceDependence(SlicerInstance from, SlicerInstance to, int distance) { for (SliceVisitor vis : this.sliceVisitorsArray) vis.visitSliceDependence(from, to, null, distance); // since "to" controls the execution of "from", we want to track all data dependences of "to" // to find out why it took this decision // exception: method invocations; here we only want to track why the method was executed, // but not the data that it consumed // important to check that "from" comes from inside the method which is called by "from" boolean calledMethodDependence = false; if (to.getInstruction().getType() == InstructionType.METHODINVOCATION) { MethodInvocationInstruction mtdInv = (MethodInvocationInstruction) to.getInstruction(); ReadMethod calledMethod = from.getInstruction().getMethod(); if (mtdInv.getInvokedMethodName().equals(calledMethod.getName()) && mtdInv.getInvokedMethodDesc().equals(calledMethod.getDesc())) { calledMethodDependence = true; } } if (!calledMethodDependence) { to.fullTransitiveClosure = true; } } @Override public void visitDataDependence(SlicerInstance from, SlicerInstance to, Collection<? extends Variable> fromVars, Variable toVar, DataDependenceType type) throws InterruptedException { assert type == DataDependenceType.READ_AFTER_WRITE; if (from.onDynamicSlice && // from must definitively be on the dynamic slice (from.fullTransitiveClosure || // and either we want to track all data dependencies (from.interestingVariable != null && ( // or (if the interestingVariable is set) ... from.interestingVariable.equals(toVar) || // the interestingVariable must be the one we are just visiting (from.moreInterestingVariables != null && from.moreInterestingVariables.contains(toVar)))))) { // or it must be in the set of more variables Instruction insn = to.getInstruction(); assert insn.getType() != InstructionType.LABEL; int distance = from.criterionDistance + 1; if (distance < to.criterionDistance) to.criterionDistance = distance; for (SliceVisitor vis : this.sliceVisitorsArray) vis.visitSliceDependence(from, to, toVar, distance); if (!fromVars.isEmpty()) { Iterator<? extends Variable> varIt = fromVars.iterator(); assert varIt .hasNext() : "Iterator of a non-empty collection should have at least one element"; Variable first = varIt.next(); if (to.interestingVariable == null || to.interestingVariable.equals(first)) { to.interestingVariable = first; first = varIt.hasNext() ? varIt.next() : null; } if (first != null) { if (to.moreInterestingVariables == null) to.moreInterestingVariables = new HashSet<Variable>(8); to.moreInterestingVariables.add(first); while (varIt.hasNext()) to.moreInterestingVariables.add(varIt.next()); } } to.onDynamicSlice = true; } } @Override public void visitMethodLeave(ReadMethod method, int stackDepth) throws InterruptedException { if (this.interestingLocalVariables.length > stackDepth && this.interestingLocalVariables[stackDepth] != null) { this.interestingLocalVariables[stackDepth] = null; } } @Override public void visitMethodEntry(ReadMethod method, int stackDepth) throws InterruptedException { if (this.interestingLocalVariables.length > stackDepth && this.interestingLocalVariables[stackDepth] != null) { this.enteredMethod = method; this.interestingLocalVariables[stackDepth] = null; } } @Override public void visitUntracedMethodCall(SlicerInstance instrInstance) throws InterruptedException { for (UntracedCallVisitor vis : this.untracedCallsVisitorsArray) vis.visitUntracedMethodCall(instrInstance); } }, capabilities); depExtractor.processBackwardTrace(threadId, multithreaded); }
From source file:de.zib.sfs.instrument.AbstractSfsAdapter.java
License:BSD License
protected void wrapMethod(int access, String name, Type returnType, Type[] argumentTypes, String signature, String[] exceptions, String callbackName, Type additionalCallbackArgumentType, ResultPasser resultPasser) {/*from w w w. j av a 2 s .co 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()) { 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((access & Opcodes.ACC_STATIC) == 0 ? Opcodes.INVOKESPECIAL : Opcodes.INVOKESTATIC, 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(instrumentationActiveLabel); // 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((access & Opcodes.ACC_STATIC) == 0 ? Opcodes.INVOKESPECIAL : Opcodes.INVOKESTATIC, 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.AbstractSfsAdapter.java
License:BSD License
protected void storeTime(MethodVisitor mv, int index) { // long time = System.nanoTime(); mv.visitMethodInsn(Opcodes.INVOKESTATIC, this.systemInternalName, "nanoTime", this.nanoTimeDescriptor, false);/* w w w. jav a 2 s . c o m*/ mv.visitVarInsn(Opcodes.LSTORE, index); }
From source file:de.zib.sfs.instrument.DirectByteBufferAdapter.java
License:BSD License
@Override protected void appendWrappedMethods(ClassVisitor visitor) { // override from MappedByteBuffer so we can re-init the callback // properly// w w w .ja va 2 s .c om // 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)); // callback.openCallback(this.fileDescriptor); settFileDescriptorMV.visitVarInsn(Opcodes.ALOAD, 0); settFileDescriptorMV.visitFieldInsn(Opcodes.GETFIELD, this.instrumentedTypeInternalName, "callback", this.callbackTypeDescriptor); settFileDescriptorMV.visitVarInsn(Opcodes.ALOAD, 0); settFileDescriptorMV.visitFieldInsn(Opcodes.GETFIELD, Type.getInternalName(MappedByteBuffer.class), "fileDescriptor", Type.getDescriptor(FileDescriptor.class)); settFileDescriptorMV.visitMethodInsn(Opcodes.INVOKEVIRTUAL, this.callbackTypeInternalName, "openCallback", Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(FileDescriptor.class)), false); // } settFileDescriptorMV.visitInsn(Opcodes.RETURN); settFileDescriptorMV.visitMaxs(0, 0); settFileDescriptorMV.visitEnd(); // also override from MappedByteBuffer // 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(); if (!skipReads()) { wrapMethod(Opcodes.ACC_PUBLIC, "get", Type.getType(ByteBuffer.class), new Type[] { Type.getType(byte[].class), Type.INT_TYPE, Type.INT_TYPE }, null, null, "getCallback", Type.INT_TYPE, new ParameterResultPasser(3)); } if (!skipWrites()) { wrapMethod(Opcodes.ACC_PUBLIC, "put", Type.getType(ByteBuffer.class), new Type[] { Type.getType(byte[].class), Type.INT_TYPE, Type.INT_TYPE }, null, null, "putCallback", Type.INT_TYPE, new ParameterResultPasser(3)); } if (!skipWrites()) { // public ByteBuffer put(ByteBuffer src) { MethodVisitor bulkPutMV = visitor.visitMethod(Opcodes.ACC_PUBLIC, "put", Type.getMethodDescriptor(Type.getType(ByteBuffer.class), Type.getType(ByteBuffer.class)), null, null); bulkPutMV.visitCode(); // if (isInstrumentationActive()) { isInstrumentationActive(bulkPutMV); Label instrumentationActiveLabel = new Label(); bulkPutMV.visitJumpInsn(Opcodes.IFEQ, instrumentationActiveLabel); // return nativeMethodPrefixput(src); bulkPutMV.visitVarInsn(Opcodes.ALOAD, 0); bulkPutMV.visitVarInsn(Opcodes.ALOAD, 1); bulkPutMV.visitMethodInsn(Opcodes.INVOKESPECIAL, this.instrumentedTypeInternalName, this.methodPrefix + "put", Type.getMethodDescriptor(Type.getType(ByteBuffer.class), Type.getType(ByteBuffer.class)), false); bulkPutMV.visitInsn(Opcodes.ARETURN); // } bulkPutMV.visitLabel(instrumentationActiveLabel); // setInstrumentationActive(fromFileChannel); bulkPutMV.visitVarInsn(Opcodes.ALOAD, 0); bulkPutMV.visitVarInsn(Opcodes.ALOAD, 0); bulkPutMV.visitFieldInsn(Opcodes.GETFIELD, this.instrumentedTypeInternalName, "fromFileChannel", Type.getDescriptor(Boolean.TYPE)); bulkPutMV.visitMethodInsn(Opcodes.INVOKEVIRTUAL, this.instrumentedTypeInternalName, "setInstrumentationActive", Type.getMethodDescriptor(Type.VOID_TYPE, Type.BOOLEAN_TYPE), false); // boolean srcInstrumentationActive = false; bulkPutMV.visitInsn(Opcodes.ICONST_0); bulkPutMV.visitVarInsn(Opcodes.ISTORE, 2); // if (src instanceof MappedByteBuffer) { bulkPutMV.visitVarInsn(Opcodes.ALOAD, 1); bulkPutMV.visitTypeInsn(Opcodes.INSTANCEOF, Type.getInternalName(MappedByteBuffer.class)); Label srcInstanceofMappedByteBufferLabel = new Label(); bulkPutMV.visitJumpInsn(Opcodes.IFEQ, srcInstanceofMappedByteBufferLabel); // srcInstrumentationActive = src.isFromFileChannel(); bulkPutMV.visitVarInsn(Opcodes.ALOAD, 1); bulkPutMV.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(MappedByteBuffer.class), "isFromFileChannel", Type.getMethodDescriptor(Type.BOOLEAN_TYPE), false); bulkPutMV.visitVarInsn(Opcodes.ISTORE, 2); // src.setInstrumentationActive(true); bulkPutMV.visitVarInsn(Opcodes.ALOAD, 1); bulkPutMV.visitInsn(Opcodes.ICONST_1); bulkPutMV.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(MappedByteBuffer.class), "setInstrumentationActive", Type.getMethodDescriptor(Type.VOID_TYPE, Type.BOOLEAN_TYPE), false); // } bulkPutMV.visitLabel(srcInstanceofMappedByteBufferLabel); // int length = src.remaining(); bulkPutMV.visitVarInsn(Opcodes.ALOAD, 1); bulkPutMV.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Buffer.class), "remaining", Type.getMethodDescriptor(Type.INT_TYPE), false); bulkPutMV.visitVarInsn(Opcodes.ISTORE, 4); // long startTime = System.nanoTime(); bulkPutMV.visitMethodInsn(Opcodes.INVOKESTATIC, this.systemInternalName, "nanoTime", this.nanoTimeDescriptor, false); bulkPutMV.visitVarInsn(Opcodes.LSTORE, 5); // ByteBuffer result = nativeMethodPrefixput(src); bulkPutMV.visitVarInsn(Opcodes.ALOAD, 0); bulkPutMV.visitVarInsn(Opcodes.ALOAD, 1); bulkPutMV.visitMethodInsn(Opcodes.INVOKESPECIAL, this.instrumentedTypeInternalName, this.methodPrefix + "put", Type.getMethodDescriptor(Type.getType(ByteBuffer.class), Type.getType(ByteBuffer.class)), false); bulkPutMV.visitVarInsn(Opcodes.ASTORE, 7); // long endTime = System.nanoTime(); bulkPutMV.visitMethodInsn(Opcodes.INVOKESTATIC, this.systemInternalName, "nanoTime", this.nanoTimeDescriptor, false); bulkPutMV.visitVarInsn(Opcodes.LSTORE, 8); // if (isInstrumentationActive()) { isInstrumentationActive(bulkPutMV); Label instrumentationStillActiveLabel = new Label(); bulkPutMV.visitJumpInsn(Opcodes.IFEQ, instrumentationStillActiveLabel); // callback.putCallback(startTime, endTime, length); bulkPutMV.visitVarInsn(Opcodes.ALOAD, 0); bulkPutMV.visitFieldInsn(Opcodes.GETFIELD, this.instrumentedTypeInternalName, "callback", this.callbackTypeDescriptor); bulkPutMV.visitVarInsn(Opcodes.LLOAD, 5); bulkPutMV.visitVarInsn(Opcodes.LLOAD, 8); bulkPutMV.visitVarInsn(Opcodes.ILOAD, 4); bulkPutMV.visitMethodInsn(Opcodes.INVOKEVIRTUAL, this.callbackTypeInternalName, "putCallback", Type.getMethodDescriptor(Type.VOID_TYPE, Type.LONG_TYPE, Type.LONG_TYPE, Type.INT_TYPE), false); // setInstrumentationActive(false); setInstrumentationActive(bulkPutMV, false); // } bulkPutMV.visitLabel(instrumentationStillActiveLabel); // if (srcInstrumentationActive) { bulkPutMV.visitVarInsn(Opcodes.ILOAD, 2); Label srcInstrumentationActiveLabel = new Label(); bulkPutMV.visitJumpInsn(Opcodes.IFEQ, srcInstrumentationActiveLabel); // callback.onGetEnd(src.getFileDescriptor(), startTime, endTime, // length); bulkPutMV.visitVarInsn(Opcodes.ALOAD, 1); bulkPutMV.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(MappedByteBuffer.class), "getFileDescriptor", Type.getMethodDescriptor(Type.getType(FileDescriptor.class)), false); bulkPutMV.visitVarInsn(Opcodes.LLOAD, 5); bulkPutMV.visitVarInsn(Opcodes.LLOAD, 8); bulkPutMV.visitVarInsn(Opcodes.ILOAD, 4); bulkPutMV.visitMethodInsn(Opcodes.INVOKESTATIC, this.callbackTypeInternalName, "getCallback", Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(FileDescriptor.class), Type.LONG_TYPE, Type.LONG_TYPE, Type.INT_TYPE), false); // src.setInstrumentationActive(false); bulkPutMV.visitVarInsn(Opcodes.ALOAD, 1); bulkPutMV.visitInsn(Opcodes.ICONST_0); bulkPutMV.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(MappedByteBuffer.class), "setInstrumentationActive", Type.getMethodDescriptor(Type.VOID_TYPE, Type.BOOLEAN_TYPE), false); // } bulkPutMV.visitLabel(srcInstrumentationActiveLabel); // return result; // } bulkPutMV.visitVarInsn(Opcodes.ALOAD, 7); bulkPutMV.visitInsn(Opcodes.ARETURN); bulkPutMV.visitMaxs(0, 0); bulkPutMV.visitEnd(); } ResultPasser resultDiscarder = new DiscardResultPasser(); // regular gets and puts for (Map.Entry<String, Type> type : TYPES.entrySet()) { if (!skipReads()) { // public TYPE getTYPE() { ... } wrapMethod(Opcodes.ACC_PUBLIC, "get" + type.getKey(), type.getValue(), null, null, null, "get" + type.getKey() + "Callback", null, resultDiscarder); // public TYPE getTYPE(int index) { ... } wrapMethod(Opcodes.ACC_PUBLIC, "get" + type.getKey(), type.getValue(), new Type[] { Type.INT_TYPE }, null, null, "get" + type.getKey() + "Callback", null, resultDiscarder); } if (!skipWrites()) { // public ByteBuffer putTYPE(TYPE value) { ... } wrapMethod(Opcodes.ACC_PUBLIC, "put" + type.getKey(), Type.getType(ByteBuffer.class), new Type[] { type.getValue() }, null, null, "put" + type.getKey() + "Callback", null, resultDiscarder); // public ByteBuffer putTYPE(int index, TYPE value) { ... } wrapMethod(Opcodes.ACC_PUBLIC, "put" + type.getKey(), Type.getType(ByteBuffer.class), new Type[] { Type.INT_TYPE, type.getValue() }, null, null, "put" + type.getKey() + "Callback", null, resultDiscarder); } } visitor.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();/* w w w . ja va 2 s. c o m*/ // 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.ZipFileAdapter.java
License:BSD License
@Override public void visitEnd() { if (!this.skip.contains(OperationCategory.ZIP)) { // public void close() { MethodVisitor closeMethodMV = this.cv.visitMethod(Opcodes.ACC_PUBLIC, "close", Type.getMethodDescriptor(Type.VOID_TYPE), null, new String[] { Type.getInternalName(IOException.class) }); closeMethodMV.visitCode();/*from w w w . ja v a 2 s. c o m*/ // ZipFileCallback.closeCallback(jzfile); closeMethodMV.visitVarInsn(Opcodes.ALOAD, 0); closeMethodMV.visitFieldInsn(Opcodes.GETFIELD, Type.getInternalName(ZipFile.class), "jzfile", Type.getDescriptor(Long.TYPE)); closeMethodMV.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(ZipFileCallback.class), "closeCallback", Type.getMethodDescriptor(Type.VOID_TYPE, Type.LONG_TYPE), false); // methodPrefixclose(); closeMethodMV.visitVarInsn(Opcodes.ALOAD, 0); closeMethodMV.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(ZipFile.class), this.methodPrefix + "close", Type.getMethodDescriptor(Type.VOID_TYPE), false); // } closeMethodMV.visitInsn(Opcodes.RETURN); closeMethodMV.visitMaxs(0, 0); closeMethodMV.visitEnd(); } this.cv.visitEnd(); }
From source file:dimmunix.InstrumentationMethodAdapter.java
License:Open Source License
public void visitLineNumber(int line, Label start) { this.curLine = line; mv.visitLineNumber(line, start);//w w w .j a v a 2 s .c o m //code for skipping avoidance Vector<Pair<Integer, Integer>> sigsToSkipBefore = DimmunixDeadlock.instance .getIdsSignaturesToSkip(className, methodName, curLine, true); for (Pair<Integer, Integer> sig : sigsToSkipBefore) { mv.visitLdcInsn(sig.v1); mv.visitLdcInsn(sig.v2); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "dimmunix/deadlock/DimmunixDeadlock", "skipAvoidance", "(II)V"); } }