JDK-8080852 : Java heap dump doesn't contain klass mirror objects unless they are explicitly referenced
  • Type: Bug
  • Component: hotspot
  • Sub-Component: svc
  • Affected Version: 9
  • Priority: P3
  • Status: Closed
  • Resolution: Cannot Reproduce
  • Submitted: 2015-05-21
  • Updated: 2019-05-22
  • Resolved: 2017-08-29
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 10
10Resolved
Related Reports
Relates :  
Relates :  
Description
VM doesn't dump Java class mirror objects unless they are part of root set or referenced from other Java objects. It means that for most classes their mirrors are absent in a heap dump. Since mirror object contains reference fields, its referents are shown as dangling objects (no incoming refs).
Comments
Anonymous class mirrors are dumped after this change, so you would have seen them when you filed this bug. changeset: 5452:539144972c1e parent: 5450:e831448418ac user: sla date: Fri Oct 11 14:08:02 2013 +0200 summary: 8024425: VM_HeapDumper doesn't put anonymous classes in the heap dump I don't see this problem inspecting the hprof file with yourkit. I also compared this with the jdk7 heap dumper to see if we dropped anything but there is no differences wrt classes reported. We should have gotten all the mirrors. I'm going to close this as CNR and work on the resolved reference problem.
29-08-2017

[~coleenp] sorry, I forgot the details, but I vaguely remember I hit that when experimenting with a fix for JDK-8081323 which added a synthetic static field on class mirror for ConstantPool::_resolved_references array. In that case I still didn't see the mirror object when browsing the heap dump (so the _resolved_references array was still shown as dangling). I suspect the problem is specific to VM anonymous classes. As you noted, normal classes should be referenced from corresponding class loader.
29-08-2017

[~vlivanov] doesn't this suggested change change the HPROF format? Also class mirrors are dumped from the class_loader object, and from the CLD::classes_do() call. How do you observe what you found in this bug?
29-08-2017

Have no idea. It seems like a regression since 8.
29-04-2016

[~vlivanov] Is this a regression in 9?
29-04-2016

I did some experiments trying to fix the problem. Spotted a couple of issues: - mirror is used as class ID - there's no link recorded between mirror and it's class diff --git a/src/share/vm/services/heapDumper.cpp b/src/share/vm/services/heapDumper.cpp --- a/src/share/vm/services/heapDumper.cpp +++ b/src/share/vm/services/heapDumper.cpp @@ -433,6 +433,7 @@ void write_symbolID(Symbol* o); void write_classID(Klass* k); void write_id(u4 x); + void write_id(address a); }; DumpWriter::DumpWriter(const char* path) { @@ -575,12 +576,7 @@ } void DumpWriter::write_symbolID(Symbol* s) { - address a = (address)((uintptr_t)s); -#ifdef _LP64 - write_u8((u8)a); -#else - write_u4((u4)a); -#endif + write_id((address)((uintptr_t)s)); } void DumpWriter::write_id(u4 x) { @@ -591,9 +587,16 @@ #endif } -// We use java mirror as the class ID +void DumpWriter::write_id(address a) { +#ifdef _LP64 + write_u8((u8)a); +#else + write_u4((u4)a); +#endif +} + void DumpWriter::write_classID(Klass* k) { - write_objectID(k->java_mirror()); + write_id((address)((uintptr_t)k)); } @@ -933,6 +936,8 @@ // description of instance fields dump_instance_field_descriptors(writer, k); + dump_instance(writer, ik->java_mirror()); + // array classes k = klass->array_klass_or_null(); while (k != NULL) { @@ -959,6 +964,8 @@ writer->write_u2(0); // static fields writer->write_u2(0); // instance fields + dump_instance(writer, k->java_mirror()); + // get the array class for the next rank k = klass->array_klass_or_null(); }
21-05-2015