author | zgu |
Thu, 08 Feb 2018 13:21:22 -0500 | |
changeset 48884 | 7e17b00dc245 |
parent 48874 | f09fdaad7321 |
child 51959 | db0c3952de52 |
permissions | -rw-r--r-- |
13195 | 1 |
/* |
48884
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
2 |
* Copyright (c) 2012, 2018, 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 |
|
48884
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
26 |
#include "classfile/classLoaderData.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) { |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
67 |
res = (int)(s1.flags() - s2.flags()); |
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 |
||
26288 | 159 |
_malloc_sites.move(malloc_walker.malloc_sites()); |
25946 | 160 |
// The malloc sites are collected in size order |
161 |
_malloc_sites_order = by_size; |
|
162 |
||
163 |
// Virtual memory allocation sites |
|
26288 | 164 |
VirtualMemoryAllocationWalker virtual_memory_walker; |
25946 | 165 |
if (!VirtualMemoryTracker::walk_virtual_memory(&virtual_memory_walker)) { |
166 |
return false; |
|
167 |
} |
|
168 |
||
169 |
// Virtual memory allocations are collected in call stack order |
|
26288 | 170 |
_virtual_memory_allocations.move(virtual_memory_walker.virtual_memory_allocations()); |
25946 | 171 |
|
172 |
if (!aggregate_virtual_memory_allocation_sites()) { |
|
173 |
return false; |
|
174 |
} |
|
175 |
// Virtual memory allocation sites are aggregrated in call stack order |
|
176 |
_virtual_memory_sites_order = by_address; |
|
13195 | 177 |
|
178 |
return true; |
|
179 |
} |
|
180 |
||
25946 | 181 |
bool MemBaseline::baseline(bool summaryOnly) { |
182 |
reset(); |
|
14120
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13195
diff
changeset
|
183 |
|
48884
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
184 |
_instance_class_count = ClassLoaderDataGraph::num_instance_classes(); |
7e17b00dc245
8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents:
48874
diff
changeset
|
185 |
_array_class_count = ClassLoaderDataGraph::num_array_classes(); |
14120
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13195
diff
changeset
|
186 |
|
25946 | 187 |
if (!baseline_summary()) { |
14120
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13195
diff
changeset
|
188 |
return false; |
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13195
diff
changeset
|
189 |
} |
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13195
diff
changeset
|
190 |
|
25946 | 191 |
_baseline_type = Summary_baselined; |
14120
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13195
diff
changeset
|
192 |
|
25946 | 193 |
// baseline details |
194 |
if (!summaryOnly && |
|
195 |
MemTracker::tracking_level() == NMT_detail) { |
|
196 |
baseline_allocation_sites(); |
|
197 |
_baseline_type = Detail_baselined; |
|
14120
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13195
diff
changeset
|
198 |
} |
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13195
diff
changeset
|
199 |
|
13195 | 200 |
return true; |
201 |
} |
|
202 |
||
25946 | 203 |
int compare_allocation_site(const VirtualMemoryAllocationSite& s1, |
204 |
const VirtualMemoryAllocationSite& s2) { |
|
205 |
return s1.call_stack()->compare(*s2.call_stack()); |
|
206 |
} |
|
207 |
||
208 |
bool MemBaseline::aggregate_virtual_memory_allocation_sites() { |
|
26288 | 209 |
SortedLinkedList<VirtualMemoryAllocationSite, compare_allocation_site> allocation_sites; |
25946 | 210 |
|
211 |
VirtualMemoryAllocationIterator itr = virtual_memory_allocations(); |
|
212 |
const ReservedMemoryRegion* rgn; |
|
213 |
VirtualMemoryAllocationSite* site; |
|
214 |
while ((rgn = itr.next()) != NULL) { |
|
215 |
VirtualMemoryAllocationSite tmp(*rgn->call_stack()); |
|
216 |
site = allocation_sites.find(tmp); |
|
217 |
if (site == NULL) { |
|
218 |
LinkedListNode<VirtualMemoryAllocationSite>* node = |
|
219 |
allocation_sites.add(tmp); |
|
220 |
if (node == NULL) return false; |
|
221 |
site = node->data(); |
|
222 |
} |
|
223 |
site->reserve_memory(rgn->size()); |
|
224 |
site->commit_memory(rgn->committed_size()); |
|
17074 | 225 |
} |
13195 | 226 |
|
26288 | 227 |
_virtual_memory_sites.move(&allocation_sites); |
25946 | 228 |
return true; |
13195 | 229 |
} |
230 |
||
25946 | 231 |
MallocSiteIterator MemBaseline::malloc_sites(SortingOrder order) { |
26288 | 232 |
assert(!_malloc_sites.is_empty(), "Not detail baseline"); |
25946 | 233 |
switch(order) { |
234 |
case by_size: |
|
235 |
malloc_sites_to_size_order(); |
|
236 |
break; |
|
237 |
case by_site: |
|
238 |
malloc_sites_to_allocation_site_order(); |
|
239 |
break; |
|
46711
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
240 |
case by_site_and_type: |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
241 |
malloc_sites_to_allocation_site_and_type_order(); |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
242 |
break; |
25946 | 243 |
case by_address: |
244 |
default: |
|
245 |
ShouldNotReachHere(); |
|
13195 | 246 |
} |
25946 | 247 |
return MallocSiteIterator(_malloc_sites.head()); |
13195 | 248 |
} |
249 |
||
25946 | 250 |
VirtualMemorySiteIterator MemBaseline::virtual_memory_sites(SortingOrder order) { |
26288 | 251 |
assert(!_virtual_memory_sites.is_empty(), "Not detail baseline"); |
25946 | 252 |
switch(order) { |
253 |
case by_size: |
|
254 |
virtual_memory_sites_to_size_order(); |
|
255 |
break; |
|
256 |
case by_site: |
|
257 |
virtual_memory_sites_to_reservation_site_order(); |
|
258 |
break; |
|
259 |
case by_address: |
|
260 |
default: |
|
261 |
ShouldNotReachHere(); |
|
13195 | 262 |
} |
25946 | 263 |
return VirtualMemorySiteIterator(_virtual_memory_sites.head()); |
13195 | 264 |
} |
265 |
||
266 |
||
25946 | 267 |
// Sorting allocations sites in different orders |
268 |
void MemBaseline::malloc_sites_to_size_order() { |
|
269 |
if (_malloc_sites_order != by_size) { |
|
26288 | 270 |
SortedLinkedList<MallocSite, compare_malloc_size> tmp; |
13195 | 271 |
|
25946 | 272 |
// Add malloc sites to sorted linked list to sort into size order |
273 |
tmp.move(&_malloc_sites); |
|
274 |
_malloc_sites.set_head(tmp.head()); |
|
275 |
tmp.set_head(NULL); |
|
276 |
_malloc_sites_order = by_size; |
|
13195 | 277 |
} |
278 |
} |
|
279 |
||
25946 | 280 |
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
|
281 |
if (_malloc_sites_order != by_site && _malloc_sites_order != by_site_and_type) { |
26288 | 282 |
SortedLinkedList<MallocSite, compare_malloc_site> tmp; |
25946 | 283 |
// Add malloc sites to sorted linked list to sort into site (address) order |
284 |
tmp.move(&_malloc_sites); |
|
285 |
_malloc_sites.set_head(tmp.head()); |
|
286 |
tmp.set_head(NULL); |
|
287 |
_malloc_sites_order = by_site; |
|
288 |
} |
|
13195 | 289 |
} |
290 |
||
46711
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
291 |
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
|
292 |
if (_malloc_sites_order != by_site_and_type) { |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
293 |
SortedLinkedList<MallocSite, compare_malloc_site_and_type> tmp; |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
294 |
// 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
|
295 |
tmp.move(&_malloc_sites); |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
296 |
_malloc_sites.set_head(tmp.head()); |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
297 |
tmp.set_head(NULL); |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
298 |
_malloc_sites_order = by_site_and_type; |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
299 |
} |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
300 |
} |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
26288
diff
changeset
|
301 |
|
25946 | 302 |
void MemBaseline::virtual_memory_sites_to_size_order() { |
303 |
if (_virtual_memory_sites_order != by_size) { |
|
26288 | 304 |
SortedLinkedList<VirtualMemoryAllocationSite, compare_virtual_memory_size> tmp; |
13195 | 305 |
|
25946 | 306 |
tmp.move(&_virtual_memory_sites); |
307 |
||
308 |
_virtual_memory_sites.set_head(tmp.head()); |
|
309 |
tmp.set_head(NULL); |
|
310 |
_virtual_memory_sites_order = by_size; |
|
311 |
} |
|
13195 | 312 |
} |
313 |
||
25946 | 314 |
void MemBaseline::virtual_memory_sites_to_reservation_site_order() { |
315 |
if (_virtual_memory_sites_order != by_size) { |
|
26288 | 316 |
SortedLinkedList<VirtualMemoryAllocationSite, compare_virtual_memory_site> tmp; |
13195 | 317 |
|
26288 | 318 |
tmp.move(&_virtual_memory_sites); |
25946 | 319 |
|
320 |
_virtual_memory_sites.set_head(tmp.head()); |
|
321 |
tmp.set_head(NULL); |
|
322 |
||
323 |
_virtual_memory_sites_order = by_size; |
|
324 |
} |
|
13195 | 325 |
} |
326 |