author | zgu |
Tue, 23 May 2017 11:58:32 -0400 | |
changeset 46489 | 40abcea5a9d5 |
parent 25946 | 1572c9f03fb9 |
child 46711 | 0ccef2260315 |
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, |
315 |
size_t early_amount, size_t early_count) const { |
|
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); |
320 |
long amount_diff = diff_in_current_scale(current_amount, early_amount); |
|
321 |
if (amount_diff != 0) { |
|
322 |
out->print(" %+ld%s", amount_diff, scale); |
|
323 |
} |
|
324 |
if (current_count > 0) { |
|
325 |
out->print(" #" SIZE_FORMAT "", current_count); |
|
326 |
if (current_count != early_count) { |
|
327 |
out->print(" %+d", (int)(current_count - early_count)); |
|
13195 | 328 |
} |
329 |
} |
|
330 |
} |
|
331 |
||
25946 | 332 |
void MemSummaryDiffReporter::print_arena_diff(size_t current_amount, size_t current_count, |
333 |
size_t early_amount, size_t early_count) const { |
|
334 |
const char* scale = current_scale(); |
|
335 |
outputStream* out = output(); |
|
336 |
out->print("arena=" SIZE_FORMAT "%s", amount_in_current_scale(current_amount), scale); |
|
337 |
if (diff_in_current_scale(current_amount, early_amount) != 0) { |
|
338 |
out->print(" %+ld", diff_in_current_scale(current_amount, early_amount)); |
|
339 |
} |
|
340 |
||
341 |
out->print(" #" SIZE_FORMAT "", current_count); |
|
342 |
if (current_count != early_count) { |
|
343 |
out->print(" %+d", (int)(current_count - early_count)); |
|
344 |
} |
|
345 |
} |
|
13195 | 346 |
|
25946 | 347 |
void MemSummaryDiffReporter::print_virtual_memory_diff(size_t current_reserved, size_t current_committed, |
348 |
size_t early_reserved, size_t early_committed) const { |
|
349 |
const char* scale = current_scale(); |
|
350 |
outputStream* out = output(); |
|
351 |
out->print("reserved=" SIZE_FORMAT "%s", amount_in_current_scale(current_reserved), scale); |
|
352 |
long reserved_diff = diff_in_current_scale(current_reserved, early_reserved); |
|
353 |
if (reserved_diff != 0) { |
|
354 |
out->print(" %+ld%s", reserved_diff, scale); |
|
355 |
} |
|
356 |
||
357 |
out->print(", committed=" SIZE_FORMAT "%s", amount_in_current_scale(current_committed), scale); |
|
358 |
long committed_diff = diff_in_current_scale(current_committed, early_committed); |
|
359 |
if (committed_diff != 0) { |
|
360 |
out->print(" %+ld%s", committed_diff, scale); |
|
13195 | 361 |
} |
362 |
} |
|
363 |
||
25946 | 364 |
|
365 |
void MemSummaryDiffReporter::diff_summary_of_type(MEMFLAGS flag, const MallocMemory* early_malloc, |
|
366 |
const VirtualMemory* early_vm, const MallocMemory* current_malloc, |
|
367 |
const VirtualMemory* current_vm) const { |
|
368 |
||
369 |
outputStream* out = output(); |
|
370 |
const char* scale = current_scale(); |
|
371 |
||
372 |
// Total reserved and committed memory in current baseline |
|
373 |
size_t current_reserved_amount = reserved_total (current_malloc, current_vm); |
|
374 |
size_t current_committed_amount = committed_total(current_malloc, current_vm); |
|
375 |
||
376 |
// Total reserved and committed memory in early baseline |
|
377 |
size_t early_reserved_amount = reserved_total(early_malloc, early_vm); |
|
378 |
size_t early_committed_amount = committed_total(early_malloc, early_vm); |
|
13195 | 379 |
|
25946 | 380 |
// Adjust virtual memory total |
381 |
if (flag == mtThread) { |
|
382 |
const VirtualMemory* early_thread_stack_usage = |
|
383 |
_early_baseline.virtual_memory(mtThreadStack); |
|
384 |
const VirtualMemory* current_thread_stack_usage = |
|
385 |
_current_baseline.virtual_memory(mtThreadStack); |
|
386 |
||
387 |
early_reserved_amount += early_thread_stack_usage->reserved(); |
|
388 |
early_committed_amount += early_thread_stack_usage->committed(); |
|
389 |
||
390 |
current_reserved_amount += current_thread_stack_usage->reserved(); |
|
391 |
current_committed_amount += current_thread_stack_usage->committed(); |
|
392 |
} else if (flag == mtNMT) { |
|
393 |
early_reserved_amount += _early_baseline.malloc_tracking_overhead(); |
|
394 |
early_committed_amount += _early_baseline.malloc_tracking_overhead(); |
|
395 |
||
396 |
current_reserved_amount += _current_baseline.malloc_tracking_overhead(); |
|
397 |
current_committed_amount += _current_baseline.malloc_tracking_overhead(); |
|
398 |
} |
|
13195 | 399 |
|
25946 | 400 |
if (amount_in_current_scale(current_reserved_amount) > 0 || |
401 |
diff_in_current_scale(current_reserved_amount, early_reserved_amount) != 0) { |
|
402 |
||
403 |
// print summary line |
|
404 |
out->print("-%26s (", NMTUtil::flag_to_name(flag)); |
|
405 |
print_virtual_memory_diff(current_reserved_amount, current_committed_amount, |
|
406 |
early_reserved_amount, early_committed_amount); |
|
407 |
out->print_cr(")"); |
|
13195 | 408 |
|
25946 | 409 |
// detail lines |
410 |
if (flag == mtClass) { |
|
411 |
// report class count |
|
412 |
out->print("%27s (classes #" SIZE_FORMAT "", " ", _current_baseline.class_count()); |
|
413 |
int class_count_diff = (int)(_current_baseline.class_count() - |
|
414 |
_early_baseline.class_count()); |
|
415 |
if (_current_baseline.class_count() != _early_baseline.class_count()) { |
|
416 |
out->print(" %+d", (int)(_current_baseline.class_count() - _early_baseline.class_count())); |
|
417 |
} |
|
418 |
out->print_cr(")"); |
|
419 |
} else if (flag == mtThread) { |
|
420 |
// report thread count |
|
421 |
out->print("%27s (thread #" SIZE_FORMAT "", " ", _current_baseline.thread_count()); |
|
422 |
int thread_count_diff = (int)(_current_baseline.thread_count() - |
|
423 |
_early_baseline.thread_count()); |
|
424 |
if (thread_count_diff != 0) { |
|
425 |
out->print(" %+d", thread_count_diff); |
|
426 |
} |
|
427 |
out->print_cr(")"); |
|
13195 | 428 |
|
25946 | 429 |
// report thread stack |
430 |
const VirtualMemory* current_thread_stack = |
|
431 |
_current_baseline.virtual_memory(mtThreadStack); |
|
432 |
const VirtualMemory* early_thread_stack = |
|
433 |
_early_baseline.virtual_memory(mtThreadStack); |
|
13195 | 434 |
|
25946 | 435 |
out->print("%27s (stack: ", " "); |
436 |
print_virtual_memory_diff(current_thread_stack->reserved(), current_thread_stack->committed(), |
|
437 |
early_thread_stack->reserved(), early_thread_stack->committed()); |
|
438 |
out->print_cr(")"); |
|
13195 | 439 |
} |
440 |
||
25946 | 441 |
// Report malloc'd memory |
442 |
size_t current_malloc_amount = current_malloc->malloc_size(); |
|
443 |
size_t early_malloc_amount = early_malloc->malloc_size(); |
|
444 |
if (amount_in_current_scale(current_malloc_amount) > 0 || |
|
445 |
diff_in_current_scale(current_malloc_amount, early_malloc_amount) != 0) { |
|
446 |
out->print("%28s(", " "); |
|
447 |
print_malloc_diff(current_malloc_amount, (flag == mtChunk) ? 0 : current_malloc->malloc_count(), |
|
448 |
early_malloc_amount, early_malloc->malloc_count()); |
|
449 |
out->print_cr(")"); |
|
450 |
} |
|
13195 | 451 |
|
25946 | 452 |
// Report virtual memory |
453 |
if (amount_in_current_scale(current_vm->reserved()) > 0 || |
|
454 |
diff_in_current_scale(current_vm->reserved(), early_vm->reserved()) != 0) { |
|
455 |
out->print("%27s (mmap: ", " "); |
|
456 |
print_virtual_memory_diff(current_vm->reserved(), current_vm->committed(), |
|
457 |
early_vm->reserved(), early_vm->committed()); |
|
458 |
out->print_cr(")"); |
|
13195 | 459 |
} |
460 |
||
25946 | 461 |
// Report arena memory |
462 |
if (amount_in_current_scale(current_malloc->arena_size()) > 0 || |
|
463 |
diff_in_current_scale(current_malloc->arena_size(), early_malloc->arena_size()) != 0) { |
|
464 |
out->print("%28s(", " "); |
|
465 |
print_arena_diff(current_malloc->arena_size(), current_malloc->arena_count(), |
|
466 |
early_malloc->arena_size(), early_malloc->arena_count()); |
|
467 |
out->print_cr(")"); |
|
13195 | 468 |
} |
469 |
||
25946 | 470 |
// Report native memory tracking overhead |
471 |
if (flag == mtNMT) { |
|
472 |
size_t current_tracking_overhead = amount_in_current_scale(_current_baseline.malloc_tracking_overhead()); |
|
473 |
size_t early_tracking_overhead = amount_in_current_scale(_early_baseline.malloc_tracking_overhead()); |
|
13195 | 474 |
|
25946 | 475 |
out->print("%27s (tracking overhead=" SIZE_FORMAT "%s", " ", |
476 |
amount_in_current_scale(_current_baseline.malloc_tracking_overhead()), scale); |
|
13195 | 477 |
|
25946 | 478 |
long overhead_diff = diff_in_current_scale(_current_baseline.malloc_tracking_overhead(), |
479 |
_early_baseline.malloc_tracking_overhead()); |
|
480 |
if (overhead_diff != 0) { |
|
481 |
out->print(" %+ld%s", overhead_diff, scale); |
|
13195 | 482 |
} |
25946 | 483 |
out->print_cr(")"); |
13195 | 484 |
} |
25946 | 485 |
out->print_cr(" "); |
13195 | 486 |
} |
487 |
} |
|
488 |
||
25946 | 489 |
void MemDetailDiffReporter::report_diff() { |
490 |
MemSummaryDiffReporter::report_diff(); |
|
491 |
diff_malloc_sites(); |
|
492 |
diff_virtual_memory_sites(); |
|
493 |
} |
|
494 |
||
495 |
void MemDetailDiffReporter::diff_malloc_sites() const { |
|
496 |
MallocSiteIterator early_itr = _early_baseline.malloc_sites(MemBaseline::by_site); |
|
497 |
MallocSiteIterator current_itr = _current_baseline.malloc_sites(MemBaseline::by_site); |
|
498 |
||
499 |
const MallocSite* early_site = early_itr.next(); |
|
500 |
const MallocSite* current_site = current_itr.next(); |
|
501 |
||
502 |
while (early_site != NULL || current_site != NULL) { |
|
503 |
if (early_site == NULL) { |
|
504 |
new_malloc_site(current_site); |
|
505 |
current_site = current_itr.next(); |
|
506 |
} else if (current_site == NULL) { |
|
507 |
old_malloc_site(early_site); |
|
508 |
early_site = early_itr.next(); |
|
13195 | 509 |
} else { |
25946 | 510 |
int compVal = current_site->call_stack()->compare(*early_site->call_stack()); |
511 |
if (compVal < 0) { |
|
512 |
new_malloc_site(current_site); |
|
513 |
current_site = current_itr.next(); |
|
514 |
} else if (compVal > 0) { |
|
515 |
old_malloc_site(early_site); |
|
516 |
early_site = early_itr.next(); |
|
13195 | 517 |
} else { |
25946 | 518 |
diff_malloc_site(early_site, current_site); |
519 |
early_site = early_itr.next(); |
|
520 |
current_site = current_itr.next(); |
|
13195 | 521 |
} |
522 |
} |
|
25946 | 523 |
} |
524 |
} |
|
13195 | 525 |
|
25946 | 526 |
void MemDetailDiffReporter::diff_virtual_memory_sites() const { |
527 |
VirtualMemorySiteIterator early_itr = _early_baseline.virtual_memory_sites(MemBaseline::by_site); |
|
528 |
VirtualMemorySiteIterator current_itr = _current_baseline.virtual_memory_sites(MemBaseline::by_site); |
|
529 |
||
530 |
const VirtualMemoryAllocationSite* early_site = early_itr.next(); |
|
531 |
const VirtualMemoryAllocationSite* current_site = current_itr.next(); |
|
532 |
||
533 |
while (early_site != NULL || current_site != NULL) { |
|
534 |
if (early_site == NULL) { |
|
535 |
new_virtual_memory_site(current_site); |
|
536 |
current_site = current_itr.next(); |
|
537 |
} else if (current_site == NULL) { |
|
538 |
old_virtual_memory_site(early_site); |
|
539 |
early_site = early_itr.next(); |
|
540 |
} else { |
|
541 |
int compVal = current_site->call_stack()->compare(*early_site->call_stack()); |
|
542 |
if (compVal < 0) { |
|
543 |
new_virtual_memory_site(current_site); |
|
544 |
current_site = current_itr.next(); |
|
545 |
} else if (compVal > 0) { |
|
546 |
old_virtual_memory_site(early_site); |
|
547 |
early_site = early_itr.next(); |
|
548 |
} else { |
|
549 |
diff_virtual_memory_site(early_site, current_site); |
|
550 |
early_site = early_itr.next(); |
|
551 |
current_site = current_itr.next(); |
|
552 |
} |
|
13195 | 553 |
} |
554 |
} |
|
555 |
} |
|
556 |
||
25946 | 557 |
|
558 |
void MemDetailDiffReporter::new_malloc_site(const MallocSite* malloc_site) const { |
|
559 |
diff_malloc_site(malloc_site->call_stack(), malloc_site->size(), malloc_site->count(), |
|
560 |
0, 0); |
|
561 |
} |
|
562 |
||
563 |
void MemDetailDiffReporter::old_malloc_site(const MallocSite* malloc_site) const { |
|
564 |
diff_malloc_site(malloc_site->call_stack(), 0, 0, malloc_site->size(), |
|
565 |
malloc_site->count()); |
|
566 |
} |
|
567 |
||
568 |
void MemDetailDiffReporter::diff_malloc_site(const MallocSite* early, |
|
569 |
const MallocSite* current) const { |
|
570 |
diff_malloc_site(current->call_stack(), current->size(), current->count(), |
|
571 |
early->size(), early->count()); |
|
572 |
} |
|
573 |
||
574 |
void MemDetailDiffReporter::diff_malloc_site(const NativeCallStack* stack, size_t current_size, |
|
575 |
size_t current_count, size_t early_size, size_t early_count) const { |
|
576 |
outputStream* out = output(); |
|
577 |
||
578 |
assert(stack != NULL, "NULL stack"); |
|
579 |
||
580 |
if (diff_in_current_scale(current_size, early_size) == 0) { |
|
581 |
return; |
|
582 |
} |
|
583 |
||
584 |
stack->print_on(out); |
|
585 |
out->print("%28s (", " "); |
|
586 |
print_malloc_diff(current_size, current_count, |
|
587 |
early_size, early_count); |
|
13195 | 588 |
|
25946 | 589 |
out->print_cr(")\n"); |
590 |
} |
|
591 |
||
592 |
||
593 |
void MemDetailDiffReporter::new_virtual_memory_site(const VirtualMemoryAllocationSite* site) const { |
|
594 |
diff_virtual_memory_site(site->call_stack(), site->reserved(), site->committed(), 0, 0); |
|
595 |
} |
|
596 |
||
597 |
void MemDetailDiffReporter::old_virtual_memory_site(const VirtualMemoryAllocationSite* site) const { |
|
598 |
diff_virtual_memory_site(site->call_stack(), 0, 0, site->reserved(), site->committed()); |
|
599 |
} |
|
600 |
||
601 |
void MemDetailDiffReporter::diff_virtual_memory_site(const VirtualMemoryAllocationSite* early, |
|
602 |
const VirtualMemoryAllocationSite* current) const { |
|
603 |
diff_virtual_memory_site(current->call_stack(), current->reserved(), current->committed(), |
|
604 |
early->reserved(), early->committed()); |
|
605 |
} |
|
606 |
||
607 |
void MemDetailDiffReporter::diff_virtual_memory_site(const NativeCallStack* stack, size_t current_reserved, |
|
608 |
size_t current_committed, size_t early_reserved, size_t early_committed) const { |
|
609 |
outputStream* out = output(); |
|
610 |
||
611 |
// no change |
|
612 |
if (diff_in_current_scale(current_reserved, early_reserved) == 0 && |
|
613 |
diff_in_current_scale(current_committed, early_committed) == 0) { |
|
614 |
return; |
|
13195 | 615 |
} |
25946 | 616 |
|
617 |
stack->print_on(out); |
|
618 |
out->print("%28s (mmap: ", " "); |
|
619 |
print_virtual_memory_diff(current_reserved, current_committed, |
|
620 |
early_reserved, early_committed); |
|
621 |
||
622 |
out->print_cr(")\n"); |
|
623 |
} |
|
624 |