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

Heap dumps should exclude dormant CDS archived objects of unloaded classes

    XMLWordPrintable

Details

    • b15

    Backports

      Description

        Similar to JDK-8214756 -- when the JVM creates an hprof dump, it should exclude CDS archived objects whose class is not yet loaded. Otherwise the dumped hprof file would fail to load in heap analysis tools, such as Eclipse Memory Analyzer (MAT).

        public class HelloGC {
          public static void main(String ... args) throws Exception {
            if (args.length > 0) {
              loadArray("java.lang.Byte");
              loadArray("java.lang.Character");
              loadArray("java.lang.Integer");
              loadArray("java.lang.Long");
              loadArray("java.lang.Short");
              loadArray("java.util.HashMap$Node");
              loadArray("jdk.internal.math.FDBigInteger");
              loadArray("sun.util.locale.BaseLocale");
            }

            System.gc();
          }

          static void loadArray(String className) throws Exception {
            Class c = Class.forName(className);
            Object array = java.lang.reflect.Array.newInstance(c, 0);
            System.out.println(array);
          }
        }

        The following produces an hprof file that fails to load in Eclipse MAT with
        "Error: Found instance segment but expected class segment (see FAQ): 0x0". See java_pid8323.hprof in attachment.

        $ java -XX:+HeapDumpAfterFullGC HelloGC

        The problem can be worked around by explicitly loading the required classes before doing the heap dump. See java_pid32027.hprof in attachment.

        $ java -XX:+HeapDumpAfterFullGC HelloGC fixit

        Attachments

          1. java_pid32027.hprof
            5.95 MB
            Ioi Lam
          2. java_pid8323.hprof
            5.93 MB
            Ioi Lam

          Issue Links

            Activity

              People

                iklam Ioi Lam
                iklam Ioi Lam
                Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: