Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/services/nmtCommon.hpp
41144 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
enum NMT_TrackingLevel {
36
NMT_unknown = 0xFF,
37
NMT_off = 0x00,
38
NMT_minimal = 0x01,
39
NMT_summary = 0x02,
40
NMT_detail = 0x03
41
};
42
43
// Number of stack frames to capture. This is a
44
// build time decision.
45
const int NMT_TrackingStackDepth = 4;
46
47
// A few common utilities for native memory tracking
48
class NMTUtil : AllStatic {
49
public:
50
// Check if index is a valid MEMFLAGS enum value (including mtNone)
51
static inline bool flag_index_is_valid(int index) {
52
return index >= 0 && index < mt_number_of_types;
53
}
54
55
// Check if flag value is a valid MEMFLAGS enum value (including mtNone)
56
static inline bool flag_is_valid(MEMFLAGS flag) {
57
const int index = static_cast<int>(flag);
58
return flag_index_is_valid(index);
59
}
60
61
// Map memory type to index
62
static inline int flag_to_index(MEMFLAGS flag) {
63
assert(flag_is_valid(flag), "Invalid flag");
64
return static_cast<int>(flag);
65
}
66
67
// Map memory type to human readable name
68
static const char* flag_to_name(MEMFLAGS flag) {
69
return _memory_type_names[flag_to_index(flag)];
70
}
71
72
// Map an index to memory type
73
static MEMFLAGS index_to_flag(int index) {
74
assert(flag_index_is_valid(index), "Invalid flag");
75
return static_cast<MEMFLAGS>(index);
76
}
77
78
// Memory size scale
79
static const char* scale_name(size_t scale);
80
static size_t scale_from_name(const char* scale);
81
82
// Translate memory size in specified scale
83
static size_t amount_in_scale(size_t amount, size_t scale) {
84
return (amount + scale / 2) / scale;
85
}
86
private:
87
static const char* _memory_type_names[mt_number_of_types];
88
};
89
90
91
#endif // SHARE_SERVICES_NMTCOMMON_HPP
92
93