jvm-sandbox UnsupportedOperationException
在使用基于 jvm-sandbox 的agent chaosblade-jvm-exec 的attach java进程的时候,发现某些 AOP 切点无法被正常切到,错误如下
java.lang.unsupportedoperationexception: class redefinition failed: attempted to change superclass or interfaces
经过排查是跟公司内部的其他 java agent 有冲突导致的,另外一个 agent 使用 ByteBuddy 进行字节码增强的。
经过中间件同学的排查和相关资料的搜索,发现在 Arthas 和 skywalking agent之间也存在类似的问题。
相关issue如下
- https://github.com/alibaba/arthas/issues/1502
- https://github.com/alibaba/arthas/issues/1141
- https://github.com/apache/skywalking/blob/master/docs/en/FAQ/Compatible-with-other-javaagent-bytecode-processing.md
从最后一个链接能看到pr作者的原因描述。
The SkyWalking agent uses ByteBuddy to transform classes when the Java application starts. ByteBuddy generates auxiliary classes with different random names every time.
When another Java agent retransforms the same class, it triggers the SkyWalking agent to enhance the class again. Since the bytecode has been regenerated by ByteBuddy, the fields and imported class names have been modified, and the JVM verifications on class bytecode have failed, the retransform classes would therefore be unsuccessful.
ByteBuddy 对同一个class进行多次 enhance,但是每次生成的辅助类又不一样,加了一个缓存,这样就避免多次 增强。