8134030: test/serviceability/dcmd/gc/HeapDumpTest fails to verify the dump

Reviewed-by: dholmes
diff --git a/hotspot/src/share/vm/services/heapDumper.cpp b/hotspot/src/share/vm/services/heapDumper.cpp
index 44ef64c..73d786e 100644
--- a/hotspot/src/share/vm/services/heapDumper.cpp
+++ b/hotspot/src/share/vm/services/heapDumper.cpp
@@ -897,8 +897,10 @@
 void DumperSupport::dump_class_and_array_classes(DumpWriter* writer, Klass* k) {
   InstanceKlass* ik = InstanceKlass::cast(k);
 
-  // Ignore the class if it hasn't been initialized yet
-  if (!ik->is_linked()) {
+  // We can safepoint and do a heap dump at a point where we have a Klass,
+  // but no java mirror class has been setup for it. So we need to check
+  // that the class is at least loaded, to avoid crash from a null mirror.
+  if (!ik->is_loaded()) {
     return;
   }
 
diff --git a/hotspot/test/serviceability/dcmd/gc/HeapDumpTest.java b/hotspot/test/serviceability/dcmd/gc/HeapDumpTest.java
index cadf3ef..20f766d 100644
--- a/hotspot/test/serviceability/dcmd/gc/HeapDumpTest.java
+++ b/hotspot/test/serviceability/dcmd/gc/HeapDumpTest.java
@@ -66,6 +66,7 @@
         String cmd = "GC.heap_dump " + heapDumpArgs + " " + dump.getAbsolutePath();
         executor.execute(cmd);
 
+        verifyHeapDump(dump);
         dump.delete();
     }