jdk 动态代理与 cglib 动态代理原理

1. JDK 动态代理

jdk 动态代理是通过实现被代理类的接口来实现的,通过 jdk 动态代理生成的类会继承 java.lang.reflect.Proxy,同时实现被代理类的接口。
由于 jdk 动态代理已经继承了  java.lang.reflect.Proxy,所以它就不能通过继承类的方式来实现动态代理了,所以选择了实现接口的方式来生成动态代理。

举例:为 IHello 接口生成一个动态代理类,并将它的字节码文件输出到文件中
(不管是动态生成的类,还是普通的类,最后都需要拿到二进制的字节码数组,然后通过 classloader 加载到 jvm 中,所以,不管是什么类,理论上我们都可以将它的字节码数组拿到并输出到文件中

 1 public interface IHello {
 2     public String sayHello(String name);
 3 }
 4 
 5 // 通过 java.lang.reflect.Proxy 来为 IHello 生成一个代理类
 6 IHello realObj = new HelloImpl();
 7 IHello proxyObj = (IHello) Proxy.newProxyInstance(realObj.getClass().getClassLoader(),
 8         realObj.getClass().getInterfaces(), new InvocationHandler() {
 9             @Override
10             public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
11                 // 方法执行前可以插入逻辑
12                 // 执行被代理类的方法
13                 Object obj = method.invoke(realObj, args);
14                 // 方法执行后可以插入逻辑
15                 return obj;
16             }
17         });

 

断点打在 java.lang.reflect.Proxy.ProxyClassFactory#apply() Line 642 处
调用如下代码,将字节码文件进行输出,然后拿到文件反编译
new FileOutputStream("d:\\a.class").getChannel().write(ByteBuffer.wrap(proxyClassFile))

 1 public final class $Proxy0 extends Proxy implements IHello
 2 {
 3     private static Method m1;
 4     private static Method m3;
 5     private static Method m2;
 6     private static Method m0;
 7     
 8     public $Proxy0(final InvocationHandler invocationHandler) {
 9         super(invocationHandler);
10     }
11     
12     public final boolean equals(final Object o) {
13         try {
14             return (boolean)super.h.invoke(this, $Proxy0.m1, new Object[] { o });
15         }
16         catch (Error | RuntimeException error) {
17             throw;
18         }
19         catch (Throwable t) {
20             throw new UndeclaredThrowableException(t);
21         }
22     }
23     
24     public final String sayHello(final String s) {
25         try {
26             return (String)super.h.invoke(this, $Proxy0.m3, new Object[] { s });
27         }
28         catch (Error | RuntimeException error) {
29             throw;
30         }
31         catch (Throwable t) {
32             throw new UndeclaredThrowableException(t);
33         }
34     }
35     
36     public final String toString() {
37         try {
38             return (String)super.h.invoke(this, $Proxy0.m2, null);
39         }
40         catch (Error | RuntimeException error) {
41             throw;
42         }
43         catch (Throwable t) {
44             throw new UndeclaredThrowableException(t);
45         }
46     }
47     
48     public final int hashCode() {
49         try {
50             return (int)super.h.invoke(this, $Proxy0.m0, null);
51         }
52         catch (Error | RuntimeException error) {
53             throw;
54         }
55         catch (Throwable t) {
56             throw new UndeclaredThrowableException(t);
57         }
58     }
59     
60     static {
61         try {
62             $Proxy0.m1 = Class.forName("java.lang.Object").getMethod("equals", Class.forName("java.lang.Object"));
63             $Proxy0.m3 = Class.forName("com.cn.zsy.proxy.jdkProxy.IHello").getMethod("sayHello", Class.forName("java.lang.String"));
64             $Proxy0.m2 = Class.forName("java.lang.Object").getMethod("toString", (Class<?>[])new Class[0]);
65             $Proxy0.m0 = Class.forName("java.lang.Object").getMethod("hashCode", (Class<?>[])new Class[0]);
66         }
67         catch (NoSuchMethodException ex) {
68             throw new NoSuchMethodError(ex.getMessage());
69         }
70         catch (ClassNotFoundException ex2) {
71             throw new NoClassDefFoundError(ex2.getMessage());
72         }
73     }
74 }
View Code

 

跟源码:

1. java.lang.reflect.Proxy#newProxyInstance()
    1.1 sun.misc.ProxyGenerator#generateClassFile()
        1.1.1 sun.misc.ProxyGenerator#generateProxyClass()
            1.1.1.1 sun.misc.ProxyGenerator#generateClassFile() // line 209,直接生成 java 字节码数组。里面会继承 java.lang.reflect.Proxy


