20360
|
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
|
|
41 enum 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.
|
|
51 const int NMT_TrackingStackDepth = 4;
|
|
52
|
|
53 // A few common utilities for native memory tracking
|
|
54 class NMTUtil : AllStatic {
|
|
55 public:
|
|
56 // Map memory type to index
|
|
57 static inline int flag_to_index(MEMFLAGS flag) {
|
|
58 return (flag & 0xff);
|
|
59 }
|
|
60
|
|
61 // Map memory type to human readable name
|
|
62 static const char* flag_to_name(MEMFLAGS flag) {
|
|
63 return _memory_type_names[flag_to_index(flag)];
|
|
64 }
|
|
65
|
|
66 // Map an index to memory type
|
|
67 static MEMFLAGS index_to_flag(int index) {
|
|
68 return (MEMFLAGS)index;
|
|
69 }
|
|
70
|
|
71 // Memory size scale
|
|
72 static const char* scale_name(size_t scale);
|
|
73 static size_t scale_from_name(const char* scale);
|
|
74
|
|
75 // Translate memory size in specified scale
|
|
76 static size_t amount_in_scale(size_t amount, size_t scale) {
|
|
77 return (amount + scale / 2) / scale;
|
|
78 }
|
|
79 private:
|
|
80 static const char* _memory_type_names[mt_number_of_types];
|
|
81 };
|
|
82
|
|
83
|
|
84 #endif
|