author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 46711 | hotspot/src/share/vm/services/memReporter.cpp@0ccef2260315 |
child 47553 | 5d20359dd938 |
permissions | -rw-r--r-- |
13195 | 1 |
/* |
46489
40abcea5a9d5
8139673: NMT stack traces in output should show mtcomponent
zgu
parents:
25946
diff
changeset
|
2 |
* Copyright (c) 2012, 2017, 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 |
|
26 |
#include "memory/allocation.hpp" |
|
27 |
#include "services/mallocTracker.hpp" |
|
13195 | 28 |
#include "services/memReporter.hpp" |
25946 | 29 |
#include "services/virtualMemoryTracker.hpp" |
30 |
#include "utilities/globalDefinitions.hpp" |
|
31 |
||
32 |
size_t MemReporterBase::reserved_total(const MallocMemory* malloc, const VirtualMemory* vm) const { |
|
33 |
return malloc->malloc_size() + malloc->arena_size() + vm->reserved(); |
|
34 |
} |
|
35 |
||
36 |
size_t MemReporterBase::committed_total(const MallocMemory* malloc, const VirtualMemory* vm) const { |
|
37 |
return malloc->malloc_size() + malloc->arena_size() + vm->committed(); |
|
38 |
} |
|
13195 | 39 |
|
25946 | 40 |
void MemReporterBase::print_total(size_t reserved, size_t committed) const { |
41 |
const char* scale = current_scale(); |
|
42 |
output()->print("reserved=" SIZE_FORMAT "%s, committed=" SIZE_FORMAT "%s", |
|
43 |
amount_in_current_scale(reserved), scale, amount_in_current_scale(committed), scale); |
|
44 |
} |
|
45 |
||
46489
40abcea5a9d5
8139673: NMT stack traces in output should show mtcomponent
zgu
parents:
25946
diff
changeset
|
46 |
void MemReporterBase::print_malloc(size_t amount, size_t count, MEMFLAGS flag) const { |
25946 | 47 |
const char* scale = current_scale(); |
48 |
outputStream* out = output(); |
|
46489
40abcea5a9d5
8139673: NMT stack traces in output should show mtcomponent
zgu
parents:
25946
diff
changeset
|
49 |
if (flag != mtNone) { |
40abcea5a9d5
8139673: NMT stack traces in output should show mtcomponent
zgu
parents:
25946
diff
changeset
|
50 |
out->print("(malloc=" SIZE_FORMAT "%s type=%s", |
40abcea5a9d5
8139673: NMT stack traces in output should show mtcomponent
zgu
parents:
25946
diff
changeset
|
51 |
amount_in_current_scale(amount), scale, NMTUtil::flag_to_name(flag)); |
40abcea5a9d5
8139673: NMT stack traces in output should show mtcomponent
zgu
parents:
25946
diff
changeset
|
52 |
} else { |
40abcea5a9d5
8139673: NMT stack traces in output should show mtcomponent
zgu
parents:
25946
diff
changeset
|
53 |
out->print("(malloc=" SIZE_FORMAT "%s", |
40abcea5a9d5
8139673: NMT stack traces in output should show mtcomponent
zgu
parents:
25946
diff
changeset
|
54 |
amount_in_current_scale(amount), scale); |
40abcea5a9d5
8139673: NMT stack traces in output should show mtcomponent
zgu
parents:
25946
diff
changeset
|
55 |
} |
25946 | 56 |
|
57 |
if (count > 0) { |
|
58 |
out->print(" #" SIZE_FORMAT "", count); |
|
59 |
} |
|
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
22234
diff
changeset
|
60 |
|
25946 | 61 |
out->print(")"); |
62 |
} |
|
63 |
||
64 |
void MemReporterBase::print_virtual_memory(size_t reserved, size_t committed) const { |
|
65 |
const char* scale = current_scale(); |
|
66 |
output()->print("(mmap: reserved=" SIZE_FORMAT "%s, committed=" SIZE_FORMAT "%s)", |
|
67 |
amount_in_current_scale(reserved), scale, amount_in_current_scale(committed), scale); |
|
68 |
} |
|
69 |
||
70 |
void MemReporterBase::print_malloc_line(size_t amount, size_t count) const { |
|
71 |
output()->print("%28s", " "); |
|
72 |
print_malloc(amount, count); |
|
73 |
output()->print_cr(" "); |
|
74 |
} |
|
75 |
||
76 |
void MemReporterBase::print_virtual_memory_line(size_t reserved, size_t committed) const { |
|
77 |
output()->print("%28s", " "); |
|
78 |
print_virtual_memory(reserved, committed); |
|
79 |
output()->print_cr(" "); |
|
80 |
} |
|
81 |
||
82 |
void MemReporterBase::print_arena_line(size_t amount, size_t count) const { |
|
83 |
const char* scale = current_scale(); |
|
84 |
output()->print_cr("%27s (arena=" SIZE_FORMAT "%s #" SIZE_FORMAT ")", " ", |
|
85 |
amount_in_current_scale(amount), scale, count); |
|
86 |
} |
|
87 |
||
88 |
void MemReporterBase::print_virtual_memory_region(const char* type, address base, size_t size) const { |
|
89 |
const char* scale = current_scale(); |
|
90 |
output()->print("[" PTR_FORMAT " - " PTR_FORMAT "] %s " SIZE_FORMAT "%s", |
|
91 |
p2i(base), p2i(base + size), type, amount_in_current_scale(size), scale); |
|
13195 | 92 |
} |
93 |
||
94 |
||
25946 | 95 |
void MemSummaryReporter::report() { |
96 |
const char* scale = current_scale(); |
|
97 |
outputStream* out = output(); |
|
98 |
size_t total_reserved_amount = _malloc_snapshot->total() + |
|
99 |
_vm_snapshot->total_reserved(); |
|
100 |
size_t total_committed_amount = _malloc_snapshot->total() + |
|
101 |
_vm_snapshot->total_committed(); |
|
13195 | 102 |
|
25946 | 103 |
// Overall total |
104 |
out->print_cr("\nNative Memory Tracking:\n"); |
|
105 |
out->print("Total: "); |
|
106 |
print_total(total_reserved_amount, total_committed_amount); |
|
107 |
out->print("\n"); |
|
13195 | 108 |
|
25946 | 109 |
// Summary by memory type |
110 |
for (int index = 0; index < mt_number_of_types; index ++) { |
|
111 |
MEMFLAGS flag = NMTUtil::index_to_flag(index); |
|
112 |
// thread stack is reported as part of thread category |
|
113 |
if (flag == mtThreadStack) continue; |
|
114 |
MallocMemory* malloc_memory = _malloc_snapshot->by_type(flag); |
|
115 |
VirtualMemory* virtual_memory = _vm_snapshot->by_type(flag); |
|
116 |
||
117 |
report_summary_of_type(flag, malloc_memory, virtual_memory); |
|
14120
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13195
diff
changeset
|
118 |
} |
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13195
diff
changeset
|
119 |
} |
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13195
diff
changeset
|
120 |
|
25946 | 121 |
void MemSummaryReporter::report_summary_of_type(MEMFLAGS flag, |
122 |
MallocMemory* malloc_memory, VirtualMemory* virtual_memory) { |
|
13195 | 123 |
|
25946 | 124 |
size_t reserved_amount = reserved_total (malloc_memory, virtual_memory); |
125 |
size_t committed_amount = committed_total(malloc_memory, virtual_memory); |
|
13195 | 126 |
|
25946 | 127 |
// Count thread's native stack in "Thread" category |
128 |
if (flag == mtThread) { |
|
129 |
const VirtualMemory* thread_stack_usage = |
|
130 |
(const VirtualMemory*)_vm_snapshot->by_type(mtThreadStack); |
|
131 |
reserved_amount += thread_stack_usage->reserved(); |
|
132 |
committed_amount += thread_stack_usage->committed(); |
|
133 |
} else if (flag == mtNMT) { |
|
134 |
// Count malloc headers in "NMT" category |
|
135 |
reserved_amount += _malloc_snapshot->malloc_overhead()->size(); |
|
136 |
committed_amount += _malloc_snapshot->malloc_overhead()->size(); |
|
13195 | 137 |
} |
138 |
||
25946 | 139 |
if (amount_in_current_scale(reserved_amount) > 0) { |
140 |
outputStream* out = output(); |
|
141 |
const char* scale = current_scale(); |
|
142 |
out->print("-%26s (", NMTUtil::flag_to_name(flag)); |
|
143 |
print_total(reserved_amount, committed_amount); |
|
144 |
out->print_cr(")"); |
|
13195 | 145 |
|
25946 | 146 |
if (flag == mtClass) { |
147 |
// report class count |
|
148 |
out->print_cr("%27s (classes #" SIZE_FORMAT ")", " ", _class_count); |
|
149 |
} else if (flag == mtThread) { |
|
150 |
// report thread count |
|
151 |
out->print_cr("%27s (thread #" SIZE_FORMAT ")", " ", _malloc_snapshot->thread_count()); |
|
152 |
const VirtualMemory* thread_stack_usage = |
|
153 |
_vm_snapshot->by_type(mtThreadStack); |
|
154 |
out->print("%27s (stack: ", " "); |
|
155 |
print_total(thread_stack_usage->reserved(), thread_stack_usage->committed()); |
|
156 |
out->print_cr(")"); |
|
157 |
} |
|
13195 | 158 |
|
25946 | 159 |
// report malloc'd memory |
160 |
if (amount_in_current_scale(malloc_memory->malloc_size()) > 0) { |
|
161 |
// We don't know how many arena chunks are in used, so don't report the count |
|
162 |
size_t count = (flag == mtChunk) ? 0 : malloc_memory->malloc_count(); |
|
163 |
print_malloc_line(malloc_memory->malloc_size(), count); |
|
164 |
} |
|
13195 | 165 |
|
25946 | 166 |
if (amount_in_current_scale(virtual_memory->reserved()) > 0) { |
167 |
print_virtual_memory_line(virtual_memory->reserved(), virtual_memory->committed()); |
|
168 |
} |
|
13195 | 169 |
|
25946 | 170 |
if (amount_in_current_scale(malloc_memory->arena_size()) > 0) { |
171 |
print_arena_line(malloc_memory->arena_size(), malloc_memory->arena_count()); |
|
172 |
} |
|
173 |
||
174 |
if (flag == mtNMT && |
|
175 |
amount_in_current_scale(_malloc_snapshot->malloc_overhead()->size()) > 0) { |
|
176 |
out->print_cr("%27s (tracking overhead=" SIZE_FORMAT "%s)", " ", |
|
177 |
amount_in_current_scale(_malloc_snapshot->malloc_overhead()->size()), scale); |
|
178 |
} |
|
179 |
||
180 |
out->print_cr(" "); |
|
13195 | 181 |
} |
182 |
} |
|
183 |
||
25946 | 184 |
void MemDetailReporter::report_detail() { |
185 |
// Start detail report |
|
186 |
outputStream* out = output(); |
|
187 |
out->print_cr("Details:\n"); |
|
188 |
||
189 |
report_malloc_sites(); |
|
190 |
report_virtual_memory_allocation_sites(); |
|
191 |
} |
|
192 |
||
193 |
void MemDetailReporter::report_malloc_sites() { |
|
194 |
MallocSiteIterator malloc_itr = _baseline.malloc_sites(MemBaseline::by_size); |
|
195 |
if (malloc_itr.is_empty()) return; |
|
196 |
||
197 |
outputStream* out = output(); |
|
13195 | 198 |
|
25946 | 199 |
const MallocSite* malloc_site; |
200 |
while ((malloc_site = malloc_itr.next()) != NULL) { |
|
201 |
// Don't report if size is too small |
|
202 |
if (amount_in_current_scale(malloc_site->size()) == 0) |
|
203 |
continue; |
|
13195 | 204 |
|
25946 | 205 |
const NativeCallStack* stack = malloc_site->call_stack(); |
206 |
stack->print_on(out); |
|
207 |
out->print("%29s", " "); |
|
46489
40abcea5a9d5
8139673: NMT stack traces in output should show mtcomponent
zgu
parents:
25946
diff
changeset
|
208 |
MEMFLAGS flag = malloc_site->flags(); |
40abcea5a9d5
8139673: NMT stack traces in output should show mtcomponent
zgu
parents:
25946
diff
changeset
|
209 |
assert((flag >= 0 && flag < (int)mt_number_of_types) && flag != mtNone, |
40abcea5a9d5
8139673: NMT stack traces in output should show mtcomponent
zgu
parents:
25946
diff
changeset
|
210 |
"Must have a valid memory type"); |
40abcea5a9d5
8139673: NMT stack traces in output should show mtcomponent
zgu
parents:
25946
diff
changeset
|
211 |
print_malloc(malloc_site->size(), malloc_site->count(),flag); |
25946 | 212 |
out->print_cr("\n"); |
213 |
} |
|
214 |
} |
|
215 |
||
216 |
void MemDetailReporter::report_virtual_memory_allocation_sites() { |
|
217 |
VirtualMemorySiteIterator virtual_memory_itr = |
|
218 |
_baseline.virtual_memory_sites(MemBaseline::by_size); |
|
219 |
||
220 |
if (virtual_memory_itr.is_empty()) return; |
|
221 |
||
222 |
outputStream* out = output(); |
|
223 |
const VirtualMemoryAllocationSite* virtual_memory_site; |
|
13195 | 224 |
|
25946 | 225 |
while ((virtual_memory_site = virtual_memory_itr.next()) != NULL) { |
226 |
// Don't report if size is too small |
|
227 |
if (amount_in_current_scale(virtual_memory_site->reserved()) == 0) |
|
228 |
continue; |
|
229 |
||
230 |
const NativeCallStack* stack = virtual_memory_site->call_stack(); |
|
231 |
stack->print_on(out); |
|
232 |
out->print("%28s (", " "); |
|
233 |
print_total(virtual_memory_site->reserved(), virtual_memory_site->committed()); |
|
234 |
out->print_cr(")\n"); |
|
235 |
} |
|
236 |
} |
|
237 |
||
238 |
||
239 |
void MemDetailReporter::report_virtual_memory_map() { |
|
240 |
// Virtual memory map always in base address order |
|
241 |
VirtualMemoryAllocationIterator itr = _baseline.virtual_memory_allocations(); |
|
242 |
const ReservedMemoryRegion* rgn; |
|
243 |
||
244 |
output()->print_cr("Virtual memory map:"); |
|
245 |
while ((rgn = itr.next()) != NULL) { |
|
246 |
report_virtual_memory_region(rgn); |
|
247 |
} |
|
248 |
} |
|
249 |
||
250 |
void MemDetailReporter::report_virtual_memory_region(const ReservedMemoryRegion* reserved_rgn) { |
|
251 |
assert(reserved_rgn != NULL, "NULL pointer"); |
|
252 |
||
253 |
// Don't report if size is too small |
|
254 |
if (amount_in_current_scale(reserved_rgn->size()) == 0) return; |
|
255 |
||
256 |
outputStream* out = output(); |
|
257 |
const char* scale = current_scale(); |
|
258 |
const NativeCallStack* stack = reserved_rgn->call_stack(); |
|
259 |
bool all_committed = reserved_rgn->all_committed(); |
|
260 |
const char* region_type = (all_committed ? "reserved and committed" : "reserved"); |
|
261 |
out->print_cr(" "); |
|
262 |
print_virtual_memory_region(region_type, reserved_rgn->base(), reserved_rgn->size()); |
|
263 |
out->print(" for %s", NMTUtil::flag_to_name(reserved_rgn->flag())); |
|
264 |
if (stack->is_empty()) { |
|
265 |
out->print_cr(" "); |
|
266 |
} else { |
|
267 |
out->print_cr(" from"); |
|
268 |
stack->print_on(out, 4); |
|
13195 | 269 |
} |
270 |
||
25946 | 271 |
if (all_committed) return; |
13195 | 272 |
|
25946 | 273 |
CommittedRegionIterator itr = reserved_rgn->iterate_committed_regions(); |
274 |
const CommittedMemoryRegion* committed_rgn; |
|
275 |
while ((committed_rgn = itr.next()) != NULL) { |
|
276 |
// Don't report if size is too small |
|
277 |
if (amount_in_current_scale(committed_rgn->size()) == 0) continue; |
|
278 |
stack = committed_rgn->call_stack(); |
|
279 |
out->print("\n\t"); |
|
280 |
print_virtual_memory_region("committed", committed_rgn->base(), committed_rgn->size()); |
|
281 |
if (stack->is_empty()) { |
|
282 |
out->print_cr(" "); |
|
283 |
} else { |
|
284 |
out->print_cr(" from"); |
|
285 |
stack->print_on(out, 12); |
|
13195 | 286 |
} |
287 |
} |
|
288 |
} |
|
289 |
||
25946 | 290 |
void MemSummaryDiffReporter::report_diff() { |
291 |
const char* scale = current_scale(); |
|
292 |
outputStream* out = output(); |
|
293 |
out->print_cr("\nNative Memory Tracking:\n"); |
|
13195 | 294 |
|
25946 | 295 |
// Overall diff |
296 |
out->print("Total: "); |
|
297 |
print_virtual_memory_diff(_current_baseline.total_reserved_memory(), |
|
298 |
_current_baseline.total_committed_memory(), _early_baseline.total_reserved_memory(), |
|
299 |
_early_baseline.total_committed_memory()); |
|
14120
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13195
diff
changeset
|
300 |
|
25946 | 301 |
out->print_cr("\n"); |
14120
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13195
diff
changeset
|
302 |
|
25946 | 303 |
// Summary diff by memory type |
304 |
for (int index = 0; index < mt_number_of_types; index ++) { |
|
305 |
MEMFLAGS flag = NMTUtil::index_to_flag(index); |
|
306 |
// thread stack is reported as part of thread category |
|
307 |
if (flag == mtThreadStack) continue; |
|
308 |
diff_summary_of_type(flag, _early_baseline.malloc_memory(flag), |
|
309 |
_early_baseline.virtual_memory(flag), _current_baseline.malloc_memory(flag), |
|
310 |
_current_baseline.virtual_memory(flag)); |
|
14120
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13195
diff
changeset
|
311 |
} |
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13195
diff
changeset
|
312 |
} |
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13195
diff
changeset
|
313 |
|
25946 | 314 |
void MemSummaryDiffReporter::print_malloc_diff(size_t current_amount, size_t current_count, |
46711
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
46489
diff
changeset
|
315 |
size_t early_amount, size_t early_count, MEMFLAGS flags) const { |
25946 | 316 |
const char* scale = current_scale(); |
317 |
outputStream* out = output(); |
|
13195 | 318 |
|
25946 | 319 |
out->print("malloc=" SIZE_FORMAT "%s", amount_in_current_scale(current_amount), scale); |
46711
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
46489
diff
changeset
|
320 |
// Report type only if it is valid |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
46489
diff
changeset
|
321 |
if (flags != mtNone) { |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
46489
diff
changeset
|
322 |
out->print(" type=%s", NMTUtil::flag_to_name(flags)); |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
46489
diff
changeset
|
323 |
} |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
46489
diff
changeset
|
324 |
|
25946 | 325 |
long amount_diff = diff_in_current_scale(current_amount, early_amount); |
326 |
if (amount_diff != 0) { |
|
327 |
out->print(" %+ld%s", amount_diff, scale); |
|
328 |
} |
|
329 |
if (current_count > 0) { |
|
330 |
out->print(" #" SIZE_FORMAT "", current_count); |
|
331 |
if (current_count != early_count) { |
|
332 |
out->print(" %+d", (int)(current_count - early_count)); |
|
13195 | 333 |
} |
334 |
} |
|
335 |
} |
|
336 |
||
25946 | 337 |
void MemSummaryDiffReporter::print_arena_diff(size_t current_amount, size_t current_count, |
338 |
size_t early_amount, size_t early_count) const { |
|
339 |
const char* scale = current_scale(); |
|
340 |
outputStream* out = output(); |
|
341 |
out->print("arena=" SIZE_FORMAT "%s", amount_in_current_scale(current_amount), scale); |
|
342 |
if (diff_in_current_scale(current_amount, early_amount) != 0) { |
|
343 |
out->print(" %+ld", diff_in_current_scale(current_amount, early_amount)); |
|
344 |
} |
|
345 |
||
346 |
out->print(" #" SIZE_FORMAT "", current_count); |
|
347 |
if (current_count != early_count) { |
|
348 |
out->print(" %+d", (int)(current_count - early_count)); |
|
349 |
} |
|
350 |
} |
|
13195 | 351 |
|
25946 | 352 |
void MemSummaryDiffReporter::print_virtual_memory_diff(size_t current_reserved, size_t current_committed, |
353 |
size_t early_reserved, size_t early_committed) const { |
|
354 |
const char* scale = current_scale(); |
|
355 |
outputStream* out = output(); |
|
356 |
out->print("reserved=" SIZE_FORMAT "%s", amount_in_current_scale(current_reserved), scale); |
|
357 |
long reserved_diff = diff_in_current_scale(current_reserved, early_reserved); |
|
358 |
if (reserved_diff != 0) { |
|
359 |
out->print(" %+ld%s", reserved_diff, scale); |
|
360 |
} |
|
361 |
||
362 |
out->print(", committed=" SIZE_FORMAT "%s", amount_in_current_scale(current_committed), scale); |
|
363 |
long committed_diff = diff_in_current_scale(current_committed, early_committed); |
|
364 |
if (committed_diff != 0) { |
|
365 |
out->print(" %+ld%s", committed_diff, scale); |
|
13195 | 366 |
} |
367 |
} |
|
368 |
||
25946 | 369 |
|
370 |
void MemSummaryDiffReporter::diff_summary_of_type(MEMFLAGS flag, const MallocMemory* early_malloc, |
|
371 |
const VirtualMemory* early_vm, const MallocMemory* current_malloc, |
|
372 |
const VirtualMemory* current_vm) const { |
|
373 |
||
374 |
outputStream* out = output(); |
|
375 |
const char* scale = current_scale(); |
|
376 |
||
377 |
// Total reserved and committed memory in current baseline |
|
378 |
size_t current_reserved_amount = reserved_total (current_malloc, current_vm); |
|
379 |
size_t current_committed_amount = committed_total(current_malloc, current_vm); |
|
380 |
||
381 |
// Total reserved and committed memory in early baseline |
|
382 |
size_t early_reserved_amount = reserved_total(early_malloc, early_vm); |
|
383 |
size_t early_committed_amount = committed_total(early_malloc, early_vm); |
|
13195 | 384 |
|
25946 | 385 |
// Adjust virtual memory total |
386 |
if (flag == mtThread) { |
|
387 |
const VirtualMemory* early_thread_stack_usage = |
|
388 |
_early_baseline.virtual_memory(mtThreadStack); |
|
389 |
const VirtualMemory* current_thread_stack_usage = |
|
390 |
_current_baseline.virtual_memory(mtThreadStack); |
|
391 |
||
392 |
early_reserved_amount += early_thread_stack_usage->reserved(); |
|
393 |
early_committed_amount += early_thread_stack_usage->committed(); |
|
394 |
||
395 |
current_reserved_amount += current_thread_stack_usage->reserved(); |
|
396 |
current_committed_amount += current_thread_stack_usage->committed(); |
|
397 |
} else if (flag == mtNMT) { |
|
398 |
early_reserved_amount += _early_baseline.malloc_tracking_overhead(); |
|
399 |
early_committed_amount += _early_baseline.malloc_tracking_overhead(); |
|
400 |
||
401 |
current_reserved_amount += _current_baseline.malloc_tracking_overhead(); |
|
402 |
current_committed_amount += _current_baseline.malloc_tracking_overhead(); |
|
403 |
} |
|
13195 | 404 |
|
25946 | 405 |
if (amount_in_current_scale(current_reserved_amount) > 0 || |
406 |
diff_in_current_scale(current_reserved_amount, early_reserved_amount) != 0) { |
|
407 |
||
408 |
// print summary line |
|
409 |
out->print("-%26s (", NMTUtil::flag_to_name(flag)); |
|
410 |
print_virtual_memory_diff(current_reserved_amount, current_committed_amount, |
|
411 |
early_reserved_amount, early_committed_amount); |
|
412 |
out->print_cr(")"); |
|
13195 | 413 |
|
25946 | 414 |
// detail lines |
415 |
if (flag == mtClass) { |
|
416 |
// report class count |
|
417 |
out->print("%27s (classes #" SIZE_FORMAT "", " ", _current_baseline.class_count()); |
|
418 |
int class_count_diff = (int)(_current_baseline.class_count() - |
|
419 |
_early_baseline.class_count()); |
|
420 |
if (_current_baseline.class_count() != _early_baseline.class_count()) { |
|
421 |
out->print(" %+d", (int)(_current_baseline.class_count() - _early_baseline.class_count())); |
|
422 |
} |
|
423 |
out->print_cr(")"); |
|
424 |
} else if (flag == mtThread) { |
|
425 |
// report thread count |
|
426 |
out->print("%27s (thread #" SIZE_FORMAT "", " ", _current_baseline.thread_count()); |
|
427 |
int thread_count_diff = (int)(_current_baseline.thread_count() - |
|
428 |
_early_baseline.thread_count()); |
|
429 |
if (thread_count_diff != 0) { |
|
430 |
out->print(" %+d", thread_count_diff); |
|
431 |
} |
|
432 |
out->print_cr(")"); |
|
13195 | 433 |
|
25946 | 434 |
// report thread stack |
435 |
const VirtualMemory* current_thread_stack = |
|
436 |
_current_baseline.virtual_memory(mtThreadStack); |
|
437 |
const VirtualMemory* early_thread_stack = |
|
438 |
_early_baseline.virtual_memory(mtThreadStack); |
|
13195 | 439 |
|
25946 | 440 |
out->print("%27s (stack: ", " "); |
441 |
print_virtual_memory_diff(current_thread_stack->reserved(), current_thread_stack->committed(), |
|
442 |
early_thread_stack->reserved(), early_thread_stack->committed()); |
|
443 |
out->print_cr(")"); |
|
13195 | 444 |
} |
445 |
||
25946 | 446 |
// Report malloc'd memory |
447 |
size_t current_malloc_amount = current_malloc->malloc_size(); |
|
448 |
size_t early_malloc_amount = early_malloc->malloc_size(); |
|
449 |
if (amount_in_current_scale(current_malloc_amount) > 0 || |
|
450 |
diff_in_current_scale(current_malloc_amount, early_malloc_amount) != 0) { |
|
451 |
out->print("%28s(", " "); |
|
452 |
print_malloc_diff(current_malloc_amount, (flag == mtChunk) ? 0 : current_malloc->malloc_count(), |
|
46711
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
46489
diff
changeset
|
453 |
early_malloc_amount, early_malloc->malloc_count(), mtNone); |
25946 | 454 |
out->print_cr(")"); |
455 |
} |
|
13195 | 456 |
|
25946 | 457 |
// Report virtual memory |
458 |
if (amount_in_current_scale(current_vm->reserved()) > 0 || |
|
459 |
diff_in_current_scale(current_vm->reserved(), early_vm->reserved()) != 0) { |
|
460 |
out->print("%27s (mmap: ", " "); |
|
461 |
print_virtual_memory_diff(current_vm->reserved(), current_vm->committed(), |
|
462 |
early_vm->reserved(), early_vm->committed()); |
|
463 |
out->print_cr(")"); |
|
13195 | 464 |
} |
465 |
||
25946 | 466 |
// Report arena memory |
467 |
if (amount_in_current_scale(current_malloc->arena_size()) > 0 || |
|
468 |
diff_in_current_scale(current_malloc->arena_size(), early_malloc->arena_size()) != 0) { |
|
469 |
out->print("%28s(", " "); |
|
470 |
print_arena_diff(current_malloc->arena_size(), current_malloc->arena_count(), |
|
471 |
early_malloc->arena_size(), early_malloc->arena_count()); |
|
472 |
out->print_cr(")"); |
|
13195 | 473 |
} |
474 |
||
25946 | 475 |
// Report native memory tracking overhead |
476 |
if (flag == mtNMT) { |
|
477 |
size_t current_tracking_overhead = amount_in_current_scale(_current_baseline.malloc_tracking_overhead()); |
|
478 |
size_t early_tracking_overhead = amount_in_current_scale(_early_baseline.malloc_tracking_overhead()); |
|
13195 | 479 |
|
25946 | 480 |
out->print("%27s (tracking overhead=" SIZE_FORMAT "%s", " ", |
481 |
amount_in_current_scale(_current_baseline.malloc_tracking_overhead()), scale); |
|
13195 | 482 |
|
25946 | 483 |
long overhead_diff = diff_in_current_scale(_current_baseline.malloc_tracking_overhead(), |
484 |
_early_baseline.malloc_tracking_overhead()); |
|
485 |
if (overhead_diff != 0) { |
|
486 |
out->print(" %+ld%s", overhead_diff, scale); |
|
13195 | 487 |
} |
25946 | 488 |
out->print_cr(")"); |
13195 | 489 |
} |
25946 | 490 |
out->print_cr(" "); |
13195 | 491 |
} |
492 |
} |
|
493 |
||
25946 | 494 |
void MemDetailDiffReporter::report_diff() { |
495 |
MemSummaryDiffReporter::report_diff(); |
|
496 |
diff_malloc_sites(); |
|
497 |
diff_virtual_memory_sites(); |
|
498 |
} |
|
499 |
||
500 |
void MemDetailDiffReporter::diff_malloc_sites() const { |
|
46711
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
46489
diff
changeset
|
501 |
MallocSiteIterator early_itr = _early_baseline.malloc_sites(MemBaseline::by_site_and_type); |
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
46489
diff
changeset
|
502 |
MallocSiteIterator current_itr = _current_baseline.malloc_sites(MemBaseline::by_site_and_type); |
25946 | 503 |
|
504 |
const MallocSite* early_site = early_itr.next(); |
|
505 |
const MallocSite* current_site = current_itr.next(); |
|
506 |
||
507 |
while (early_site != NULL || current_site != NULL) { |
|
508 |
if (early_site == NULL) { |
|
509 |
new_malloc_site(current_site); |
|
510 |
current_site = current_itr.next(); |
|
511 |
} else if (current_site == NULL) { |
|
512 |
old_malloc_site(early_site); |
|
513 |
early_site = early_itr.next(); |
|
13195 | 514 |
} else { |
25946 | 515 |
int compVal = current_site->call_stack()->compare(*early_site->call_stack()); |
516 |
if (compVal < 0) { |
|
517 |
new_malloc_site(current_site); |
|
518 |
current_site = current_itr.next(); |
|
519 |
} else if (compVal > 0) { |
|
520 |
old_malloc_site(early_site); |
|
521 |
early_site = early_itr.next(); |
|
13195 | 522 |
} else { |
25946 | 523 |
diff_malloc_site(early_site, current_site); |
524 |
early_site = early_itr.next(); |
|
525 |
current_site = current_itr.next(); |
|
13195 | 526 |
} |
527 |
} |
|
25946 | 528 |
} |
529 |
} |
|
13195 | 530 |
|
25946 | 531 |
void MemDetailDiffReporter::diff_virtual_memory_sites() const { |
532 |
VirtualMemorySiteIterator early_itr = _early_baseline.virtual_memory_sites(MemBaseline::by_site); |
|
533 |
VirtualMemorySiteIterator current_itr = _current_baseline.virtual_memory_sites(MemBaseline::by_site); |
|
534 |
||
535 |
const VirtualMemoryAllocationSite* early_site = early_itr.next(); |
|
536 |
const VirtualMemoryAllocationSite* current_site = current_itr.next(); |
|
537 |
||
538 |
while (early_site != NULL || current_site != NULL) { |
|
539 |
if (early_site == NULL) { |
|
540 |
new_virtual_memory_site(current_site); |
|
541 |
current_site = current_itr.next(); |
|
542 |
} else if (current_site == NULL) { |
|
543 |
old_virtual_memory_site(early_site); |
|
544 |
early_site = early_itr.next(); |
|
545 |
} else { |
|
546 |
int compVal = current_site->call_stack()->compare(*early_site->call_stack()); |
|
547 |
if (compVal < 0) { |
|
548 |
new_virtual_memory_site(current_site); |
|
549 |
current_site = current_itr.next(); |
|
550 |
} else if (compVal > 0) { |
|
551 |
old_virtual_memory_site(early_site); |
|
552 |
early_site = early_itr.next(); |
|
553 |
} else { |
|
554 |
diff_virtual_memory_site(early_site, current_site); |
|
555 |
early_site = early_itr.next(); |
|
556 |
current_site = current_itr.next(); |
|
557 |
} |
|
13195 | 558 |
} |
559 |
} |
|
560 |
} |
|
561 |
||
25946 | 562 |
|
563 |
void MemDetailDiffReporter::new_malloc_site(const MallocSite* malloc_site) const { |
|
564 |
diff_malloc_site(malloc_site->call_stack(), malloc_site->size(), malloc_site->count(), |
|
46711
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
46489
diff
changeset
|
565 |
0, 0, malloc_site->flags()); |
25946 | 566 |
} |
567 |
||
568 |
void MemDetailDiffReporter::old_malloc_site(const MallocSite* malloc_site) const { |
|
569 |
diff_malloc_site(malloc_site->call_stack(), 0, 0, malloc_site->size(), |
|
46711
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
46489
diff
changeset
|
570 |
malloc_site->count(), malloc_site->flags()); |
25946 | 571 |
} |
572 |
||
573 |
void MemDetailDiffReporter::diff_malloc_site(const MallocSite* early, |
|
574 |
const MallocSite* current) const { |
|
46711
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
46489
diff
changeset
|
575 |
assert(early->flags() == current->flags(), "Must be the same memory type"); |
25946 | 576 |
diff_malloc_site(current->call_stack(), current->size(), current->count(), |
46711
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
46489
diff
changeset
|
577 |
early->size(), early->count(), early->flags()); |
25946 | 578 |
} |
579 |
||
580 |
void MemDetailDiffReporter::diff_malloc_site(const NativeCallStack* stack, size_t current_size, |
|
46711
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
46489
diff
changeset
|
581 |
size_t current_count, size_t early_size, size_t early_count, MEMFLAGS flags) const { |
25946 | 582 |
outputStream* out = output(); |
583 |
||
584 |
assert(stack != NULL, "NULL stack"); |
|
585 |
||
586 |
if (diff_in_current_scale(current_size, early_size) == 0) { |
|
587 |
return; |
|
588 |
} |
|
589 |
||
590 |
stack->print_on(out); |
|
591 |
out->print("%28s (", " "); |
|
592 |
print_malloc_diff(current_size, current_count, |
|
46711
0ccef2260315
8184991: NMT detail diff should take memory type into account
zgu
parents:
46489
diff
changeset
|
593 |
early_size, early_count, flags); |
13195 | 594 |
|
25946 | 595 |
out->print_cr(")\n"); |
596 |
} |
|
597 |
||
598 |
||
599 |
void MemDetailDiffReporter::new_virtual_memory_site(const VirtualMemoryAllocationSite* site) const { |
|
600 |
diff_virtual_memory_site(site->call_stack(), site->reserved(), site->committed(), 0, 0); |
|
601 |
} |
|
602 |
||
603 |
void MemDetailDiffReporter::old_virtual_memory_site(const VirtualMemoryAllocationSite* site) const { |
|
604 |
diff_virtual_memory_site(site->call_stack(), 0, 0, site->reserved(), site->committed()); |
|
605 |
} |
|
606 |
||
607 |
void MemDetailDiffReporter::diff_virtual_memory_site(const VirtualMemoryAllocationSite* early, |
|
608 |
const VirtualMemoryAllocationSite* current) const { |
|
609 |
diff_virtual_memory_site(current->call_stack(), current->reserved(), current->committed(), |
|
610 |
early->reserved(), early->committed()); |
|
611 |
} |
|
612 |
||
613 |
void MemDetailDiffReporter::diff_virtual_memory_site(const NativeCallStack* stack, size_t current_reserved, |
|
614 |
size_t current_committed, size_t early_reserved, size_t early_committed) const { |
|
615 |
outputStream* out = output(); |
|
616 |
||
617 |
// no change |
|
618 |
if (diff_in_current_scale(current_reserved, early_reserved) == 0 && |
|
619 |
diff_in_current_scale(current_committed, early_committed) == 0) { |
|
620 |
return; |
|
13195 | 621 |
} |
25946 | 622 |
|
623 |
stack->print_on(out); |
|
624 |
out->print("%28s (mmap: ", " "); |
|
625 |
print_virtual_memory_diff(current_reserved, current_committed, |
|
626 |
early_reserved, early_committed); |
|
627 |
||
628 |
out->print_cr(")\n"); |
|
629 |
} |
|
630 |