Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/services/memBaseline.hpp
41144 views
1
/*
2
* Copyright (c) 2012, 2019, 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_MEMBASELINE_HPP
26
#define SHARE_SERVICES_MEMBASELINE_HPP
27
28
#if INCLUDE_NMT
29
30
#include "memory/metaspaceStats.hpp"
31
#include "runtime/mutex.hpp"
32
#include "services/mallocSiteTable.hpp"
33
#include "services/mallocTracker.hpp"
34
#include "services/nmtCommon.hpp"
35
#include "services/virtualMemoryTracker.hpp"
36
#include "utilities/linkedlist.hpp"
37
38
typedef LinkedListIterator<MallocSite> MallocSiteIterator;
39
typedef LinkedListIterator<VirtualMemoryAllocationSite> VirtualMemorySiteIterator;
40
typedef LinkedListIterator<ReservedMemoryRegion> VirtualMemoryAllocationIterator;
41
42
/*
43
* Baseline a memory snapshot
44
*/
45
class MemBaseline {
46
public:
47
48
enum BaselineType {
49
Not_baselined,
50
Summary_baselined,
51
Detail_baselined
52
};
53
54
enum SortingOrder {
55
by_address, // by memory address
56
by_size, // by memory size
57
by_site, // by call site where the memory is allocated from
58
by_site_and_type // by call site and memory type
59
};
60
61
private:
62
// Summary information
63
MallocMemorySnapshot _malloc_memory_snapshot;
64
VirtualMemorySnapshot _virtual_memory_snapshot;
65
MetaspaceCombinedStats _metaspace_stats;
66
67
size_t _instance_class_count;
68
size_t _array_class_count;
69
70
// Allocation sites information
71
// Malloc allocation sites
72
LinkedListImpl<MallocSite> _malloc_sites;
73
74
// All virtual memory allocations
75
LinkedListImpl<ReservedMemoryRegion> _virtual_memory_allocations;
76
77
// Virtual memory allocations by allocation sites, always in by_address
78
// order
79
LinkedListImpl<VirtualMemoryAllocationSite> _virtual_memory_sites;
80
81
SortingOrder _malloc_sites_order;
82
SortingOrder _virtual_memory_sites_order;
83
84
BaselineType _baseline_type;
85
86
public:
87
// create a memory baseline
88
MemBaseline():
89
_instance_class_count(0), _array_class_count(0),
90
_baseline_type(Not_baselined) {
91
}
92
93
bool baseline(bool summaryOnly = true);
94
95
BaselineType baseline_type() const { return _baseline_type; }
96
97
MallocMemorySnapshot* malloc_memory_snapshot() {
98
return &_malloc_memory_snapshot;
99
}
100
101
VirtualMemorySnapshot* virtual_memory_snapshot() {
102
return &_virtual_memory_snapshot;
103
}
104
105
const MetaspaceCombinedStats& metaspace_stats() const {
106
return _metaspace_stats;
107
}
108
109
MallocSiteIterator malloc_sites(SortingOrder order);
110
VirtualMemorySiteIterator virtual_memory_sites(SortingOrder order);
111
112
// Virtual memory allocation iterator always returns in virtual memory
113
// base address order.
114
VirtualMemoryAllocationIterator virtual_memory_allocations() {
115
assert(!_virtual_memory_allocations.is_empty(), "Not detail baseline");
116
return VirtualMemoryAllocationIterator(_virtual_memory_allocations.head());
117
}
118
119
// Total reserved memory = total malloc'd memory + total reserved virtual
120
// memory
121
size_t total_reserved_memory() const {
122
assert(baseline_type() != Not_baselined, "Not yet baselined");
123
size_t amount = _malloc_memory_snapshot.total() +
124
_virtual_memory_snapshot.total_reserved();
125
return amount;
126
}
127
128
// Total committed memory = total malloc'd memory + total committed
129
// virtual memory
130
size_t total_committed_memory() const {
131
assert(baseline_type() != Not_baselined, "Not yet baselined");
132
size_t amount = _malloc_memory_snapshot.total() +
133
_virtual_memory_snapshot.total_committed();
134
return amount;
135
}
136
137
size_t total_arena_memory() const {
138
assert(baseline_type() != Not_baselined, "Not yet baselined");
139
return _malloc_memory_snapshot.total_arena();
140
}
141
142
size_t malloc_tracking_overhead() const {
143
assert(baseline_type() != Not_baselined, "Not yet baselined");
144
MemBaseline* bl = const_cast<MemBaseline*>(this);
145
return bl->_malloc_memory_snapshot.malloc_overhead()->size();
146
}
147
148
MallocMemory* malloc_memory(MEMFLAGS flag) {
149
assert(baseline_type() != Not_baselined, "Not yet baselined");
150
return _malloc_memory_snapshot.by_type(flag);
151
}
152
153
VirtualMemory* virtual_memory(MEMFLAGS flag) {
154
assert(baseline_type() != Not_baselined, "Not yet baselined");
155
return _virtual_memory_snapshot.by_type(flag);
156
}
157
158
159
size_t class_count() const {
160
assert(baseline_type() != Not_baselined, "Not yet baselined");
161
return _instance_class_count + _array_class_count;
162
}
163
164
size_t instance_class_count() const {
165
assert(baseline_type() != Not_baselined, "Not yet baselined");
166
return _instance_class_count;
167
}
168
169
size_t array_class_count() const {
170
assert(baseline_type() != Not_baselined, "Not yet baselined");
171
return _array_class_count;
172
}
173
174
size_t thread_count() const {
175
assert(baseline_type() != Not_baselined, "Not yet baselined");
176
return _malloc_memory_snapshot.thread_count();
177
}
178
179
// reset the baseline for reuse
180
void reset() {
181
_baseline_type = Not_baselined;
182
// _malloc_memory_snapshot and _virtual_memory_snapshot are copied over.
183
_instance_class_count = 0;
184
_array_class_count = 0;
185
186
_malloc_sites.clear();
187
_virtual_memory_sites.clear();
188
_virtual_memory_allocations.clear();
189
}
190
191
private:
192
// Baseline summary information
193
bool baseline_summary();
194
195
// Baseline allocation sites (detail tracking only)
196
bool baseline_allocation_sites();
197
198
// Aggregate virtual memory allocation by allocation sites
199
bool aggregate_virtual_memory_allocation_sites();
200
201
// Sorting allocation sites in different orders
202
// Sort allocation sites in size order
203
void malloc_sites_to_size_order();
204
// Sort allocation sites in call site address order
205
void malloc_sites_to_allocation_site_order();
206
// Sort allocation sites in call site address and memory type order
207
void malloc_sites_to_allocation_site_and_type_order();
208
209
// Sort allocation sites in reserved size order
210
void virtual_memory_sites_to_size_order();
211
// Sort allocation sites in call site address order
212
void virtual_memory_sites_to_reservation_site_order();
213
};
214
215
#endif // INCLUDE_NMT
216
217
#endif // SHARE_SERVICES_MEMBASELINE_HPP
218
219