zgu@7074: /* zgu@7074: * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. zgu@7074: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. zgu@7074: * zgu@7074: * This code is free software; you can redistribute it and/or modify it zgu@7074: * under the terms of the GNU General Public License version 2 only, as zgu@7074: * published by the Free Software Foundation. zgu@7074: * zgu@7074: * This code is distributed in the hope that it will be useful, but WITHOUT zgu@7074: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or zgu@7074: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License zgu@7074: * version 2 for more details (a copy is included in the LICENSE file that zgu@7074: * accompanied this code). zgu@7074: * zgu@7074: * You should have received a copy of the GNU General Public License version zgu@7074: * 2 along with this work; if not, write to the Free Software Foundation, zgu@7074: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. zgu@7074: * zgu@7074: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA zgu@7074: * or visit www.oracle.com if you need additional information or have any zgu@7074: * questions. zgu@7074: * zgu@7074: */ zgu@7074: zgu@7074: #ifndef SHARE_VM_SERVICES_NMT_COMMON_HPP zgu@7074: #define SHARE_VM_SERVICES_NMT_COMMON_HPP zgu@7074: zgu@7074: #include "memory/allocation.hpp" zgu@7074: #include "utilities/globalDefinitions.hpp" zgu@7074: zgu@7074: #define CALC_OBJ_SIZE_IN_TYPE(obj, type) (align_size_up_(sizeof(obj), sizeof(type))/sizeof(type)) zgu@7074: zgu@7074: // Data type for memory counters zgu@7074: #ifdef _LP64 zgu@7074: typedef jlong MemoryCounterType; zgu@7074: #else zgu@7074: typedef jint MemoryCounterType; zgu@7074: #endif zgu@7074: zgu@7074: // Native memory tracking level zgu@7074: enum NMT_TrackingLevel { zgu@7074: NMT_unknown = 0xFF, zgu@7074: NMT_off = 0x00, zgu@7074: NMT_minimal = 0x01, zgu@7074: NMT_summary = 0x02, zgu@7074: NMT_detail = 0x03 zgu@7074: }; zgu@7074: zgu@7074: // Number of stack frames to capture. This is a zgu@7074: // build time decision. zgu@7074: const int NMT_TrackingStackDepth = 4; zgu@7074: zgu@7074: class NativeCallStack; zgu@7074: extern NativeCallStack emptyStack; zgu@7074: zgu@7074: // A few common utilities for native memory tracking zgu@7074: class NMTUtil : AllStatic { zgu@7074: public: zgu@7074: // Map memory type to index zgu@7074: static inline int flag_to_index(MEMFLAGS flag) { zgu@7074: return (flag & 0xff); zgu@7074: } zgu@7074: zgu@7074: // Map memory type to human readable name zgu@7074: static const char* flag_to_name(MEMFLAGS flag) { zgu@7074: return _memory_type_names[flag_to_index(flag)]; zgu@7074: } zgu@7074: zgu@7074: // Map an index to memory type zgu@7074: static MEMFLAGS index_to_flag(int index) { zgu@7074: return (MEMFLAGS)index; zgu@7074: } zgu@7074: zgu@7074: // Memory size scale zgu@7074: static const char* scale_name(size_t scale); zgu@7074: static size_t scale_from_name(const char* scale); zgu@7074: zgu@7074: // Translate memory size in specified scale zgu@7074: static size_t amount_in_scale(size_t amount, size_t scale) { zgu@7074: return (amount + scale / 2) / scale; zgu@7074: } zgu@7074: private: zgu@7074: static const char* _memory_type_names[mt_number_of_types]; zgu@7074: }; zgu@7074: zgu@7074: zgu@7074: #endif