补充:(2020.9.14)
我们也可以直接调用 sun.misc.ProxyGenerator#generateProxyClass(java.lang.String, java.lang.Class<?>[])  这个静态方法来拿到新生成类的字节码数组,然后将它输出到文件,然后反编译后进行观察

 

 

2. cglib 动态代理

cglib 动态代理是通过继承被代理类来实现的。

举例:

 1 public class Hello{
 2     public String sayHello(String name) {
 3         return "hello " + name;
 4     }
 5 }
 6 
 7 
 8 // 为 Hello 类生成代理类
 9 public static Object createProxy(final Object originObj){
10     Enhancer enhancer = new Enhancer();
11     enhancer.setClassLoader(originObj.getClass().getClassLoader());
12     enhancer.setSuperclass(originObj.getClass());
13     Callback[] callbacks = new Callback[]{new MethodInterceptor() {
14         @Override
15         public Object intercept(Object proxyObj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
16             // 被代理的方法执行前可以做一些事情
17             return method.invoke(originObj, args);
18         }
19     }};
20     enhancer.setCallbacks(callbacks);
21     return enhancer.create();
22 }

 

调用流程:

1. net.sf.cglib.proxy.Enhancer#create()
    1.1 net.sf.cglib.core.AbstractClassGenerator#generate()    // line 329,断点后,将字节码文件输出
                                // new FileOutputStream("d:\\b.class").getChannel().write(ByteBuffer.wrap(b))

 

