2012-06-28 17:03:16 -04:00
|
|
|
/*
|
2018-07-31 07:35:16 -04:00
|
|
|
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
|
2012-06-28 17:03:16 -04:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "precompiled.hpp"
|
2014-08-07 12:18:58 -07:00
|
|
|
#include "services/nmtCommon.hpp"
|
2018-04-24 18:06:32 +02:00
|
|
|
#include "utilities/globalDefinitions.hpp"
|
2014-08-07 12:18:58 -07:00
|
|
|
|
2018-09-01 12:02:07 -07:00
|
|
|
#define MEMORY_TYPE_DECLARE_NAME(type, human_readable) \
|
2018-09-04 08:06:31 +02:00
|
|
|
human_readable,
|
2018-09-01 12:02:07 -07:00
|
|
|
|
2014-08-07 12:18:58 -07:00
|
|
|
const char* NMTUtil::_memory_type_names[] = {
|
2018-09-01 12:02:07 -07:00
|
|
|
MEMORY_TYPES_DO(MEMORY_TYPE_DECLARE_NAME)
|
2014-08-07 12:18:58 -07:00
|
|
|
};
|
|
|
|
|
2012-06-28 17:03:16 -04:00
|
|
|
|
2014-08-07 12:18:58 -07:00
|
|
|
const char* NMTUtil::scale_name(size_t scale) {
|
|
|
|
switch(scale) {
|
|
|
|
case K: return "KB";
|
|
|
|
case M: return "MB";
|
|
|
|
case G: return "GB";
|
|
|
|
}
|
|
|
|
ShouldNotReachHere();
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-06-28 17:03:16 -04:00
|
|
|
|
2014-08-07 12:18:58 -07:00
|
|
|
size_t NMTUtil::scale_from_name(const char* scale) {
|
|
|
|
assert(scale != NULL, "Null pointer check");
|
2018-04-24 18:06:32 +02:00
|
|
|
if (strcasecmp(scale, "1") == 0 || strcasecmp(scale, "b") == 0) {
|
|
|
|
return 1;
|
|
|
|
} else if (strcasecmp(scale, "kb") == 0 || strcasecmp(scale, "k") == 0) {
|
2014-08-07 12:18:58 -07:00
|
|
|
return K;
|
2018-04-24 18:06:32 +02:00
|
|
|
} else if (strcasecmp(scale, "mb") == 0 || strcasecmp(scale, "m") == 0) {
|
2014-08-07 12:18:58 -07:00
|
|
|
return M;
|
2018-04-24 18:06:32 +02:00
|
|
|
} else if (strcasecmp(scale, "gb") == 0 || strcasecmp(scale, "g") == 0) {
|
2014-08-07 12:18:58 -07:00
|
|
|
return G;
|
2013-09-04 08:55:08 -04:00
|
|
|
} else {
|
2014-08-07 12:18:58 -07:00
|
|
|
return 0; // Invalid value
|
2012-06-28 17:03:16 -04:00
|
|
|
}
|
2014-08-07 12:18:58 -07:00
|
|
|
return K;
|
2012-06-28 17:03:16 -04:00
|
|
|
}
|
|
|
|
|