List of usage examples for org.objectweb.asm MethodVisitor visitMethodInsn
public void visitMethodInsn(final int opcode, final String owner, final String name, final String descriptor, final boolean isInterface)
From source file:com.cinnober.msgcodec.blink.BaseByteCodeGenerator.java
License:Open Source License
/** * Generate value decoding using the blink input. * * <p>Defaults to <code>readUInt16[Null].</code> * * @param required true if the field is required, otherwise false. * @param mv the method visitor, not null. * @see #generateDecodeValue// w w w . jav a 2s. com */ protected void generateDecodeCharacterValue(boolean required, MethodVisitor mv) { if (required) { mv.visitMethodInsn(INVOKESTATIC, blinkInputIName, "readUInt16", "(Lcom/cinnober/msgcodec/io/ByteSource;)S", false); mv.visitInsn(I2C); } else { mv.visitMethodInsn(INVOKESTATIC, blinkInputIName, "readUInt16Null", "(Lcom/cinnober/msgcodec/io/ByteSource;)Ljava/lang/Short;", false); Label nullLabel = new Label(); mv.visitInsn(DUP); mv.visitJumpInsn(IFNULL, nullLabel); unbox(mv, Short.class); mv.visitInsn(I2C); box(mv, Character.class); mv.visitLabel(nullLabel); mv.visitTypeInsn(CHECKCAST, Type.getInternalName(Character.class)); } }
From source file:com.cinnober.msgcodec.blink.BaseByteCodeGenerator.java
License:Open Source License
/** * Generate value decoding using the blink input. * * <p>Defaults to <code>readUInt16[Null].</code> * * @param required true if the field is required, otherwise false. * @param mv the method visitor, not null. * @see #generateDecodeValue//from ww w .j a v a 2s . co m */ protected void generateDecodeUInt16Value(boolean required, MethodVisitor mv) { if (required) { mv.visitMethodInsn(INVOKESTATIC, blinkInputIName, "readUInt16", "(Lcom/cinnober/msgcodec/io/ByteSource;)S", false); } else { mv.visitMethodInsn(INVOKESTATIC, blinkInputIName, "readUInt16Null", "(Lcom/cinnober/msgcodec/io/ByteSource;)Ljava/lang/Short;", false); } }
From source file:com.cinnober.msgcodec.blink.BaseByteCodeGenerator.java
License:Open Source License
/** * Generate value decoding using the blink input. * * <p>Defaults to <code>readInt16[Null].</code> * * @param required true if the field is required, otherwise false. * @param mv the method visitor, not null. * @see #generateDecodeValue/* w w w.j a v a 2 s . c o m*/ */ protected void generateDecodeInt16Value(boolean required, MethodVisitor mv) { if (required) { mv.visitMethodInsn(INVOKESTATIC, blinkInputIName, "readInt16", "(Lcom/cinnober/msgcodec/io/ByteSource;)S", false); } else { mv.visitMethodInsn(INVOKESTATIC, blinkInputIName, "readInt16Null", "(Lcom/cinnober/msgcodec/io/ByteSource;)Ljava/lang/Short;", false); } }
From source file:com.cinnober.msgcodec.blink.BaseByteCodeGenerator.java
License:Open Source License
/** * Generate value decoding using the blink input. * * <p>Defaults to <code>readUInt8[Null].</code> * * @param required true if the field is required, otherwise false. * @param mv the method visitor, not null. * @see #generateDecodeValue/*from ww w . ja v a2 s . co m*/ */ protected void generateDecodeUInt8Value(boolean required, MethodVisitor mv) { if (required) { mv.visitMethodInsn(INVOKESTATIC, blinkInputIName, "readUInt8", "(Lcom/cinnober/msgcodec/io/ByteSource;)B", false); } else { mv.visitMethodInsn(INVOKESTATIC, blinkInputIName, "readUInt8Null", "(Lcom/cinnober/msgcodec/io/ByteSource;)Ljava/lang/Byte;", false); } }
From source file:com.cinnober.msgcodec.blink.BaseByteCodeGenerator.java
License:Open Source License
/** * Generate value decoding using the blink input. * * <p>Defaults to <code>readInt8[Null].</code> * * @param required true if the field is required, otherwise false. * @param mv the method visitor, not null. * @see #generateDecodeValue/*from w ww .ja v a2 s . c o m*/ */ protected void generateDecodeInt8Value(boolean required, MethodVisitor mv) { if (required) { mv.visitMethodInsn(INVOKESTATIC, blinkInputIName, "readInt8", "(Lcom/cinnober/msgcodec/io/ByteSource;)B", false); } else { mv.visitMethodInsn(INVOKESTATIC, blinkInputIName, "readInt8Null", "(Lcom/cinnober/msgcodec/io/ByteSource;)Ljava/lang/Byte;", false); } }
From source file:com.cinnober.msgcodec.blink.BaseByteCodeGenerator.java
License:Open Source License
protected void generateDecodeTimeValue(TypeDef.Time type, Class<?> javaClass, boolean required, MethodVisitor mv, LocalVariable nextVar) throws IllegalArgumentException { if (javaClass == long.class || javaClass == Long.class) { generateDecodeInt64Value(required, mv); } else if (javaClass == int.class || javaClass == Integer.class) { generateDecodeInt32Value(required, mv); } else if (javaClass == Date.class) { int timeVar = nextVar.next(); nextVar.next(); // note: 2 variable slots Label endLabel = new Label(); if (required) { generateDecodeInt64Value(true, mv); } else {/*from w ww . ja va 2s . co m*/ generateDecodeInt64Value(false, mv); mv.visitInsn(DUP); Label nonNullLabel = new Label(); mv.visitJumpInsn(IFNONNULL, nonNullLabel); // null mv.visitTypeInsn(CHECKCAST, "java/util/Date"); mv.visitJumpInsn(GOTO, endLabel); // not null mv.visitLabel(nonNullLabel); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Long", "longValue", "()J", false); } mv.visitVarInsn(LSTORE, timeVar); mv.visitTypeInsn(NEW, "java/util/Date"); mv.visitInsn(DUP); mv.visitVarInsn(LLOAD, timeVar); // handle differences in UNIT and EPOCH long epochOffset = DateUtil.getEpochOffset(type.getEpoch()); long timeInMillis = DateUtil.getTimeInMillis(type.getUnit()); // dateTime = wireTime * timeUnitInMillis + epochOffset; if (timeInMillis != 1) { mv.visitLdcInsn(timeInMillis); mv.visitInsn(LMUL); } if (epochOffset != 0) { mv.visitLdcInsn(epochOffset); mv.visitInsn(LADD); } mv.visitMethodInsn(INVOKESPECIAL, "java/util/Date", "<init>", "(J)V", false); if (!required) { // end mv.visitLabel(endLabel); } } else { throw new IllegalArgumentException("Illegal time javaClass: " + javaClass); } }
From source file:com.cinnober.msgcodec.blink.BaseByteCodeGenerator.java
License:Open Source License
/** * @see #generateDecodeInt32Value(boolean, org.objectweb.asm.MethodVisitor) *//*www.j a va 2 s.c o m*/ protected void generateDecodeEnumValue(boolean required, MethodVisitor mv, TypeDef type, String genClassInternalName, String fieldIdentifier, LocalVariable nextVar, Class<?> javaClass, String debugValueLabel) throws IllegalArgumentException { Label endLabel = new Label(); if (required) { generateDecodeInt32Value(true, mv); box(mv, Integer.class); } else { generateDecodeInt32Value(false, mv); mv.visitInsn(DUP); mv.visitJumpInsn(IFNULL, endLabel); // Label nonNullLabel = new Label(); // mv.visitJumpInsn(IFNONNULL, nonNullLabel); // mv.visitTypeInsn(CHECKCAST, Type.getInternalName(javaClass)); // mv.visitJumpInsn(GOTO, endLabel); // not null // mv.visitLabel(nonNullLabel); // mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Integer", "intValue", "()I", false); // unbox(mv, Integer.class); } // SymbolMapping mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, genClassInternalName, "symbolMapping_" + fieldIdentifier, "Lcom/cinnober/msgcodec/SymbolMapping;"); mv.visitInsn(SWAP); mv.visitMethodInsn(INVOKEINTERFACE, "com/cinnober/msgcodec/SymbolMapping", "lookup", "(Ljava/lang/Integer;)Ljava/lang/Object;", true); // // switch // TypeDef.Enum enumType = (TypeDef.Enum) type; // List<Symbol> symbols = enumType.getSymbols(); // int numSymbols = symbols.size(); // int[] ids = new int[numSymbols]; // Label[] labels = new Label[numSymbols]; // for (int i=0; i<numSymbols; i++) { // ids[i] = symbols.get(i).getId(); // labels[i] = new Label(); // } // Label defaultLabel = new Label(); // int symbolIdVar = nextVar.next(); // mv.visitInsn(DUP); // mv.visitVarInsn(ISTORE, symbolIdVar); // EnumSymbols enumSymbols = null; // if (javaClass.isEnum()) { // enumSymbols = new EnumSymbols(enumType, javaClass); // } // mv.visitLookupSwitchInsn(defaultLabel, ids, labels); // for (int i=0; i<numSymbols; i++) { // boolean addGotoEnd = true; // mv.visitLabel(labels[i]); // if (javaClass.isEnum()) { // Enum enumValue = enumSymbols.getEnum(ids[i]); // if (enumValue != null) { // //mv.visitLdcInsn(Type.getType(javaClass)); // mv.visitFieldInsn(GETSTATIC, Type.getInternalName(javaClass), // enumValue.name(), // Type.getDescriptor(javaClass)); // } else { // mv.visitLdcInsn(debugValueLabel); // mv.visitLdcInsn(ids[i]); // mv.visitLdcInsn(Type.getType(javaClass)); // mv.visitMethodInsn(INVOKESTATIC, baseclassIName, "unmappableEnumSymbolId", // "(Ljava/lang/String;ILjava/lang/Class;)Lcom/cinnober/msgcodec/DecodeException;", false); // mv.visitInsn(ATHROW); // addGotoEnd = false; // } // } else if (javaClass == int.class || javaClass == Integer.class) { // mv.visitLdcInsn(ids[i]); // if (!required) { // box(mv, Integer.class); // } // } else { // throw new IllegalArgumentException("Illegal enum javaClass: " + javaClass); // } // if (addGotoEnd) { // mv.visitJumpInsn(GOTO, endLabel); // } // } // mv.visitLabel(defaultLabel); // mv.visitLdcInsn(debugValueLabel); // mv.visitVarInsn(ILOAD, symbolIdVar); // mv.visitMethodInsn(INVOKESTATIC, baseclassIName, "unknownEnumSymbol", // "(Ljava/lang/String;I)Lcom/cinnober/msgcodec/DecodeException;", false); // mv.visitInsn(ATHROW); // end mv.visitLabel(endLabel); if (!javaClass.isEnum()) { mv.visitTypeInsn(CHECKCAST, Type.getInternalName(Integer.class)); if (required) { unbox(mv, Integer.class); } } else { mv.visitTypeInsn(CHECKCAST, Type.getInternalName(javaClass)); } }
From source file:com.cinnober.msgcodec.blink.BaseByteCodeGenerator.java
License:Open Source License
protected void generateDecodeDynRefValue(MethodVisitor mv, boolean required, GroupDef refGroup, Class<?> javaClass) { mv.visitVarInsn(ALOAD, 0); // this mv.visitInsn(SWAP); // this and in if (required) { mv.visitMethodInsn(INVOKEVIRTUAL, baseclassIName, "readDynamicGroup", "(Lcom/cinnober/msgcodec/io/ByteSource;)Ljava/lang/Object;", false); } else {/*from w ww . j a va 2 s.c om*/ mv.visitMethodInsn(INVOKEVIRTUAL, baseclassIName, "readDynamicGroupNull", "(Lcom/cinnober/msgcodec/io/ByteSource;)Ljava/lang/Object;", false); } if (refGroup != null) { mv.visitTypeInsn(CHECKCAST, Type.getInternalName(javaClass)); } }
From source file:com.cinnober.msgcodec.blink.BaseByteCodeGenerator.java
License:Open Source License
protected void generateDecodeRefValue(GroupDef refGroup, boolean required, MethodVisitor mv, int byteSourceVar, String genClassInternalName, Class<?> javaClass, TypeDef type, boolean javaClassCodec) throws IllegalArgumentException { if (refGroup != null) { String groupDescriptor = getTypeDescriptor(javaClass, javaClassCodec); if (required) { mv.visitInsn(POP); // input stream mv.visitVarInsn(ALOAD, 0);/*from www . j a v a 2s . co m*/ mv.visitVarInsn(ALOAD, byteSourceVar); mv.visitMethodInsn(INVOKEVIRTUAL, genClassInternalName, "readStaticGroup_" + refGroup.getName(), "(Lcom/cinnober/msgcodec/io/ByteSource;)" + groupDescriptor, false); } else { mv.visitMethodInsn(INVOKESTATIC, blinkInputIName, "readPresenceByte", "(Lcom/cinnober/msgcodec/io/ByteSource;)Z", false); Label nonNullLabel = new Label(); Label endLabel = new Label(); mv.visitJumpInsn(IFNE, nonNullLabel); // not false, i.e. true // null mv.visitInsn(ACONST_NULL); mv.visitJumpInsn(GOTO, endLabel); // not null mv.visitLabel(nonNullLabel); mv.visitFrame(F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, byteSourceVar); mv.visitMethodInsn(INVOKEVIRTUAL, genClassInternalName, "readStaticGroup_" + refGroup.getName(), "(Lcom/cinnober/msgcodec/io/ByteSource;)" + groupDescriptor, false); mv.visitLabel(endLabel); // PENDING: mv.visitFrame? mv.visitFrame(F_SAME, 0, null, 0, null); } } else { throw new IllegalArgumentException("Illegal reference: " + type); } }
From source file:com.cinnober.msgcodec.blink.BaseByteCodeGenerator.java
License:Open Source License
protected void generateDecodeSequenceValue(Class<?> javaClass, LocalVariable nextVar, boolean required, MethodVisitor mv, Class<?> componentJavaClass, int byteSourceVar, TypeDef type, Schema schema, String genClassInternalName, String fieldIdentifier, String debugValueLabel, boolean javaClassCodec) throws IllegalArgumentException { if (!javaClass.isArray() && javaClass != List.class) { throw new IllegalArgumentException("Illegal sequence javaClass: " + javaClass); }//from w ww.ja va 2s . co m int lengthVar = nextVar.next(); int sequenceVar = nextVar.next(); Label finalEndLabel = new Label(); if (required) { mv.visitMethodInsn(INVOKESTATIC, blinkInputIName, "readUInt32", "(Lcom/cinnober/msgcodec/io/ByteSource;)I", false); mv.visitVarInsn(ISTORE, lengthVar); } else { mv.visitMethodInsn(INVOKESTATIC, blinkInputIName, "readUInt32Null", "(Lcom/cinnober/msgcodec/io/ByteSource;)Ljava/lang/Integer;", false); mv.visitInsn(DUP); mv.visitJumpInsn(IFNULL, finalEndLabel); unbox(mv, Integer.class); mv.visitVarInsn(ISTORE, lengthVar); } if (javaClass.isArray()) { mv.visitVarInsn(ILOAD, lengthVar); generateNewArray(mv, componentJavaClass); } else { mv.visitTypeInsn(NEW, "java/util/ArrayList"); mv.visitInsn(DUP); mv.visitVarInsn(ILOAD, lengthVar); mv.visitMethodInsn(INVOKESPECIAL, "java/util/ArrayList", "<init>", "(I)V", false); } mv.visitVarInsn(ASTORE, sequenceVar); // for loop Label endLabel = new Label(); int loopVar = nextVar.next(); mv.visitInsn(ICONST_0); mv.visitVarInsn(ISTORE, loopVar); Label loopLabel = new Label(); mv.visitLabel(loopLabel); // PENDING: mv.visitFrame? mv.visitFrame(F_SAME, 0, null, 0, null); mv.visitVarInsn(ILOAD, loopVar); mv.visitVarInsn(ILOAD, lengthVar); mv.visitJumpInsn(IF_ICMPGE, endLabel); mv.visitVarInsn(ALOAD, sequenceVar); mv.visitVarInsn(ILOAD, loopVar); mv.visitVarInsn(ALOAD, byteSourceVar); // decode the element TypeDef.Sequence seqType = (TypeDef.Sequence) type; generateDecodeValue(mv, byteSourceVar, nextVar, true, seqType.getComponentType(), componentJavaClass, null, schema, genClassInternalName, fieldIdentifier, debugValueLabel + ".component", javaClassCodec); // store the value if (javaClass.isArray()) { generateArrayStore(mv, componentJavaClass); } else { mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/ArrayList", "add", "(ILjava/lang/Object;)V", false); } mv.visitIincInsn(loopVar, 1); mv.visitJumpInsn(GOTO, loopLabel); mv.visitLabel(endLabel); mv.visitFrame(F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, sequenceVar); mv.visitLabel(finalEndLabel); mv.visitFrame(F_SAME, 0, null, 0, null); if (javaClass.isArray()) { mv.visitTypeInsn(CHECKCAST, Type.getInternalName(javaClass)); } }