Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/src/hotspot/share/services/nmtCommon.hpp
64440 views
1
/*
2
* Copyright (c) 2014, 2020, 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_SERVICES_NMTCOMMON_HPP
26
#define SHARE_SERVICES_NMTCOMMON_HPP
27
28
#include "memory/allocation.hpp"
29
#include "utilities/align.hpp"
30
#include "utilities/globalDefinitions.hpp"
31
32
#define CALC_OBJ_SIZE_IN_TYPE(obj, type) (align_up(sizeof(obj), sizeof(type))/sizeof(type))
33
34
// Native memory tracking level
35
//
36
// The meaning of the different states:
37
//
38
// "unknown": pre-init phase (before parsing NMT arguments)
39
//
40
// "off": after initialization - NMT confirmed off.
41
// - nothing is tracked
42
// - no malloc headers are used
43
//
44
// "minimal": after shutdown - NMT had been on at some point but has been switched off
45
// - nothing is tracked
46
// - malloc headers are allocated but not initialized not used
47
//
48
// "summary": after initialization with NativeMemoryTracking=summary - NMT in summary mode
49
// - category summaries per tag are tracked
50
// - thread stacks are tracked
51
// - malloc headers are used
52
// - malloc call site table is allocated and used
53
//
54
// "detail": after initialization with NativeMemoryTracking=detail - NMT in detail mode
55
// - category summaries per tag are tracked
56
// - malloc details per call site are tracked
57
// - virtual memory mapping info is tracked
58
// - thread stacks are tracked
59
// - malloc headers are used
60
// - malloc call site table is allocated and used
61
//
62
// Valid state transitions:
63
//
64
// unknown ----> off
65
// |
66
// |--> summary --
67
// | |
68
// |--> detail --+--> minimal
69
//
70
71
72
// Please keep relation of numerical values!
73
// unknown < off < minimal < summary < detail
74
//
75
enum NMT_TrackingLevel {
76
NMT_unknown = 0,
77
NMT_off = 1,
78
NMT_minimal = 2,
79
NMT_summary = 3,
80
NMT_detail = 4
81
};
82
83
// Number of stack frames to capture. This is a
84
// build time decision.
85
const int NMT_TrackingStackDepth = 4;
86
87
// A few common utilities for native memory tracking
88
class NMTUtil : AllStatic {
89
public:
90
// Check if index is a valid MEMFLAGS enum value (including mtNone)
91
static inline bool flag_index_is_valid(int index) {
92
return index >= 0 && index < mt_number_of_types;
93
}
94
95
// Check if flag value is a valid MEMFLAGS enum value (including mtNone)
96
static inline bool flag_is_valid(MEMFLAGS flag) {
97
const int index = static_cast<int>(flag);
98
return flag_index_is_valid(index);
99
}
100
101
// Map memory type to index
102
static inline int flag_to_index(MEMFLAGS flag) {
103
assert(flag_is_valid(flag), "Invalid flag");
104
return static_cast<int>(flag);
105
}
106
107
// Map memory type to human readable name
108
static const char* flag_to_name(MEMFLAGS flag) {
109
return _memory_type_names[flag_to_index(flag)];
110
}
111
112
// Map an index to memory type
113
static MEMFLAGS index_to_flag(int index) {
114
assert(flag_index_is_valid(index), "Invalid flag");
115
return static_cast<MEMFLAGS>(index);
116
}
117
118
// Memory size scale
119
static const char* scale_name(size_t scale);
120
static size_t scale_from_name(const char* scale);
121
122
// Translate memory size in specified scale
123
static size_t amount_in_scale(size_t amount, size_t scale) {
124
return (amount + scale / 2) / scale;
125
}
126
127
// Parses the tracking level from a string. Returns NMT_unknown if
128
// string is not a valid level.
129
static NMT_TrackingLevel parse_tracking_level(const char* s);
130
131
// Returns textual representation of a tracking level.
132
static const char* tracking_level_to_string(NMT_TrackingLevel level);
133
134
private:
135
static const char* _memory_type_names[mt_number_of_types];
136
};
137
138
139
#endif // SHARE_SERVICES_NMTCOMMON_HPP
140
141