List of usage examples for org.objectweb.asm Opcodes PUTFIELD
int PUTFIELD
To view the source code for org.objectweb.asm Opcodes PUTFIELD.
Click Source Link
From source file:de.sanandrew.core.manpack.transformer.TransformELBAttackingPlayer.java
License:Creative Commons License
private static byte[] transformAttackingPlayer(byte[] bytes) { ClassNode clazz = ASMHelper.createClassNode(bytes); /** ADD GETTER FOR ATTACKING PLAYER **/ {/*from ww w .j ava 2 s . co m*/ MethodNode method = new MethodNode(Opcodes.ACC_PUBLIC, "_SAP_getAttackingPlayer", "()Lnet/minecraft/entity/player/EntityPlayer;", null, null); method.visitCode(); Label l0 = new Label(); method.visitLabel(l0); method.visitVarInsn(Opcodes.ALOAD, 0); method.visitFieldInsn(Opcodes.GETFIELD, "net/minecraft/entity/EntityLivingBase", ASMNames.F_attackingPlayer, "Lnet/minecraft/entity/player/EntityPlayer;"); method.visitInsn(Opcodes.ARETURN); Label l1 = new Label(); method.visitLabel(l1); method.visitLocalVariable("this", "Lnet/minecraft/entity/EntityLivingBase;", null, l0, l1, 0); method.visitMaxs(0, 0); method.visitEnd(); clazz.methods.add(method); } /** ADD SETTER FOR ATTACKING PLAYER **/ { MethodNode method = new MethodNode(Opcodes.ACC_PUBLIC, "_SAP_setAttackingPlayer", "(Lnet/minecraft/entity/player/EntityPlayer;)V", null, null); method.visitCode(); Label l0 = new Label(); method.visitLabel(l0); method.visitVarInsn(Opcodes.ALOAD, 0); method.visitVarInsn(Opcodes.ALOAD, 1); method.visitFieldInsn(Opcodes.PUTFIELD, "net/minecraft/entity/EntityLivingBase", ASMNames.F_attackingPlayer, "Lnet/minecraft/entity/player/EntityPlayer;"); Label l1 = new Label(); method.visitLabel(l1); method.visitInsn(Opcodes.RETURN); Label l2 = new Label(); method.visitLabel(l2); method.visitLocalVariable("this", "Lnet/minecraft/entity/EntityLivingBase;", null, l0, l2, 0); method.visitLocalVariable("player", "Lnet/minecraft/entity/player/EntityPlayer;", null, l0, l2, 1); method.visitMaxs(0, 0); method.visitEnd(); clazz.methods.add(method); } /** ADD GETTER FOR RECENTLY HIT **/ { MethodNode method = new MethodNode(Opcodes.ACC_PUBLIC, "_SAP_getRecentlyHit", "()I", null, null); method.visitCode(); Label l0 = new Label(); method.visitLabel(l0); method.visitVarInsn(Opcodes.ALOAD, 0); method.visitFieldInsn(Opcodes.GETFIELD, "net/minecraft/entity/EntityLivingBase", ASMNames.F_recentlyHit, "I"); method.visitInsn(Opcodes.IRETURN); Label l1 = new Label(); method.visitLabel(l1); method.visitLocalVariable("this", "Lnet/minecraft/entity/EntityLivingBase;", null, l0, l1, 0); method.visitMaxs(0, 0); method.visitEnd(); clazz.methods.add(method); } /** ADD SETTER FOR RECENTLY HIT **/ { MethodNode method = new MethodNode(Opcodes.ACC_PUBLIC, "_SAP_setRecentlyHit", "(I)V", null, null); method.visitCode(); Label l0 = new Label(); method.visitLabel(l0); method.visitVarInsn(Opcodes.ALOAD, 0); method.visitVarInsn(Opcodes.ILOAD, 1); method.visitFieldInsn(Opcodes.PUTFIELD, "net/minecraft/entity/EntityLivingBase", ASMNames.F_recentlyHit, "I"); Label l1 = new Label(); method.visitLabel(l1); method.visitInsn(Opcodes.RETURN); Label l2 = new Label(); method.visitLabel(l2); method.visitLocalVariable("this", "Lnet/minecraft/entity/EntityLivingBase;", null, l0, l2, 0); method.visitLocalVariable("hit", "I", null, l0, l2, 1); method.visitMaxs(0, 0); method.visitEnd(); clazz.methods.add(method); } bytes = ASMHelper.createBytes(clazz, /*ClassWriter.COMPUTE_FRAMES |*/ ClassWriter.COMPUTE_MAXS); return bytes; }
From source file:de.sanandrew.core.manpack.transformer.TransformHorseArmor.java
License:Creative Commons License
private static void transformArmorTexture(MethodNode method) { InsnList needle = new InsnList(); needle.add(new VarInsnNode(Opcodes.ALOAD, 0)); needle.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_HORSE_FUNC110241CB, false)); needle.add(new VarInsnNode(Opcodes.ISTORE, 3)); AbstractInsnNode node = ASMHelper.findLastNodeFromNeedle(method.instructions, needle); InsnList newInstr = new InsnList(); LabelNode l17 = new LabelNode(); newInstr.add(l17);/*w ww . jav a 2s . com*/ newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0)); newInstr.add( ASMHelper.getMethodInsnNode(Opcodes.INVOKESPECIAL, ASMNames.MD_SAP_GET_CUSTOM_ARMOR_ITEM, false)); newInstr.add(new VarInsnNode(Opcodes.ASTORE, 4)); LabelNode l18 = new LabelNode(); newInstr.add(l18); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 4)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_ITEMSTACK_GET_ITEM, false)); newInstr.add(new TypeInsnNode(Opcodes.INSTANCEOF, ASMNames.CL_ITEM_HORSE_ARMOR)); LabelNode l19 = new LabelNode(); newInstr.add(new JumpInsnNode(Opcodes.IFEQ, l19)); LabelNode l20 = new LabelNode(); newInstr.add(l20); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0)); newInstr.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_HORSE_FIELD110280BR)); newInstr.add(new InsnNode(Opcodes.ICONST_2)); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 4)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_ITEMSTACK_GET_ITEM, false)); newInstr.add(new TypeInsnNode(Opcodes.CHECKCAST, ASMNames.CL_ITEM_HORSE_ARMOR)); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0)); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 4)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_SAP_GET_ARMOR_TEXTURE, false)); newInstr.add(new InsnNode(Opcodes.AASTORE)); LabelNode l21 = new LabelNode(); newInstr.add(l21); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0)); newInstr.add(new TypeInsnNode(Opcodes.NEW, ASMNames.CL_STRING_BUILDER)); newInstr.add(new InsnNode(Opcodes.DUP)); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0)); newInstr.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_HORSE_FIELD110286BQ)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKESTATIC, ASMNames.MD_STRING_VALUE_OF, false)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKESPECIAL, ASMNames.MD_STRINGBUILDER_INIT, false)); newInstr.add(new LdcInsnNode("cst-")); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_STRINGBUILDER_APPEND, false)); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 4)); newInstr.add( ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_ITEMSTACK_GET_UNLOC_NAME, false)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_STRINGBUILDER_APPEND, false)); newInstr.add( ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_STRINGBUILDER_TO_STRING, false)); newInstr.add(ASMHelper.getFieldInsnNode(Opcodes.PUTFIELD, ASMNames.FD_HORSE_FIELD110286BQ)); newInstr.add(new InsnNode(Opcodes.RETURN)); newInstr.add(l19); method.instructions.insert(node, newInstr); }
From source file:de.tuberlin.uebb.jbop.access.ConstructorBuilder.java
License:Open Source License
private static int createInstructions(final int param, final FieldNode field, final ClassNode node, final InsnList instructions) { final AbstractInsnNode nThis = new VarInsnNode(Opcodes.ALOAD, 0); final int opcode = Opcodes.ALOAD; final int nextParam = param + 1; final AbstractInsnNode unboxing = getUnboxingNode(field); instructions.add(nThis);/*from w w w .ja va 2 s . c o m*/ final AbstractInsnNode nParam = new VarInsnNode(opcode, param); instructions.add(nParam); if (unboxing != null) { instructions.add(unboxing); } final AbstractInsnNode nPut = new FieldInsnNode(Opcodes.PUTFIELD, node.name, field.name, field.desc); instructions.add(nPut); return nextParam; }
From source file:de.tuberlin.uebb.jbop.optimizer.ClassNodeBuilder.java
License:Open Source License
/** * Creates a setter for the last added field. * /*from w ww. ja va 2 s . co m*/ * @return the class node builder */ public ClassNodeBuilder withSetter() { if (isInterface) { return this; } final String name = lastField.name; final String desc = lastField.desc; addMethod("set" + Character.toUpperCase(name.charAt(0)) + name.substring(1), "(" + desc + ")V"); final Type type = Type.getType(desc); addInsn(new VarInsnNode(Opcodes.ALOAD, 0)); addInsn(new VarInsnNode(type.getOpcode(Opcodes.ILOAD), 1)); addInsn(new FieldInsnNode(Opcodes.PUTFIELD, classNode.name, name, desc)); addInsn(new InsnNode(Opcodes.RETURN)); return this; }
From source file:de.tuberlin.uebb.jbop.optimizer.ClassNodeBuilder.java
License:Open Source License
/** * Initializes a classField in the default lastConstructor * (eg: if fieldType of field "field" is "TestObject", field = new TestObject() is called). * /* w w w .j a va 2 s .c o m*/ * Numbers and Strings are used to assign "field", every other value leads to new Object. * * @param object * the object to Use. * @return the abstract optimizer test */ public ClassNodeBuilder initWith(final Object object) { if (isInterface) { return this; } final InsnList list = new InsnList(); if (object instanceof String || object instanceof Number || object instanceof Boolean || object instanceof Character) { list.add(new VarInsnNode(Opcodes.ALOAD, 0)); final AbstractInsnNode numberNode = NodeHelper.getInsnNodeFor(object); list.add(numberNode); if (lastField.desc.startsWith("L") && object instanceof Number) { list.add(ConstructorBuilder.getBoxingNode(lastField)); } list.add(new FieldInsnNode(Opcodes.PUTFIELD, classNode.name, lastField.name, lastField.desc)); } else { list.add(new VarInsnNode(ALOAD, 0)); list.add(newObject(lastField.desc)); list.add(new MethodInsnNode(INVOKESPECIAL, StringUtils.removeEnd(StringUtils.removeStart(lastField.desc, "L"), ";"), "<init>", "()V")); list.add(new FieldInsnNode(Opcodes.PUTFIELD, classNode.name, lastField.name, lastField.desc)); } addToConstructor(list); return this; }
From source file:de.tuberlin.uebb.jbop.optimizer.ClassNodeBuilder.java
License:Open Source License
/** * Initializes a classField of type Array in the default lastConstructor with the given length. * (eg: if fieldType of field "field" is "double[]", field = new double[length] is called). * /*from ww w .ja v a2 s. co m*/ * @param length * the length * @return the abstract optimizer test */ public ClassNodeBuilder initArray(final int... length) { if (isInterface) { return this; } final InsnList list = new InsnList(); list.add(new VarInsnNode(Opcodes.ALOAD, 0)); final AbstractInsnNode node; if (length.length == 1) { final Type elementType = Type.getType(lastField.desc).getElementType(); list.add(NodeHelper.getInsnNodeFor(Integer.valueOf(length[0]))); if (elementType.getDescriptor().startsWith("L")) { node = new TypeInsnNode(Opcodes.ANEWARRAY, elementType.getInternalName()); } else { node = new IntInsnNode(Opcodes.NEWARRAY, getSort(elementType)); } } else { for (final int currentLength : length) { list.add(NodeHelper.getInsnNodeFor(Integer.valueOf(currentLength))); } node = new MultiANewArrayInsnNode(lastField.desc, length.length); } list.add(node); list.add(new VarInsnNode(Opcodes.ASTORE, constructorVarIndex)); list.add(new VarInsnNode(Opcodes.ALOAD, constructorVarIndex)); lastConstructorVarIndex = constructorVarIndex; constructorVarIndex++; list.add(new FieldInsnNode(Opcodes.PUTFIELD, classNode.name, lastField.name, lastField.desc)); addToConstructor(list); return this; }
From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.FieldInstruction.java
License:Open Source License
@Override public String toString() { String type;//from w w w. j a v a 2s. c om switch (getOpcode()) { case Opcodes.PUTSTATIC: type = "PUTSTATIC"; break; case Opcodes.GETSTATIC: type = "GETSTATIC"; break; case Opcodes.GETFIELD: type = "GETFIELD"; break; case Opcodes.PUTFIELD: type = "PUTFIELD"; break; default: assert false; type = "--ERROR--"; break; } StringBuilder sb = new StringBuilder(type.length() + this.ownerInternalClassName.length() + this.fieldName.length() + this.fieldDesc.length() + 3); sb.append(type).append(' ').append(this.ownerInternalClassName).append('.').append(this.fieldName) .append(' ').append(this.fieldDesc); return sb.toString(); }
From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.FieldInstruction2.java
License:Open Source License
@Override public String toString() { String type;//from w ww . j av a 2s. com switch (getOpcode()) { case Opcodes.PUTSTATIC: type = "PUTSTATIC"; break; case Opcodes.GETSTATIC: type = "GETSTATIC"; break; case Opcodes.GETFIELD: type = "GETFIELD"; break; case Opcodes.PUTFIELD: type = "PUTFIELD"; break; default: assert false; type = "--ERROR--"; break; } StringBuilder sb = new StringBuilder(type.length() + this.ownerInternalClassName.length() + this.fieldName.length() + this.fieldDesc.length() + 3); sb.append(type).append(' ').append(this.ownerInternalClassName).append(".&&").append(this.fieldName) .append(' ').append(this.fieldDesc); return sb.toString(); }
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/* ww w . ja v a 2s. 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.MappedByteBufferAdapter.java
License:BSD License
@Override protected void initializeFields(MethodVisitor constructorMV, String constructorDesc) { // fromFileChannel = false; constructorMV.visitVarInsn(Opcodes.ALOAD, 0); constructorMV.visitInsn(Opcodes.ICONST_0); constructorMV.visitFieldInsn(Opcodes.PUTFIELD, Type.getInternalName(MappedByteBuffer.class), "fromFileChannel", Type.getDescriptor(Boolean.TYPE)); }