一、静态代理
二、动态代理
2.1 JDK
JDK的Proxy动态代理,必须要求有接口和实现类,然后对接口中的方法进行增强,同时,他只能读取接口中方法上的注解信息。
2.1.1 示例
Calculator接口
/*** 计算器接口** @author maomaochong* @date 2022/07/07 21:27**/public interface Calculator {int add(int i, int j);int sub(int i, int j);int mul(int i, int j);int div(int i, int j);}
Calculator实现类
/*** 自定义计算器** @author maomaochong* @date 2022/07/07 21:28**/public class MyCalculator implements Calculator{@Overridepublic int add(int i, int j) {return i + j;}@Overridepublic int sub(int i, int j) {return i - j;}@Overridepublic int mul(int i, int j) {return i * j;}@Overridepublic int div(int i, int j) {return i / j;}}
代理生成类
/*** 计算器代理类** @author maomaochong* @date 2022/07/07 21:29**/public class CalculatorProxy {public static Calculator getProxy(Calculator calculator) {// 获取类加载器ClassLoader classLoader = calculator.getClass().getClassLoader();// 获取被代理实现的接口Class<?>[] interfaces = calculator.getClass().getInterfaces();// 生成InvocationHandlerInvocationHandler invocationHandler = new InvocationHandler() {@Overridepublic Object invoke(Object proxy, Method method, Object[] args) throws Throwable {Object result = null;try {result = method.invoke(calculator, args);} catch (Exception e) {e.printStackTrace();}return result;}};Object proxyInstance = Proxy.newProxyInstance(classLoader, interfaces, invocationHandler);return (Calculator) proxyInstance;}}
测试类
/*** jdk动态代理测试类** @author maomaochong* @date 2022/07/07 21:36**/public class JdkProxyTest {public static void main(String[] args) {// 获取被代理类对象MyCalculator myCalculator = new MyCalculator();// 获取代理类对象Calculator proxy = CalculatorProxy.getProxy(myCalculator);System.out.println(proxy.add(1, 1));System.out.println(proxy.getClass());}}
2.1.2 源码分析
1. 获取代理类对象核心方法
此方法是生成动态代理的代理类的核心方法:
public static Object newProxyInstance(ClassLoader loader,Class<?>[] interfaces,InvocationHandler h)throws IllegalArgumentException{// 判断InvocationHandler,不能为空Objects.requireNonNull(h);// 克隆被代理类实现的接口的字节码信息final Class<?>[] intfs = interfaces.clone();final SecurityManager sm = System.getSecurityManager();if (sm != null) {checkProxyAccess(Reflection.getCallerClass(), loader, intfs);}/** Look up or generate the designated proxy class.*/// 此方法是核心,获取代理类的字节码信息Class<?> cl = getProxyClass0(loader, intfs);/** Invoke its constructor with the designated invocation handler.*/// 执行InvocationHandler设计好的代理类的构造方法try {if (sm != null) {checkNewProxyPermission(Reflection.getCallerClass(), cl);}// 获取构造方法final Constructor<?> cons = cl.getConstructor(constructorParams);final InvocationHandler ih = h;// 判断修饰符,确定是否开启访问权限if (!Modifier.isPublic(cl.getModifiers())) {AccessController.doPrivileged(new PrivilegedAction<Void>() {public Void run() {cons.setAccessible(true);return null;}});}// 生成代理类对象return cons.newInstance(new Object[]{h});} catch (IllegalAccessException|InstantiationException e) {throw new InternalError(e.toString(), e);} catch (InvocationTargetException e) {Throwable t = e.getCause();if (t instanceof RuntimeException) {throw (RuntimeException) t;} else {throw new InternalError(t.toString(), t);}} catch (NoSuchMethodException e) {throw new InternalError(e.toString(), e);}}
1.1 获取代理类字节码信息
获取代理类的字节码信息:
private static Class<?> getProxyClass0(ClassLoader loader,Class<?>... interfaces) {// 判断被代理类实现的接口数量,超出此数目则抛出异常if (interfaces.length > 65535) {throw new IllegalArgumentException("interface limit exceeded");}// If the proxy class defined by the given loader implementing// the given interfaces exists, this will simply return the cached copy;// otherwise, it will create the proxy class via the ProxyClassFactory// 如果给定的类加载器定义的实现了指定接口的代理类已经存在,就返回缓存中的副本,// 否则就通过代理类工厂创建代理类// 此处实际上调用的是 WeakCache 中 的get方法return proxyClassCache.get(loader, interfaces);}
1.1.1 从缓存获取代理类信息
尝试从缓存中获取代理类信息:
public V get(K key, P parameter) {// 判断给定的接口信息不能为空Objects.requireNonNull(parameter);expungeStaleEntries();Object cacheKey = CacheKey.valueOf(key, refQueue);// lazily install the 2nd level valuesMap for the particular cacheKeyConcurrentMap<Object, Supplier<V>> valuesMap = map.get(cacheKey);if (valuesMap == null) {ConcurrentMap<Object, Supplier<V>> oldValuesMap= map.putIfAbsent(cacheKey,valuesMap = new ConcurrentHashMap<>());if (oldValuesMap != null) {valuesMap = oldValuesMap;}}// create subKey and retrieve the possible Supplier<V> stored by that// subKey from valuesMap// 此处是重点,通过函数式接口,实际使用Proxy内部的ProxyClassFactory中的apply方法获取到代理类的字节码信息Object subKey = Objects.requireNonNull(subKeyFactory.apply(key, parameter));Supplier<V> supplier = valuesMap.get(subKey);Factory factory = null;while (true) {if (supplier != null) {// supplier might be a Factory or a CacheValue<V> instanceV value = supplier.get();if (value != null) {// 上边生成代理类字节码信息之后,在此处返回return value;}}// else no supplier in cache// or a supplier that returned null (could be a cleared CacheValue// or a Factory that wasn't successful in installing the CacheValue)// lazily construct a Factory// 因为最初的map中没有其他的键存在,所以会来到这一步,构建工厂if (factory == null) {factory = new Factory(key, parameter, subKey, valuesMap);}if (supplier == null) {supplier = valuesMap.putIfAbsent(subKey, factory);if (supplier == null) {// successfully installed Factory// 在此处将工厂赋值给函数式接口supplier = factory;}// else retry with winning supplier} else {if (valuesMap.replace(subKey, supplier, factory)) {// successfully replaced// cleared CacheEntry / unsuccessful Factory// with our Factorysupplier = factory;} else {// retry with current suppliersupplier = valuesMap.get(subKey);}}}}
生成代理类的字节码信息:
private static final class ProxyClassFactoryimplements BiFunction<ClassLoader, Class<?>[], Class<?>>{// prefix for all proxy class names// 代理类名前缀private static final String proxyClassNamePrefix = "$Proxy";// next number to use for generation of unique proxy class namesprivate static final AtomicLong nextUniqueNumber = new AtomicLong();@Overridepublic Class<?> apply(ClassLoader loader, Class<?>[] interfaces) {Map<Class<?>, Boolean> interfaceSet = new IdentityHashMap<>(interfaces.length);for (Class<?> intf : interfaces) {/** Verify that the class loader resolves the name of this* interface to the same Class object.*/Class<?> interfaceClass = null;try {// 获取接口字节码interfaceClass = Class.forName(intf.getName(), false, loader);} catch (ClassNotFoundException e) {}// 验证获取的字节码 类加载是否可见if (interfaceClass != intf) {throw new IllegalArgumentException(intf + " is not visible from class loader");}/** Verify that the Class object actually represents an* interface.*/// 验证字节码对象是一个接口if (!interfaceClass.isInterface()) {throw new IllegalArgumentException(interfaceClass.getName() + " is not an interface");}/** Verify that this interface is not a duplicate.*/// 验证此接口是否重复if (interfaceSet.put(interfaceClass, Boolean.TRUE) != null) {throw new IllegalArgumentException("repeated interface: " + interfaceClass.getName());}}String proxyPkg = null; // package to define proxy class inint accessFlags = Modifier.PUBLIC | Modifier.FINAL;/** Record the package of a non-public proxy interface so that the* proxy class will be defined in the same package. Verify that* all non-public proxy interfaces are in the same package.*/for (Class<?> intf : interfaces) {int flags = intf.getModifiers();if (!Modifier.isPublic(flags)) {accessFlags = Modifier.FINAL;String name = intf.getName();int n = name.lastIndexOf('.');String pkg = ((n == -1) ? "" : name.substring(0, n + 1));if (proxyPkg == null) {proxyPkg = pkg;} else if (!pkg.equals(proxyPkg)) {throw new IllegalArgumentException("non-public interfaces from different packages");}}}if (proxyPkg == null) {// if no non-public proxy interfaces, use com.sun.proxy package// 如果是非公开的代理接口,使用 com.sun.proxy 包proxyPkg = ReflectUtil.PROXY_PACKAGE + ".";}/** Choose a name for the proxy class to generate.*/// 拼接类名前缀和随机数long num = nextUniqueNumber.getAndIncrement();// 包名 + 类前缀 + 随机数 组成代理类名String proxyName = proxyPkg + proxyClassNamePrefix + num;/** Generate the specified proxy class.*/// 生成特定的代理类的字节数组byte[] proxyClassFile = ProxyGenerator.generateProxyClass(proxyName, interfaces, accessFlags);try {return defineClass0(loader, proxyName,proxyClassFile, 0, proxyClassFile.length);} catch (ClassFormatError e) {/** A ClassFormatError here means that (barring bugs in the* proxy class generation code) there was some other* invalid aspect of the arguments supplied to the proxy* class creation (such as virtual machine limitations* exceeded).*/throw new IllegalArgumentException(e.toString());}}}
1.2 调用字节码的构造方法,生成代理类对象
2. 生成具体的代理类文件
我们可以通过配置,来将生成的代理类字节码信息产生具体的文件:
/*** jdk动态代理测试类** @author maomaochong* @date 2022/07/07 21:36**/public class JdkProxyTest {public static void main(String[] args) {// 配置此内容,产生具体的代理类文件System.getProperties().put("sun.misc.ProxyGenerator.saveGeneratedFiles", "true");// 获取被代理类对象MyCalculator myCalculator = new MyCalculator();// 获取代理类对象Calculator proxy = CalculatorProxy.getProxy(myCalculator);System.out.println(proxy.add(1, 1));System.out.println(proxy.getClass());}}
包路径如下:
具体内容如下:
//// Source code recreated from a .class file by IntelliJ IDEA// (powered by FernFlower decompiler)//package com.sun.proxy;import com.moomooyu.proxy.jdk.Calculator;import java.lang.reflect.InvocationHandler;import java.lang.reflect.Method;import java.lang.reflect.Proxy;import java.lang.reflect.UndeclaredThrowableException;public final class $Proxy0 extends Proxy implements Calculator {private static Method m1;private static Method m2;private static Method m5;private static Method m3;private static Method m4;private static Method m6;private static Method m0;public $Proxy0(InvocationHandler var1) throws {super(var1);}public final boolean equals(Object var1) throws {try {return (Boolean)super.h.invoke(this, m1, new Object[]{var1});} catch (RuntimeException | Error var3) {throw var3;} catch (Throwable var4) {throw new UndeclaredThrowableException(var4);}}public final String toString() throws {try {return (String)super.h.invoke(this, m2, (Object[])null);} catch (RuntimeException | Error var2) {throw var2;} catch (Throwable var3) {throw new UndeclaredThrowableException(var3);}}public final int mul(int var1, int var2) throws {try {return (Integer)super.h.invoke(this, m5, new Object[]{var1, var2});} catch (RuntimeException | Error var4) {throw var4;} catch (Throwable var5) {throw new UndeclaredThrowableException(var5);}}public final int add(int var1, int var2) throws {try {return (Integer)super.h.invoke(this, m3, new Object[]{var1, var2});} catch (RuntimeException | Error var4) {throw var4;} catch (Throwable var5) {throw new UndeclaredThrowableException(var5);}}public final int sub(int var1, int var2) throws {try {return (Integer)super.h.invoke(this, m4, new Object[]{var1, var2});} catch (RuntimeException | Error var4) {throw var4;} catch (Throwable var5) {throw new UndeclaredThrowableException(var5);}}public final int div(int var1, int var2) throws {try {return (Integer)super.h.invoke(this, m6, new Object[]{var1, var2});} catch (RuntimeException | Error var4) {throw var4;} catch (Throwable var5) {throw new UndeclaredThrowableException(var5);}}public final int hashCode() throws {try {return (Integer)super.h.invoke(this, m0, (Object[])null);} catch (RuntimeException | Error var2) {throw var2;} catch (Throwable var3) {throw new UndeclaredThrowableException(var3);}}static {try {m1 = Class.forName("java.lang.Object").getMethod("equals", Class.forName("java.lang.Object"));m2 = Class.forName("java.lang.Object").getMethod("toString");m5 = Class.forName("com.moomooyu.proxy.jdk.Calculator").getMethod("mul", Integer.TYPE, Integer.TYPE);m3 = Class.forName("com.moomooyu.proxy.jdk.Calculator").getMethod("add", Integer.TYPE, Integer.TYPE);m4 = Class.forName("com.moomooyu.proxy.jdk.Calculator").getMethod("sub", Integer.TYPE, Integer.TYPE);m6 = Class.forName("com.moomooyu.proxy.jdk.Calculator").getMethod("div", Integer.TYPE, Integer.TYPE);m0 = Class.forName("java.lang.Object").getMethod("hashCode");} catch (NoSuchMethodException var2) {throw new NoSuchMethodError(var2.getMessage());} catch (ClassNotFoundException var3) {throw new NoClassDefFoundError(var3.getMessage());}}}
2.2 CGLib
Cglib的动态代理是面向父类实现的,和接口没有直接的关系。它不仅仅可以增强接口中定义的方法,还可以增强一个类其他的方法。同时,它还可以利用反射来读取父类方法上的所有注解。
2.2.1 示例
被代理类
/*** 自定义计算器** @author maomaochong* @date 2022/07/07 21:28**/public class MyCalculator {public int add(int i, int j) {return i + j;}public int sub(int i, int j) {return i - j;}public int mul(int i, int j) {return i * j;}public int div(int i, int j) {return i / j;}}
方法拦截器
/*** 计算器方法代理** @author maomaochong* @date 2022/07/07 21:29**/public class CalculatorProxy implements MethodInterceptor {/*** Object o:代理类对象* Method method:拦截方法* Object[] objects:入参* MethodProxy methodProxy:未被拦截方法,super方法***/@Overridepublic Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {System.out.println("方法执行之前。。。");Object result = methodProxy.invokeSuper(o, objects);System.out.println("方法执行之后。。。");return result;}}
测试类
/*** cglib动态代理测试类** @author maomaochong* @date 2022/07/07 21:36**/public class CglibProxyTest {public static void main(String[] args) {// 生成代理类文件System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY, "E:\\Workspace\\Study\\thinking-in-spring");// 创建cglib获取代理对象的操作对象Enhancer enhancer = new Enhancer();// 设置enhancer对象的父类enhancer.setSuperclass(MyCalculator.class);// 设置enhancer的回调对象enhancer.setCallback(new CalculatorProxy());// 创建代理对象MyCalculator myCalculator = (MyCalculator) enhancer.create();myCalculator.add(1, 1);System.out.println(myCalculator.getClass());}}
2.2.2 源码分析
public Object create() {classOnly = false;argumentTypes = null;return createHelper();}
private Object createHelper() {validate();if (superclass != null) {setNamePrefix(superclass.getName());} else if (interfaces != null) {setNamePrefix(interfaces[ReflectUtils.findPackageProtected(interfaces)].getName());}// KEY_FACTORY.newInstance():生成了一个EnhancerKey代理对象,该代理对象里面保存了用户所设置的代理信息// super.create():去创建代理对象return super.create(KEY_FACTORY.newInstance((superclass != null) ? superclass.getName() : null,ReflectUtils.getNames(interfaces),filter,callbackTypes,useFactory,interceptDuringConstruction,serialVersionUID));}
protected Object create(Object key) {try {Class gen = null;synchronized (source) {ClassLoader loader = getClassLoader();Map cache2 = null;cache2 = (Map)source.cache.get(loader);if (cache2 == null) {cache2 = new HashMap();cache2.put(NAME_KEY, new HashSet());source.cache.put(loader, cache2);} else if (useCache) {Reference ref = (Reference)cache2.get(key);gen = (Class) (( ref == null ) ? null : ref.get());}if (gen == null) {Object save = CURRENT.get();CURRENT.set(this);try {this.key = key;if (attemptLoad) {try {gen = loader.loadClass(getClassName());} catch (ClassNotFoundException e) {// ignore}}if (gen == null) {// 使用策略生成代理类byte[] b = strategy.generate(this);String className = ClassNameReader.getClassName(new ClassReader(b));getClassNameCache(loader).add(className);gen = ReflectUtils.defineClass(className, b, loader);}// 如果使用缓存,就把生成的代理类加入缓存if (useCache) {cache2.put(key, new WeakReference(gen));}// 调用代理类的构造方法生成一个代理对象return firstInstance(gen);} finally {CURRENT.set(save);}}}return firstInstance(gen);} catch (RuntimeException e) {throw e;} catch (Error e) {throw e;} catch (Exception e) {throw new CodeGenerationException(e);}}
public byte[] generate(ClassGenerator cg) throws Exception {DebuggingClassWriter cw = getClassVisitor();transform(cg).generateClass(cw);return transform(cw.toByteArray());}
// import org.objectweb.asm.ClassWriter;// 使用asm技术生成protected DebuggingClassWriter getClassVisitor() throws Exception {return new DebuggingClassWriter(ClassWriter.COMPUTE_MAXS);}
public void generateClass(ClassVisitor v) throws Exception {Class sc = (superclass == null) ? Object.class : superclass;// 被代理类是final,不能有自类,所以抛异常if (TypeUtils.isFinal(sc.getModifiers()))throw new IllegalArgumentException("Cannot subclass final class " + sc);List constructors = new ArrayList(Arrays.asList(sc.getDeclaredConstructors()));filterConstructors(sc, constructors);// Order is very important: must add superclass, then// its superclass chain, then each interface and// its superinterfaces.List actualMethods = new ArrayList();List interfaceMethods = new ArrayList();final Set forcePublic = new HashSet();// sc表示superclass,拿到父类或接口中所有的方法getMethods(sc, interfaces, actualMethods, interfaceMethods, forcePublic);List methods = CollectionUtils.transform(actualMethods, new Transformer() {public Object transform(Object value) {Method method = (Method)value;int modifiers = Constants.ACC_FINAL| (method.getModifiers()& ~Constants.ACC_ABSTRACT& ~Constants.ACC_NATIVE& ~Constants.ACC_SYNCHRONIZED);if (forcePublic.contains(MethodWrapper.create(method))) {modifiers = (modifiers & ~Constants.ACC_PROTECTED) | Constants.ACC_PUBLIC;}return ReflectUtils.getMethodInfo(method, modifiers);}});ClassEmitter e = new ClassEmitter(v);// 生成类,继承父类,实现接口e.begin_class(Constants.V1_2,Constants.ACC_PUBLIC,// 获取代理类名称getClassName(),Type.getType(sc),(useFactory ?TypeUtils.add(TypeUtils.getTypes(interfaces), FACTORY) :TypeUtils.getTypes(interfaces)),Constants.SOURCE_FILE);// 生成构造方法,父类有什么构造方法,子类就有什么构造方法List constructorInfo = CollectionUtils.transform(constructors, MethodInfoTransformer.getInstance());// 生成cglib自己所需要的字段e.declare_field(Constants.ACC_PRIVATE, BOUND_FIELD, Type.BOOLEAN_TYPE, null);if (!interceptDuringConstruction) {e.declare_field(Constants.ACC_PRIVATE, CONSTRUCTED_FIELD, Type.BOOLEAN_TYPE, null);}e.declare_field(Constants.PRIVATE_FINAL_STATIC, THREAD_CALLBACKS_FIELD, THREAD_LOCAL, null);e.declare_field(Constants.PRIVATE_FINAL_STATIC, STATIC_CALLBACKS_FIELD, CALLBACK_ARRAY, null);if (serialVersionUID != null) {e.declare_field(Constants.PRIVATE_FINAL_STATIC, Constants.SUID_FIELD_NAME, Type.LONG_TYPE, serialVersionUID);}// 根据设置的callback生成对应字段,用来设置代理对象用有用的callbackfor (int i = 0; i < callbackTypes.length; i++) {e.declare_field(Constants.ACC_PRIVATE, getCallbackField(i), callbackTypes[i], null);}emitMethods(e, methods, actualMethods);emitConstructors(e, constructorInfo);emitSetThreadCallbacks(e);emitSetStaticCallbacks(e);emitBindCallbacks(e);if (useFactory) {int[] keys = getCallbackKeys();emitNewInstanceCallbacks(e);emitNewInstanceCallback(e);emitNewInstanceMultiarg(e, constructorInfo);emitGetCallback(e, keys);emitSetCallback(e, keys);emitGetCallbacks(e);emitSetCallbacks(e);}e.end_class();}
protected Object firstInstance(Class type) throws Exception {if (classOnly) {return type;} else {return createUsingReflection(type);}}
private Object createUsingReflection(Class type) {// 设置回调方法setThreadCallbacks(type, callbacks);try{if (argumentTypes != null) {return ReflectUtils.newInstance(type, argumentTypes, arguments);} else {return ReflectUtils.newInstance(type);}}finally{// clear thread callbacks to allow them to be gc'dsetThreadCallbacks(type, null);}}
private static void setThreadCallbacks(Class type, Callback[] callbacks) {setCallbacksHelper(type, callbacks, SET_THREAD_CALLBACKS_NAME);}private static void setCallbacksHelper(Class type, Callback[] callbacks, String methodName) {// TODO: optimizetry {// 获取到对应的方法Method setter = getCallbacksSetter(type, methodName);// 静态方法执行,并传入回调方法setter.invoke(null, new Object[]{ callbacks });} catch (NoSuchMethodException e) {throw new IllegalArgumentException(type + " is not an enhanced class");} catch (IllegalAccessException e) {throw new CodeGenerationException(e);} catch (InvocationTargetException e) {throw new CodeGenerationException(e);}}
生成具体的代理类文件
在测试类中配置环境参数,指定文件生成位置:
// 生成代理类文件System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY, "生成路径");
生成文件:
//// Source code recreated from a .class file by IntelliJ IDEA// (powered by FernFlower decompiler)//package com.moomooyu.proxy.cglib;import java.lang.reflect.Method;import net.sf.cglib.core.ReflectUtils;import net.sf.cglib.core.Signature;import net.sf.cglib.proxy.Callback;import net.sf.cglib.proxy.Factory;import net.sf.cglib.proxy.MethodInterceptor;import net.sf.cglib.proxy.MethodProxy;public class MyCalculator$$EnhancerByCGLIB$$5f866cd3 extends MyCalculator implements Factory {private boolean CGLIB$BOUND;private static final ThreadLocal CGLIB$THREAD_CALLBACKS;private static final Callback[] CGLIB$STATIC_CALLBACKS;private MethodInterceptor CGLIB$CALLBACK_0;private static final Method CGLIB$add$0$Method;private static final MethodProxy CGLIB$add$0$Proxy;private static final Object[] CGLIB$emptyArgs;private static final Method CGLIB$div$1$Method;private static final MethodProxy CGLIB$div$1$Proxy;private static final Method CGLIB$sub$2$Method;private static final MethodProxy CGLIB$sub$2$Proxy;private static final Method CGLIB$mul$3$Method;private static final MethodProxy CGLIB$mul$3$Proxy;private static final Method CGLIB$finalize$4$Method;private static final MethodProxy CGLIB$finalize$4$Proxy;private static final Method CGLIB$equals$5$Method;private static final MethodProxy CGLIB$equals$5$Proxy;private static final Method CGLIB$toString$6$Method;private static final MethodProxy CGLIB$toString$6$Proxy;private static final Method CGLIB$hashCode$7$Method;private static final MethodProxy CGLIB$hashCode$7$Proxy;private static final Method CGLIB$clone$8$Method;private static final MethodProxy CGLIB$clone$8$Proxy;static void CGLIB$STATICHOOK1() {CGLIB$THREAD_CALLBACKS = new ThreadLocal();CGLIB$emptyArgs = new Object[0];Class var0 = Class.forName("com.moomooyu.proxy.cglib.MyCalculator$$EnhancerByCGLIB$$5f866cd3");Class var1;Method[] var10000 = ReflectUtils.findMethods(new String[]{"add", "(II)I", "div", "(II)I", "sub", "(II)I", "mul", "(II)I"}, (var1 = Class.forName("com.moomooyu.proxy.cglib.MyCalculator")).getDeclaredMethods());CGLIB$add$0$Method = var10000[0];CGLIB$add$0$Proxy = MethodProxy.create(var1, var0, "(II)I", "add", "CGLIB$add$0");CGLIB$div$1$Method = var10000[1];CGLIB$div$1$Proxy = MethodProxy.create(var1, var0, "(II)I", "div", "CGLIB$div$1");CGLIB$sub$2$Method = var10000[2];CGLIB$sub$2$Proxy = MethodProxy.create(var1, var0, "(II)I", "sub", "CGLIB$sub$2");CGLIB$mul$3$Method = var10000[3];CGLIB$mul$3$Proxy = MethodProxy.create(var1, var0, "(II)I", "mul", "CGLIB$mul$3");var10000 = ReflectUtils.findMethods(new String[]{"finalize", "()V", "equals", "(Ljava/lang/Object;)Z", "toString", "()Ljava/lang/String;", "hashCode", "()I", "clone", "()Ljava/lang/Object;"}, (var1 = Class.forName("java.lang.Object")).getDeclaredMethods());CGLIB$finalize$4$Method = var10000[0];CGLIB$finalize$4$Proxy = MethodProxy.create(var1, var0, "()V", "finalize", "CGLIB$finalize$4");CGLIB$equals$5$Method = var10000[1];CGLIB$equals$5$Proxy = MethodProxy.create(var1, var0, "(Ljava/lang/Object;)Z", "equals", "CGLIB$equals$5");CGLIB$toString$6$Method = var10000[2];CGLIB$toString$6$Proxy = MethodProxy.create(var1, var0, "()Ljava/lang/String;", "toString", "CGLIB$toString$6");CGLIB$hashCode$7$Method = var10000[3];CGLIB$hashCode$7$Proxy = MethodProxy.create(var1, var0, "()I", "hashCode", "CGLIB$hashCode$7");CGLIB$clone$8$Method = var10000[4];CGLIB$clone$8$Proxy = MethodProxy.create(var1, var0, "()Ljava/lang/Object;", "clone", "CGLIB$clone$8");}final int CGLIB$add$0(int var1, int var2) {return super.add(var1, var2);}public final int add(int var1, int var2) {MethodInterceptor var10000 = this.CGLIB$CALLBACK_0;if (var10000 == null) {CGLIB$BIND_CALLBACKS(this);var10000 = this.CGLIB$CALLBACK_0;}if (var10000 != null) {Object var3 = var10000.intercept(this, CGLIB$add$0$Method, new Object[]{new Integer(var1), new Integer(var2)}, CGLIB$add$0$Proxy);return var3 == null ? 0 : ((Number)var3).intValue();} else {return super.add(var1, var2);}}final int CGLIB$div$1(int var1, int var2) {return super.div(var1, var2);}public final int div(int var1, int var2) {MethodInterceptor var10000 = this.CGLIB$CALLBACK_0;if (var10000 == null) {CGLIB$BIND_CALLBACKS(this);var10000 = this.CGLIB$CALLBACK_0;}if (var10000 != null) {Object var3 = var10000.intercept(this, CGLIB$div$1$Method, new Object[]{new Integer(var1), new Integer(var2)}, CGLIB$div$1$Proxy);return var3 == null ? 0 : ((Number)var3).intValue();} else {return super.div(var1, var2);}}final int CGLIB$sub$2(int var1, int var2) {return super.sub(var1, var2);}public final int sub(int var1, int var2) {MethodInterceptor var10000 = this.CGLIB$CALLBACK_0;if (var10000 == null) {CGLIB$BIND_CALLBACKS(this);var10000 = this.CGLIB$CALLBACK_0;}if (var10000 != null) {Object var3 = var10000.intercept(this, CGLIB$sub$2$Method, new Object[]{new Integer(var1), new Integer(var2)}, CGLIB$sub$2$Proxy);return var3 == null ? 0 : ((Number)var3).intValue();} else {return super.sub(var1, var2);}}final int CGLIB$mul$3(int var1, int var2) {return super.mul(var1, var2);}public final int mul(int var1, int var2) {MethodInterceptor var10000 = this.CGLIB$CALLBACK_0;if (var10000 == null) {CGLIB$BIND_CALLBACKS(this);var10000 = this.CGLIB$CALLBACK_0;}if (var10000 != null) {Object var3 = var10000.intercept(this, CGLIB$mul$3$Method, new Object[]{new Integer(var1), new Integer(var2)}, CGLIB$mul$3$Proxy);return var3 == null ? 0 : ((Number)var3).intValue();} else {return super.mul(var1, var2);}}final void CGLIB$finalize$4() throws Throwable {super.finalize();}protected final void finalize() throws Throwable {MethodInterceptor var10000 = this.CGLIB$CALLBACK_0;if (var10000 == null) {CGLIB$BIND_CALLBACKS(this);var10000 = this.CGLIB$CALLBACK_0;}if (var10000 != null) {var10000.intercept(this, CGLIB$finalize$4$Method, CGLIB$emptyArgs, CGLIB$finalize$4$Proxy);} else {super.finalize();}}final boolean CGLIB$equals$5(Object var1) {return super.equals(var1);}public final boolean equals(Object var1) {MethodInterceptor var10000 = this.CGLIB$CALLBACK_0;if (var10000 == null) {CGLIB$BIND_CALLBACKS(this);var10000 = this.CGLIB$CALLBACK_0;}if (var10000 != null) {Object var2 = var10000.intercept(this, CGLIB$equals$5$Method, new Object[]{var1}, CGLIB$equals$5$Proxy);return var2 == null ? false : (Boolean)var2;} else {return super.equals(var1);}}final String CGLIB$toString$6() {return super.toString();}public final String toString() {MethodInterceptor var10000 = this.CGLIB$CALLBACK_0;if (var10000 == null) {CGLIB$BIND_CALLBACKS(this);var10000 = this.CGLIB$CALLBACK_0;}return var10000 != null ? (String)var10000.intercept(this, CGLIB$toString$6$Method, CGLIB$emptyArgs, CGLIB$toString$6$Proxy) : super.toString();}final int CGLIB$hashCode$7() {return super.hashCode();}public final int hashCode() {MethodInterceptor var10000 = this.CGLIB$CALLBACK_0;if (var10000 == null) {CGLIB$BIND_CALLBACKS(this);var10000 = this.CGLIB$CALLBACK_0;}if (var10000 != null) {Object var1 = var10000.intercept(this, CGLIB$hashCode$7$Method, CGLIB$emptyArgs, CGLIB$hashCode$7$Proxy);return var1 == null ? 0 : ((Number)var1).intValue();} else {return super.hashCode();}}final Object CGLIB$clone$8() throws CloneNotSupportedException {return super.clone();}protected final Object clone() throws CloneNotSupportedException {MethodInterceptor var10000 = this.CGLIB$CALLBACK_0;if (var10000 == null) {CGLIB$BIND_CALLBACKS(this);var10000 = this.CGLIB$CALLBACK_0;}return var10000 != null ? var10000.intercept(this, CGLIB$clone$8$Method, CGLIB$emptyArgs, CGLIB$clone$8$Proxy) : super.clone();}public static MethodProxy CGLIB$findMethodProxy(Signature var0) {String var10000 = var0.toString();switch(var10000.hashCode()) {case -2131682232:if (var10000.equals("sub(II)I")) {return CGLIB$sub$2$Proxy;}break;case -1574182249:if (var10000.equals("finalize()V")) {return CGLIB$finalize$4$Proxy;}break;case -1287932281:if (var10000.equals("add(II)I")) {return CGLIB$add$0$Proxy;}break;case -508378822:if (var10000.equals("clone()Ljava/lang/Object;")) {return CGLIB$clone$8$Proxy;}break;case 303407255:if (var10000.equals("div(II)I")) {return CGLIB$div$1$Proxy;}break;case 582649156:if (var10000.equals("mul(II)I")) {return CGLIB$mul$3$Proxy;}break;case 1826985398:if (var10000.equals("equals(Ljava/lang/Object;)Z")) {return CGLIB$equals$5$Proxy;}break;case 1913648695:if (var10000.equals("toString()Ljava/lang/String;")) {return CGLIB$toString$6$Proxy;}break;case 1984935277:if (var10000.equals("hashCode()I")) {return CGLIB$hashCode$7$Proxy;}}return null;}public MyCalculator$$EnhancerByCGLIB$$5f866cd3() {CGLIB$BIND_CALLBACKS(this);}public static void CGLIB$SET_THREAD_CALLBACKS(Callback[] var0) {CGLIB$THREAD_CALLBACKS.set(var0);}public static void CGLIB$SET_STATIC_CALLBACKS(Callback[] var0) {CGLIB$STATIC_CALLBACKS = var0;}private static final void CGLIB$BIND_CALLBACKS(Object var0) {MyCalculator$$EnhancerByCGLIB$$5f866cd3 var1 = (MyCalculator$$EnhancerByCGLIB$$5f866cd3)var0;if (!var1.CGLIB$BOUND) {var1.CGLIB$BOUND = true;Object var10000 = CGLIB$THREAD_CALLBACKS.get();if (var10000 == null) {var10000 = CGLIB$STATIC_CALLBACKS;if (var10000 == null) {return;}}var1.CGLIB$CALLBACK_0 = (MethodInterceptor)((Callback[])var10000)[0];}}public Object newInstance(Callback[] var1) {CGLIB$SET_THREAD_CALLBACKS(var1);MyCalculator$$EnhancerByCGLIB$$5f866cd3 var10000 = new MyCalculator$$EnhancerByCGLIB$$5f866cd3();CGLIB$SET_THREAD_CALLBACKS((Callback[])null);return var10000;}public Object newInstance(Callback var1) {CGLIB$SET_THREAD_CALLBACKS(new Callback[]{var1});MyCalculator$$EnhancerByCGLIB$$5f866cd3 var10000 = new MyCalculator$$EnhancerByCGLIB$$5f866cd3();CGLIB$SET_THREAD_CALLBACKS((Callback[])null);return var10000;}public Object newInstance(Class[] var1, Object[] var2, Callback[] var3) {CGLIB$SET_THREAD_CALLBACKS(var3);MyCalculator$$EnhancerByCGLIB$$5f866cd3 var10000 = new MyCalculator$$EnhancerByCGLIB$$5f866cd3;switch(var1.length) {case 0:var10000.<init>();CGLIB$SET_THREAD_CALLBACKS((Callback[])null);return var10000;default:throw new IllegalArgumentException("Constructor not found");}}public Callback getCallback(int var1) {CGLIB$BIND_CALLBACKS(this);MethodInterceptor var10000;switch(var1) {case 0:var10000 = this.CGLIB$CALLBACK_0;break;default:var10000 = null;}return var10000;}public void setCallback(int var1, Callback var2) {switch(var1) {case 0:this.CGLIB$CALLBACK_0 = (MethodInterceptor)var2;default:}}public Callback[] getCallbacks() {CGLIB$BIND_CALLBACKS(this);return new Callback[]{this.CGLIB$CALLBACK_0};}public void setCallbacks(Callback[] var1) {this.CGLIB$CALLBACK_0 = (MethodInterceptor)var1[0];}static {CGLIB$STATICHOOK1();}}
