nmtCommon.hpp revision 6853:91eeb8807a03
1/*
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25#ifndef SHARE_VM_SERVICES_NMT_COMMON_HPP
26#define SHARE_VM_SERVICES_NMT_COMMON_HPP
27
28#include "memory/allocation.hpp"
29#include "utilities/globalDefinitions.hpp"
30
31#define CALC_OBJ_SIZE_IN_TYPE(obj, type) (align_size_up_(sizeof(obj), sizeof(type))/sizeof(type))
32
33// Data type for memory counters
34#ifdef _LP64
35  typedef jlong    MemoryCounterType;
36#else
37  typedef jint     MemoryCounterType;
38#endif
39
40// Native memory tracking level
41enum NMT_TrackingLevel {
42  NMT_unknown = 0xFF,
43  NMT_off     = 0x00,
44  NMT_minimal = 0x01,
45  NMT_summary = 0x02,
46  NMT_detail  = 0x03
47};
48
49// Number of stack frames to capture. This is a
50// build time decision.
51const int NMT_TrackingStackDepth = 4;
52
53class NativeCallStack;
54extern NativeCallStack emptyStack;
55
56// A few common utilities for native memory tracking
57class NMTUtil : AllStatic {
58 public:
59  // Map memory type to index
60  static inline int flag_to_index(MEMFLAGS flag) {
61    return (flag & 0xff);
62  }
63
64  // Map memory type to human readable name
65  static const char* flag_to_name(MEMFLAGS flag) {
66    return _memory_type_names[flag_to_index(flag)];
67  }
68
69  // Map an index to memory type
70  static MEMFLAGS index_to_flag(int index) {
71    return (MEMFLAGS)index;
72  }
73
74  // Memory size scale
75  static const char* scale_name(size_t scale);
76  static size_t scale_from_name(const char* scale);
77
78  // Translate memory size in specified scale
79  static size_t amount_in_scale(size_t amount, size_t scale) {
80    return (amount + scale / 2) / scale;
81  }
82 private:
83  static const char* _memory_type_names[mt_number_of_types];
84};
85
86
87#endif
88