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

Try to link all classes during dynamic CDS dump

XMLWordPrintable

    • b14

      Currently during dynamic archive dumping, we excluded all classes that are loaded but not yet linked.

      See http://hg.openjdk.java.net/jdk/jdk/file/23a06a5eeddd/src/hotspot/share/classfile/systemDictionaryShared.cpp#l1111

          // TODO -- rethink how this can be handled.
          // We should try to link ik, however, we can't do it here because
          // 1. We are at VM exit
          // 2. linking a class may cause other classes to be loaded, which means
          // a custom ClassLoader.loadClass() may be called, at a point where the
          // class loader doesn't expect it.

      We should investigate if it's possible to link the classes that are loaded by the built-in loaders.

      [update]
      There unlinked classes are usually loaded during verification. They are not linked because they are referenced only by methods that were never executed during dynamic dumping. Here's an example

      class Parent {
          int get() {return 1;}
      }

      class Child extends Parent {
          int get() {return 2;}
      }

      class LinkClassApp {
          public static void main(String args[]) {
              if (args.length > 0 && args[0].equals("run")) {
                  System.out.println("test() = " + test());
              } else {
                  // Executed during dynamic dumping.
                  System.out.println("Test.class is initialized.");
                  System.out.println("Parent.class and Child.class are loaded when Test.class is verified,");
                  System.out.println("but these two classes are not linked");
              }
          }

          static int test() {
              // Verification of Test.test() would load Child and Parent, and create a verification constraint that
              // Child must be a subtype of Parent.
              //
              // Child and Parent are not linked until Test.test() is actually executed.
              Parent x = new Child();
              return x.get();
          }
      }

      The "Child" and "Parent" classes are loaded during verification but never linked.

      Note that the LinkClassApp has been verified during dump time, so we can skip most of the bytecode verification steps during run time. However, when LinkClassApp is linked at run time, Child/Parent will be resolved to ensure that Child is still a subclass of Parent (otherwise the bytecodes in LinkClassApp.test() will be invalid). This is done here:

      http://hg.openjdk.java.net/jdk/jdk/file/0edc7fd0d7a3/src/hotspot/share/classfile/systemDictionaryShared.cpp#l1267

      Before this RFE, Child/Parent will be loaded from classfiles, which slows down the link time of LinkClassApp.

            ccheung Calvin Cheung
            iklam Ioi Lam
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: