Path: blob/master/src/hotspot/share/memory/metaspace/printCLDMetaspaceInfoClosure.cpp
40957 views
/*1* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2018, 2020 SAP SE. All rights reserved.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425#include "precompiled.hpp"26#include "classfile/classLoaderData.inline.hpp"27#include "classfile/javaClasses.hpp"28#include "memory/classLoaderMetaspace.hpp"29#include "memory/metaspace/metaspaceCommon.hpp"30#include "memory/metaspace/printCLDMetaspaceInfoClosure.hpp"31#include "memory/metaspace/printMetaspaceInfoKlassClosure.hpp"32#include "memory/resourceArea.hpp"33#include "runtime/safepoint.hpp"34#include "utilities/globalDefinitions.hpp"35#include "utilities/ostream.hpp"3637namespace metaspace {3839PrintCLDMetaspaceInfoClosure::PrintCLDMetaspaceInfoClosure(outputStream* out, size_t scale, bool do_print,40bool do_print_classes, bool break_down_by_chunktype) :41_out(out),42_scale(scale),43_do_print(do_print),44_do_print_classes(do_print_classes),45_break_down_by_chunktype(break_down_by_chunktype),46_num_loaders(0),47_num_loaders_without_metaspace(0),48_num_loaders_unloading(0),49_num_classes(0), _num_classes_shared(0)50{51memset(_num_loaders_by_spacetype, 0, sizeof(_num_loaders_by_spacetype));52memset(_num_classes_by_spacetype, 0, sizeof(_num_classes_by_spacetype));53memset(_num_classes_shared_by_spacetype, 0, sizeof(_num_classes_shared_by_spacetype));54}5556// A closure just to count classes57class CountKlassClosure : public KlassClosure {58public:5960uintx _num_classes;61uintx _num_classes_shared;6263CountKlassClosure() : _num_classes(0), _num_classes_shared(0) {}64void do_klass(Klass* k) {65_num_classes++;66if (k->is_shared()) {67_num_classes_shared++;68}69}7071}; // end: PrintKlassInfoClosure7273void PrintCLDMetaspaceInfoClosure::do_cld(ClassLoaderData* cld) {74assert(SafepointSynchronize::is_at_safepoint(), "Must be at a safepoint");7576if (cld->is_unloading()) {77_num_loaders_unloading++;78return;79}8081ClassLoaderMetaspace* msp = cld->metaspace_or_null();82if (msp == NULL) {83_num_loaders_without_metaspace++;84return;85}8687// Collect statistics for this class loader metaspace88ClmsStats this_cld_stat;89msp->add_to_statistics(&this_cld_stat);9091// And add it to the running totals92_stats_total.add(this_cld_stat);93_num_loaders++;94_stats_by_spacetype[msp->space_type()].add(this_cld_stat);95_num_loaders_by_spacetype[msp->space_type()] ++;9697// Count classes loaded by this CLD.98CountKlassClosure ckc;99cld->classes_do(&ckc);100// accumulate.101_num_classes += ckc._num_classes;102_num_classes_by_spacetype[msp->space_type()] += ckc._num_classes;103_num_classes_shared += ckc._num_classes_shared;104_num_classes_shared_by_spacetype[msp->space_type()] += ckc._num_classes_shared;105106// Optionally, print107if (_do_print) {108_out->print(UINTX_FORMAT_W(4) ": ", _num_loaders);109110// Print "CLD for [<loader name>,] instance of <loader class name>"111// or "CLD for <hidden>, loaded by [<loader name>,] instance of <loader class name>"112ResourceMark rm;113const char* name = NULL;114const char* class_name = NULL;115116// Note: this should also work if unloading:117Klass* k = cld->class_loader_klass();118if (k != NULL) {119class_name = k->external_name();120Symbol* s = cld->name();121if (s != NULL) {122name = s->as_C_string();123}124} else {125name = "<bootstrap>";126}127128129_out->print("CLD " PTR_FORMAT, p2i(cld));130if (cld->is_unloading()) {131_out->print(" (unloading)");132}133_out->print(":");134if (cld->has_class_mirror_holder()) {135_out->print(" <hidden class>, loaded by");136}137if (name != NULL) {138_out->print(" \"%s\"", name);139}140if (class_name != NULL) {141_out->print(" instance of %s", class_name);142}143144if (_do_print_classes) {145// Print a detailed description of all loaded classes.146streamIndentor sti(_out, 6);147_out->cr_indent();148_out->print("Loaded classes");149if (ckc._num_classes_shared > 0) {150_out->print("('s' = shared)");151}152_out->print(":");153PrintMetaspaceInfoKlassClosure pkic(_out, true);154cld->classes_do(&pkic);155_out->cr_indent();156_out->print("-total-: ");157print_number_of_classes(_out, ckc._num_classes, ckc._num_classes_shared);158} else {159// Just print a summary about how many classes have been loaded.160_out->print(", ");161print_number_of_classes(_out, ckc._num_classes, ckc._num_classes_shared);162}163164// Print statistics165this_cld_stat.print_on(_out, _scale, _break_down_by_chunktype);166_out->cr();167}168}169170} // namespace metaspace171172173174