use of org.hotswap.agent.plugin.proxy.hscglib.GeneratorParams in project HotswapAgent by HotswapProjects.
the class ProxyPlugin method transformCglibProxy.
// @OnClassLoadEvent(classNameRegexp = "com/sun/proxy/\\$Proxy.*", events = LoadEvent.REDEFINE, skipSynthetic = false)
// public static byte[] transformJavaProxy(final Class<?> classBeingRedefined, final byte[] classfileBuffer,
// final ClassPool cp, final CtClass cc) throws IllegalClassFormatException, IOException, RuntimeException {
// try {
// return JavassistProxyTransformer.transform(classBeingRedefined, classfileBuffer, cc, cp);
// } catch (Exception e) {
// LOGGER.error("Error redifining Cglib proxy {}", e, classBeingRedefined.getName());
// }
// return classfileBuffer;
// }
// alternative method of redefining Java proxies, uses a new classlaoder instance
// @OnClassLoadEvent(classNameRegexp = "com/sun/proxy/\\$Proxy.*", events = LoadEvent.REDEFINE, skipSynthetic =
// false)
// public static byte[] transformJavaProxy(final Class<?> classBeingRedefined, final byte[] classfileBuffer,
// final ClassLoader loader) throws IllegalClassFormatException, IOException, RuntimeException {
// try {
// return NewClassLoaderJavaProxyTransformer.transform(classBeingRedefined, classfileBuffer, loader);
// } catch (Exception e) {
// LOGGER.error("Error redifining Cglib proxy {}", e, classBeingRedefined.getName());
// }
// return classfileBuffer;
// }
//
// // alternative method of redefining Java proxies, uses a 2 step process. Crashed with jvm8
// @OnClassLoadEvent(classNameRegexp = "com/sun/proxy/\\$Proxy.*", events = LoadEvent.REDEFINE, skipSynthetic =
// false)
// public static byte[] transformJavaProxy(final Class<?> classBeingRedefined, final byte[] classfileBuffer,
// final ClassPool cp) {
// try {
// return JavaProxyTransformer.transform(classBeingRedefined, cp, classfileBuffer);
// } catch (Exception e) {
// LOGGER.error("Error redifining Cglib proxy {}", e, classBeingRedefined.getName());
// }
// return classfileBuffer;
// }
@OnClassLoadEvent(classNameRegexp = ".*", events = LoadEvent.REDEFINE, skipSynthetic = false)
public static byte[] transformCglibProxy(final Class<?> classBeingRedefined, final byte[] classfileBuffer, final ClassLoader loader, final ClassPool cp) throws Exception {
GeneratorParams generatorParams = GeneratorParametersTransformer.getGeneratorParams(loader, classBeingRedefined.getName());
if (!ClassLoaderHelper.isClassLoderStarted(loader)) {
return classfileBuffer;
}
if (generatorParams == null) {
return classfileBuffer;
}
// flush standard java beans caches
loader.loadClass("java.beans.Introspector").getMethod("flushCaches").invoke(null);
if (generatorParams.getParam().getClass().getName().endsWith(".Enhancer")) {
try {
return CglibEnhancerProxyTransformer.transform(classBeingRedefined, cp, classfileBuffer, loader, generatorParams);
} catch (Exception e) {
LOGGER.error("Error redifining Cglib Enhancer proxy {}", e, classBeingRedefined.getName());
}
}
// Multistep transformation crashed jvm in java8 u05
if (!isJava8OrNewer)
try {
return CglibProxyTransformer.transform(classBeingRedefined, cp, classfileBuffer, generatorParams);
} catch (Exception e) {
LOGGER.error("Error redifining Cglib proxy {}", e, classBeingRedefined.getName());
}
return classfileBuffer;
}
Aggregations