author | herrick |
Fri, 18 Oct 2019 14:14:37 -0400 | |
branch | JDK-8200758-branch |
changeset 58696 | 61c44899b4eb |
parent 53244 | 9807daeb47c4 |
permissions | -rw-r--r-- |
13195 | 1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
51334
diff
changeset
|
2 |
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. |
13195 | 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 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
51334
diff
changeset
|
25 |
#ifndef SHARE_SERVICES_MEMBASELINE_HPP |
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
51334
diff
changeset
|
26 |
#define SHARE_SERVICES_MEMBASELINE_HPP |
13195 | 27 |
|
25946 | 28 |
#if INCLUDE_NMT |
29 |
||
13195 | 30 |
#include "runtime/mutex.hpp" |
25946 | 31 |
#include "services/mallocSiteTable.hpp" |
32 |
#include "services/mallocTracker.hpp" |
|
33 |
#include "services/nmtCommon.hpp" |
|
34 |
#include "services/virtualMemoryTracker.hpp" |
|
35 |
#include "utilities/linkedlist.hpp" |
|
13195 | 36 |
|
25946 | 37 |
typedef LinkedListIterator<MallocSite> MallocSiteIterator; |
38 |
typedef LinkedListIterator<VirtualMemoryAllocationSite> VirtualMemorySiteIterator; |
|
39 |
typedef LinkedListIterator<ReservedMemoryRegion> VirtualMemoryAllocationIterator; |
|
13195 | 40 |
|
41 |
/* |
|
25946 | 42 |
* Baseline a memory snapshot |
13195 | 43 |
*/ |
49364
601146c66cad
8173070: Remove ValueObj class for allocation subclassing for runtime code
coleenp
parents:
48884
diff
changeset
|
44 |
class MemBaseline { |
13195 | 45 |
public: |
25946 | 46 |
enum BaselineThreshold { |
47 |
SIZE_THRESHOLD = K // Only allocation size over this threshold will be baselined. |
|
48 |
}; |
|
13195 | 49 |
|
25946 | 50 |
enum BaselineType { |
51 |
Not_baselined, |
|
52 |
Summary_baselined, |
|
53 |
Detail_baselined |
|
54 |
}; |
|
13195 | 55 |
|
25946 | 56 |
enum SortingOrder { |
46711
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
27162
diff
changeset
|
57 |
by_address, // by memory address |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
27162
diff
changeset
|
58 |
by_size, // by memory size |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
27162
diff
changeset
|
59 |
by_site, // by call site where the memory is allocated from |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
27162
diff
changeset
|
60 |
by_site_and_type // by call site and memory type |
13195 | 61 |
}; |
62 |
||
25946 | 63 |
private: |
64 |
// Summary information |
|
26288 | 65 |
MallocMemorySnapshot _malloc_memory_snapshot; |
66 |
VirtualMemorySnapshot _virtual_memory_snapshot; |
|
47553
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
67 |
MetaspaceSnapshot _metaspace_snapshot; |
25946 | 68 |
|
48884
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
69 |
size_t _instance_class_count; |
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
70 |
size_t _array_class_count; |
13195 | 71 |
|
25946 | 72 |
// Allocation sites information |
73 |
// Malloc allocation sites |
|
26288 | 74 |
LinkedListImpl<MallocSite> _malloc_sites; |
25946 | 75 |
|
76 |
// All virtual memory allocations |
|
26288 | 77 |
LinkedListImpl<ReservedMemoryRegion> _virtual_memory_allocations; |
13195 | 78 |
|
25946 | 79 |
// Virtual memory allocations by allocation sites, always in by_address |
80 |
// order |
|
26288 | 81 |
LinkedListImpl<VirtualMemoryAllocationSite> _virtual_memory_sites; |
25946 | 82 |
|
83 |
SortingOrder _malloc_sites_order; |
|
84 |
SortingOrder _virtual_memory_sites_order; |
|
85 |
||
86 |
BaselineType _baseline_type; |
|
13195 | 87 |
|
88 |
public: |
|
25946 | 89 |
// create a memory baseline |
90 |
MemBaseline(): |
|
51334
cc2c79d22508
8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents:
49621
diff
changeset
|
91 |
_instance_class_count(0), _array_class_count(0), |
cc2c79d22508
8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents:
49621
diff
changeset
|
92 |
_baseline_type(Not_baselined) { |
13195 | 93 |
} |
94 |
||
25946 | 95 |
bool baseline(bool summaryOnly = true); |
13195 | 96 |
|
25946 | 97 |
BaselineType baseline_type() const { return _baseline_type; } |
13195 | 98 |
|
26288 | 99 |
MallocMemorySnapshot* malloc_memory_snapshot() { |
100 |
return &_malloc_memory_snapshot; |
|
13195 | 101 |
} |
102 |
||
26288 | 103 |
VirtualMemorySnapshot* virtual_memory_snapshot() { |
104 |
return &_virtual_memory_snapshot; |
|
13195 | 105 |
} |
106 |
||
47553
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
107 |
MetaspaceSnapshot* metaspace_snapshot() { |
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
108 |
return &_metaspace_snapshot; |
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
109 |
} |
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
110 |
|
25946 | 111 |
MallocSiteIterator malloc_sites(SortingOrder order); |
112 |
VirtualMemorySiteIterator virtual_memory_sites(SortingOrder order); |
|
13195 | 113 |
|
25946 | 114 |
// Virtual memory allocation iterator always returns in virtual memory |
115 |
// base address order. |
|
116 |
VirtualMemoryAllocationIterator virtual_memory_allocations() { |
|
117 |
assert(!_virtual_memory_allocations.is_empty(), "Not detail baseline"); |
|
118 |
return VirtualMemoryAllocationIterator(_virtual_memory_allocations.head()); |
|
13195 | 119 |
} |
120 |
||
25946 | 121 |
// Total reserved memory = total malloc'd memory + total reserved virtual |
122 |
// memory |
|
123 |
size_t total_reserved_memory() const { |
|
124 |
assert(baseline_type() != Not_baselined, "Not yet baselined"); |
|
26288 | 125 |
size_t amount = _malloc_memory_snapshot.total() + |
126 |
_virtual_memory_snapshot.total_reserved(); |
|
25946 | 127 |
return amount; |
13195 | 128 |
} |
129 |
||
25946 | 130 |
// Total committed memory = total malloc'd memory + total committed |
131 |
// virtual memory |
|
132 |
size_t total_committed_memory() const { |
|
133 |
assert(baseline_type() != Not_baselined, "Not yet baselined"); |
|
26288 | 134 |
size_t amount = _malloc_memory_snapshot.total() + |
135 |
_virtual_memory_snapshot.total_committed(); |
|
25946 | 136 |
return amount; |
13195 | 137 |
} |
138 |
||
25946 | 139 |
size_t total_arena_memory() const { |
140 |
assert(baseline_type() != Not_baselined, "Not yet baselined"); |
|
26288 | 141 |
return _malloc_memory_snapshot.total_arena(); |
13195 | 142 |
} |
143 |
||
25946 | 144 |
size_t malloc_tracking_overhead() const { |
145 |
assert(baseline_type() != Not_baselined, "Not yet baselined"); |
|
26288 | 146 |
MemBaseline* bl = const_cast<MemBaseline*>(this); |
147 |
return bl->_malloc_memory_snapshot.malloc_overhead()->size(); |
|
13195 | 148 |
} |
149 |
||
26288 | 150 |
MallocMemory* malloc_memory(MEMFLAGS flag) { |
151 |
assert(baseline_type() != Not_baselined, "Not yet baselined"); |
|
152 |
return _malloc_memory_snapshot.by_type(flag); |
|
13195 | 153 |
} |
154 |
||
26288 | 155 |
VirtualMemory* virtual_memory(MEMFLAGS flag) { |
156 |
assert(baseline_type() != Not_baselined, "Not yet baselined"); |
|
157 |
return _virtual_memory_snapshot.by_type(flag); |
|
13195 | 158 |
} |
159 |
||
160 |
||
25946 | 161 |
size_t class_count() const { |
162 |
assert(baseline_type() != Not_baselined, "Not yet baselined"); |
|
48884
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
163 |
return _instance_class_count + _array_class_count; |
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
164 |
} |
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
165 |
|
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
166 |
size_t instance_class_count() const { |
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
167 |
assert(baseline_type() != Not_baselined, "Not yet baselined"); |
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
168 |
return _instance_class_count; |
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
169 |
} |
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
170 |
|
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
171 |
size_t array_class_count() const { |
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
172 |
assert(baseline_type() != Not_baselined, "Not yet baselined"); |
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
173 |
return _array_class_count; |
13195 | 174 |
} |
175 |
||
25946 | 176 |
size_t thread_count() const { |
177 |
assert(baseline_type() != Not_baselined, "Not yet baselined"); |
|
26288 | 178 |
return _malloc_memory_snapshot.thread_count(); |
13195 | 179 |
} |
180 |
||
181 |
// reset the baseline for reuse |
|
25946 | 182 |
void reset() { |
183 |
_baseline_type = Not_baselined; |
|
27162
0a4a7276949b
8059100: SIGSEGV VirtualMemoryTracker::remove_released_region
coleenp
parents:
26288
diff
changeset
|
184 |
// _malloc_memory_snapshot and _virtual_memory_snapshot are copied over. |
48884
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
185 |
_instance_class_count = 0; |
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
186 |
_array_class_count = 0; |
13195 | 187 |
|
26288 | 188 |
_malloc_sites.clear(); |
189 |
_virtual_memory_sites.clear(); |
|
190 |
_virtual_memory_allocations.clear(); |
|
13195 | 191 |
} |
192 |
||
25946 | 193 |
private: |
194 |
// Baseline summary information |
|
195 |
bool baseline_summary(); |
|
13195 | 196 |
|
25946 | 197 |
// Baseline allocation sites (detail tracking only) |
198 |
bool baseline_allocation_sites(); |
|
199 |
||
200 |
// Aggregate virtual memory allocation by allocation sites |
|
201 |
bool aggregate_virtual_memory_allocation_sites(); |
|
13195 | 202 |
|
25946 | 203 |
// Sorting allocation sites in different orders |
204 |
// Sort allocation sites in size order |
|
205 |
void malloc_sites_to_size_order(); |
|
206 |
// Sort allocation sites in call site address order |
|
207 |
void malloc_sites_to_allocation_site_order(); |
|
46711
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
27162
diff
changeset
|
208 |
// Sort allocation sites in call site address and memory type order |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
27162
diff
changeset
|
209 |
void malloc_sites_to_allocation_site_and_type_order(); |
13195 | 210 |
|
25946 | 211 |
// Sort allocation sites in reserved size order |
212 |
void virtual_memory_sites_to_size_order(); |
|
213 |
// Sort allocation sites in call site address order |
|
214 |
void virtual_memory_sites_to_reservation_site_order(); |
|
13195 | 215 |
}; |
216 |
||
25946 | 217 |
#endif // INCLUDE_NMT |
13195 | 218 |
|
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
51334
diff
changeset
|
219 |
#endif // SHARE_SERVICES_MEMBASELINE_HPP |