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 2018/12/07 07:22:25 UTC

[GitHub] wu-sheng closed pull request #2016: fix classloader dead lock in jdk7+

wu-sheng closed pull request #2016: fix classloader dead lock in jdk7+
URL: https://github.com/apache/incubator-skywalking/pull/2016
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/loader/AgentClassLoader.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/loader/AgentClassLoader.java
index 638fed0b3..42c209fe5 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/loader/AgentClassLoader.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/loader/AgentClassLoader.java
@@ -23,6 +23,7 @@
 import java.io.File;
 import java.io.FilenameFilter;
 import java.io.IOException;
+import java.lang.reflect.Method;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Enumeration;
@@ -45,6 +46,11 @@
  * @author wusheng
  */
 public class AgentClassLoader extends ClassLoader {
+
+    static {
+        tryRegisterAsParallelCapable();
+    }
+
     private static final ILog logger = LogManager.getLogger(AgentClassLoader.class);
     /**
      * The default class loader for the agent.
@@ -55,6 +61,27 @@
     private List<Jar> allJars;
     private ReentrantLock jarScanLock = new ReentrantLock();
 
+    /**
+     * Functional Description: solve the classloader dead lock when jvm start
+     * only support JDK7+, since ParallelCapable appears in JDK7+
+     */
+    private static void tryRegisterAsParallelCapable() {
+        Method[] methods = ClassLoader.class.getDeclaredMethods();
+        for (int i = 0; i < methods.length; i++) {
+            Method method = methods[i];
+            String methodName = method.getName();
+            if ("registerAsParallelCapable".equalsIgnoreCase(methodName)) {
+                try {
+                    method.setAccessible(true);
+                    method.invoke(null);
+                } catch (Exception e) {
+                    logger.warn(e, "can not invoke ClassLoader.registerAsParallelCapable()");
+                }
+                return;
+            }
+        }
+    }
+
     public static AgentClassLoader getDefault() {
         return DEFAULT_LOADER;
     }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services