--- old/src/hotspot/share/memory/metaspace/printCLDMetaspaceInfoClosure.cpp 2018-05-20 08:39:01.441500566 +0200 +++ new/src/hotspot/share/memory/metaspace/printCLDMetaspaceInfoClosure.cpp 2018-05-20 08:39:01.349499789 +0200 @@ -22,7 +22,8 @@ * */ #include "precompiled.hpp" -#include "classfile/classLoaderData.hpp" +#include "classfile/classLoaderData.inline.hpp" +#include "classfile/javaClasses.hpp" #include "memory/metaspace/printCLDMetaspaceInfoClosure.hpp" #include "memory/resourceArea.hpp" #include "runtime/safepoint.hpp" @@ -63,17 +64,62 @@ _out->print(UINTX_FORMAT_W(4) ": ", _num_loaders); - if (cld->is_anonymous()) { - _out->print("ClassLoaderData " PTR_FORMAT " for anonymous class", p2i(cld)); + // Print "CLD for , instance of " + // or "CLD for , loaded by , instance of " + + // Note: ClassloaderData::loader_name is no good here, see JDK-8203456. So we have to do this by hand for now. + ResourceMark rm; + const char* name = NULL; + const char* class_name = NULL; + if (cld->is_unloading()) { + // use values cached inside CLD + Klass* k = cld->class_loader_klass(); + if (k != NULL) { + class_name = k->external_name(); + Symbol* s = cld->class_loader_name(); + if (s != NULL) { + name = s->as_C_string(); + } + } else { + name = ""; + } } else { - ResourceMark rm; - _out->print("ClassLoaderData " PTR_FORMAT " for %s", p2i(cld), cld->loader_name()); + oop loader_oop = cld->class_loader(); + if (loader_oop != NULL) { + oop nameOop = java_lang_ClassLoader::name(loader_oop); + if (nameOop != NULL) { + name = java_lang_String::as_utf8_string(nameOop); + } else { + name = ""; + } + Klass* k = loader_oop->klass(); + if (k != NULL) { + class_name = k->external_name(); + } + } else { + name = ""; + } } + // Print + _out->print("CLD " PTR_FORMAT, p2i(cld)); if (cld->is_unloading()) { _out->print(" (unloading)"); } + _out->print(" for"); + if (cld->is_anonymous()) { + _out->print(" , loaded by"); + } + if (name != NULL) { + _out->print(" %s", name); + } + if (class_name != NULL) { + _out->print(", instance of %s", class_name); + } + + _out->cr(); + // Print statistics this_cld_stat.print_on(_out, _scale, _break_down_by_chunktype); _out->cr();