wu-sheng commented on a change in pull request #4858: URL: https://github.com/apache/skywalking/pull/4858#discussion_r448051948
########## File path: docs/en/FAQ/Compatible-with-other-javaagent-bytecode-processing.md ########## @@ -0,0 +1,53 @@ +## Compatible with other javaagent bytecode processing + +### Problem +1. when use skywalking agent, arthas can't work well +https://github.com/apache/skywalking/pull/4858 + +2. Custom java agent retransform class fails with Skywalking agent + https://github.com/hengyunabc/skywalking-error-demo + +### Reason +Skywalking agent uses ByteBuddy to retransform classes when java application starts. +ByteBuddy generates auxiliary classes with different random names every time. + +When other javaagent retransforms the same class, it will trigger the SkyWalking agent to enhance the class again. +The bytecode regenerated by ByteBuddy is changed, the fields and imports are modified, the jvm verifys class bytecode failed, and the retransform fails. + + +### Resolve + +**1.Enable the class cache feature** + +Add JVM parameters: +`-Dskywalking.agent.is_cache_enhanced_class=true -Dskywalking.agent.class_cache_mode=MEMORY` + +Or uncomment options in `agent.conf`: + +``` +# If true, SkyWalking agent will cache all instrumented classes files to memory or disk files (decided by class cache mode), +# allow other javaagent to enhance those classes that enhanced by SkyWalking agent. +agent.is_cache_enhanced_class = ${SW_AGENT_CACHE_CLASS:false} + +# The instrumented classes cache mode: MEMORY or FILE +# MEMORY: cache class bytes to memory, if instrumented classes is too many or too large, it may take up more memory +# FILE: cache class bytes to user temp folder starts with 'class-cache', automatically clean up cached class files when the application exits +agent.class_cache_mode = ${SW_AGENT_CLASS_CACHE_MODE:MEMORY} + +``` + +If the class cahce feature is enabled, save the class bytecode of the ByteBuddy retransform to memory or a temporary file. +When other java agents retransform the same class, Skywalking agent first attempts to load from the cache. + +If the cached class is found, it will be used directly without regenerating a new random name auxiliary class, +which will not affect the processing of the subsequent java agent. + +**2.Class cache save mode** +It is recommended to put the cache class in memory, but if it takes up more memory, it should be placed in a temporary file. Set the class cache save mode through the following options: Review comment: ```suggestion It is recommended to put the cache class in memory, meanwhile if it costs more memory resources. Another option is using the local file system. Set the class cache mode through the following options: ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org