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

Classes used by CDS at runtime should be archived

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 24
    • None
    • hotspot
    • b18

      $ javac HelloWorld.java
      $ jar cf HelloWorld.jar HelloWorld.class
      $ java -Xshare:off -XX:DumpLoadedClassList=hw.classlist -cp HelloWorld.jar HelloWorld
      $ java -Xshare:dump -XX:SharedArchiveFile=hw.jsa -XX:SharedClassListFile=hw.classlist -cp HelloWorld.jar
      $ java -cp HelloWorld.jar -XX:SharedArchiveFile=hw.jsa -Xlog:class+load HelloWorld | grep class.load | grep -v shared.objects
      [0.248s][info][class,load] java.nio.file.FileSystems source: jrt:/java.base loader: boot_loader
      [0.248s][info][class,load] java.nio.file.FileSystems$DefaultFileSystemHolder source: jrt:/java.base loader: boot_loader
      [0.249s][info][class,load] java.nio.file.FileSystems$DefaultFileSystemHolder$1 source: jrt:/java.base loader: boot_loader
      [0.254s][info][class,load] java.net.URI$Parser source: jrt:/java.base loader: boot_loader
      ===================
      The above 4 classes are not loaded during the -XX:DumpLoadedClassList run. Instead, they are used only when the hw.jsa is loaded at runtime (when the CDS initialization code calls ClassLoaders::toFileURL()

      https://github.com/openjdk/jdk/blob/a474b37212da5edbd5868c9157aff90aae00ca50/src/hotspot/share/cds/cdsProtectionDomain.cpp#L207-L210

      ->

      https://github.com/openjdk/jdk/blame/a474b37212da5edbd5868c9157aff90aae00ca50/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java#L228C24-L237

          private static URL toFileURL(String s) {
              try {
                  // Use an intermediate File object to construct a URI/URL without
                  // authority component as URLClassPath can't handle URLs with a UNC
                  // server name in the authority component.
                  return Path.of(s).toRealPath().toFile().toURI().toURL();
              } catch (InvalidPathException | IOException ignore) {
                  // malformed path string or class path element does not exist
                  return null;
              }
      =====================
      Suggested fix:

      When dumping the CDS archive, the CDS code should make a dummy call to ClassLoaders::toFileURL(). This would ensure that all classes used by that method will be added to the CDS archive.

            matsaave Matias Saavedra Silva
            iklam Ioi Lam
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: