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