Path: blob/master/src/hotspot/share/services/nmtCommon.hpp
64440 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 level34//35// The meaning of the different states:36//37// "unknown": pre-init phase (before parsing NMT arguments)38//39// "off": after initialization - NMT confirmed off.40// - nothing is tracked41// - no malloc headers are used42//43// "minimal": after shutdown - NMT had been on at some point but has been switched off44// - nothing is tracked45// - malloc headers are allocated but not initialized not used46//47// "summary": after initialization with NativeMemoryTracking=summary - NMT in summary mode48// - category summaries per tag are tracked49// - thread stacks are tracked50// - malloc headers are used51// - malloc call site table is allocated and used52//53// "detail": after initialization with NativeMemoryTracking=detail - NMT in detail mode54// - category summaries per tag are tracked55// - malloc details per call site are tracked56// - virtual memory mapping info is tracked57// - thread stacks are tracked58// - malloc headers are used59// - malloc call site table is allocated and used60//61// Valid state transitions:62//63// unknown ----> off64// |65// |--> summary --66// | |67// |--> detail --+--> minimal68//697071// Please keep relation of numerical values!72// unknown < off < minimal < summary < detail73//74enum NMT_TrackingLevel {75NMT_unknown = 0,76NMT_off = 1,77NMT_minimal = 2,78NMT_summary = 3,79NMT_detail = 480};8182// Number of stack frames to capture. This is a83// build time decision.84const int NMT_TrackingStackDepth = 4;8586// A few common utilities for native memory tracking87class NMTUtil : AllStatic {88public:89// Check if index is a valid MEMFLAGS enum value (including mtNone)90static inline bool flag_index_is_valid(int index) {91return index >= 0 && index < mt_number_of_types;92}9394// Check if flag value is a valid MEMFLAGS enum value (including mtNone)95static inline bool flag_is_valid(MEMFLAGS flag) {96const int index = static_cast<int>(flag);97return flag_index_is_valid(index);98}99100// Map memory type to index101static inline int flag_to_index(MEMFLAGS flag) {102assert(flag_is_valid(flag), "Invalid flag");103return static_cast<int>(flag);104}105106// Map memory type to human readable name107static const char* flag_to_name(MEMFLAGS flag) {108return _memory_type_names[flag_to_index(flag)];109}110111// Map an index to memory type112static MEMFLAGS index_to_flag(int index) {113assert(flag_index_is_valid(index), "Invalid flag");114return static_cast<MEMFLAGS>(index);115}116117// Memory size scale118static const char* scale_name(size_t scale);119static size_t scale_from_name(const char* scale);120121// Translate memory size in specified scale122static size_t amount_in_scale(size_t amount, size_t scale) {123return (amount + scale / 2) / scale;124}125126// Parses the tracking level from a string. Returns NMT_unknown if127// string is not a valid level.128static NMT_TrackingLevel parse_tracking_level(const char* s);129130// Returns textual representation of a tracking level.131static const char* tracking_level_to_string(NMT_TrackingLevel level);132133private:134static const char* _memory_type_names[mt_number_of_types];135};136137138#endif // SHARE_SERVICES_NMTCOMMON_HPP139140141