Package org.hotswap.agent.plugin.jvm
Class AnonymousClassPatchPlugin
- java.lang.Object
-
- org.hotswap.agent.plugin.jvm.AnonymousClassPatchPlugin
-
@Plugin(name="AnonymousClassPatch", description="Swap anonymous inner class names to avoid not compatible changes.", testedVersions="DCEVM") public class AnonymousClassPatchPlugin extends Object
Class names MyClass$1, MyClass$2 are created in the order as anonymous class appears in the source code. After anonymous class insertion/deletion the indexes are shifted producing not compatible hot swap. This patch will create class state info before the change (from current ClassLoader via reflection) and after the change (from filesystem using javassist) find all compatible transitions. For example if you exchange order the anonymous class appears in the source code, Transition may produce something like:- MyClass$1 -> MyClass$2
- MyClass$2 -> MyClass$3
- MyClass$3 -> MyClass$1
- When the class MyClass$1 is hot swapped, the bytecode from MyClass$2 is returned (and renamed to MyClass$1)
- When the class MyClass$2 is hot swapped, the bytecode from MyClass$3 is returned (and renamed to MyClass$2)
- When the class MyClass$3 is hot swapped, the bytecode from MyClass$1 is returned (and renamed to MyClass$3)
- When the class MyClass is hot swapped, all occurences of MyClass$1 are exchanged for MyClass$3
- , all occurences of MyClass$2 are exchanged for MyClass$1
- , all occurences of MyClass$3 are exchanged for MyClass$2
- Author:
- Jiri Bubnik
-
-
Constructor Summary
Constructors Constructor Description AnonymousClassPatchPlugin()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static CtClasspatchAnonymousClass(ClassLoader classLoader, ClassPool classPool, String className, Class original)Replace an anonymous class with an compatible change (from another class according to state info).static byte[]patchMainClass(String className, ClassPool classPool, CtClass ctClass, ClassLoader classLoader, ProtectionDomain protectionDomain)If class contains anonymous classes, rename class references to compatible transition classes.
-
-
-
Method Detail
-
patchAnonymousClass
@OnClassLoadEvent(classNameRegexp=".*\\$\\d+", events=REDEFINE) public static CtClass patchAnonymousClass(ClassLoader classLoader, ClassPool classPool, String className, Class original) throws IOException, NotFoundException, CannotCompileException
Replace an anonymous class with an compatible change (from another class according to state info). If no compatible class exists, replace with compatible empty implementation.
-
patchMainClass
@OnClassLoadEvent(classNameRegexp=".*", events=REDEFINE) public static byte[] patchMainClass(String className, ClassPool classPool, CtClass ctClass, ClassLoader classLoader, ProtectionDomain protectionDomain) throws IOException, CannotCompileException, NotFoundException
If class contains anonymous classes, rename class references to compatible transition classes. If the transitioned class is not loaded by hotswap replace, catch class define event to do the replacement. Define new synthetic classes for not compatible changes.
-
-