Path: blob/master/src/hotspot/share/memory/metaspace/metaspaceDCmd.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 "memory/metaspace.hpp"27#include "memory/metaspace/metaspaceDCmd.hpp"28#include "memory/metaspace/metaspaceReporter.hpp"29#include "memory/metaspaceUtils.hpp"30#include "memory/resourceArea.hpp"31#include "runtime/vmOperations.hpp"32#include "services/diagnosticCommand.hpp"33#include "services/nmtCommon.hpp"3435namespace metaspace {3637MetaspaceDCmd::MetaspaceDCmd(outputStream* output, bool heap) :38DCmdWithParser(output, heap),39_basic("basic", "Prints a basic summary (does not need a safepoint).", "BOOLEAN", false, "false"),40_show_loaders("show-loaders", "Shows usage by class loader.", "BOOLEAN", false, "false"),41_by_spacetype("by-spacetype", "Break down numbers by loader type.", "BOOLEAN", false, "false"),42_by_chunktype("by-chunktype", "Break down numbers by chunk type.", "BOOLEAN", false, "false"),43_show_vslist("vslist", "Shows details about the underlying virtual space.", "BOOLEAN", false, "false"),44_scale("scale", "Memory usage in which to scale. Valid values are: 1, KB, MB or GB (fixed scale) "45"or \"dynamic\" for a dynamically choosen scale.",46"STRING", false, "dynamic"),47_show_classes("show-classes", "If show-loaders is set, shows loaded classes for each loader.", "BOOLEAN", false, "false")48{49_dcmdparser.add_dcmd_option(&_basic);50_dcmdparser.add_dcmd_option(&_show_loaders);51_dcmdparser.add_dcmd_option(&_show_classes);52_dcmdparser.add_dcmd_option(&_by_chunktype);53_dcmdparser.add_dcmd_option(&_by_spacetype);54_dcmdparser.add_dcmd_option(&_show_vslist);55_dcmdparser.add_dcmd_option(&_scale);56}5758int MetaspaceDCmd::num_arguments() {59ResourceMark rm;60MetaspaceDCmd* dcmd = new MetaspaceDCmd(NULL, false);61if (dcmd != NULL) {62DCmdMark mark(dcmd);63return dcmd->_dcmdparser.num_arguments();64} else {65return 0;66}67}6869void MetaspaceDCmd::execute(DCmdSource source, TRAPS) {70// Parse scale value.71const char* scale_value = _scale.value();72size_t scale = 0;73if (scale_value != NULL) {74if (strcasecmp("dynamic", scale_value) == 0) {75scale = 0;76} else {77scale = NMT_ONLY(NMTUtil::scale_from_name(scale_value)) NOT_NMT(0);78if (scale == 0) {79output()->print_cr("Invalid scale: \"%s\". Will use dynamic scaling.", scale_value);80}81}82}83if (_basic.value() == true) {84if (_show_loaders.value() || _by_chunktype.value() || _by_spacetype.value() ||85_show_vslist.value()) {86// Basic mode. Just print essentials. Does not need to be at a safepoint.87output()->print_cr("In basic mode, additional arguments are ignored.");88}89MetaspaceUtils::print_basic_report(output(), scale);90} else {91// Full mode. Requires safepoint.92int flags = 0;93if (_show_loaders.value()) flags |= (int)MetaspaceReporter::Option::ShowLoaders;94if (_show_classes.value()) flags |= (int)MetaspaceReporter::Option::ShowClasses;95if (_by_chunktype.value()) flags |= (int)MetaspaceReporter::Option::BreakDownByChunkType;96if (_by_spacetype.value()) flags |= (int)MetaspaceReporter::Option::BreakDownBySpaceType;97if (_show_vslist.value()) flags |= (int)MetaspaceReporter::Option::ShowVSList;98VM_PrintMetadata op(output(), scale, flags);99VMThread::execute(&op);100}101}102103} // namespace metaspace104105106107