[Chaoblade]jvm-sandbox UnsupportedOperationException错误

Posted orangleliu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Chaoblade]jvm-sandbox UnsupportedOperationException错误相关的知识,希望对你有一定的参考价值。

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,但是每次生成的辅助类又不一样,加了一个缓存,这样就避免多次 增强。

以上是关于[Chaoblade]jvm-sandbox UnsupportedOperationException错误的主要内容,如果未能解决你的问题,请参考以下文章

[Chaoblade]jvm-sandbox UnsupportedOperationException错误

[Chaoblade]jvm-sandbox UnsupportedOperationException错误

ChaoBlade 的实现原理

ChaoBlade 的实现原理

ChaoBlade 的实现原理

[jvm-sandbox] 多个agent并用