Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8253280

Use class name as class loading lock

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
      None

      Description

      On behalf of robert.lyb@alibaba-inc.com

      When many thread try to load same class, the thread will stuck on ClassLoader.loadClass.
      At current jdk, the stacktrace is:

      ```
      "Thread-4" prio=5 Id=15 BLOCKED on java.lang.Object@b4c966a owned by "Thread-2" Id=13
      at java.base@14.0.2/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:612)
      - blocked on java.lang.Object@b4c966a
      at java.base@14.0.2/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:600)
      at java.base@14.0.2/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
      at java.base@14.0.2/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
      at app//Main.test(Main.java:18)
      at app//Main$$Lambda$5/0x0000000800b64c40.run(Unknown Source)
      at java.base@14.0.2/java.lang.Thread.run(Thread.java:832)

      output by Main.java
      ```

      It's not easy to get which class stuck the thread.

      If there is a method to get locked Object, and print it in stacktrace, like this:

      ```
      "Thread-2" prio=5 Id=13 BLOCKED on java.lang.String@724af044 owned by "Thread-3" Id=14
      at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:612)
      - blocked on java.lang.String@724af044 val="java.lang.String" --- this String is classname
      at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:600)
      at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
      at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
      at app//Main2.test(Main2.java:18)
      at app//Main2$$Lambda$38/0x0000000100097440.run(Unknown Source)
      at java.base/java.lang.Thread.run(Thread.java:832)


      output by Main2.java
      ```

      That is, user will know which class stuck the thread, in this example, the class is java.lang.String. It's helpful for troubleshooting.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              ddong Denghui Dong
              Reporter:
              ddong Denghui Dong
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: