author | zgu |
Tue, 26 Mar 2019 15:50:34 -0400 | |
changeset 54292 | c31faeacf00a |
parent 53685 | df83034c9275 |
permissions | -rw-r--r-- |
13195 | 1 |
/* |
53685
df83034c9275
8218558: NMT stack traces in output should show mt component for virtual memory allocations
zgu
parents:
51959
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 |
#include "precompiled.hpp" |
|
25946 | 25 |
|
51959
db0c3952de52
8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents:
48884
diff
changeset
|
26 |
#include "classfile/classLoaderDataGraph.inline.hpp" |
13195 | 27 |
#include "memory/allocation.hpp" |
17074 | 28 |
#include "runtime/safepoint.hpp" |
29 |
#include "runtime/thread.inline.hpp" |
|
13195 | 30 |
#include "services/memBaseline.hpp" |
31 |
#include "services/memTracker.hpp" |
|
32 |
||
25946 | 33 |
/* |
34 |
* Sizes are sorted in descenting order for reporting |
|
35 |
*/ |
|
36 |
int compare_malloc_size(const MallocSite& s1, const MallocSite& s2) { |
|
37 |
if (s1.size() == s2.size()) { |
|
38 |
return 0; |
|
39 |
} else if (s1.size() > s2.size()) { |
|
40 |
return -1; |
|
41 |
} else { |
|
42 |
return 1; |
|
13195 | 43 |
} |
44 |
} |
|
45 |
||
46 |
||
25946 | 47 |
int compare_virtual_memory_size(const VirtualMemoryAllocationSite& s1, |
48 |
const VirtualMemoryAllocationSite& s2) { |
|
49 |
if (s1.reserved() == s2.reserved()) { |
|
50 |
return 0; |
|
51 |
} else if (s1.reserved() > s2.reserved()) { |
|
52 |
return -1; |
|
53 |
} else { |
|
54 |
return 1; |
|
13195 | 55 |
} |
25946 | 56 |
} |
13195 | 57 |
|
25946 | 58 |
// Sort into allocation site addresses order for baseline comparison |
59 |
int compare_malloc_site(const MallocSite& s1, const MallocSite& s2) { |
|
60 |
return s1.call_stack()->compare(*s2.call_stack()); |
|
13195 | 61 |
} |
62 |
||
46711
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
63 |
// Sort into allocation site addresses and memory type order for baseline comparison |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
64 |
int compare_malloc_site_and_type(const MallocSite& s1, const MallocSite& s2) { |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
65 |
int res = compare_malloc_site(s1, s2); |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
66 |
if (res == 0) { |
53685
df83034c9275
8218558: NMT stack traces in output should show mt component for virtual memory allocations
zgu
parents:
51959
diff
changeset
|
67 |
res = (int)(s1.flag() - s2.flag()); |
46711
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
68 |
} |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
69 |
|
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
70 |
return res; |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
71 |
} |
13195 | 72 |
|
25946 | 73 |
int compare_virtual_memory_site(const VirtualMemoryAllocationSite& s1, |
74 |
const VirtualMemoryAllocationSite& s2) { |
|
75 |
return s1.call_stack()->compare(*s2.call_stack()); |
|
13195 | 76 |
} |
77 |
||
25946 | 78 |
/* |
79 |
* Walker to walk malloc allocation site table |
|
80 |
*/ |
|
81 |
class MallocAllocationSiteWalker : public MallocSiteWalker { |
|
82 |
private: |
|
26288 | 83 |
SortedLinkedList<MallocSite, compare_malloc_size> _malloc_sites; |
25946 | 84 |
size_t _count; |
85 |
||
86 |
// Entries in MallocSiteTable with size = 0 and count = 0, |
|
87 |
// when the malloc site is not longer there. |
|
88 |
public: |
|
26288 | 89 |
MallocAllocationSiteWalker() : _count(0) { } |
25946 | 90 |
|
91 |
inline size_t count() const { return _count; } |
|
92 |
||
93 |
LinkedList<MallocSite>* malloc_sites() { |
|
94 |
return &_malloc_sites; |
|
95 |
} |
|
96 |
||
97 |
bool do_malloc_site(const MallocSite* site) { |
|
98 |
if (site->size() >= MemBaseline::SIZE_THRESHOLD) { |
|
99 |
if (_malloc_sites.add(*site) != NULL) { |
|
100 |
_count++; |
|
101 |
return true; |
|
102 |
} else { |
|
103 |
return false; // OOM |
|
104 |
} |
|
105 |
} else { |
|
106 |
// malloc site does not meet threshold, ignore and continue |
|
107 |
return true; |
|
108 |
} |
|
109 |
} |
|
110 |
}; |
|
111 |
||
112 |
// Compare virtual memory region's base address |
|
113 |
int compare_virtual_memory_base(const ReservedMemoryRegion& r1, const ReservedMemoryRegion& r2) { |
|
114 |
return r1.compare(r2); |
|
13195 | 115 |
} |
116 |
||
25946 | 117 |
// Walk all virtual memory regions for baselining |
118 |
class VirtualMemoryAllocationWalker : public VirtualMemoryWalker { |
|
119 |
private: |
|
26288 | 120 |
SortedLinkedList<ReservedMemoryRegion, compare_virtual_memory_base> |
25946 | 121 |
_virtual_memory_regions; |
122 |
size_t _count; |
|
123 |
||
124 |
public: |
|
26288 | 125 |
VirtualMemoryAllocationWalker() : _count(0) { } |
25946 | 126 |
|
127 |
bool do_allocation_site(const ReservedMemoryRegion* rgn) { |
|
128 |
if (rgn->size() >= MemBaseline::SIZE_THRESHOLD) { |
|
129 |
if (_virtual_memory_regions.add(*rgn) != NULL) { |
|
130 |
_count ++; |
|
131 |
return true; |
|
132 |
} else { |
|
133 |
return false; |
|
13195 | 134 |
} |
135 |
} |
|
25946 | 136 |
return true; |
13195 | 137 |
} |
138 |
||
25946 | 139 |
LinkedList<ReservedMemoryRegion>* virtual_memory_allocations() { |
140 |
return &_virtual_memory_regions; |
|
141 |
} |
|
142 |
}; |
|
143 |
||
144 |
||
145 |
bool MemBaseline::baseline_summary() { |
|
26288 | 146 |
MallocMemorySummary::snapshot(&_malloc_memory_snapshot); |
147 |
VirtualMemorySummary::snapshot(&_virtual_memory_snapshot); |
|
47553
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
148 |
MetaspaceSnapshot::snapshot(_metaspace_snapshot); |
25946 | 149 |
return true; |
150 |
} |
|
151 |
||
152 |
bool MemBaseline::baseline_allocation_sites() { |
|
153 |
// Malloc allocation sites |
|
26288 | 154 |
MallocAllocationSiteWalker malloc_walker; |
25946 | 155 |
if (!MallocSiteTable::walk_malloc_site(&malloc_walker)) { |
156 |
return false; |
|
157 |
} |
|
158 |
||
54292
c31faeacf00a
8204552: NMT: Separate thread stack tracking from virtual memory tracking
zgu
parents:
53685
diff
changeset
|
159 |
// Walk simple thread stacks |
c31faeacf00a
8204552: NMT: Separate thread stack tracking from virtual memory tracking
zgu
parents:
53685
diff
changeset
|
160 |
if (!ThreadStackTracker::walk_simple_thread_stack_site(&malloc_walker)) { |
c31faeacf00a
8204552: NMT: Separate thread stack tracking from virtual memory tracking
zgu
parents:
53685
diff
changeset
|
161 |
return false; |
c31faeacf00a
8204552: NMT: Separate thread stack tracking from virtual memory tracking
zgu
parents:
53685
diff
changeset
|
162 |
} |
c31faeacf00a
8204552: NMT: Separate thread stack tracking from virtual memory tracking
zgu
parents:
53685
diff
changeset
|
163 |
|
26288 | 164 |
_malloc_sites.move(malloc_walker.malloc_sites()); |
25946 | 165 |
// The malloc sites are collected in size order |
166 |
_malloc_sites_order = by_size; |
|
167 |
||
168 |
// Virtual memory allocation sites |
|
26288 | 169 |
VirtualMemoryAllocationWalker virtual_memory_walker; |
25946 | 170 |
if (!VirtualMemoryTracker::walk_virtual_memory(&virtual_memory_walker)) { |
171 |
return false; |
|
172 |
} |
|
173 |
||
174 |
// Virtual memory allocations are collected in call stack order |
|
26288 | 175 |
_virtual_memory_allocations.move(virtual_memory_walker.virtual_memory_allocations()); |
25946 | 176 |
|
177 |
if (!aggregate_virtual_memory_allocation_sites()) { |
|
178 |
return false; |
|
179 |
} |
|
180 |
// Virtual memory allocation sites are aggregrated in call stack order |
|
181 |
_virtual_memory_sites_order = by_address; |
|
13195 | 182 |
|
183 |
return true; |
|
184 |
} |
|
185 |
||
25946 | 186 |
bool MemBaseline::baseline(bool summaryOnly) { |
187 |
reset(); |
|
14120
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13195
diff
changeset
|
188 |
|
48884
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
189 |
_instance_class_count = ClassLoaderDataGraph::num_instance_classes(); |
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
190 |
_array_class_count = ClassLoaderDataGraph::num_array_classes(); |
14120
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13195
diff
changeset
|
191 |
|
25946 | 192 |
if (!baseline_summary()) { |
14120
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13195
diff
changeset
|
193 |
return false; |
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13195
diff
changeset
|
194 |
} |
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13195
diff
changeset
|
195 |
|
25946 | 196 |
_baseline_type = Summary_baselined; |
14120
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13195
diff
changeset
|
197 |
|
25946 | 198 |
// baseline details |
199 |
if (!summaryOnly && |
|
200 |
MemTracker::tracking_level() == NMT_detail) { |
|
201 |
baseline_allocation_sites(); |
|
202 |
_baseline_type = Detail_baselined; |
|
14120
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13195
diff
changeset
|
203 |
} |
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13195
diff
changeset
|
204 |
|
13195 | 205 |
return true; |
206 |
} |
|
207 |
||
25946 | 208 |
int compare_allocation_site(const VirtualMemoryAllocationSite& s1, |
209 |
const VirtualMemoryAllocationSite& s2) { |
|
210 |
return s1.call_stack()->compare(*s2.call_stack()); |
|
211 |
} |
|
212 |
||
213 |
bool MemBaseline::aggregate_virtual_memory_allocation_sites() { |
|
26288 | 214 |
SortedLinkedList<VirtualMemoryAllocationSite, compare_allocation_site> allocation_sites; |
25946 | 215 |
|
216 |
VirtualMemoryAllocationIterator itr = virtual_memory_allocations(); |
|
217 |
const ReservedMemoryRegion* rgn; |
|
218 |
VirtualMemoryAllocationSite* site; |
|
219 |
while ((rgn = itr.next()) != NULL) { |
|
53685
df83034c9275
8218558: NMT stack traces in output should show mt component for virtual memory allocations
zgu
parents:
51959
diff
changeset
|
220 |
VirtualMemoryAllocationSite tmp(*rgn->call_stack(), rgn->flag()); |
25946 | 221 |
site = allocation_sites.find(tmp); |
222 |
if (site == NULL) { |
|
223 |
LinkedListNode<VirtualMemoryAllocationSite>* node = |
|
224 |
allocation_sites.add(tmp); |
|
225 |
if (node == NULL) return false; |
|
226 |
site = node->data(); |
|
227 |
} |
|
228 |
site->reserve_memory(rgn->size()); |
|
229 |
site->commit_memory(rgn->committed_size()); |
|
17074 | 230 |
} |
13195 | 231 |
|
26288 | 232 |
_virtual_memory_sites.move(&allocation_sites); |
25946 | 233 |
return true; |
13195 | 234 |
} |
235 |
||
25946 | 236 |
MallocSiteIterator MemBaseline::malloc_sites(SortingOrder order) { |
26288 | 237 |
assert(!_malloc_sites.is_empty(), "Not detail baseline"); |
25946 | 238 |
switch(order) { |
239 |
case by_size: |
|
240 |
malloc_sites_to_size_order(); |
|
241 |
break; |
|
242 |
case by_site: |
|
243 |
malloc_sites_to_allocation_site_order(); |
|
244 |
break; |
|
46711
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
245 |
case by_site_and_type: |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
246 |
malloc_sites_to_allocation_site_and_type_order(); |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
247 |
break; |
25946 | 248 |
case by_address: |
249 |
default: |
|
250 |
ShouldNotReachHere(); |
|
13195 | 251 |
} |
25946 | 252 |
return MallocSiteIterator(_malloc_sites.head()); |
13195 | 253 |
} |
254 |
||
25946 | 255 |
VirtualMemorySiteIterator MemBaseline::virtual_memory_sites(SortingOrder order) { |
26288 | 256 |
assert(!_virtual_memory_sites.is_empty(), "Not detail baseline"); |
25946 | 257 |
switch(order) { |
258 |
case by_size: |
|
259 |
virtual_memory_sites_to_size_order(); |
|
260 |
break; |
|
261 |
case by_site: |
|
262 |
virtual_memory_sites_to_reservation_site_order(); |
|
263 |
break; |
|
264 |
case by_address: |
|
265 |
default: |
|
266 |
ShouldNotReachHere(); |
|
13195 | 267 |
} |
25946 | 268 |
return VirtualMemorySiteIterator(_virtual_memory_sites.head()); |
13195 | 269 |
} |
270 |
||
271 |
||
25946 | 272 |
// Sorting allocations sites in different orders |
273 |
void MemBaseline::malloc_sites_to_size_order() { |
|
274 |
if (_malloc_sites_order != by_size) { |
|
26288 | 275 |
SortedLinkedList<MallocSite, compare_malloc_size> tmp; |
13195 | 276 |
|
25946 | 277 |
// Add malloc sites to sorted linked list to sort into size order |
278 |
tmp.move(&_malloc_sites); |
|
279 |
_malloc_sites.set_head(tmp.head()); |
|
280 |
tmp.set_head(NULL); |
|
281 |
_malloc_sites_order = by_size; |
|
13195 | 282 |
} |
283 |
} |
|
284 |
||
25946 | 285 |
void MemBaseline::malloc_sites_to_allocation_site_order() { |
46711
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
286 |
if (_malloc_sites_order != by_site && _malloc_sites_order != by_site_and_type) { |
26288 | 287 |
SortedLinkedList<MallocSite, compare_malloc_site> tmp; |
25946 | 288 |
// Add malloc sites to sorted linked list to sort into site (address) order |
289 |
tmp.move(&_malloc_sites); |
|
290 |
_malloc_sites.set_head(tmp.head()); |
|
291 |
tmp.set_head(NULL); |
|
292 |
_malloc_sites_order = by_site; |
|
293 |
} |
|
13195 | 294 |
} |
295 |
||
46711
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
296 |
void MemBaseline::malloc_sites_to_allocation_site_and_type_order() { |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
297 |
if (_malloc_sites_order != by_site_and_type) { |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
298 |
SortedLinkedList<MallocSite, compare_malloc_site_and_type> tmp; |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
299 |
// Add malloc sites to sorted linked list to sort into site (address) order |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
300 |
tmp.move(&_malloc_sites); |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
301 |
_malloc_sites.set_head(tmp.head()); |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
302 |
tmp.set_head(NULL); |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
303 |
_malloc_sites_order = by_site_and_type; |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
304 |
} |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
305 |
} |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
306 |
|
25946 | 307 |
void MemBaseline::virtual_memory_sites_to_size_order() { |
308 |
if (_virtual_memory_sites_order != by_size) { |
|
26288 | 309 |
SortedLinkedList<VirtualMemoryAllocationSite, compare_virtual_memory_size> tmp; |
13195 | 310 |
|
25946 | 311 |
tmp.move(&_virtual_memory_sites); |
312 |
||
313 |
_virtual_memory_sites.set_head(tmp.head()); |
|
314 |
tmp.set_head(NULL); |
|
315 |
_virtual_memory_sites_order = by_size; |
|
316 |
} |
|
13195 | 317 |
} |
318 |
||
25946 | 319 |
void MemBaseline::virtual_memory_sites_to_reservation_site_order() { |
320 |
if (_virtual_memory_sites_order != by_size) { |
|
26288 | 321 |
SortedLinkedList<VirtualMemoryAllocationSite, compare_virtual_memory_site> tmp; |
13195 | 322 |
|
26288 | 323 |
tmp.move(&_virtual_memory_sites); |
25946 | 324 |
|
325 |
_virtual_memory_sites.set_head(tmp.head()); |
|
326 |
tmp.set_head(NULL); |
|
327 |
||
328 |
_virtual_memory_sites_order = by_size; |
|
329 |
} |
|
13195 | 330 |
} |
331 |