You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2021/08/15 12:16:43 UTC

[GitHub] [skywalking] daimingzhi commented on issue #3661: "java -ext.dirs" is not supported

daimingzhi commented on issue #3661:
URL: https://github.com/apache/skywalking/issues/3661#issuecomment-899041830


   I built a demo for testing this case and found `-Xbootclasspath/a`  is  not able to resolve it
   
   you can found the demo in https://github.com/daimingzhi/skywalkingTestDemo.git
   
   I tested two scenarios:
   
   - enhance instance(intercept constructor of instance or intercept method of instance)
   - enhance class
   
   ## Scenario one
   
   In the first scenario, the application starts normally, but the enhancement did not take effect, and the following log can be found in file `skywalking-api.log`
   
   ```
   ERROR 2021-08-15 14:18:47:133 main SkyWalkingAgent : Enhance class com.easy4coding.jar.Person error. 
   org.apache.skywalking.apm.agent.core.plugin.PluginException: Can't create InstanceMethodsAroundInterceptor.
   	at org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstMethodsInter.<init>(InstMethodsInter.java:98)
   	at org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassEnhancePluginDefine.enhanceInstance(ClassEnhancePluginDefine.java:177)
   	at org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassEnhancePluginDefine.enhance(ClassEnhancePluginDefine.java:74)
   	at org.apache.skywalking.apm.agent.core.plugin.AbstractClassEnhancePluginDefine.define(AbstractClassEnhancePluginDefine.java:77)
   	at org.apache.skywalking.apm.agent.SkyWalkingAgent$Transformer.transform(SkyWalkingAgent.java:144)
   	at org.apache.skywalking.apm.dependencies.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.doTransform(AgentBuilder.java:10325)
   	at org.apache.skywalking.apm.dependencies.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.transform(AgentBuilder.java:10263)
   	at org.apache.skywalking.apm.dependencies.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.access$1600(AgentBuilder.java:10029)
   	at org.apache.skywalking.apm.dependencies.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer$LegacyVmDispatcher.run(AgentBuilder.java:10648)
   	at org.apache.skywalking.apm.dependencies.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer$LegacyVmDispatcher.run(AgentBuilder.java:10595)
   	at java.security.AccessController.doPrivileged(Native Method)
   	at org.apache.skywalking.apm.dependencies.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.transform(AgentBuilder.java:10186)
   	at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
   	at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
   	at java.lang.ClassLoader.defineClass1(Native Method)
   	at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
   	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
   	at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
   	at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
   	at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
   	at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
   	at java.security.AccessController.doPrivileged(Native Method)
   	at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
   	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
   	at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
   	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
   	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
   	at java.lang.Class.forName0(Native Method)
   	at java.lang.Class.forName(Class.java:264)
   	at com.easy4coding.agent.MainClass.main(MainClass.java:13)
   Caused by: java.lang.ClassNotFoundException: Can't find org.apache.skywalking.apm.plugin.tomcat78x.ExtNonStaticInterceptor
   	at org.apache.skywalking.apm.agent.core.plugin.loader.AgentClassLoader.findClass(AgentClassLoader.java:118)
   	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
   	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
   	at java.lang.Class.forName0(Native Method)
   	at java.lang.Class.forName(Class.java:348)
   	at org.apache.skywalking.apm.agent.core.plugin.loader.InterceptorInstanceLoader.load(InterceptorInstanceLoader.java:71)
   	at org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstMethodsInter.<init>(InstMethodsInter.java:96)
   	... 29 more
   ```
   
   I debugged the code to find more detailed messages.
   
   ![image-20210815143422388](https://gitee.com/easy4coding/blogImage/raw/master/image/image-20210815143422388.png)
   
   We used `AgentClassLoader` which parent classLoader is `ExtClassLoader`(because the class we wanted to enhance is loaded by `ExtClassLoader`), to load a Interceptor defined in `skywalking.jar`,but `skywalking.jar` is loader by `AppClassLoader`。Therefore,the load will fail with an `classNotFoundException` thrown
   
   ## Scenario two
   
   In the second scenario, the application starts failed.
   
   ![image-20210815174633818](https://gitee.com/easy4coding/blogImage/raw/master/image/image-20210815174633818.png)
   
   This is because, when a static method is enhanced, `ByteBuddy` generates a static field for the class. The field is of type `StaticMethodsInter`, which will be set approach by reflection and this behavior will trigger loading of `StaticMethodsInter`
   
   however,the enhanced class is loaded by `ExtClassLoader`,and it can not load `StaticMethodsInter`  from `skywalking.jar` .
   
   It can be seen from the above,use `BootstrapClassLoader` to load the class need to enhanced may not take effect。because, the same as `ExtClassLoader`,`BootstrapClassLoader` can not load any class from `skywalking.jar` .
   
   ![image-20210815192554254](https://gitee.com/easy4coding/blogImage/raw/master/image/image-20210815192554254.png)
   
   In my demo,I did like this to resolve this problem.
   
   ```java
   @Override
   public boolean isBootstrapInstrumentation() {
      return true;
   }
   ```
   
   Maybe skywalking can support some configuration to config default return value of this method instead of using  "false". For example, We can use `Plugin.BootstrapInstrumentation.dirs=apm-sniffer\apm-sdk-plugin\httpClient-4.x-plugin`  to make all  methods named `isBootstrapInstrumentation` in `apm-sniffer\apm-sdk-plugin\httpClient-4.x-plugin` directory return true。
   
   


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org