Path: blob/master/src/hotspot/share/services/nmtCommon.cpp
64441 views
/*1* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/23#include "precompiled.hpp"24#include "services/nmtCommon.hpp"25#include "utilities/globalDefinitions.hpp"2627#define MEMORY_TYPE_DECLARE_NAME(type, human_readable) \28human_readable,2930const char* NMTUtil::_memory_type_names[] = {31MEMORY_TYPES_DO(MEMORY_TYPE_DECLARE_NAME)32};333435const char* NMTUtil::scale_name(size_t scale) {36switch(scale) {37case 1: return "";38case K: return "KB";39case M: return "MB";40case G: return "GB";41}42ShouldNotReachHere();43return NULL;44}4546size_t NMTUtil::scale_from_name(const char* scale) {47assert(scale != NULL, "Null pointer check");48if (strcasecmp(scale, "1") == 0 || strcasecmp(scale, "b") == 0) {49return 1;50} else if (strcasecmp(scale, "kb") == 0 || strcasecmp(scale, "k") == 0) {51return K;52} else if (strcasecmp(scale, "mb") == 0 || strcasecmp(scale, "m") == 0) {53return M;54} else if (strcasecmp(scale, "gb") == 0 || strcasecmp(scale, "g") == 0) {55return G;56} else {57return 0; // Invalid value58}59return K;60}6162const char* NMTUtil::tracking_level_to_string(NMT_TrackingLevel lvl) {63switch(lvl) {64case NMT_unknown: return "unknown"; break;65case NMT_off: return "off"; break;66case NMT_minimal: return "minimal"; break;67case NMT_summary: return "summary"; break;68case NMT_detail: return "detail"; break;69default: return "invalid"; break;70}71}7273// Returns the parsed level; NMT_unknown if string is invalid74NMT_TrackingLevel NMTUtil::parse_tracking_level(const char* s) {75if (s != NULL) {76if (strcmp(s, "summary") == 0) {77return NMT_summary;78} else if (strcmp(s, "detail") == 0) {79return NMT_detail;80} else if (strcmp(s, "off") == 0) {81return NMT_off;82}83}84return NMT_unknown;85}868788