反编译后的代码 如下:

  1 public class Hello$$EnhancerByCGLIB$$41f98a2b extends Hello implements Factory
  2 {
  3     private boolean CGLIB$BOUND;
  4     public static Object CGLIB$FACTORY_DATA;
  5     private static final ThreadLocal CGLIB$THREAD_CALLBACKS;
  6     private static final Callback[] CGLIB$STATIC_CALLBACKS;
  7     private MethodInterceptor CGLIB$CALLBACK_0;
  8     private static Object CGLIB$CALLBACK_FILTER;
  9     private static final Method CGLIB$sayHello$0$Method;
 10     private static final MethodProxy CGLIB$sayHello$0$Proxy;
 11     private static final Object[] CGLIB$emptyArgs;
 12     private static final Method CGLIB$equals$1$Method;
 13     private static final MethodProxy CGLIB$equals$1$Proxy;
 14     private static final Method CGLIB$toString$2$Method;
 15     private static final MethodProxy CGLIB$toString$2$Proxy;
 16     private static final Method CGLIB$hashCode$3$Method;
 17     private static final MethodProxy CGLIB$hashCode$3$Proxy;
 18     private static final Method CGLIB$clone$4$Method;
 19     private static final MethodProxy CGLIB$clone$4$Proxy;
 20     
 21     static void CGLIB$STATICHOOK1() {
 22         CGLIB$THREAD_CALLBACKS = new ThreadLocal();
 23         CGLIB$emptyArgs = new Object[0];
 24         final Class<?> forName = Class.forName("com.cn.zsy.proxy.cglibProxy.Hello$$EnhancerByCGLIB$$41f98a2b");
 25         final Class<?> forName2;
 26         final Method[] methods = ReflectUtils.findMethods(new String[] { "equals", "(Ljava/lang/Object;)Z", "toString", "()Ljava/lang/String;", "hashCode", "()I", "clone", "()Ljava/lang/Object;" }, (forName2 = Class.forName("java.lang.Object")).getDeclaredMethods());
 27         CGLIB$equals$1$Method = methods[0];
 28         CGLIB$equals$1$Proxy = MethodProxy.create((Class)forName2, (Class)forName, "(Ljava/lang/Object;)Z", "equals", "CGLIB$equals$1");
 29         CGLIB$toString$2$Method = methods[1];
 30         CGLIB$toString$2$Proxy = MethodProxy.create((Class)forName2, (Class)forName, "()Ljava/lang/String;", "toString", "CGLIB$toString$2");
 31         CGLIB$hashCode$3$Method = methods[2];
 32         CGLIB$hashCode$3$Proxy = MethodProxy.create((Class)forName2, (Class)forName, "()I", "hashCode", "CGLIB$hashCode$3");
 33         CGLIB$clone$4$Method = methods[3];
 34         CGLIB$clone$4$Proxy = MethodProxy.create((Class)forName2, (Class)forName, "()Ljava/lang/Object;", "clone", "CGLIB$clone$4");
 35         final Class<?> forName3;
 36         CGLIB$sayHello$0$Method = ReflectUtils.findMethods(new String[] { "sayHello", "(Ljava/lang/String;)Ljava/lang/String;" }, (forName3 = Class.forName("com.cn.zsy.proxy.cglibProxy.Hello")).getDeclaredMethods())[0];
 37         CGLIB$sayHello$0$Proxy = MethodProxy.create((Class)forName3, (Class)forName, "(Ljava/lang/String;)Ljava/lang/String;", "sayHello", "CGLIB$sayHello$0");
 38     }
 39     
 40     final String CGLIB$sayHello$0(final String s) {
 41         return super.sayHello(s);
 42     }
 43     
 44     public final String sayHello(final String s) {
 45         MethodInterceptor cglib$CALLBACK_2;
 46         MethodInterceptor cglib$CALLBACK_0;
 47         if ((cglib$CALLBACK_0 = (cglib$CALLBACK_2 = this.CGLIB$CALLBACK_0)) == null) {
 48             CGLIB$BIND_CALLBACKS(this);
 49             cglib$CALLBACK_2 = (cglib$CALLBACK_0 = this.CGLIB$CALLBACK_0);
 50         }
 51         if (cglib$CALLBACK_0 != null) {
 52             return (String)cglib$CALLBACK_2.intercept((Object)this, Hello$$EnhancerByCGLIB$$41f98a2b.CGLIB$sayHello$0$Method, new Object[] { s }, Hello$$EnhancerByCGLIB$$41f98a2b.CGLIB$sayHello$0$Proxy);
 53         }
 54         return super.sayHello(s);
 55     }
 56     
 57     final boolean CGLIB$equals$1(final Object o) {
 58         return super.equals(o);
 59     }
 60     
 61     public final boolean equals(final Object o) {
 62         MethodInterceptor cglib$CALLBACK_2;
 63         MethodInterceptor cglib$CALLBACK_0;
 64         if ((cglib$CALLBACK_0 = (cglib$CALLBACK_2 = this.CGLIB$CALLBACK_0)) == null) {
 65             CGLIB$BIND_CALLBACKS(this);
 66             cglib$CALLBACK_2 = (cglib$CALLBACK_0 = this.CGLIB$CALLBACK_0);
 67         }
 68         if (cglib$CALLBACK_0 != null) {
 69             final Object intercept = cglib$CALLBACK_2.intercept((Object)this, Hello$$EnhancerByCGLIB$$41f98a2b.CGLIB$equals$1$Method, new Object[] { o }, Hello$$EnhancerByCGLIB$$41f98a2b.CGLIB$equals$1$Proxy);
 70             return intercept != null && (boolean)intercept;
 71         }
 72         return super.equals(o);
 73     }
 74     
 75     final String CGLIB$toString$2() {
 76         return super.toString();
 77     }
 78     
 79     public final String toString() {
 80         MethodInterceptor cglib$CALLBACK_2;
 81         MethodInterceptor cglib$CALLBACK_0;
 82         if ((cglib$CALLBACK_0 = (cglib$CALLBACK_2 = this.CGLIB$CALLBACK_0)) == null) {
 83             CGLIB$BIND_CALLBACKS(this);
 84             cglib$CALLBACK_2 = (cglib$CALLBACK_0 = this.CGLIB$CALLBACK_0);
 85         }
 86         if (cglib$CALLBACK_0 != null) {
 87             return (String)cglib$CALLBACK_2.intercept((Object)this, Hello$$EnhancerByCGLIB$$41f98a2b.CGLIB$toString$2$Method, Hello$$EnhancerByCGLIB$$41f98a2b.CGLIB$emptyArgs, Hello$$EnhancerByCGLIB$$41f98a2b.CGLIB$toString$2$Proxy);
 88         }
 89         return super.toString();
 90     }
 91     
 92     final int CGLIB$hashCode$3() {
 93         return super.hashCode();
 94     }
 95     
 96     public final int hashCode() {
 97         MethodInterceptor cglib$CALLBACK_2;
 98         MethodInterceptor cglib$CALLBACK_0;
 99         if ((cglib$CALLBACK_0 = (cglib$CALLBACK_2 = this.CGLIB$CALLBACK_0)) == null) {
100             CGLIB$BIND_CALLBACKS(this);
101             cglib$CALLBACK_2 = (cglib$CALLBACK_0 = this.CGLIB$CALLBACK_0);
102         }
103         if (cglib$CALLBACK_0 != null) {
104             final Object intercept = cglib$CALLBACK_2.intercept((Object)this, Hello$$EnhancerByCGLIB$$41f98a2b.CGLIB$hashCode$3$Method, Hello$$EnhancerByCGLIB$$41f98a2b.CGLIB$emptyArgs, Hello$$EnhancerByCGLIB$$41f98a2b.CGLIB$hashCode$3$Proxy);
105             return (intercept == null) ? 0 : ((Number)intercept).intValue();
106         }
107         return super.hashCode();
108     }
109     
110     final Object CGLIB$clone$4() throws CloneNotSupportedException {
111         return super.clone();
112     }
113     
114     protected final Object clone() throws CloneNotSupportedException {
115         MethodInterceptor cglib$CALLBACK_2;
116         MethodInterceptor cglib$CALLBACK_0;
117         if ((cglib$CALLBACK_0 = (cglib$CALLBACK_2 = this.CGLIB$CALLBACK_0)) == null) {
118             CGLIB$BIND_CALLBACKS(this);
119             cglib$CALLBACK_2 = (cglib$CALLBACK_0 = this.CGLIB$CALLBACK_0);
120         }
121         if (cglib$CALLBACK_0 != null) {
122             return cglib$CALLBACK_2.intercept((Object)this, Hello$$EnhancerByCGLIB$$41f98a2b.CGLIB$clone$4$Method, Hello$$EnhancerByCGLIB$$41f98a2b.CGLIB$emptyArgs, Hello$$EnhancerByCGLIB$$41f98a2b.CGLIB$clone$4$Proxy);
123         }
124         return super.clone();
125     }
126     
127     public static MethodProxy CGLIB$findMethodProxy(final Signature signature) {
128         final String string = signature.toString();
129         switch (string.hashCode()) {
130             case -1816210712: {
131                 if (string.equals("sayHello(Ljava/lang/String;)Ljava/lang/String;")) {
132                     return Hello$$EnhancerByCGLIB$$41f98a2b.CGLIB$sayHello$0$Proxy;
133                 }
134                 break;
135             }
136             case -508378822: {
137                 if (string.equals("clone()Ljava/lang/Object;")) {
138                     return Hello$$EnhancerByCGLIB$$41f98a2b.CGLIB$clone$4$Proxy;
139                 }
140                 break;
141             }
142             case 1826985398: {
143                 if (string.equals("equals(Ljava/lang/Object;)Z")) {
144                     return Hello$$EnhancerByCGLIB$$41f98a2b.CGLIB$equals$1$Proxy;
145                 }
146                 break;
147             }
148             case 1913648695: {
149                 if (string.equals("toString()Ljava/lang/String;")) {
150                     return Hello$$EnhancerByCGLIB$$41f98a2b.CGLIB$toString$2$Proxy;
151                 }
152                 break;
153             }
154             case 1984935277: {
155                 if (string.equals("hashCode()I")) {
156                     return Hello$$EnhancerByCGLIB$$41f98a2b.CGLIB$hashCode$3$Proxy;
157                 }
158                 break;
159             }
160         }
161         return null;
162     }
163     
164     public Hello$$EnhancerByCGLIB$$41f98a2b() {
165         CGLIB$BIND_CALLBACKS(this);
166     }
167     
168     public static void CGLIB$SET_THREAD_CALLBACKS(final Callback[] array) {
169         Hello$$EnhancerByCGLIB$$41f98a2b.CGLIB$THREAD_CALLBACKS.set(array);
170     }
171     
172     public static void CGLIB$SET_STATIC_CALLBACKS(final Callback[] cglib$STATIC_CALLBACKS) {
173         CGLIB$STATIC_CALLBACKS = cglib$STATIC_CALLBACKS;
174     }
175     
176     private static final void CGLIB$BIND_CALLBACKS(final Object o) {
177         final Hello$$EnhancerByCGLIB$$41f98a2b hello$$EnhancerByCGLIB$$41f98a2b = (Hello$$EnhancerByCGLIB$$41f98a2b)o;
178         if (!hello$$EnhancerByCGLIB$$41f98a2b.CGLIB$BOUND) {
179             hello$$EnhancerByCGLIB$$41f98a2b.CGLIB$BOUND = true;
180             Object o2;
181             if ((o2 = Hello$$EnhancerByCGLIB$$41f98a2b.CGLIB$THREAD_CALLBACKS.get()) != null || (o2 = Hello$$EnhancerByCGLIB$$41f98a2b.CGLIB$STATIC_CALLBACKS) != null) {
182                 hello$$EnhancerByCGLIB$$41f98a2b.CGLIB$CALLBACK_0 = (MethodInterceptor)((Callback[])o2)[0];
183             }
184         }
185     }
186     
187     public Object newInstance(final Callback[] array) {
188         CGLIB$SET_THREAD_CALLBACKS(array);
189         final Hello$$EnhancerByCGLIB$$41f98a2b hello$$EnhancerByCGLIB$$41f98a2b = new Hello$$EnhancerByCGLIB$$41f98a2b();
190         CGLIB$SET_THREAD_CALLBACKS(null);
191         return hello$$EnhancerByCGLIB$$41f98a2b;
192     }
193     
194     public Object newInstance(final Callback callback) {
195         CGLIB$SET_THREAD_CALLBACKS(new Callback[] { callback });
196         final Hello$$EnhancerByCGLIB$$41f98a2b hello$$EnhancerByCGLIB$$41f98a2b = new Hello$$EnhancerByCGLIB$$41f98a2b();
197         CGLIB$SET_THREAD_CALLBACKS(null);
198         return hello$$EnhancerByCGLIB$$41f98a2b;
199     }
200     
201     public Object newInstance(final Class[] array, final Object[] array2, final Callback[] array3) {
202         CGLIB$SET_THREAD_CALLBACKS(array3);
203         switch (array.length) {
204             case 0: {
205                 final Hello$$EnhancerByCGLIB$$41f98a2b hello$$EnhancerByCGLIB$$41f98a2b = new Hello$$EnhancerByCGLIB$$41f98a2b();
206                 CGLIB$SET_THREAD_CALLBACKS(null);
207                 return hello$$EnhancerByCGLIB$$41f98a2b;
208             }
209             default: {
210                 throw new IllegalArgumentException("Constructor not found");
211             }
212         }
213     }
214     
215     public Callback getCallback(final int n) {
216         CGLIB$BIND_CALLBACKS(this);
217         Object cglib$CALLBACK_0 = null;
218         switch (n) {
219             case 0: {
220                 cglib$CALLBACK_0 = this.CGLIB$CALLBACK_0;
221                 break;
222             }
223             default: {
224                 cglib$CALLBACK_0 = null;
225                 break;
226             }
227         }
228         return (Callback)cglib$CALLBACK_0;
229     }
230     
231     public void setCallback(final int n, final Callback callback) {
232         switch (n) {
233             case 0: {
234                 this.CGLIB$CALLBACK_0 = (MethodInterceptor)callback;
235                 break;
236             }
237         }
238     }
239     
240     public Callback[] getCallbacks() {
241         CGLIB$BIND_CALLBACKS(this);
242         return new Callback[] { this.CGLIB$CALLBACK_0 };
243     }
244     
245     public void setCallbacks(final Callback[] array) {
246         this.CGLIB$CALLBACK_0 = (MethodInterceptor)array[0];
247     }
248     
249     static {
250         CGLIB$STATICHOOK1();
251     }
252 }
View Code

 

