private void _createInstance(Context context, MethodVisitor mw) { JavaBeanInfo beanInfo = context.beanInfo; Constructor<?> defaultConstructor = beanInfo.defaultConstructor; if (Modifier.isPublic(defaultConstructor.getModifiers())) { mw.visitTypeInsn(NEW, type(context.getInstClass())); mw.visitInsn(DUP); mw.visitMethodInsn(INVOKESPECIAL, type(defaultConstructor.getDeclaringClass()), "<init>", "()V"); mw.visitVarInsn(ASTORE, context.var("instance")); } else { mw.visitVarInsn(ALOAD, 0); mw.visitVarInsn(ALOAD, 1); mw.visitVarInsn(ALOAD, 0); mw.visitFieldInsn(GETFIELD, type(JavaBeanDeserializer.class), "clazz", "Ljava/lang/Class;"); mw.visitMethodInsn(INVOKESPECIAL, type(JavaBeanDeserializer.class), "createInstance", "(L" + DefaultJSONParser + ";Ljava/lang/reflect/Type;)Ljava/lang/Object;"); mw.visitTypeInsn(CHECKCAST, type(context.getInstClass())); // cast mw.visitVarInsn(ASTORE, context.var("instance")); } }
private void _batchSet(Context context, MethodVisitor mw, boolean flag) { for (int i = 0, size = context.fieldInfoList.length; i < size; ++i) { Label notSet_ = new Label(); if (flag) { _isFlag(mw, context, i, notSet_); } FieldInfo fieldInfo = context.fieldInfoList[i]; _loadAndSet(context, mw, fieldInfo); if (flag) { mw.visitLabel(notSet_); } } }
private void _getCollectionFieldItemDeser(Context context, MethodVisitor mw, FieldInfo fieldInfo, Class<?> itemType) { Label notNull_ = new Label(); mw.visitVarInsn(ALOAD, 0); mw.visitFieldInsn(GETFIELD, context.className, fieldInfo.name + "_asm_list_item_deser__", desc(ObjectDeserializer.class)); mw.visitJumpInsn(IFNONNULL, notNull_); mw.visitVarInsn(ALOAD, 0); mw.visitVarInsn(ALOAD, 1); mw.visitMethodInsn(INVOKEVIRTUAL, DefaultJSONParser, "getConfig", "()" + desc(ParserConfig.class)); mw.visitLdcInsn(com.alibaba.fastjson.asm.Type.getType(desc(itemType))); mw.visitMethodInsn(INVOKEVIRTUAL, type(ParserConfig.class), "getDeserializer", "(Ljava/lang/reflect/Type;)" + desc(ObjectDeserializer.class)); mw.visitFieldInsn(PUTFIELD, context.className, fieldInfo.name + "_asm_list_item_deser__", desc(ObjectDeserializer.class)); mw.visitLabel(notNull_); mw.visitVarInsn(ALOAD, 0); mw.visitFieldInsn(GETFIELD, context.className, fieldInfo.name + "_asm_list_item_deser__", desc(ObjectDeserializer.class)); }
private void _getFieldDeser(Context context, MethodVisitor mw, FieldInfo fieldInfo) { Label notNull_ = new Label(); mw.visitVarInsn(ALOAD, 0); mw.visitFieldInsn(GETFIELD, context.className, fieldInfo.name + "_asm_deser__", desc(ObjectDeserializer.class)); mw.visitJumpInsn(IFNONNULL, notNull_); mw.visitVarInsn(ALOAD, 0); mw.visitVarInsn(ALOAD, 1); mw.visitMethodInsn(INVOKEVIRTUAL, DefaultJSONParser, "getConfig", "()" + desc(ParserConfig.class)); mw.visitLdcInsn(com.alibaba.fastjson.asm.Type.getType(desc(fieldInfo.fieldClass))); mw.visitMethodInsn(INVOKEVIRTUAL, type(ParserConfig.class), "getDeserializer", "(Ljava/lang/reflect/Type;)" + desc(ObjectDeserializer.class)); mw.visitFieldInsn(PUTFIELD, context.className, fieldInfo.name + "_asm_deser__", desc(ObjectDeserializer.class)); mw.visitLabel(notNull_); mw.visitVarInsn(ALOAD, 0); mw.visitFieldInsn(GETFIELD, context.className, fieldInfo.name + "_asm_deser__", desc(ObjectDeserializer.class)); }
private void _createInstance(ClassWriter cw, Context context) { Constructor<?> defaultConstructor = context.beanInfo.defaultConstructor; if (!Modifier.isPublic(defaultConstructor.getModifiers())) { return; } MethodVisitor mw = new MethodWriter(cw, ACC_PUBLIC, "createInstance", "(L" + DefaultJSONParser + ";Ljava/lang/reflect/Type;)Ljava/lang/Object;", null, null); mw.visitTypeInsn(NEW, type(context.getInstClass())); mw.visitInsn(DUP); mw.visitMethodInsn(INVOKESPECIAL, type(context.getInstClass()), "<init>", "()V"); mw.visitInsn(ARETURN); mw.visitMaxs(3, 3); mw.visitEnd(); }
private void _newCollection(MethodVisitor mw, Class<?> fieldClass) { if (fieldClass.isAssignableFrom(ArrayList.class)) { mw.visitTypeInsn(187, "java/util/ArrayList"); mw.visitInsn(89); mw.visitMethodInsn(183, "java/util/ArrayList", "<init>", "()V"); } else if (fieldClass.isAssignableFrom(LinkedList.class)) { mw.visitTypeInsn(187, ASMUtils.getType(LinkedList.class)); mw.visitInsn(89); mw.visitMethodInsn(183, ASMUtils.getType(LinkedList.class), "<init>", "()V"); } else if (fieldClass.isAssignableFrom(HashSet.class)) { mw.visitTypeInsn(187, ASMUtils.getType(HashSet.class)); mw.visitInsn(89); mw.visitMethodInsn(183, ASMUtils.getType(HashSet.class), "<init>", "()V"); } else if (fieldClass.isAssignableFrom(TreeSet.class)) { mw.visitTypeInsn(187, ASMUtils.getType(TreeSet.class)); mw.visitInsn(89); mw.visitMethodInsn(183, ASMUtils.getType(TreeSet.class), "<init>", "()V"); } else { mw.visitTypeInsn(187, ASMUtils.getType(fieldClass)); mw.visitInsn(89); mw.visitMethodInsn(183, ASMUtils.getType(fieldClass), "<init>", "()V"); } mw.visitTypeInsn(192, ASMUtils.getType(fieldClass)); }
private void _decimal(Class<?> cls, MethodVisitor mw, FieldInfo property, Context context) { Label _end = new Label(); _nameApply(mw, property, context, _end); _get(mw, context, property); mw.visitVarInsn(58, context.var("decimal")); _filters(mw, property, context, _end); Label _if = new Label(); Label _else = new Label(); Label _end_if = new Label(); mw.visitLabel(_if); mw.visitVarInsn(25, context.var("decimal")); mw.visitJumpInsn(199, _else); _if_write_null(mw, property, context); mw.visitJumpInsn(167, _end_if); mw.visitLabel(_else); mw.visitVarInsn(25, context.var("out")); mw.visitVarInsn(21, context.var("seperator")); mw.visitVarInsn(25, context.fieldName()); mw.visitVarInsn(25, context.var("decimal")); mw.visitMethodInsn(182, "com/alibaba/fastjson/serializer/SerializeWriter", "writeFieldValue", "(CLjava/lang/String;Ljava/math/BigDecimal;)V"); _seperator(mw, context); mw.visitJumpInsn(167, _end_if); mw.visitLabel(_end_if); mw.visitLabel(_end); }
private void _string(Class<?> cls, MethodVisitor mw, FieldInfo property, Context context) { Label _end = new Label(); _nameApply(mw, property, context, _end); _get(mw, context, property); mw.visitVarInsn(58, context.var("string")); _filters(mw, property, context, _end); Label _else = new Label(); Label _end_if = new Label(); mw.visitVarInsn(25, context.var("string")); mw.visitJumpInsn(199, _else); _if_write_null(mw, property, context); mw.visitJumpInsn(167, _end_if); mw.visitLabel(_else); mw.visitVarInsn(25, context.var("out")); mw.visitVarInsn(21, context.var("seperator")); mw.visitVarInsn(25, context.fieldName()); mw.visitVarInsn(25, context.var("string")); mw.visitMethodInsn(182, "com/alibaba/fastjson/serializer/SerializeWriter", "writeFieldValue", "(CLjava/lang/String;Ljava/lang/String;)V"); _seperator(mw, context); mw.visitLabel(_end_if); mw.visitLabel(_end); }
private void _filters(MethodVisitor mw, FieldInfo property, Context context, Label _end) { if (property.getField() != null && Modifier.isTransient(property.getField().getModifiers())) { mw.visitVarInsn(25, context.var("out")); mw.visitFieldInsn(178, "com/alibaba/fastjson/serializer/SerializerFeature", "SkipTransientField", "Lcom/alibaba/fastjson/serializer/SerializerFeature;"); mw.visitMethodInsn(182, "com/alibaba/fastjson/serializer/SerializeWriter", "isEnabled", "(Lcom/alibaba/fastjson/serializer/SerializerFeature;)Z"); mw.visitJumpInsn(154, _end); } _notWriteDefault(mw, property, context, _end); _apply(mw, property, context); mw.visitJumpInsn(153, _end); _processKey(mw, property, context); Label _else_processKey = new Label(); _processValue(mw, property, context); mw.visitVarInsn(25, context.original()); mw.visitVarInsn(25, context.processValue()); mw.visitJumpInsn(165, _else_processKey); _writeObject(mw, property, context, _end); mw.visitJumpInsn(167, _end); mw.visitLabel(_else_processKey); }
private void _createInstance(Context context, MethodVisitor mw) { Constructor<?> defaultConstructor = context.getBeanInfo().getDefaultConstructor(); if (Modifier.isPublic(defaultConstructor.getModifiers())) { mw.visitTypeInsn(NEW, getType(context.getClazz())); mw.visitInsn(DUP); mw.visitMethodInsn(INVOKESPECIAL, getType(context.getClazz()), "<init>", "()V"); mw.visitVarInsn(ASTORE, context.var("instance")); } else { mw.visitVarInsn(ALOAD, 0); mw.visitVarInsn(ALOAD, 1); mw.visitMethodInsn(INVOKESPECIAL, "com/alibaba/fastjson/parser/deserializer/ASMJavaBeanDeserializer", "createInstance", "(Lcom/alibaba/fastjson/parser/DefaultJSONParser;)Ljava/lang/Object;"); mw.visitTypeInsn(CHECKCAST, getType(context.getClazz())); // cast mw.visitVarInsn(ASTORE, context.var("instance")); } }
private void _batchSet(Context context, MethodVisitor mw, boolean flag) { for (int i = 0, size = context.getFieldInfoList().size(); i < size; ++i) { Label notSet_ = new Label(); if (flag) { _isFlag(mw, context, i, notSet_); } FieldInfo fieldInfo = context.getFieldInfoList().get(i); _loadAndSet(context, mw, fieldInfo); if (flag) { mw.visitLabel(notSet_); } } }
private void _setContext(Context context, MethodVisitor mw) { mw.visitVarInsn(ALOAD, 1); // parser mw.visitVarInsn(ALOAD, context.var("context")); mw.visitMethodInsn(INVOKEVIRTUAL, "com/alibaba/fastjson/parser/DefaultJSONParser", "setContext", "(Lcom/alibaba/fastjson/parser/ParseContext;)V"); Label endIf_ = new Label(); mw.visitVarInsn(ALOAD, context.var("childContext")); mw.visitJumpInsn(IFNULL, endIf_); mw.visitVarInsn(ALOAD, context.var("childContext")); mw.visitVarInsn(ALOAD, context.var("instance")); mw.visitMethodInsn(INVOKEVIRTUAL, "com/alibaba/fastjson/parser/ParseContext", "setObject", "(Ljava/lang/Object;)V"); mw.visitLabel(endIf_); }
private void _deserialize_endCheck(Context context, MethodVisitor mw, Label reset_) { // Label nextToken_ = new Label(); // mw.visitFieldInsn(GETSTATIC, getType(System.class), "out", "Ljava/io/PrintStream;"); // mw.visitIntInsn(ILOAD, context.var("matchedCount")); // mw.visitMethodInsn(INVOKEVIRTUAL, getType(java.io.PrintStream.class), "println", "(I)V"); mw.visitIntInsn(ILOAD, context.var("matchedCount")); mw.visitJumpInsn(IFLE, reset_); // mw.visitFieldInsn(GETSTATIC, getType(System.class), "out", "Ljava/io/PrintStream;"); // mw.visitVarInsn(ALOAD, context.var("lexer")); // mw.visitMethodInsn(INVOKEVIRTUAL, "com/alibaba/fastjson/parser/JSONLexerBase", "token", "()I"); // mw.visitMethodInsn(INVOKEVIRTUAL, getType(java.io.PrintStream.class), "println", "(I)V"); mw.visitVarInsn(ALOAD, context.var("lexer")); mw.visitMethodInsn(INVOKEVIRTUAL, "com/alibaba/fastjson/parser/JSONLexerBase", "token", "()I"); mw.visitFieldInsn(GETSTATIC, "com/alibaba/fastjson/parser/JSONToken", "RBRACE", "I"); mw.visitJumpInsn(IF_ICMPNE, reset_); // mw.visitLabel(nextToken_); mw.visitVarInsn(ALOAD, context.var("lexer")); mw.visitFieldInsn(GETSTATIC, "com/alibaba/fastjson/parser/JSONToken", "COMMA", "I"); mw.visitMethodInsn(INVOKEVIRTUAL, "com/alibaba/fastjson/parser/JSONLexerBase", "nextToken", "(I)V"); }
private void _getCollectionFieldItemDeser(Context context, MethodVisitor mw, FieldInfo fieldInfo, Class<?> itemType) { Label notNull_ = new Label(); mw.visitVarInsn(ALOAD, 0); mw.visitFieldInsn(GETFIELD, context.getClassName(), fieldInfo.getName() + "_asm_list_item_deser__", "Lcom/alibaba/fastjson/parser/deserializer/ObjectDeserializer;"); mw.visitJumpInsn(IFNONNULL, notNull_); mw.visitVarInsn(ALOAD, 0); mw.visitVarInsn(ALOAD, 1); mw.visitMethodInsn(INVOKEVIRTUAL, "com/alibaba/fastjson/parser/DefaultJSONParser", "getConfig", "()" + "Lcom/alibaba/fastjson/parser/ParserConfig;"); mw.visitLdcInsn(com.alibaba.fastjson.asm.Type.getType(getDesc(itemType))); mw.visitMethodInsn(INVOKEVIRTUAL, "com/alibaba/fastjson/parser/ParserConfig", "getDeserializer", "(Ljava/lang/reflect/Type;)Lcom/alibaba/fastjson/parser/deserializer/ObjectDeserializer;"); mw.visitFieldInsn(PUTFIELD, context.getClassName(), fieldInfo.getName() + "_asm_list_item_deser__", "Lcom/alibaba/fastjson/parser/deserializer/ObjectDeserializer;"); mw.visitLabel(notNull_); mw.visitVarInsn(ALOAD, 0); mw.visitFieldInsn(GETFIELD, context.getClassName(), fieldInfo.getName() + "_asm_list_item_deser__", "Lcom/alibaba/fastjson/parser/deserializer/ObjectDeserializer;"); }
private void _newCollection(MethodVisitor mw, Class<?> fieldClass) { if (fieldClass.isAssignableFrom(ArrayList.class)) { mw.visitTypeInsn(NEW, "java/util/ArrayList"); mw.visitInsn(DUP); mw.visitMethodInsn(INVOKESPECIAL, "java/util/ArrayList", "<init>", "()V"); } else if (fieldClass.isAssignableFrom(LinkedList.class)) { mw.visitTypeInsn(NEW, getType(LinkedList.class)); mw.visitInsn(DUP); mw.visitMethodInsn(INVOKESPECIAL, getType(LinkedList.class), "<init>", "()V"); } else if (fieldClass.isAssignableFrom(HashSet.class)) { mw.visitTypeInsn(NEW, getType(HashSet.class)); mw.visitInsn(DUP); mw.visitMethodInsn(INVOKESPECIAL, getType(HashSet.class), "<init>", "()V"); } else if (fieldClass.isAssignableFrom(TreeSet.class)) { mw.visitTypeInsn(NEW, getType(TreeSet.class)); mw.visitInsn(DUP); mw.visitMethodInsn(INVOKESPECIAL, getType(TreeSet.class), "<init>", "()V"); } else { mw.visitTypeInsn(NEW, getType(fieldClass)); mw.visitInsn(DUP); mw.visitMethodInsn(INVOKESPECIAL, getType(fieldClass), "<init>", "()V"); } mw.visitTypeInsn(CHECKCAST, getType(fieldClass)); // cast }
private void _deserObject(Context context, MethodVisitor mw, FieldInfo fieldInfo, Class<?> fieldClass) { _getFieldDeser(context, mw, fieldInfo); mw.visitVarInsn(ALOAD, 1); if (fieldInfo.getFieldType() instanceof Class) { mw.visitLdcInsn(com.alibaba.fastjson.asm.Type.getType(getDesc(fieldInfo.getFieldClass()))); } else { mw.visitVarInsn(ALOAD, 0); mw.visitLdcInsn(fieldInfo.getName()); mw.visitMethodInsn(INVOKEVIRTUAL, "com/alibaba/fastjson/parser/deserializer/ASMJavaBeanDeserializer", "getFieldType", "(Ljava/lang/String;)Ljava/lang/reflect/Type;"); } mw.visitLdcInsn(fieldInfo.getName()); mw.visitMethodInsn(INVOKEINTERFACE, "com/alibaba/fastjson/parser/deserializer/ObjectDeserializer", "deserialze", "(Lcom/alibaba/fastjson/parser/DefaultJSONParser;Ljava/lang/reflect/Type;Ljava/lang/Object;)Ljava/lang/Object;"); mw.visitTypeInsn(CHECKCAST, getType(fieldClass)); // cast mw.visitVarInsn(ASTORE, context.var(fieldInfo.getName() + "_asm")); }
private void _getFieldDeser(Context context, MethodVisitor mw, FieldInfo fieldInfo) { Label notNull_ = new Label(); mw.visitVarInsn(ALOAD, 0); mw.visitFieldInsn(GETFIELD, context.getClassName(), fieldInfo.getName() + "_asm_deser__", "Lcom/alibaba/fastjson/parser/deserializer/ObjectDeserializer;"); mw.visitJumpInsn(IFNONNULL, notNull_); mw.visitVarInsn(ALOAD, 0); mw.visitVarInsn(ALOAD, 1); mw.visitMethodInsn(INVOKEVIRTUAL, "com/alibaba/fastjson/parser/DefaultJSONParser", "getConfig", "()" + "Lcom/alibaba/fastjson/parser/ParserConfig;"); mw.visitLdcInsn(com.alibaba.fastjson.asm.Type.getType(getDesc(fieldInfo.getFieldClass()))); mw.visitMethodInsn(INVOKEVIRTUAL, "com/alibaba/fastjson/parser/ParserConfig", "getDeserializer", "(Ljava/lang/reflect/Type;)Lcom/alibaba/fastjson/parser/deserializer/ObjectDeserializer;"); mw.visitFieldInsn(PUTFIELD, context.getClassName(), fieldInfo.getName() + "_asm_deser__", "Lcom/alibaba/fastjson/parser/deserializer/ObjectDeserializer;"); mw.visitLabel(notNull_); mw.visitVarInsn(ALOAD, 0); mw.visitFieldInsn(GETFIELD, context.getClassName(), fieldInfo.getName() + "_asm_deser__", "Lcom/alibaba/fastjson/parser/deserializer/ObjectDeserializer;"); }
private void _long(Class<?> clazz, MethodVisitor mw, FieldInfo property, Context context) { Label _end = new Label(); _nameApply(mw, property, context, _end); _get(mw, context, property); mw.visitVarInsn(LSTORE, context.var("long", 2)); _filters(mw, property, context, _end); mw.visitVarInsn(ALOAD, context.var("out")); mw.visitVarInsn(ILOAD, context.var("seperator")); mw.visitVarInsn(ALOAD, context.fieldName()); mw.visitVarInsn(LLOAD, context.var("long", 2)); mw.visitMethodInsn(INVOKEVIRTUAL, "com/alibaba/fastjson/serializer/SerializeWriter", "writeFieldValue", "(CLjava/lang/String;J)V"); _seperator(mw, context); mw.visitLabel(_end); }
private void _float(Class<?> clazz, MethodVisitor mw, FieldInfo property, Context context) { Label _end = new Label(); _nameApply(mw, property, context, _end); _get(mw, context, property); mw.visitVarInsn(FSTORE, context.var("float")); _filters(mw, property, context, _end); mw.visitVarInsn(ALOAD, context.var("out")); mw.visitVarInsn(ILOAD, context.var("seperator")); mw.visitVarInsn(ALOAD, context.fieldName()); mw.visitVarInsn(FLOAD, context.var("float")); mw.visitMethodInsn(INVOKEVIRTUAL, "com/alibaba/fastjson/serializer/SerializeWriter", "writeFieldValue", "(CLjava/lang/String;F)V"); _seperator(mw, context); mw.visitLabel(_end); }
private void _double(Class<?> clazz, MethodVisitor mw, FieldInfo property, Context context) { Label _end = new Label(); _nameApply(mw, property, context, _end); _get(mw, context, property); mw.visitVarInsn(DSTORE, context.var("double", 2)); _filters(mw, property, context, _end); mw.visitVarInsn(ALOAD, context.var("out")); mw.visitVarInsn(ILOAD, context.var("seperator")); mw.visitVarInsn(ALOAD, context.fieldName()); mw.visitVarInsn(DLOAD, context.var("double", 2)); mw.visitMethodInsn(INVOKEVIRTUAL, "com/alibaba/fastjson/serializer/SerializeWriter", "writeFieldValue", "(CLjava/lang/String;D)V"); _seperator(mw, context); mw.visitLabel(_end); }
private void _char(Class<?> clazz, MethodVisitor mw, FieldInfo property, Context context) { Label _end = new Label(); _nameApply(mw, property, context, _end); _get(mw, context, property); mw.visitVarInsn(ISTORE, context.var("char")); _filters(mw, property, context, _end); mw.visitVarInsn(ALOAD, context.var("out")); mw.visitVarInsn(ILOAD, context.var("seperator")); mw.visitVarInsn(ALOAD, context.fieldName()); mw.visitVarInsn(ILOAD, context.var("char")); mw.visitMethodInsn(INVOKEVIRTUAL, "com/alibaba/fastjson/serializer/SerializeWriter", "writeFieldValue", "(CLjava/lang/String;C)V"); _seperator(mw, context); mw.visitLabel(_end); }
private void _boolean(Class<?> clazz, MethodVisitor mw, FieldInfo property, Context context) { Label _end = new Label(); _nameApply(mw, property, context, _end); _get(mw, context, property); mw.visitVarInsn(ISTORE, context.var("boolean")); _filters(mw, property, context, _end); mw.visitVarInsn(ALOAD, context.var("out")); mw.visitVarInsn(ILOAD, context.var("seperator")); mw.visitVarInsn(ALOAD, context.fieldName()); mw.visitVarInsn(ILOAD, context.var("boolean")); mw.visitMethodInsn(INVOKEVIRTUAL, "com/alibaba/fastjson/serializer/SerializeWriter", "writeFieldValue", "(CLjava/lang/String;Z)V"); _seperator(mw, context); mw.visitLabel(_end); }
private void _byte(Class<?> clazz, MethodVisitor mw, FieldInfo property, Context context) { Label _end = new Label(); _nameApply(mw, property, context, _end); _get(mw, context, property); mw.visitVarInsn(ISTORE, context.var("byte")); _filters(mw, property, context, _end); mw.visitVarInsn(ALOAD, context.var("out")); mw.visitVarInsn(ILOAD, context.var("seperator")); mw.visitVarInsn(ALOAD, context.fieldName()); mw.visitVarInsn(ILOAD, context.var("byte")); mw.visitMethodInsn(INVOKEVIRTUAL, "com/alibaba/fastjson/serializer/SerializeWriter", "writeFieldValue", "(CLjava/lang/String;I)V"); _seperator(mw, context); mw.visitLabel(_end); }
private void _short(Class<?> clazz, MethodVisitor mw, FieldInfo property, Context context) { Label _end = new Label(); _nameApply(mw, property, context, _end); _get(mw, context, property); mw.visitVarInsn(ISTORE, context.var("short")); _filters(mw, property, context, _end); mw.visitVarInsn(ALOAD, context.var("out")); mw.visitVarInsn(ILOAD, context.var("seperator")); mw.visitVarInsn(ALOAD, context.fieldName()); mw.visitVarInsn(ILOAD, context.var("short")); mw.visitMethodInsn(INVOKEVIRTUAL, "com/alibaba/fastjson/serializer/SerializeWriter", "writeFieldValue", "(CLjava/lang/String;I)V"); _seperator(mw, context); mw.visitLabel(_end); }
private void _int(Class<?> clazz, MethodVisitor mw, FieldInfo property, Context context) { Label _end = new Label(); _nameApply(mw, property, context, _end); _get(mw, context, property); mw.visitVarInsn(ISTORE, context.var("int")); _filters(mw, property, context, _end); mw.visitVarInsn(ALOAD, context.var("out")); mw.visitVarInsn(ILOAD, context.var("seperator")); mw.visitVarInsn(ALOAD, context.fieldName()); mw.visitVarInsn(ILOAD, context.var("int")); mw.visitMethodInsn(INVOKEVIRTUAL, "com/alibaba/fastjson/serializer/SerializeWriter", "writeFieldValue", "(CLjava/lang/String;I)V"); _seperator(mw, context); mw.visitLabel(_end); }
private void _setFlag(MethodVisitor mw, Context context, int i) { String varName = "_asm_flag_" + (i / 32); mw.visitVarInsn(ILOAD, context.var(varName)); mw.visitLdcInsn(1 << i); mw.visitInsn(IOR); mw.visitVarInsn(ISTORE, context.var(varName)); }
private void _isFlag(MethodVisitor mw, Context context, int i, Label label) { mw.visitVarInsn(ILOAD, context.var("_asm_flag_" + (i / 32))); mw.visitLdcInsn(1 << i); mw.visitInsn(IAND); mw.visitJumpInsn(IFEQ, label); }
private void _set(Context context, MethodVisitor mw, FieldInfo fieldInfo) { Method method = fieldInfo.method; if (method != null) { Class<?> declaringClass = method.getDeclaringClass(); mw.visitMethodInsn(declaringClass.isInterface() ? INVOKEINTERFACE : INVOKEVIRTUAL, type(fieldInfo.declaringClass), method.getName(), desc(method)); if (!fieldInfo.method.getReturnType().equals(Void.TYPE)) { mw.visitInsn(POP); } } else { mw.visitFieldInsn(PUTFIELD, type(fieldInfo.declaringClass), fieldInfo.field.getName(), desc(fieldInfo.fieldClass)); } }
private void _setContext(Context context, MethodVisitor mw) { mw.visitVarInsn(ALOAD, 1); // parser mw.visitVarInsn(ALOAD, context.var("context")); mw.visitMethodInsn(INVOKEVIRTUAL, DefaultJSONParser, "setContext", "(" + desc(ParseContext.class) + ")V"); Label endIf_ = new Label(); mw.visitVarInsn(ALOAD, context.var("childContext")); mw.visitJumpInsn(IFNULL, endIf_); mw.visitVarInsn(ALOAD, context.var("childContext")); mw.visitVarInsn(ALOAD, context.var("instance")); mw.visitFieldInsn(PUTFIELD, type(ParseContext.class), "object", "Ljava/lang/Object;"); mw.visitLabel(endIf_); }
private void _deserialize_endCheck(Context context, MethodVisitor mw, Label reset_) { mw.visitIntInsn(ILOAD, context.var("matchedCount")); mw.visitJumpInsn(IFLE, reset_); mw.visitVarInsn(ALOAD, context.var("lexer")); mw.visitMethodInsn(INVOKEVIRTUAL, JSONLexerBase, "token", "()I"); mw.visitLdcInsn(JSONToken.RBRACE); mw.visitJumpInsn(IF_ICMPNE, reset_); // mw.visitLabel(nextToken_); _quickNextTokenComma(context, mw); }
private void _quickNextToken(Context context, MethodVisitor mw, int token) { Label quickElse_ = new Label(), quickEnd_ = new Label(); mw.visitVarInsn(ALOAD, context.var("lexer")); mw.visitMethodInsn(INVOKEVIRTUAL, JSONLexerBase, "getCurrent", "()C"); if (token == JSONToken.LBRACE) { mw.visitVarInsn(BIPUSH, '{'); } else if (token == JSONToken.LBRACKET) { mw.visitVarInsn(BIPUSH, '['); } else { throw new IllegalStateException(); } mw.visitJumpInsn(IF_ICMPNE, quickElse_); mw.visitVarInsn(ALOAD, context.var("lexer")); mw.visitMethodInsn(INVOKEVIRTUAL, JSONLexerBase, "next", "()C"); mw.visitInsn(POP); mw.visitVarInsn(ALOAD, context.var("lexer")); mw.visitLdcInsn(token); mw.visitMethodInsn(INVOKEVIRTUAL, JSONLexerBase, "setToken", "(I)V"); mw.visitJumpInsn(GOTO, quickEnd_); mw.visitLabel(quickElse_); mw.visitVarInsn(ALOAD, context.var("lexer")); mw.visitLdcInsn(token); mw.visitMethodInsn(INVOKEVIRTUAL, JSONLexerBase, "nextToken", "(I)V"); mw.visitLabel(quickEnd_); }
private void _newCollection(MethodVisitor mw, Class<?> fieldClass, int i, boolean set) { if (fieldClass.isAssignableFrom(ArrayList.class) && !set) { mw.visitTypeInsn(NEW, "java/util/ArrayList"); mw.visitInsn(DUP); mw.visitMethodInsn(INVOKESPECIAL, "java/util/ArrayList", "<init>", "()V"); } else if (fieldClass.isAssignableFrom(LinkedList.class) && !set) { mw.visitTypeInsn(NEW, type(LinkedList.class)); mw.visitInsn(DUP); mw.visitMethodInsn(INVOKESPECIAL, type(LinkedList.class), "<init>", "()V"); } else if (fieldClass.isAssignableFrom(HashSet.class)) { mw.visitTypeInsn(NEW, type(HashSet.class)); mw.visitInsn(DUP); mw.visitMethodInsn(INVOKESPECIAL, type(HashSet.class), "<init>", "()V"); } else if (fieldClass.isAssignableFrom(TreeSet.class)) { mw.visitTypeInsn(NEW, type(TreeSet.class)); mw.visitInsn(DUP); mw.visitMethodInsn(INVOKESPECIAL, type(TreeSet.class), "<init>", "()V"); } else if (fieldClass.isAssignableFrom(LinkedHashSet.class)) { mw.visitTypeInsn(NEW, type(LinkedHashSet.class)); mw.visitInsn(DUP); mw.visitMethodInsn(INVOKESPECIAL, type(LinkedHashSet.class), "<init>", "()V"); } else if (set) { mw.visitTypeInsn(NEW, type(HashSet.class)); mw.visitInsn(DUP); mw.visitMethodInsn(INVOKESPECIAL, type(HashSet.class), "<init>", "()V"); } else { mw.visitVarInsn(ALOAD, 0); mw.visitLdcInsn(i); mw.visitMethodInsn(INVOKEVIRTUAL, type(JavaBeanDeserializer.class), "getFieldType", "(I)Ljava/lang/reflect/Type;"); mw.visitMethodInsn(INVOKESTATIC, type(TypeUtils.class), "createCollection", "(Ljava/lang/reflect/Type;)Ljava/util/Collection;"); } mw.visitTypeInsn(CHECKCAST, type(fieldClass)); // cast }
void _setFlag(MethodVisitor mw, Context context, int i) { String varName = "_asm_flag_" + (i / 32); mw.visitVarInsn(21, context.var(varName)); mw.visitLdcInsn(Integer.valueOf(1 << i)); mw.visitInsn(128); mw.visitVarInsn(54, context.var(varName)); }
private void _createInstance(Context context, MethodVisitor mw) { if (Modifier.isPublic(context.getBeanInfo().getDefaultConstructor().getModifiers())) { mw.visitTypeInsn(187, ASMUtils.getType(context.getClazz())); mw.visitInsn(89); mw.visitMethodInsn(183, ASMUtils.getType(context.getClazz()), "<init>", "()V"); mw.visitVarInsn(58, context.var("instance")); return; } mw.visitVarInsn(25, 0); mw.visitVarInsn(25, 1); mw.visitMethodInsn(183, "com/alibaba/fastjson/parser/deserializer/ASMJavaBeanDeserializer", "createInstance", "(Lcom/alibaba/fastjson/parser/DefaultJSONParser;)Ljava/lang/Object;"); mw.visitTypeInsn(192, ASMUtils.getType(context.getClazz())); mw.visitVarInsn(58, context.var("instance")); }
private void _batchSet(Context context, MethodVisitor mw, boolean flag) { int size = context.getFieldInfoList().size(); for (int i = 0; i < size; i++) { Label notSet_ = new Label(); if (flag) { _isFlag(mw, context, i, notSet_); } _loadAndSet(context, mw, (FieldInfo) context.getFieldInfoList().get(i)); if (flag) { mw.visitLabel(notSet_); } } }
private void _set(Context context, MethodVisitor mw, FieldInfo fieldInfo) { if (fieldInfo.getMethod() != null) { mw.visitMethodInsn(182, ASMUtils.getType(fieldInfo.getDeclaringClass()), fieldInfo.getMethod().getName(), ASMUtils.getDesc(fieldInfo.getMethod())); if (!fieldInfo.getMethod().getReturnType().equals(Void.TYPE)) { mw.visitInsn(87); return; } return; } mw.visitFieldInsn(181, ASMUtils.getType(fieldInfo.getDeclaringClass()), fieldInfo.getField().getName(), ASMUtils.getDesc(fieldInfo.getFieldClass())); }
private void _setContext(Context context, MethodVisitor mw) { mw.visitVarInsn(25, 1); mw.visitVarInsn(25, context.var("context")); mw.visitMethodInsn(182, "com/alibaba/fastjson/parser/DefaultJSONParser", "setContext", "(Lcom/alibaba/fastjson/parser/ParseContext;)V"); Label endIf_ = new Label(); mw.visitVarInsn(25, context.var("childContext")); mw.visitJumpInsn(198, endIf_); mw.visitVarInsn(25, context.var("childContext")); mw.visitVarInsn(25, context.var("instance")); mw.visitMethodInsn(182, "com/alibaba/fastjson/parser/ParseContext", "setObject", "(Ljava/lang/Object;)V"); mw.visitLabel(endIf_); }
private void _deserialize_endCheck(Context context, MethodVisitor mw, Label reset_) { Label _end_if = new Label(); mw.visitIntInsn(21, context.var("matchedCount")); mw.visitJumpInsn(158, reset_); mw.visitVarInsn(25, context.var("lexer")); mw.visitMethodInsn(182, "com/alibaba/fastjson/parser/JSONLexerBase", "token", "()I"); mw.visitFieldInsn(178, "com/alibaba/fastjson/parser/JSONToken", "RBRACE", "I"); mw.visitJumpInsn(160, reset_); mw.visitVarInsn(25, context.var("lexer")); mw.visitFieldInsn(178, "com/alibaba/fastjson/parser/JSONToken", "COMMA", "I"); mw.visitMethodInsn(182, "com/alibaba/fastjson/parser/JSONLexerBase", "nextToken", "(I)V"); mw.visitLabel(_end_if); }
private void _getCollectionFieldItemDeser(Context context, MethodVisitor mw, FieldInfo fieldInfo, Class<?> itemType) { Label notNull_ = new Label(); mw.visitVarInsn(25, 0); mw.visitFieldInsn(180, context.getClassName(), fieldInfo.getName() + "_asm_list_item_deser__", "Lcom/alibaba/fastjson/parser/deserializer/ObjectDeserializer;"); mw.visitJumpInsn(199, notNull_); mw.visitVarInsn(25, 0); mw.visitVarInsn(25, 1); mw.visitMethodInsn(182, "com/alibaba/fastjson/parser/DefaultJSONParser", "getConfig", "()Lcom/alibaba/fastjson/parser/ParserConfig;"); mw.visitLdcInsn(com.alibaba.fastjson.asm.Type.getType(ASMUtils.getDesc((Class) itemType))); mw.visitMethodInsn(182, "com/alibaba/fastjson/parser/ParserConfig", "getDeserializer", "(Ljava/lang/reflect/Type;)Lcom/alibaba/fastjson/parser/deserializer/ObjectDeserializer;"); mw.visitFieldInsn(181, context.getClassName(), fieldInfo.getName() + "_asm_list_item_deser__", "Lcom/alibaba/fastjson/parser/deserializer/ObjectDeserializer;"); mw.visitLabel(notNull_); mw.visitVarInsn(25, 0); mw.visitFieldInsn(180, context.getClassName(), fieldInfo.getName() + "_asm_list_item_deser__", "Lcom/alibaba/fastjson/parser/deserializer/ObjectDeserializer;"); }
private void _deserialze_obj(Context context, MethodVisitor mw, Label reset_, FieldInfo fieldInfo, Class<?> fieldClass, int i) { Label matched_ = new Label(); Label _end_if = new Label(); mw.visitVarInsn(25, context.var("lexer")); mw.visitVarInsn(25, 0); mw.visitFieldInsn(180, context.getClassName(), fieldInfo.getName() + "_asm_prefix__", "[C"); mw.visitMethodInsn(182, "com/alibaba/fastjson/parser/JSONLexerBase", "matchField", "([C)Z"); mw.visitJumpInsn(154, matched_); mw.visitInsn(1); mw.visitVarInsn(58, context.var(fieldInfo.getName() + "_asm")); mw.visitJumpInsn(167, _end_if); mw.visitLabel(matched_); _setFlag(mw, context, i); mw.visitVarInsn(21, context.var("matchedCount")); mw.visitInsn(4); mw.visitInsn(96); mw.visitVarInsn(54, context.var("matchedCount")); _deserObject(context, mw, fieldInfo, fieldClass); mw.visitVarInsn(25, 1); mw.visitMethodInsn(182, "com/alibaba/fastjson/parser/DefaultJSONParser", "getResolveStatus", "()I"); mw.visitFieldInsn(178, "com/alibaba/fastjson/parser/DefaultJSONParser", "NeedToResolve", "I"); mw.visitJumpInsn(160, _end_if); mw.visitVarInsn(25, 1); mw.visitMethodInsn(182, "com/alibaba/fastjson/parser/DefaultJSONParser", "getLastResolveTask", "()Lcom/alibaba/fastjson/parser/DefaultJSONParser$ResolveTask;"); mw.visitVarInsn(58, context.var("resolveTask")); mw.visitVarInsn(25, context.var("resolveTask")); mw.visitVarInsn(25, 1); mw.visitMethodInsn(182, "com/alibaba/fastjson/parser/DefaultJSONParser", "getContext", "()Lcom/alibaba/fastjson/parser/ParseContext;"); mw.visitMethodInsn(182, "com/alibaba/fastjson/parser/DefaultJSONParser$ResolveTask", "setOwnerContext", "(Lcom/alibaba/fastjson/parser/ParseContext;)V"); mw.visitVarInsn(25, context.var("resolveTask")); mw.visitVarInsn(25, 0); mw.visitLdcInsn(fieldInfo.getName()); mw.visitMethodInsn(182, "com/alibaba/fastjson/parser/deserializer/ASMJavaBeanDeserializer", "getFieldDeserializer", "(Ljava/lang/String;)Lcom/alibaba/fastjson/parser/deserializer/FieldDeserializer;"); mw.visitMethodInsn(182, "com/alibaba/fastjson/parser/DefaultJSONParser$ResolveTask", "setFieldDeserializer", "(Lcom/alibaba/fastjson/parser/deserializer/FieldDeserializer;)V"); mw.visitVarInsn(25, 1); mw.visitFieldInsn(178, "com/alibaba/fastjson/parser/DefaultJSONParser", "NONE", "I"); mw.visitMethodInsn(182, "com/alibaba/fastjson/parser/DefaultJSONParser", "setResolveStatus", "(I)V"); mw.visitLabel(_end_if); }