2222import java .util .concurrent .atomic .AtomicLong ;
2323
2424import com .alibaba .fastjson .JSON ;
25- import com .alibaba .fastjson .asm .ASMException ;
2625import com .alibaba .fastjson .asm .ClassWriter ;
2726import com .alibaba .fastjson .asm .FieldVisitor ;
2827import com .alibaba .fastjson .asm .Label ;
3433import com .alibaba .fastjson .util .ASMUtils ;
3534import com .alibaba .fastjson .util .DeserializeBeanInfo ;
3635import com .alibaba .fastjson .util .FieldInfo ;
36+ import com .alibaba .fastjson .util .TypeUtils ;
3737
3838public class ASMDeserializerFactory implements Opcodes {
3939
@@ -198,7 +198,7 @@ void _deserialzeArrayMapping(ClassWriter cw, Context context) {
198198 mw .visitTypeInsn (CHECKCAST , getType (fieldClass )); // cast
199199 mw .visitVarInsn (ASTORE , context .var (fieldInfo .getName () + "_asm" ));
200200 } else if (Collection .class .isAssignableFrom (fieldClass )) {
201- Class <?> itemClass = getCollectionItemClass (fieldType );
201+ Class <?> itemClass = TypeUtils . getCollectionItemClass (fieldType );
202202 if (itemClass == String .class ) {
203203 mw .visitVarInsn (ALOAD , context .var ("lexer" ));
204204 mw .visitLdcInsn (com .alibaba .fastjson .asm .Type .getType (getDesc (fieldClass )));
@@ -482,20 +482,6 @@ void _deserialze(ClassWriter cw, Context context) {
482482 mw .visitVarInsn (DSTORE , context .var (fieldInfo .getName () + "_asm" , 2 ));
483483
484484 } else if (fieldClass == String .class ) {
485- Label notEnd_ = new Label ();
486-
487- mw .visitIntInsn (ILOAD , context .var ("matchStat" ));
488- mw .visitInsn (ICONST_4 ); // END
489- mw .visitJumpInsn (IF_ICMPNE , notEnd_ );
490-
491- mw .visitVarInsn (ALOAD , context .var ("lexer" ));
492- mw .visitMethodInsn (INVOKEVIRTUAL , "com/alibaba/fastjson/parser/JSONLexerBase" , "stringDefaultValue" ,
493- "()Ljava/lang/String;" );
494- mw .visitVarInsn (ASTORE , context .var (fieldInfo .getName () + "_asm" ));
495- mw .visitJumpInsn (GOTO , notMatch_ );
496-
497- mw .visitLabel (notEnd_ );
498-
499485 mw .visitVarInsn (ALOAD , context .var ("lexer" ));
500486 mw .visitVarInsn (ALOAD , 0 );
501487 mw .visitFieldInsn (GETFIELD , context .getClassName (), fieldInfo .getName () + "_asm_prefix__" , "[C" );
@@ -533,7 +519,7 @@ void _deserialze(ClassWriter cw, Context context) {
533519 mw .visitVarInsn (ALOAD , 0 );
534520 mw .visitFieldInsn (GETFIELD , context .getClassName (), fieldInfo .getName () + "_asm_prefix__" , "[C" );
535521
536- Class <?> itemClass = getCollectionItemClass (fieldType );
522+ Class <?> itemClass = TypeUtils . getCollectionItemClass (fieldType );
537523
538524 if (itemClass == String .class ) {
539525 mw .visitLdcInsn (com .alibaba .fastjson .asm .Type .getType (getDesc (fieldClass ))); // cast
@@ -646,25 +632,6 @@ void _deserialze(ClassWriter cw, Context context) {
646632 mw .visitEnd ();
647633 }
648634
649- private Class <?> getCollectionItemClass (Type fieldType ) {
650- if (fieldType instanceof ParameterizedType ) {
651- Class <?> itemClass ;
652- Type actualTypeArgument = ((ParameterizedType ) fieldType ).getActualTypeArguments ()[0 ];
653-
654- if (actualTypeArgument instanceof Class ) {
655- itemClass = (Class <?>) actualTypeArgument ;
656- if (!Modifier .isPublic (itemClass .getModifiers ())) {
657- throw new ASMException ("can not create ASMParser" );
658- }
659- } else {
660- throw new ASMException ("can not create ASMParser" );
661- }
662- return itemClass ;
663- }
664-
665- return Object .class ;
666- }
667-
668635 private void _isEnable (Context context , MethodVisitor mw , Feature feature ) {
669636 mw .visitVarInsn (ALOAD , context .var ("lexer" ));
670637 mw .visitFieldInsn (GETSTATIC , "com/alibaba/fastjson/parser/Feature" , feature .name (), "Lcom/alibaba/fastjson/parser/Feature;" );
@@ -763,7 +730,7 @@ private void _loadAndSet(Context context, MethodVisitor mw, FieldInfo fieldInfo)
763730 _set (context , mw , fieldInfo );
764731 } else if (Collection .class .isAssignableFrom (fieldClass )) {
765732 mw .visitVarInsn (ALOAD , context .var ("instance" ));
766- Type itemType = getCollectionItemClass (fieldType );
733+ Type itemType = TypeUtils . getCollectionItemClass (fieldType );
767734 if (itemType == String .class ) {
768735 mw .visitVarInsn (ALOAD , context .var (fieldInfo .getName () + "_asm" ));
769736 mw .visitTypeInsn (CHECKCAST , getType (fieldClass )); // cast
@@ -818,7 +785,6 @@ private void _setContext(Context context, MethodVisitor mw) {
818785 }
819786
820787 private void _deserialize_endCheck (Context context , MethodVisitor mw , Label reset_ ) {
821- Label _end_if = new Label ();
822788 // Label nextToken_ = new Label();
823789
824790 // mw.visitFieldInsn(GETSTATIC, getType(System.class), "out", "Ljava/io/PrintStream;");
@@ -842,23 +808,15 @@ private void _deserialize_endCheck(Context context, MethodVisitor mw, Label rese
842808 mw .visitVarInsn (ALOAD , context .var ("lexer" ));
843809 mw .visitFieldInsn (GETSTATIC , "com/alibaba/fastjson/parser/JSONToken" , "COMMA" , "I" );
844810 mw .visitMethodInsn (INVOKEVIRTUAL , "com/alibaba/fastjson/parser/JSONLexerBase" , "nextToken" , "(I)V" );
845-
846- mw .visitLabel (_end_if );
847811 }
848812
849813 private void _deserialze_list_obj (Context context , MethodVisitor mw , Label reset_ , FieldInfo fieldInfo ,
850814 Class <?> fieldClass , Class <?> itemType , int i ) {
851- Label matched_ = new Label ();
852815 Label _end_if = new Label ();
853816
854817 mw .visitMethodInsn (INVOKEVIRTUAL , "com/alibaba/fastjson/parser/JSONLexerBase" , "matchField" , "([C)Z" );
855- mw .visitJumpInsn (IFNE , matched_ );
856- mw .visitInsn (ACONST_NULL );
857- mw .visitVarInsn (ASTORE , context .var (fieldInfo .getName () + "_asm" ));
818+ mw .visitJumpInsn (IFEQ , _end_if );
858819
859- mw .visitJumpInsn (GOTO , _end_if );
860-
861- mw .visitLabel (matched_ );
862820 _setFlag (mw , context , i );
863821
864822 Label valueNotNull_ = new Label ();
@@ -871,9 +829,6 @@ private void _deserialze_list_obj(Context context, MethodVisitor mw, Label reset
871829 mw .visitFieldInsn (GETSTATIC , "com/alibaba/fastjson/parser/JSONToken" , "COMMA" , "I" );
872830 mw .visitMethodInsn (INVOKEVIRTUAL , "com/alibaba/fastjson/parser/JSONLexerBase" , "nextToken" , "(I)V" );
873831
874- mw .visitInsn (ACONST_NULL );
875- mw .visitTypeInsn (CHECKCAST , getType (fieldClass )); // cast
876- mw .visitVarInsn (ASTORE , context .var (fieldInfo .getName () + "_asm" ));
877832 // loop_end_
878833
879834 mw .visitLabel (valueNotNull_ );
0 commit comments