注意:cglib 也可以直接对接口生成代理

 1 Enhancer enhancer = new Enhancer();
 2 enhancer.setClassLoader(IHello.class.getClassLoader());
 3 enhancer.setSuperclass(IHello.class);
 4 Callback[] callbacks = new Callback[]{new MethodInterceptor() {
 5     @Override
 6     public Object intercept(Object proxyObj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
 7         // 由于是对接口生成的代理,这里可以做一些通用逻辑
 8         // 比如:mybatis 的 mapper 类就是一个接口类,没有具体实现
 9         return ...;
10     }
11 }};
12 enhancer.setCallbacks(callbacks);
13 enhancer.create();

 

反编译代理类:

  1 public class IHello$$EnhancerByCGLIB$$6e686db0 implements IHello, Factory
  2 {
  3     private boolean CGLIB$BOUND;
  4     public static Object CGLIB$FACTORY_DATA;
  5     private static final ThreadLocal CGLIB$THREAD_CALLBACKS;
  6     private static final Callback[] CGLIB$STATIC_CALLBACKS;
  7     private MethodInterceptor CGLIB$CALLBACK_0;
  8     private static Object CGLIB$CALLBACK_FILTER;
  9     private static final Method CGLIB$equals$0$Method;
 10     private static final MethodProxy CGLIB$equals$0$Proxy;
 11     private static final Object[] CGLIB$emptyArgs;
 12     private static final Method CGLIB$toString$1$Method;
 13     private static final MethodProxy CGLIB$toString$1$Proxy;
 14     private static final Method CGLIB$hashCode$2$Method;
 15     private static final MethodProxy CGLIB$hashCode$2$Proxy;
 16     private static final Method CGLIB$clone$3$Method;
 17     private static final MethodProxy CGLIB$clone$3$Proxy;
 18     private static final Method CGLIB$sayHello$4$Method;
 19     private static final MethodProxy CGLIB$sayHello$4$Proxy;
 20     
 21     static void CGLIB$STATICHOOK1() {
 22         CGLIB$THREAD_CALLBACKS = new ThreadLocal();
 23         CGLIB$emptyArgs = new Object[0];
 24         final Class<?> forName = Class.forName("com.cn.zsy.proxy.jdkProxy.IHello$$EnhancerByCGLIB$$6e686db0");
 25         final Class<?> forName2;
 26         final Method[] methods = ReflectUtils.findMethods(new String[] { "equals", "(Ljava/lang/Object;)Z", "toString", "()Ljava/lang/String;", "hashCode", "()I", "clone", "()Ljava/lang/Object;" }, (forName2 = Class.forName("java.lang.Object")).getDeclaredMethods());
 27         CGLIB$equals$0$Method = methods[0];
 28         CGLIB$equals$0$Proxy = MethodProxy.create((Class)forName2, (Class)forName, "(Ljava/lang/Object;)Z", "equals", "CGLIB$equals$0");
 29         CGLIB$toString$1$Method = methods[1];
 30         CGLIB$toString$1$Proxy = MethodProxy.create((Class)forName2, (Class)forName, "()Ljava/lang/String;", "toString", "CGLIB$toString$1");
 31         CGLIB$hashCode$2$Method = methods[2];
 32         CGLIB$hashCode$2$Proxy = MethodProxy.create((Class)forName2, (Class)forName, "()I", "hashCode", "CGLIB$hashCode$2");
 33         CGLIB$clone$3$Method = methods[3];
 34         CGLIB$clone$3$Proxy = MethodProxy.create((Class)forName2, (Class)forName, "()Ljava/lang/Object;", "clone", "CGLIB$clone$3");
 35         final Class<?> forName3;
 36         CGLIB$sayHello$4$Method = ReflectUtils.findMethods(new String[] { "sayHello", "(Ljava/lang/String;)Ljava/lang/String;" }, (forName3 = Class.forName("com.cn.zsy.proxy.jdkProxy.IHello")).getDeclaredMethods())[0];
 37         CGLIB$sayHello$4$Proxy = MethodProxy.create((Class)forName3, (Class)forName, "(Ljava/lang/String;)Ljava/lang/String;", "sayHello", "CGLIB$sayHello$4");
 38     }
 39     
 40     final boolean CGLIB$equals$0(final Object o) {
 41         return super.equals(o);
 42     }
 43     
 44     public final boolean equals(final Object o) {
 45         MethodInterceptor cglib$CALLBACK_2;
 46         MethodInterceptor cglib$CALLBACK_0;
 47         if ((cglib$CALLBACK_0 = (cglib$CALLBACK_2 = this.CGLIB$CALLBACK_0)) == null) {
 48             CGLIB$BIND_CALLBACKS(this);
 49             cglib$CALLBACK_2 = (cglib$CALLBACK_0 = this.CGLIB$CALLBACK_0);
 50         }
 51         if (cglib$CALLBACK_0 != null) {
 52             final Object intercept = cglib$CALLBACK_2.intercept((Object)this, IHello$$EnhancerByCGLIB$$6e686db0.CGLIB$equals$0$Method, new Object[] { o }, IHello$$EnhancerByCGLIB$$6e686db0.CGLIB$equals$0$Proxy);
 53             return intercept != null && (boolean)intercept;
 54         }
 55         return super.equals(o);
 56     }
 57     
 58     final String CGLIB$toString$1() {
 59         return super.toString();
 60     }
 61     
 62     public final String toString() {
 63         MethodInterceptor cglib$CALLBACK_2;
 64         MethodInterceptor cglib$CALLBACK_0;
 65         if ((cglib$CALLBACK_0 = (cglib$CALLBACK_2 = this.CGLIB$CALLBACK_0)) == null) {
 66             CGLIB$BIND_CALLBACKS(this);
 67             cglib$CALLBACK_2 = (cglib$CALLBACK_0 = this.CGLIB$CALLBACK_0);
 68         }
 69         if (cglib$CALLBACK_0 != null) {
 70             return (String)cglib$CALLBACK_2.intercept((Object)this, IHello$$EnhancerByCGLIB$$6e686db0.CGLIB$toString$1$Method, IHello$$EnhancerByCGLIB$$6e686db0.CGLIB$emptyArgs, IHello$$EnhancerByCGLIB$$6e686db0.CGLIB$toString$1$Proxy);
 71         }
 72         return super.toString();
 73     }
 74     
 75     final int CGLIB$hashCode$2() {
 76         return super.hashCode();
 77     }
 78     
 79     public final int hashCode() {
 80         MethodInterceptor cglib$CALLBACK_2;
 81         MethodInterceptor cglib$CALLBACK_0;
 82         if ((cglib$CALLBACK_0 = (cglib$CALLBACK_2 = this.CGLIB$CALLBACK_0)) == null) {
 83             CGLIB$BIND_CALLBACKS(this);
 84             cglib$CALLBACK_2 = (cglib$CALLBACK_0 = this.CGLIB$CALLBACK_0);
 85         }
 86         if (cglib$CALLBACK_0 != null) {
 87             final Object intercept = cglib$CALLBACK_2.intercept((Object)this, IHello$$EnhancerByCGLIB$$6e686db0.CGLIB$hashCode$2$Method, IHello$$EnhancerByCGLIB$$6e686db0.CGLIB$emptyArgs, IHello$$EnhancerByCGLIB$$6e686db0.CGLIB$hashCode$2$Proxy);
 88             return (intercept == null) ? 0 : ((Number)intercept).intValue();
 89         }
 90         return super.hashCode();
 91     }
 92     
 93     final Object CGLIB$clone$3() throws CloneNotSupportedException {
 94         return super.clone();
 95     }
 96     
 97     protected final Object clone() throws CloneNotSupportedException {
 98         MethodInterceptor cglib$CALLBACK_2;
 99         MethodInterceptor cglib$CALLBACK_0;
100         if ((cglib$CALLBACK_0 = (cglib$CALLBACK_2 = this.CGLIB$CALLBACK_0)) == null) {
101             CGLIB$BIND_CALLBACKS(this);
102             cglib$CALLBACK_2 = (cglib$CALLBACK_0 = this.CGLIB$CALLBACK_0);
103         }
104         if (cglib$CALLBACK_0 != null) {
105             return cglib$CALLBACK_2.intercept((Object)this, IHello$$EnhancerByCGLIB$$6e686db0.CGLIB$clone$3$Method, IHello$$EnhancerByCGLIB$$6e686db0.CGLIB$emptyArgs, IHello$$EnhancerByCGLIB$$6e686db0.CGLIB$clone$3$Proxy);
106         }
107         return super.clone();
108     }
109     
110     final String CGLIB$sayHello$4(final String s) {
111         return super.sayHello(s);
112     }
113     
114     public final String sayHello(final String s) {
115         MethodInterceptor cglib$CALLBACK_2;
116         MethodInterceptor cglib$CALLBACK_0;
117         if ((cglib$CALLBACK_0 = (cglib$CALLBACK_2 = this.CGLIB$CALLBACK_0)) == null) {
118             CGLIB$BIND_CALLBACKS(this);
119             cglib$CALLBACK_2 = (cglib$CALLBACK_0 = this.CGLIB$CALLBACK_0);
120         }
121         if (cglib$CALLBACK_0 != null) {
122             return (String)cglib$CALLBACK_2.intercept((Object)this, IHello$$EnhancerByCGLIB$$6e686db0.CGLIB$sayHello$4$Method, new Object[] { s }, IHello$$EnhancerByCGLIB$$6e686db0.CGLIB$sayHello$4$Proxy);
123         }
124         return super.sayHello(s);
125     }
126     
127     public static MethodProxy CGLIB$findMethodProxy(final Signature signature) {
128         final String string = signature.toString();
129         switch (string.hashCode()) {
130             case -1816210712: {
131                 if (string.equals("sayHello(Ljava/lang/String;)Ljava/lang/String;")) {
132                     return IHello$$EnhancerByCGLIB$$6e686db0.CGLIB$sayHello$4$Proxy;
133                 }
134                 break;
135             }
136             case -508378822: {
137                 if (string.equals("clone()Ljava/lang/Object;")) {
138                     return IHello$$EnhancerByCGLIB$$6e686db0.CGLIB$clone$3$Proxy;
139                 }
140                 break;
141             }
142             case 1826985398: {
143                 if (string.equals("equals(Ljava/lang/Object;)Z")) {
144                     return IHello$$EnhancerByCGLIB$$6e686db0.CGLIB$equals$0$Proxy;
145                 }
146                 break;
147             }
148             case 1913648695: {
149                 if (string.equals("toString()Ljava/lang/String;")) {
150                     return IHello$$EnhancerByCGLIB$$6e686db0.CGLIB$toString$1$Proxy;
151                 }
152                 break;
153             }
154             case 1984935277: {
155                 if (string.equals("hashCode()I")) {
156                     return IHello$$EnhancerByCGLIB$$6e686db0.CGLIB$hashCode$2$Proxy;
157                 }
158                 break;
159             }
160         }
161         return null;
162     }
163     
164     public IHello$$EnhancerByCGLIB$$6e686db0() {
165         CGLIB$BIND_CALLBACKS(this);
166     }
167     
168     public static void CGLIB$SET_THREAD_CALLBACKS(final Callback[] array) {
169         IHello$$EnhancerByCGLIB$$6e686db0.CGLIB$THREAD_CALLBACKS.set(array);
170     }
171     
172     public static void CGLIB$SET_STATIC_CALLBACKS(final Callback[] cglib$STATIC_CALLBACKS) {
173         CGLIB$STATIC_CALLBACKS = cglib$STATIC_CALLBACKS;
174     }
175     
176     private static final void CGLIB$BIND_CALLBACKS(final Object o) {
177         final IHello$$EnhancerByCGLIB$$6e686db0 hello$$EnhancerByCGLIB$$6e686db0 = (IHello$$EnhancerByCGLIB$$6e686db0)o;
178         if (!hello$$EnhancerByCGLIB$$6e686db0.CGLIB$BOUND) {
179             hello$$EnhancerByCGLIB$$6e686db0.CGLIB$BOUND = true;
180             Object o2;
181             if ((o2 = IHello$$EnhancerByCGLIB$$6e686db0.CGLIB$THREAD_CALLBACKS.get()) != null || (o2 = IHello$$EnhancerByCGLIB$$6e686db0.CGLIB$STATIC_CALLBACKS) != null) {
182                 hello$$EnhancerByCGLIB$$6e686db0.CGLIB$CALLBACK_0 = (MethodInterceptor)((Callback[])o2)[0];
183             }
184         }
185     }
186     
187     public Object newInstance(final Callback[] array) {
188         CGLIB$SET_THREAD_CALLBACKS(array);
189         final IHello$$EnhancerByCGLIB$$6e686db0 hello$$EnhancerByCGLIB$$6e686db0 = new IHello$$EnhancerByCGLIB$$6e686db0();
190         CGLIB$SET_THREAD_CALLBACKS(null);
191         return hello$$EnhancerByCGLIB$$6e686db0;
192     }
193     
194     public Object newInstance(final Callback callback) {
195         CGLIB$SET_THREAD_CALLBACKS(new Callback[] { callback });
196         final IHello$$EnhancerByCGLIB$$6e686db0 hello$$EnhancerByCGLIB$$6e686db0 = new IHello$$EnhancerByCGLIB$$6e686db0();
197         CGLIB$SET_THREAD_CALLBACKS(null);
198         return hello$$EnhancerByCGLIB$$6e686db0;
199     }
200     
201     public Object newInstance(final Class[] array, final Object[] array2, final Callback[] array3) {
202         CGLIB$SET_THREAD_CALLBACKS(array3);
203         switch (array.length) {
204             case 0: {
205                 final IHello$$EnhancerByCGLIB$$6e686db0 hello$$EnhancerByCGLIB$$6e686db0 = new IHello$$EnhancerByCGLIB$$6e686db0();
206                 CGLIB$SET_THREAD_CALLBACKS(null);
207                 return hello$$EnhancerByCGLIB$$6e686db0;
208             }
209             default: {
210                 throw new IllegalArgumentException("Constructor not found");
211             }
212         }
213     }
214     
215     public Callback getCallback(final int n) {
216         CGLIB$BIND_CALLBACKS(this);
217         Object cglib$CALLBACK_0 = null;
218         switch (n) {
219             case 0: {
220                 cglib$CALLBACK_0 = this.CGLIB$CALLBACK_0;
221                 break;
222             }
223             default: {
224                 cglib$CALLBACK_0 = null;
225                 break;
226             }
227         }
228         return (Callback)cglib$CALLBACK_0;
229     }
230     
231     public void setCallback(final int n, final Callback callback) {
232         switch (n) {
233             case 0: {
234                 this.CGLIB$CALLBACK_0 = (MethodInterceptor)callback;
235                 break;
236             }
237         }
238     }
239     
240     public Callback[] getCallbacks() {
241         CGLIB$BIND_CALLBACKS(this);
242         return new Callback[] { this.CGLIB$CALLBACK_0 };
243     }
244     
245     public void setCallbacks(final Callback[] array) {
246         this.CGLIB$CALLBACK_0 = (MethodInterceptor)array[0];
247     }
248     
249     static {
250         CGLIB$STATICHOOK1();
251     }
252 }
View Code

 

posted on 2020-07-24 15:53  快鸟  阅读(303)  评论(0编辑  收藏  举报