Path: blob/master/src/hotspot/share/services/nmtCommon.hpp
41144 views
/*1* Copyright (c) 2014, 2020, 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*/2324#ifndef SHARE_SERVICES_NMTCOMMON_HPP25#define SHARE_SERVICES_NMTCOMMON_HPP2627#include "memory/allocation.hpp"28#include "utilities/align.hpp"29#include "utilities/globalDefinitions.hpp"3031#define CALC_OBJ_SIZE_IN_TYPE(obj, type) (align_up(sizeof(obj), sizeof(type))/sizeof(type))3233// Native memory tracking level34enum NMT_TrackingLevel {35NMT_unknown = 0xFF,36NMT_off = 0x00,37NMT_minimal = 0x01,38NMT_summary = 0x02,39NMT_detail = 0x0340};4142// Number of stack frames to capture. This is a43// build time decision.44const int NMT_TrackingStackDepth = 4;4546// A few common utilities for native memory tracking47class NMTUtil : AllStatic {48public:49// Check if index is a valid MEMFLAGS enum value (including mtNone)50static inline bool flag_index_is_valid(int index) {51return index >= 0 && index < mt_number_of_types;52}5354// Check if flag value is a valid MEMFLAGS enum value (including mtNone)55static inline bool flag_is_valid(MEMFLAGS flag) {56const int index = static_cast<int>(flag);57return flag_index_is_valid(index);58}5960// Map memory type to index61static inline int flag_to_index(MEMFLAGS flag) {62assert(flag_is_valid(flag), "Invalid flag");63return static_cast<int>(flag);64}6566// Map memory type to human readable name67static const char* flag_to_name(MEMFLAGS flag) {68return _memory_type_names[flag_to_index(flag)];69}7071// Map an index to memory type72static MEMFLAGS index_to_flag(int index) {73assert(flag_index_is_valid(index), "Invalid flag");74return static_cast<MEMFLAGS>(index);75}7677// Memory size scale78static const char* scale_name(size_t scale);79static size_t scale_from_name(const char* scale);8081// Translate memory size in specified scale82static size_t amount_in_scale(size_t amount, size_t scale) {83return (amount + scale / 2) / scale;84}85private:86static const char* _memory_type_names[mt_number_of_types];87};888990#endif // SHARE_SERVICES_NMTCOMMON_HPP919293