42
42
43
43
public class ASMDeserializerFactory implements Opcodes {
44
44
45
- private static final ASMDeserializerFactory instance = new ASMDeserializerFactory ();
45
+ private static final ASMDeserializerFactory instance = new ASMDeserializerFactory ();
46
46
47
- private ASMClassLoader classLoader = new ASMClassLoader () ;
47
+ private final ASMClassLoader classLoader ;
48
48
49
- private final AtomicLong seed = new AtomicLong ();
49
+ private final AtomicLong seed = new AtomicLong ();
50
50
51
51
public String getGenClassName (Class <?> clazz ) {
52
52
return "Fastjson_ASM_" + clazz .getSimpleName () + "_" + seed .incrementAndGet ();
@@ -60,7 +60,11 @@ public String getGenFieldDeserializer(Class<?> clazz, FieldInfo fieldInfo) {
60
60
}
61
61
62
62
public ASMDeserializerFactory (){
63
+ classLoader = new ASMClassLoader ();
64
+ }
63
65
66
+ public ASMDeserializerFactory (ClassLoader parentClassLoader ){
67
+ classLoader = new ASMClassLoader (parentClassLoader );
64
68
}
65
69
66
70
public final static ASMDeserializerFactory getInstance () {
@@ -183,9 +187,8 @@ void _deserialzeArrayMapping(ClassWriter cw, Context context) {
183
187
mw .visitMethodInsn (INVOKEVIRTUAL , getType (DefaultJSONParser .class ), "getSymbolTable" ,
184
188
"()" + getDesc (SymbolTable .class ));
185
189
mw .visitVarInsn (BIPUSH , seperator );
186
- mw .visitMethodInsn (INVOKEVIRTUAL , getType (JSONLexerBase .class ), "scanEnum" , "(Ljava/lang/Class;"
187
- + getDesc (SymbolTable .class )
188
- + "C)Ljava/lang/Enum;" );
190
+ mw .visitMethodInsn (INVOKEVIRTUAL , getType (JSONLexerBase .class ), "scanEnum" ,
191
+ "(Ljava/lang/Class;" + getDesc (SymbolTable .class ) + "C)Ljava/lang/Enum;" );
189
192
mw .visitTypeInsn (CHECKCAST , getType (fieldClass )); // cast
190
193
mw .visitVarInsn (ASTORE , context .var (fieldInfo .getName () + "_asm" ));
191
194
} else if (Collection .class .isAssignableFrom (fieldClass )) {
@@ -485,7 +488,8 @@ void _deserialze(ClassWriter cw, Context context) {
485
488
mw .visitVarInsn (ALOAD , context .var ("lexer" ));
486
489
mw .visitVarInsn (ALOAD , 0 );
487
490
mw .visitFieldInsn (GETFIELD , context .getClassName (), fieldInfo .getName () + "_asm_prefix__" , "[C" );
488
- mw .visitMethodInsn (INVOKEVIRTUAL , getType (JSONLexerBase .class ), "scanFieldString" , "([C)Ljava/lang/String;" );
491
+ mw .visitMethodInsn (INVOKEVIRTUAL , getType (JSONLexerBase .class ), "scanFieldString" ,
492
+ "([C)Ljava/lang/String;" );
489
493
mw .visitVarInsn (ASTORE , context .var (fieldInfo .getName () + "_asm" ));
490
494
491
495
} else if (fieldClass .isEnum ()) {
@@ -656,7 +660,7 @@ private void _isEnable(Context context, MethodVisitor mw, Feature feature) {
656
660
mw .visitVarInsn (ALOAD , context .var ("lexer" ));
657
661
mw .visitFieldInsn (GETSTATIC , getType (Feature .class ), feature .name (), "L" + getType (Feature .class ) + ";" );
658
662
mw .visitMethodInsn (INVOKEVIRTUAL , getType (JSONLexerBase .class ), "isEnabled" , "(" + "L" + getType (Feature .class )
659
- + ";" + ")Z" );
663
+ + ";" + ")Z" );
660
664
}
661
665
662
666
private void defineVarLexer (Context context , MethodVisitor mw ) {
@@ -724,7 +728,8 @@ private void _loadAndSet(Context context, MethodVisitor mw, FieldInfo fieldInfo)
724
728
mw .visitVarInsn (ALOAD , context .var ("instance" ));
725
729
mw .visitVarInsn (LLOAD , context .var (fieldInfo .getName () + "_asm" , 2 ));
726
730
if (fieldInfo .getMethod () != null ) {
727
- mw .visitMethodInsn (INVOKEVIRTUAL , getType (context .getClazz ()), fieldInfo .getMethod ().getName (), getDesc (fieldInfo .getMethod ()));
731
+ mw .visitMethodInsn (INVOKEVIRTUAL , getType (context .getClazz ()), fieldInfo .getMethod ().getName (),
732
+ getDesc (fieldInfo .getMethod ()));
728
733
if (!fieldInfo .getMethod ().getReturnType ().equals (Void .TYPE )) {
729
734
mw .visitInsn (POP );
730
735
}
0 commit comments