1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/services/memReporter.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,639 @@ 1.4 +/* 1.5 + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 +#include "precompiled.hpp" 1.28 +#include "classfile/systemDictionary.hpp" 1.29 +#include "runtime/os.hpp" 1.30 +#include "services/memReporter.hpp" 1.31 +#include "services/memPtrArray.hpp" 1.32 +#include "services/memTracker.hpp" 1.33 + 1.34 +PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC 1.35 + 1.36 +const char* BaselineOutputer::memory_unit(size_t scale) { 1.37 + switch(scale) { 1.38 + case K: return "KB"; 1.39 + case M: return "MB"; 1.40 + case G: return "GB"; 1.41 + } 1.42 + ShouldNotReachHere(); 1.43 + return NULL; 1.44 +} 1.45 + 1.46 + 1.47 +void BaselineReporter::report_baseline(const MemBaseline& baseline, bool summary_only) { 1.48 + assert(MemTracker::is_on(), "Native memory tracking is off"); 1.49 + _outputer.start(scale()); 1.50 + _outputer.total_usage( 1.51 + amount_in_current_scale(baseline.total_malloc_amount() + baseline.total_reserved_amount()), 1.52 + amount_in_current_scale(baseline.total_malloc_amount() + baseline.total_committed_amount())); 1.53 + 1.54 + _outputer.num_of_classes(baseline.number_of_classes()); 1.55 + _outputer.num_of_threads(baseline.number_of_threads()); 1.56 + 1.57 + report_summaries(baseline); 1.58 + if (!summary_only && MemTracker::track_callsite()) { 1.59 + report_virtual_memory_map(baseline); 1.60 + report_callsites(baseline); 1.61 + } 1.62 + _outputer.done(); 1.63 +} 1.64 + 1.65 +void BaselineReporter::report_summaries(const MemBaseline& baseline) { 1.66 + _outputer.start_category_summary(); 1.67 + MEMFLAGS type; 1.68 + 1.69 + for (int index = 0; index < NUMBER_OF_MEMORY_TYPE; index ++) { 1.70 + type = MemBaseline::MemType2NameMap[index]._flag; 1.71 + _outputer.category_summary(type, 1.72 + amount_in_current_scale(baseline.reserved_amount(type)), 1.73 + amount_in_current_scale(baseline.committed_amount(type)), 1.74 + amount_in_current_scale(baseline.malloc_amount(type)), 1.75 + baseline.malloc_count(type), 1.76 + amount_in_current_scale(baseline.arena_amount(type)), 1.77 + baseline.arena_count(type)); 1.78 + } 1.79 + 1.80 + _outputer.done_category_summary(); 1.81 +} 1.82 + 1.83 +void BaselineReporter::report_virtual_memory_map(const MemBaseline& baseline) { 1.84 + _outputer.start_virtual_memory_map(); 1.85 + MemBaseline* pBL = const_cast<MemBaseline*>(&baseline); 1.86 + MemPointerArrayIteratorImpl itr = MemPointerArrayIteratorImpl(pBL->_vm_map); 1.87 + VMMemRegionEx* rgn = (VMMemRegionEx*)itr.current(); 1.88 + while (rgn != NULL) { 1.89 + if (rgn->is_reserved_region()) { 1.90 + _outputer.reserved_memory_region(FLAGS_TO_MEMORY_TYPE(rgn->flags()), 1.91 + rgn->base(), rgn->base() + rgn->size(), amount_in_current_scale(rgn->size()), rgn->pc()); 1.92 + } else { 1.93 + _outputer.committed_memory_region(rgn->base(), rgn->base() + rgn->size(), 1.94 + amount_in_current_scale(rgn->size()), rgn->pc()); 1.95 + } 1.96 + rgn = (VMMemRegionEx*)itr.next(); 1.97 + } 1.98 + 1.99 + _outputer.done_virtual_memory_map(); 1.100 +} 1.101 + 1.102 +void BaselineReporter::report_callsites(const MemBaseline& baseline) { 1.103 + _outputer.start_callsite(); 1.104 + MemBaseline* pBL = const_cast<MemBaseline*>(&baseline); 1.105 + 1.106 + pBL->_malloc_cs->sort((FN_SORT)MemBaseline::bl_malloc_sort_by_size); 1.107 + pBL->_vm_cs->sort((FN_SORT)MemBaseline::bl_vm_sort_by_size); 1.108 + 1.109 + // walk malloc callsites 1.110 + MemPointerArrayIteratorImpl malloc_itr(pBL->_malloc_cs); 1.111 + MallocCallsitePointer* malloc_callsite = 1.112 + (MallocCallsitePointer*)malloc_itr.current(); 1.113 + while (malloc_callsite != NULL) { 1.114 + _outputer.malloc_callsite(malloc_callsite->addr(), 1.115 + amount_in_current_scale(malloc_callsite->amount()), malloc_callsite->count()); 1.116 + malloc_callsite = (MallocCallsitePointer*)malloc_itr.next(); 1.117 + } 1.118 + 1.119 + // walk virtual memory callsite 1.120 + MemPointerArrayIteratorImpl vm_itr(pBL->_vm_cs); 1.121 + VMCallsitePointer* vm_callsite = (VMCallsitePointer*)vm_itr.current(); 1.122 + while (vm_callsite != NULL) { 1.123 + _outputer.virtual_memory_callsite(vm_callsite->addr(), 1.124 + amount_in_current_scale(vm_callsite->reserved_amount()), 1.125 + amount_in_current_scale(vm_callsite->committed_amount())); 1.126 + vm_callsite = (VMCallsitePointer*)vm_itr.next(); 1.127 + } 1.128 + pBL->_malloc_cs->sort((FN_SORT)MemBaseline::bl_malloc_sort_by_pc); 1.129 + pBL->_vm_cs->sort((FN_SORT)MemBaseline::bl_vm_sort_by_pc); 1.130 + _outputer.done_callsite(); 1.131 +} 1.132 + 1.133 +void BaselineReporter::diff_baselines(const MemBaseline& cur, const MemBaseline& prev, 1.134 + bool summary_only) { 1.135 + assert(MemTracker::is_on(), "Native memory tracking is off"); 1.136 + _outputer.start(scale()); 1.137 + size_t total_reserved = cur.total_malloc_amount() + cur.total_reserved_amount(); 1.138 + size_t total_committed = cur.total_malloc_amount() + cur.total_committed_amount(); 1.139 + 1.140 + _outputer.diff_total_usage( 1.141 + amount_in_current_scale(total_reserved), amount_in_current_scale(total_committed), 1.142 + diff_in_current_scale(total_reserved, (prev.total_malloc_amount() + prev.total_reserved_amount())), 1.143 + diff_in_current_scale(total_committed, (prev.total_committed_amount() + prev.total_malloc_amount()))); 1.144 + 1.145 + _outputer.diff_num_of_classes(cur.number_of_classes(), 1.146 + diff(cur.number_of_classes(), prev.number_of_classes())); 1.147 + _outputer.diff_num_of_threads(cur.number_of_threads(), 1.148 + diff(cur.number_of_threads(), prev.number_of_threads())); 1.149 + 1.150 + diff_summaries(cur, prev); 1.151 + if (!summary_only && MemTracker::track_callsite()) { 1.152 + diff_callsites(cur, prev); 1.153 + } 1.154 + _outputer.done(); 1.155 +} 1.156 + 1.157 +void BaselineReporter::diff_summaries(const MemBaseline& cur, const MemBaseline& prev) { 1.158 + _outputer.start_category_summary(); 1.159 + MEMFLAGS type; 1.160 + 1.161 + for (int index = 0; index < NUMBER_OF_MEMORY_TYPE; index ++) { 1.162 + type = MemBaseline::MemType2NameMap[index]._flag; 1.163 + _outputer.diff_category_summary(type, 1.164 + amount_in_current_scale(cur.reserved_amount(type)), 1.165 + amount_in_current_scale(cur.committed_amount(type)), 1.166 + amount_in_current_scale(cur.malloc_amount(type)), 1.167 + cur.malloc_count(type), 1.168 + amount_in_current_scale(cur.arena_amount(type)), 1.169 + cur.arena_count(type), 1.170 + diff_in_current_scale(cur.reserved_amount(type), prev.reserved_amount(type)), 1.171 + diff_in_current_scale(cur.committed_amount(type), prev.committed_amount(type)), 1.172 + diff_in_current_scale(cur.malloc_amount(type), prev.malloc_amount(type)), 1.173 + diff(cur.malloc_count(type), prev.malloc_count(type)), 1.174 + diff_in_current_scale(cur.arena_amount(type), prev.arena_amount(type)), 1.175 + diff(cur.arena_count(type), prev.arena_count(type))); 1.176 + } 1.177 + 1.178 + _outputer.done_category_summary(); 1.179 +} 1.180 + 1.181 +void BaselineReporter::diff_callsites(const MemBaseline& cur, const MemBaseline& prev) { 1.182 + _outputer.start_callsite(); 1.183 + MemBaseline* pBL_cur = const_cast<MemBaseline*>(&cur); 1.184 + MemBaseline* pBL_prev = const_cast<MemBaseline*>(&prev); 1.185 + 1.186 + // walk malloc callsites 1.187 + MemPointerArrayIteratorImpl cur_malloc_itr(pBL_cur->_malloc_cs); 1.188 + MemPointerArrayIteratorImpl prev_malloc_itr(pBL_prev->_malloc_cs); 1.189 + 1.190 + MallocCallsitePointer* cur_malloc_callsite = 1.191 + (MallocCallsitePointer*)cur_malloc_itr.current(); 1.192 + MallocCallsitePointer* prev_malloc_callsite = 1.193 + (MallocCallsitePointer*)prev_malloc_itr.current(); 1.194 + 1.195 + while (cur_malloc_callsite != NULL || prev_malloc_callsite != NULL) { 1.196 + if (prev_malloc_callsite == NULL) { 1.197 + assert(cur_malloc_callsite != NULL, "sanity check"); 1.198 + // this is a new callsite 1.199 + _outputer.diff_malloc_callsite(cur_malloc_callsite->addr(), 1.200 + amount_in_current_scale(cur_malloc_callsite->amount()), 1.201 + cur_malloc_callsite->count(), 1.202 + diff_in_current_scale(cur_malloc_callsite->amount(), 0), 1.203 + diff(cur_malloc_callsite->count(), 0)); 1.204 + cur_malloc_callsite = (MallocCallsitePointer*)cur_malloc_itr.next(); 1.205 + } else if (cur_malloc_callsite == NULL) { 1.206 + assert(prev_malloc_callsite != NULL, "Sanity check"); 1.207 + // this callsite is already gone 1.208 + _outputer.diff_malloc_callsite(prev_malloc_callsite->addr(), 1.209 + 0, 0, 1.210 + diff_in_current_scale(0, prev_malloc_callsite->amount()), 1.211 + diff(0, prev_malloc_callsite->count())); 1.212 + prev_malloc_callsite = (MallocCallsitePointer*)prev_malloc_itr.next(); 1.213 + } else { 1.214 + assert(cur_malloc_callsite != NULL, "Sanity check"); 1.215 + assert(prev_malloc_callsite != NULL, "Sanity check"); 1.216 + if (cur_malloc_callsite->addr() < prev_malloc_callsite->addr()) { 1.217 + // this is a new callsite 1.218 + _outputer.diff_malloc_callsite(cur_malloc_callsite->addr(), 1.219 + amount_in_current_scale(cur_malloc_callsite->amount()), 1.220 + cur_malloc_callsite->count(), 1.221 + diff_in_current_scale(cur_malloc_callsite->amount(), 0), 1.222 + diff(cur_malloc_callsite->count(), 0)); 1.223 + cur_malloc_callsite = (MallocCallsitePointer*)cur_malloc_itr.next(); 1.224 + } else if (cur_malloc_callsite->addr() > prev_malloc_callsite->addr()) { 1.225 + // this callsite is already gone 1.226 + _outputer.diff_malloc_callsite(prev_malloc_callsite->addr(), 1.227 + 0, 0, 1.228 + diff_in_current_scale(0, prev_malloc_callsite->amount()), 1.229 + diff(0, prev_malloc_callsite->count())); 1.230 + prev_malloc_callsite = (MallocCallsitePointer*)prev_malloc_itr.next(); 1.231 + } else { 1.232 + // the same callsite 1.233 + _outputer.diff_malloc_callsite(cur_malloc_callsite->addr(), 1.234 + amount_in_current_scale(cur_malloc_callsite->amount()), 1.235 + cur_malloc_callsite->count(), 1.236 + diff_in_current_scale(cur_malloc_callsite->amount(), prev_malloc_callsite->amount()), 1.237 + diff(cur_malloc_callsite->count(), prev_malloc_callsite->count())); 1.238 + cur_malloc_callsite = (MallocCallsitePointer*)cur_malloc_itr.next(); 1.239 + prev_malloc_callsite = (MallocCallsitePointer*)prev_malloc_itr.next(); 1.240 + } 1.241 + } 1.242 + } 1.243 + 1.244 + // walk virtual memory callsite 1.245 + MemPointerArrayIteratorImpl cur_vm_itr(pBL_cur->_vm_cs); 1.246 + MemPointerArrayIteratorImpl prev_vm_itr(pBL_prev->_vm_cs); 1.247 + VMCallsitePointer* cur_vm_callsite = (VMCallsitePointer*)cur_vm_itr.current(); 1.248 + VMCallsitePointer* prev_vm_callsite = (VMCallsitePointer*)prev_vm_itr.current(); 1.249 + while (cur_vm_callsite != NULL || prev_vm_callsite != NULL) { 1.250 + if (prev_vm_callsite == NULL || cur_vm_callsite->addr() < prev_vm_callsite->addr()) { 1.251 + // this is a new callsite 1.252 + _outputer.diff_virtual_memory_callsite(cur_vm_callsite->addr(), 1.253 + amount_in_current_scale(cur_vm_callsite->reserved_amount()), 1.254 + amount_in_current_scale(cur_vm_callsite->committed_amount()), 1.255 + diff_in_current_scale(cur_vm_callsite->reserved_amount(), 0), 1.256 + diff_in_current_scale(cur_vm_callsite->committed_amount(), 0)); 1.257 + cur_vm_callsite = (VMCallsitePointer*)cur_vm_itr.next(); 1.258 + } else if (cur_vm_callsite == NULL || cur_vm_callsite->addr() > prev_vm_callsite->addr()) { 1.259 + // this callsite is already gone 1.260 + _outputer.diff_virtual_memory_callsite(prev_vm_callsite->addr(), 1.261 + amount_in_current_scale(0), 1.262 + amount_in_current_scale(0), 1.263 + diff_in_current_scale(0, prev_vm_callsite->reserved_amount()), 1.264 + diff_in_current_scale(0, prev_vm_callsite->committed_amount())); 1.265 + prev_vm_callsite = (VMCallsitePointer*)prev_vm_itr.next(); 1.266 + } else { // the same callsite 1.267 + _outputer.diff_virtual_memory_callsite(cur_vm_callsite->addr(), 1.268 + amount_in_current_scale(cur_vm_callsite->reserved_amount()), 1.269 + amount_in_current_scale(cur_vm_callsite->committed_amount()), 1.270 + diff_in_current_scale(cur_vm_callsite->reserved_amount(), prev_vm_callsite->reserved_amount()), 1.271 + diff_in_current_scale(cur_vm_callsite->committed_amount(), prev_vm_callsite->committed_amount())); 1.272 + cur_vm_callsite = (VMCallsitePointer*)cur_vm_itr.next(); 1.273 + prev_vm_callsite = (VMCallsitePointer*)prev_vm_itr.next(); 1.274 + } 1.275 + } 1.276 + 1.277 + _outputer.done_callsite(); 1.278 +} 1.279 + 1.280 +size_t BaselineReporter::amount_in_current_scale(size_t amt) const { 1.281 + return (size_t)(((float)amt/(float)_scale) + 0.5); 1.282 +} 1.283 + 1.284 +int BaselineReporter::diff_in_current_scale(size_t value1, size_t value2) const { 1.285 + return (int)(((float)value1 - (float)value2)/((float)_scale) + 0.5); 1.286 +} 1.287 + 1.288 +int BaselineReporter::diff(size_t value1, size_t value2) const { 1.289 + return ((int)value1 - (int)value2); 1.290 +} 1.291 + 1.292 +void BaselineTTYOutputer::start(size_t scale, bool report_diff) { 1.293 + _scale = scale; 1.294 + _output->print_cr(" "); 1.295 + _output->print_cr("Native Memory Tracking:"); 1.296 + _output->print_cr(" "); 1.297 +} 1.298 + 1.299 +void BaselineTTYOutputer::done() { 1.300 + 1.301 +} 1.302 + 1.303 +void BaselineTTYOutputer::total_usage(size_t total_reserved, size_t total_committed) { 1.304 + const char* unit = memory_unit(_scale); 1.305 + _output->print_cr("Total: reserved=%d%s, committed=%d%s", 1.306 + total_reserved, unit, total_committed, unit); 1.307 +} 1.308 + 1.309 +void BaselineTTYOutputer::start_category_summary() { 1.310 + _output->print_cr(" "); 1.311 +} 1.312 + 1.313 +/** 1.314 + * report a summary of memory type 1.315 + */ 1.316 +void BaselineTTYOutputer::category_summary(MEMFLAGS type, 1.317 + size_t reserved_amt, size_t committed_amt, size_t malloc_amt, 1.318 + size_t malloc_count, size_t arena_amt, size_t arena_count) { 1.319 + 1.320 + // we report mtThreadStack under mtThread category 1.321 + if (type == mtThreadStack) { 1.322 + assert(malloc_amt == 0 && malloc_count == 0 && arena_amt == 0, 1.323 + "Just check"); 1.324 + _thread_stack_reserved = reserved_amt; 1.325 + _thread_stack_committed = committed_amt; 1.326 + } else { 1.327 + const char* unit = memory_unit(_scale); 1.328 + size_t total_reserved = (reserved_amt + malloc_amt + arena_amt); 1.329 + size_t total_committed = (committed_amt + malloc_amt + arena_amt); 1.330 + if (type == mtThread) { 1.331 + total_reserved += _thread_stack_reserved; 1.332 + total_committed += _thread_stack_committed; 1.333 + } 1.334 + 1.335 + if (total_reserved > 0) { 1.336 + _output->print_cr("-%26s (reserved=%d%s, committed=%d%s)", 1.337 + MemBaseline::type2name(type), total_reserved, unit, 1.338 + total_committed, unit); 1.339 + 1.340 + if (type == mtClass) { 1.341 + _output->print_cr("%27s (classes #%d)", " ", _num_of_classes); 1.342 + } else if (type == mtThread) { 1.343 + _output->print_cr("%27s (thread #%d)", " ", _num_of_threads); 1.344 + _output->print_cr("%27s (stack: reserved=%d%s, committed=%d%s)", " ", 1.345 + _thread_stack_reserved, unit, _thread_stack_committed, unit); 1.346 + } 1.347 + 1.348 + if (malloc_amt > 0) { 1.349 + if (type != mtChunk) { 1.350 + _output->print_cr("%27s (malloc=%d%s, #%d)", " ", malloc_amt, unit, 1.351 + malloc_count); 1.352 + } else { 1.353 + _output->print_cr("%27s (malloc=%d%s)", " ", malloc_amt, unit); 1.354 + } 1.355 + } 1.356 + 1.357 + if (reserved_amt > 0) { 1.358 + _output->print_cr("%27s (mmap: reserved=%d%s, committed=%d%s)", 1.359 + " ", reserved_amt, unit, committed_amt, unit); 1.360 + } 1.361 + 1.362 + if (arena_amt > 0) { 1.363 + _output->print_cr("%27s (arena=%d%s, #%d)", " ", arena_amt, unit, arena_count); 1.364 + } 1.365 + 1.366 + _output->print_cr(" "); 1.367 + } 1.368 + } 1.369 +} 1.370 + 1.371 +void BaselineTTYOutputer::done_category_summary() { 1.372 + _output->print_cr(" "); 1.373 +} 1.374 + 1.375 + 1.376 +void BaselineTTYOutputer::start_virtual_memory_map() { 1.377 + _output->print_cr("Virtual memory map:"); 1.378 +} 1.379 + 1.380 +void BaselineTTYOutputer::reserved_memory_region(MEMFLAGS type, address base, address end, 1.381 + size_t size, address pc) { 1.382 + const char* unit = memory_unit(_scale); 1.383 + char buf[128]; 1.384 + int offset; 1.385 + _output->print_cr(" "); 1.386 + _output->print_cr("[" PTR_FORMAT " - " PTR_FORMAT "] reserved %d%s for %s", base, end, size, unit, 1.387 + MemBaseline::type2name(type)); 1.388 + if (os::dll_address_to_function_name(pc, buf, sizeof(buf), &offset)) { 1.389 + _output->print_cr("\t\tfrom [%s+0x%x]", buf, offset); 1.390 + } 1.391 +} 1.392 + 1.393 +void BaselineTTYOutputer::committed_memory_region(address base, address end, size_t size, address pc) { 1.394 + const char* unit = memory_unit(_scale); 1.395 + char buf[128]; 1.396 + int offset; 1.397 + _output->print("\t[" PTR_FORMAT " - " PTR_FORMAT "] committed %d%s", base, end, size, unit); 1.398 + if (os::dll_address_to_function_name(pc, buf, sizeof(buf), &offset)) { 1.399 + _output->print_cr(" from [%s+0x%x]", buf, offset); 1.400 + } 1.401 +} 1.402 + 1.403 +void BaselineTTYOutputer::done_virtual_memory_map() { 1.404 + _output->print_cr(" "); 1.405 +} 1.406 + 1.407 + 1.408 + 1.409 +void BaselineTTYOutputer::start_callsite() { 1.410 + _output->print_cr("Details:"); 1.411 + _output->print_cr(" "); 1.412 +} 1.413 + 1.414 +void BaselineTTYOutputer::done_callsite() { 1.415 + _output->print_cr(" "); 1.416 +} 1.417 + 1.418 +void BaselineTTYOutputer::malloc_callsite(address pc, size_t malloc_amt, 1.419 + size_t malloc_count) { 1.420 + if (malloc_amt > 0) { 1.421 + const char* unit = memory_unit(_scale); 1.422 + char buf[128]; 1.423 + int offset; 1.424 + if (pc == 0) { 1.425 + _output->print("[BOOTSTRAP]%18s", " "); 1.426 + } else if (os::dll_address_to_function_name(pc, buf, sizeof(buf), &offset)) { 1.427 + _output->print_cr("[" PTR_FORMAT "] %s+0x%x", pc, buf, offset); 1.428 + _output->print("%28s", " "); 1.429 + } else { 1.430 + _output->print("[" PTR_FORMAT "]%18s", pc, " "); 1.431 + } 1.432 + 1.433 + _output->print_cr("(malloc=%d%s #%d)", malloc_amt, unit, malloc_count); 1.434 + _output->print_cr(" "); 1.435 + } 1.436 +} 1.437 + 1.438 +void BaselineTTYOutputer::virtual_memory_callsite(address pc, size_t reserved_amt, 1.439 + size_t committed_amt) { 1.440 + if (reserved_amt > 0) { 1.441 + const char* unit = memory_unit(_scale); 1.442 + char buf[128]; 1.443 + int offset; 1.444 + if (pc == 0) { 1.445 + _output->print("[BOOTSTRAP]%18s", " "); 1.446 + } else if (os::dll_address_to_function_name(pc, buf, sizeof(buf), &offset)) { 1.447 + _output->print_cr("[" PTR_FORMAT "] %s+0x%x", pc, buf, offset); 1.448 + _output->print("%28s", " "); 1.449 + } else { 1.450 + _output->print("[" PTR_FORMAT "]%18s", pc, " "); 1.451 + } 1.452 + 1.453 + _output->print_cr("(mmap: reserved=%d%s, committed=%d%s)", 1.454 + reserved_amt, unit, committed_amt, unit); 1.455 + _output->print_cr(" "); 1.456 + } 1.457 +} 1.458 + 1.459 +void BaselineTTYOutputer::diff_total_usage(size_t total_reserved, 1.460 + size_t total_committed, int reserved_diff, int committed_diff) { 1.461 + const char* unit = memory_unit(_scale); 1.462 + _output->print_cr("Total: reserved=%d%s %+d%s, committed=%d%s %+d%s", 1.463 + total_reserved, unit, reserved_diff, unit, total_committed, unit, 1.464 + committed_diff, unit); 1.465 +} 1.466 + 1.467 +void BaselineTTYOutputer::diff_category_summary(MEMFLAGS type, 1.468 + size_t cur_reserved_amt, size_t cur_committed_amt, 1.469 + size_t cur_malloc_amt, size_t cur_malloc_count, 1.470 + size_t cur_arena_amt, size_t cur_arena_count, 1.471 + int reserved_diff, int committed_diff, int malloc_diff, 1.472 + int malloc_count_diff, int arena_diff, int arena_count_diff) { 1.473 + 1.474 + if (type == mtThreadStack) { 1.475 + assert(cur_malloc_amt == 0 && cur_malloc_count == 0 && 1.476 + cur_arena_amt == 0, "Just check"); 1.477 + _thread_stack_reserved = cur_reserved_amt; 1.478 + _thread_stack_committed = cur_committed_amt; 1.479 + _thread_stack_reserved_diff = reserved_diff; 1.480 + _thread_stack_committed_diff = committed_diff; 1.481 + } else { 1.482 + const char* unit = memory_unit(_scale); 1.483 + size_t total_reserved = (cur_reserved_amt + cur_malloc_amt + cur_arena_amt); 1.484 + // nothing to report in this category 1.485 + if (total_reserved == 0) { 1.486 + return; 1.487 + } 1.488 + int diff_reserved = (reserved_diff + malloc_diff + arena_diff); 1.489 + 1.490 + // category summary 1.491 + _output->print("-%26s (reserved=%d%s", MemBaseline::type2name(type), 1.492 + total_reserved, unit); 1.493 + 1.494 + if (diff_reserved != 0) { 1.495 + _output->print(" %+d%s", diff_reserved, unit); 1.496 + } 1.497 + 1.498 + size_t total_committed = cur_committed_amt + cur_malloc_amt + cur_arena_amt; 1.499 + _output->print(", committed=%d%s", total_committed, unit); 1.500 + 1.501 + int total_committed_diff = committed_diff + malloc_diff + arena_diff; 1.502 + if (total_committed_diff != 0) { 1.503 + _output->print(" %+d%s", total_committed_diff, unit); 1.504 + } 1.505 + 1.506 + _output->print_cr(")"); 1.507 + 1.508 + // special cases 1.509 + if (type == mtClass) { 1.510 + _output->print("%27s (classes #%d", " ", _num_of_classes); 1.511 + if (_num_of_classes_diff != 0) { 1.512 + _output->print(" %+d", _num_of_classes_diff); 1.513 + } 1.514 + _output->print_cr(")"); 1.515 + } else if (type == mtThread) { 1.516 + // thread count 1.517 + _output->print("%27s (thread #%d", " ", _num_of_threads); 1.518 + if (_num_of_threads_diff != 0) { 1.519 + _output->print_cr(" %+d)", _num_of_threads_diff); 1.520 + } else { 1.521 + _output->print_cr(")"); 1.522 + } 1.523 + _output->print("%27s (stack: reserved=%d%s", " ", _thread_stack_reserved, unit); 1.524 + if (_thread_stack_reserved_diff != 0) { 1.525 + _output->print(" %+d%s", _thread_stack_reserved_diff, unit); 1.526 + } 1.527 + 1.528 + _output->print(", committed=%d%s", _thread_stack_committed, unit); 1.529 + if (_thread_stack_committed_diff != 0) { 1.530 + _output->print(" %+d%s",_thread_stack_committed_diff, unit); 1.531 + } 1.532 + 1.533 + _output->print_cr(")"); 1.534 + } 1.535 + 1.536 + // malloc'd memory 1.537 + if (cur_malloc_amt > 0) { 1.538 + _output->print("%27s (malloc=%d%s", " ", cur_malloc_amt, unit); 1.539 + if (malloc_diff != 0) { 1.540 + _output->print(" %+d%s", malloc_diff, unit); 1.541 + } 1.542 + if (type != mtChunk) { 1.543 + _output->print(", #%d", cur_malloc_count); 1.544 + if (malloc_count_diff) { 1.545 + _output->print(" %+d", malloc_count_diff); 1.546 + } 1.547 + } 1.548 + _output->print_cr(")"); 1.549 + } 1.550 + 1.551 + // mmap'd memory 1.552 + if (cur_reserved_amt > 0) { 1.553 + _output->print("%27s (mmap: reserved=%d%s", " ", cur_reserved_amt, unit); 1.554 + if (reserved_diff != 0) { 1.555 + _output->print(" %+d%s", reserved_diff, unit); 1.556 + } 1.557 + 1.558 + _output->print(", committed=%d%s", cur_committed_amt, unit); 1.559 + if (committed_diff != 0) { 1.560 + _output->print(" %+d%s", committed_diff, unit); 1.561 + } 1.562 + _output->print_cr(")"); 1.563 + } 1.564 + 1.565 + // arena memory 1.566 + if (cur_arena_amt > 0) { 1.567 + _output->print("%27s (arena=%d%s", " ", cur_arena_amt, unit); 1.568 + if (arena_diff != 0) { 1.569 + _output->print(" %+d%s", arena_diff, unit); 1.570 + } 1.571 + _output->print(", #%d", cur_arena_count); 1.572 + if (arena_count_diff != 0) { 1.573 + _output->print(" %+d", arena_count_diff); 1.574 + } 1.575 + _output->print_cr(")"); 1.576 + } 1.577 + 1.578 + _output->print_cr(" "); 1.579 + } 1.580 +} 1.581 + 1.582 +void BaselineTTYOutputer::diff_malloc_callsite(address pc, 1.583 + size_t cur_malloc_amt, size_t cur_malloc_count, 1.584 + int malloc_diff, int malloc_count_diff) { 1.585 + if (malloc_diff != 0) { 1.586 + const char* unit = memory_unit(_scale); 1.587 + char buf[128]; 1.588 + int offset; 1.589 + if (pc == 0) { 1.590 + _output->print_cr("[BOOTSTRAP]%18s", " "); 1.591 + } else { 1.592 + if (os::dll_address_to_function_name(pc, buf, sizeof(buf), &offset)) { 1.593 + _output->print_cr("[" PTR_FORMAT "] %s+0x%x", pc, buf, offset); 1.594 + _output->print("%28s", " "); 1.595 + } else { 1.596 + _output->print("[" PTR_FORMAT "]%18s", pc, " "); 1.597 + } 1.598 + } 1.599 + 1.600 + _output->print("(malloc=%d%s", cur_malloc_amt, unit); 1.601 + if (malloc_diff != 0) { 1.602 + _output->print(" %+d%s", malloc_diff, unit); 1.603 + } 1.604 + _output->print(", #%d", cur_malloc_count); 1.605 + if (malloc_count_diff != 0) { 1.606 + _output->print(" %+d", malloc_count_diff); 1.607 + } 1.608 + _output->print_cr(")"); 1.609 + _output->print_cr(" "); 1.610 + } 1.611 +} 1.612 + 1.613 +void BaselineTTYOutputer::diff_virtual_memory_callsite(address pc, 1.614 + size_t cur_reserved_amt, size_t cur_committed_amt, 1.615 + int reserved_diff, int committed_diff) { 1.616 + if (reserved_diff != 0 || committed_diff != 0) { 1.617 + const char* unit = memory_unit(_scale); 1.618 + char buf[64]; 1.619 + int offset; 1.620 + if (pc == 0) { 1.621 + _output->print_cr("[BOOSTRAP]%18s", " "); 1.622 + } else { 1.623 + if (os::dll_address_to_function_name(pc, buf, sizeof(buf), &offset)) { 1.624 + _output->print_cr("[" PTR_FORMAT "] %s+0x%x", pc, buf, offset); 1.625 + _output->print("%28s", " "); 1.626 + } else { 1.627 + _output->print("[" PTR_FORMAT "]%18s", pc, " "); 1.628 + } 1.629 + } 1.630 + 1.631 + _output->print("(mmap: reserved=%d%s", cur_reserved_amt, unit); 1.632 + if (reserved_diff != 0) { 1.633 + _output->print(" %+d%s", reserved_diff, unit); 1.634 + } 1.635 + _output->print(", committed=%d%s", cur_committed_amt, unit); 1.636 + if (committed_diff != 0) { 1.637 + _output->print(" %+d%s", committed_diff, unit); 1.638 + } 1.639 + _output->print_cr(")"); 1.640 + _output->print_cr(" "); 1.641 + } 1.642 +}