JDK-8230674 : Heap dumps should exclude dormant CDS archived objects of unloaded classes
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 14
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2019-09-05
  • Updated: 2023-11-28
  • Resolved: 2019-09-11
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 14
11.0.13Fixed 14 b15Fixed
Related Reports
Relates :  
Relates :  
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
Comments
Fix Request (OpenJDK 11u): I'd like to backport this fix to OpenJDK 11u. Backport was created with the /backport commit command. Original patch applied cleanly. PR: https://github.com/openjdk/jdk11u-dev/pull/89 RFR: https://mail.openjdk.java.net/pipermail/jdk-updates-dev/2021-June/006740.html
30-06-2021

URL: https://hg.openjdk.java.net/jdk/jdk/rev/91bc4d6c4054 User: iklam Date: 2019-09-11 20:47:11 +0000
11-09-2019

This bug doesn't seem to affect JDK13 (at least not for Eclipse MAT). In JDK 14, JDK-8228507 added an array of type "[Ljdk.internal.math.FDBigInteger;" to the archived heap, which seems to cause the problem in MAT in the bug description.
10-09-2019