1 /*
   2  * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
   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"
  25 #include "classfile/systemDictionary.hpp"
  26 #include "runtime/os.hpp"
  27 #include "services/memReporter.hpp"
  28 #include "services/memPtrArray.hpp"
  29 #include "services/memTracker.hpp"
  30 
  31 const char* BaselineOutputer::memory_unit(size_t scale) {
  32   switch(scale) {
  33     case K: return "KB";
  34     case M: return "MB";
  35     case G: return "GB";
  36   }
  37   ShouldNotReachHere();
  38   return NULL;
  39 }
  40 
  41 
  42 void BaselineReporter::report_baseline(const MemBaseline& baseline, bool summary_only) {
  43   assert(MemTracker::is_on(), "Native memory tracking is off");
  44   _outputer.start(scale());
  45   _outputer.total_usage(
  46     amount_in_current_scale(baseline.total_malloc_amount() + baseline.total_reserved_amount()),
  47     amount_in_current_scale(baseline.total_malloc_amount() + baseline.total_committed_amount()));
  48 
  49   _outputer.num_of_classes(baseline.number_of_classes());
  50   _outputer.num_of_threads(baseline.number_of_threads());
  51 
  52   report_summaries(baseline);
  53   if (!summary_only && MemTracker::track_callsite()) {
  54     report_virtual_memory_map(baseline);
  55     report_callsites(baseline);
  56   }
  57   _outputer.done();
  58 }
  59 
  60 void BaselineReporter::report_summaries(const MemBaseline& baseline) {
  61   _outputer.start_category_summary();
  62   MEMFLAGS type;
  63 
  64   for (int index = 0; index < NUMBER_OF_MEMORY_TYPE; index ++) {
  65     type = MemBaseline::MemType2NameMap[index]._flag;
  66     _outputer.category_summary(type,
  67       amount_in_current_scale(baseline.reserved_amount(type)),
  68       amount_in_current_scale(baseline.committed_amount(type)),
  69       amount_in_current_scale(baseline.malloc_amount(type)),
  70       baseline.malloc_count(type),
  71       amount_in_current_scale(baseline.arena_amount(type)),
  72       baseline.arena_count(type));
  73   }
  74 
  75   _outputer.done_category_summary();
  76 }
  77 
  78 void BaselineReporter::report_virtual_memory_map(const MemBaseline& baseline) {
  79   _outputer.start_virtual_memory_map();
  80   MemBaseline* pBL = const_cast<MemBaseline*>(&baseline);
  81   MemPointerArrayIteratorImpl itr = MemPointerArrayIteratorImpl(pBL->_vm_map);
  82   VMMemRegionEx* rgn = (VMMemRegionEx*)itr.current();
  83   while (rgn != NULL) {
  84     if (rgn->is_reserved_region()) {
  85       _outputer.reserved_memory_region(FLAGS_TO_MEMORY_TYPE(rgn->flags()),
  86         rgn->base(), rgn->base() + rgn->size(), amount_in_current_scale(rgn->size()), rgn->pc());
  87     } else {
  88       _outputer.committed_memory_region(rgn->base(), rgn->base() + rgn->size(),
  89         amount_in_current_scale(rgn->size()), rgn->pc());
  90     }
  91     rgn = (VMMemRegionEx*)itr.next();
  92   }
  93 
  94   _outputer.done_virtual_memory_map();
  95 }
  96 
  97 void BaselineReporter::report_callsites(const MemBaseline& baseline) {
  98   _outputer.start_callsite();
  99   MemBaseline* pBL = const_cast<MemBaseline*>(&baseline);
 100 
 101   pBL->_malloc_cs->sort((FN_SORT)MemBaseline::bl_malloc_sort_by_size);
 102   pBL->_vm_cs->sort((FN_SORT)MemBaseline::bl_vm_sort_by_size);
 103 
 104   // walk malloc callsites
 105   MemPointerArrayIteratorImpl malloc_itr(pBL->_malloc_cs);
 106   MallocCallsitePointer*      malloc_callsite =
 107                   (MallocCallsitePointer*)malloc_itr.current();
 108   while (malloc_callsite != NULL) {
 109     _outputer.malloc_callsite(malloc_callsite->addr(),
 110         amount_in_current_scale(malloc_callsite->amount()), malloc_callsite->count());
 111     malloc_callsite = (MallocCallsitePointer*)malloc_itr.next();
 112   }
 113 
 114   // walk virtual memory callsite
 115   MemPointerArrayIteratorImpl vm_itr(pBL->_vm_cs);
 116   VMCallsitePointer*          vm_callsite = (VMCallsitePointer*)vm_itr.current();
 117   while (vm_callsite != NULL) {
 118     _outputer.virtual_memory_callsite(vm_callsite->addr(),
 119       amount_in_current_scale(vm_callsite->reserved_amount()),
 120       amount_in_current_scale(vm_callsite->committed_amount()));
 121     vm_callsite = (VMCallsitePointer*)vm_itr.next();
 122   }
 123   pBL->_malloc_cs->sort((FN_SORT)MemBaseline::bl_malloc_sort_by_pc);
 124   pBL->_vm_cs->sort((FN_SORT)MemBaseline::bl_vm_sort_by_pc);
 125   _outputer.done_callsite();
 126 }
 127 
 128 void BaselineReporter::diff_baselines(const MemBaseline& cur, const MemBaseline& prev,
 129   bool summary_only) {
 130   assert(MemTracker::is_on(), "Native memory tracking is off");
 131   _outputer.start(scale());
 132   size_t total_reserved = cur.total_malloc_amount() + cur.total_reserved_amount();
 133   size_t total_committed = cur.total_malloc_amount() + cur.total_committed_amount();
 134 
 135   _outputer.diff_total_usage(
 136     amount_in_current_scale(total_reserved), amount_in_current_scale(total_committed),
 137     diff_in_current_scale(total_reserved,  (prev.total_malloc_amount() + prev.total_reserved_amount())),
 138     diff_in_current_scale(total_committed, (prev.total_committed_amount() + prev.total_malloc_amount())));
 139 
 140   _outputer.diff_num_of_classes(cur.number_of_classes(),
 141        diff(cur.number_of_classes(), prev.number_of_classes()));
 142   _outputer.diff_num_of_threads(cur.number_of_threads(),
 143        diff(cur.number_of_threads(), prev.number_of_threads()));
 144 
 145   diff_summaries(cur, prev);
 146   if (!summary_only && MemTracker::track_callsite()) {
 147     diff_callsites(cur, prev);
 148   }
 149   _outputer.done();
 150 }
 151 
 152 void BaselineReporter::diff_summaries(const MemBaseline& cur, const MemBaseline& prev) {
 153   _outputer.start_category_summary();
 154   MEMFLAGS type;
 155 
 156   for (int index = 0; index < NUMBER_OF_MEMORY_TYPE; index ++) {
 157     type = MemBaseline::MemType2NameMap[index]._flag;
 158     _outputer.diff_category_summary(type,
 159       amount_in_current_scale(cur.reserved_amount(type)),
 160       amount_in_current_scale(cur.committed_amount(type)),
 161       amount_in_current_scale(cur.malloc_amount(type)),
 162       cur.malloc_count(type),
 163       amount_in_current_scale(cur.arena_amount(type)),
 164       cur.arena_count(type),
 165       diff_in_current_scale(cur.reserved_amount(type), prev.reserved_amount(type)),
 166       diff_in_current_scale(cur.committed_amount(type), prev.committed_amount(type)),
 167       diff_in_current_scale(cur.malloc_amount(type), prev.malloc_amount(type)),
 168       diff(cur.malloc_count(type), prev.malloc_count(type)),
 169       diff_in_current_scale(cur.arena_amount(type), prev.arena_amount(type)),
 170       diff(cur.arena_count(type), prev.arena_count(type)));
 171   }
 172 
 173   _outputer.done_category_summary();
 174 }
 175 
 176 void BaselineReporter::diff_callsites(const MemBaseline& cur, const MemBaseline& prev) {
 177   _outputer.start_callsite();
 178   MemBaseline* pBL_cur = const_cast<MemBaseline*>(&cur);
 179   MemBaseline* pBL_prev = const_cast<MemBaseline*>(&prev);
 180 
 181   // walk malloc callsites
 182   MemPointerArrayIteratorImpl cur_malloc_itr(pBL_cur->_malloc_cs);
 183   MemPointerArrayIteratorImpl prev_malloc_itr(pBL_prev->_malloc_cs);
 184 
 185   MallocCallsitePointer*      cur_malloc_callsite =
 186                   (MallocCallsitePointer*)cur_malloc_itr.current();
 187   MallocCallsitePointer*      prev_malloc_callsite =
 188                   (MallocCallsitePointer*)prev_malloc_itr.current();
 189 
 190   while (cur_malloc_callsite != NULL || prev_malloc_callsite != NULL) {
 191     if (prev_malloc_callsite == NULL ||
 192         cur_malloc_callsite->addr() < prev_malloc_callsite->addr()) {
 193       // this is a new callsite
 194       _outputer.diff_malloc_callsite(cur_malloc_callsite->addr(),
 195         amount_in_current_scale(cur_malloc_callsite->amount()),
 196         cur_malloc_callsite->count(),
 197         diff_in_current_scale(cur_malloc_callsite->amount(), 0),
 198         diff(cur_malloc_callsite->count(), 0));
 199       cur_malloc_callsite = (MallocCallsitePointer*)cur_malloc_itr.next();
 200     } else if (cur_malloc_callsite == NULL ||
 201                cur_malloc_callsite->addr() > prev_malloc_callsite->addr()) {
 202       // this callsite is already gone
 203       _outputer.diff_malloc_callsite(prev_malloc_callsite->addr(),
 204         amount_in_current_scale(0), 0,
 205         diff_in_current_scale(0, prev_malloc_callsite->amount()),
 206         diff(0, prev_malloc_callsite->count()));
 207       prev_malloc_callsite = (MallocCallsitePointer*)prev_malloc_itr.next();
 208     } else {  // the same callsite
 209       _outputer.diff_malloc_callsite(cur_malloc_callsite->addr(),
 210         amount_in_current_scale(cur_malloc_callsite->amount()),
 211         cur_malloc_callsite->count(),
 212         diff_in_current_scale(cur_malloc_callsite->amount(), prev_malloc_callsite->amount()),
 213         diff(cur_malloc_callsite->count(), prev_malloc_callsite->count()));
 214       cur_malloc_callsite = (MallocCallsitePointer*)cur_malloc_itr.next();
 215       prev_malloc_callsite = (MallocCallsitePointer*)prev_malloc_itr.next();
 216     }
 217   }
 218 
 219   // walk virtual memory callsite
 220   MemPointerArrayIteratorImpl cur_vm_itr(pBL_cur->_vm_cs);
 221   MemPointerArrayIteratorImpl prev_vm_itr(pBL_prev->_vm_cs);
 222   VMCallsitePointer*          cur_vm_callsite = (VMCallsitePointer*)cur_vm_itr.current();
 223   VMCallsitePointer*          prev_vm_callsite = (VMCallsitePointer*)prev_vm_itr.current();
 224   while (cur_vm_callsite != NULL || prev_vm_callsite != NULL) {
 225     if (prev_vm_callsite == NULL || cur_vm_callsite->addr() < prev_vm_callsite->addr()) {
 226       // this is a new callsite
 227       _outputer.diff_virtual_memory_callsite(cur_vm_callsite->addr(),
 228         amount_in_current_scale(cur_vm_callsite->reserved_amount()),
 229         amount_in_current_scale(cur_vm_callsite->committed_amount()),
 230         diff_in_current_scale(cur_vm_callsite->reserved_amount(), 0),
 231         diff_in_current_scale(cur_vm_callsite->committed_amount(), 0));
 232       cur_vm_callsite = (VMCallsitePointer*)cur_vm_itr.next();
 233     } else if (cur_vm_callsite == NULL || cur_vm_callsite->addr() > prev_vm_callsite->addr()) {
 234       // this callsite is already gone
 235       _outputer.diff_virtual_memory_callsite(prev_vm_callsite->addr(),
 236         amount_in_current_scale(0),
 237         amount_in_current_scale(0),
 238         diff_in_current_scale(0, prev_vm_callsite->reserved_amount()),
 239         diff_in_current_scale(0, prev_vm_callsite->committed_amount()));
 240       prev_vm_callsite = (VMCallsitePointer*)prev_vm_itr.next();
 241     } else { // the same callsite
 242       _outputer.diff_virtual_memory_callsite(cur_vm_callsite->addr(),
 243         amount_in_current_scale(cur_vm_callsite->reserved_amount()),
 244         amount_in_current_scale(cur_vm_callsite->committed_amount()),
 245         diff_in_current_scale(cur_vm_callsite->reserved_amount(), prev_vm_callsite->reserved_amount()),
 246         diff_in_current_scale(cur_vm_callsite->committed_amount(), prev_vm_callsite->committed_amount()));
 247       cur_vm_callsite  = (VMCallsitePointer*)cur_vm_itr.next();
 248       prev_vm_callsite = (VMCallsitePointer*)prev_vm_itr.next();
 249     }
 250   }
 251 
 252   _outputer.done_callsite();
 253 }
 254 
 255 size_t BaselineReporter::amount_in_current_scale(size_t amt) const {
 256   return (size_t)(((float)amt/(float)_scale) + 0.5);
 257 }
 258 
 259 int BaselineReporter::diff_in_current_scale(size_t value1, size_t value2) const {
 260   return (int)(((float)value1 - (float)value2)/((float)_scale) + 0.5);
 261 }
 262 
 263 int BaselineReporter::diff(size_t value1, size_t value2) const {
 264   return ((int)value1 - (int)value2);
 265 }
 266 
 267 void BaselineTTYOutputer::start(size_t scale, bool report_diff) {
 268   _scale = scale;
 269   _output->print_cr(" ");
 270   _output->print_cr("Native Memory Tracking:");
 271   _output->print_cr(" ");
 272 }
 273 
 274 void BaselineTTYOutputer::done() {
 275 
 276 }
 277 
 278 void BaselineTTYOutputer::total_usage(size_t total_reserved, size_t total_committed) {
 279   const char* unit = memory_unit(_scale);
 280   _output->print_cr("Total:  reserved=%d%s,  committed=%d%s",
 281     total_reserved, unit, total_committed, unit);
 282 }
 283 
 284 void BaselineTTYOutputer::start_category_summary() {
 285   _output->print_cr(" ");
 286 }
 287 
 288 /**
 289  * report a summary of memory type
 290  */
 291 void BaselineTTYOutputer::category_summary(MEMFLAGS type,
 292   size_t reserved_amt, size_t committed_amt, size_t malloc_amt,
 293   size_t malloc_count, size_t arena_amt, size_t arena_count) {
 294 
 295   // we report mtThreadStack under mtThread category
 296   if (type == mtThreadStack) {
 297     assert(malloc_amt == 0 && malloc_count == 0 && arena_amt == 0,
 298       "Just check");
 299     _thread_stack_reserved = reserved_amt;
 300     _thread_stack_committed = committed_amt;
 301   } else {
 302     const char* unit = memory_unit(_scale);
 303     size_t total_reserved = (reserved_amt + malloc_amt + arena_amt);
 304     size_t total_committed = (committed_amt + malloc_amt + arena_amt);
 305     if (type == mtThread) {
 306       total_reserved += _thread_stack_reserved;
 307       total_committed += _thread_stack_committed;
 308     }
 309 
 310     if (total_reserved > 0) {
 311       _output->print_cr("-%26s (reserved=%d%s, committed=%d%s)",
 312         MemBaseline::type2name(type), total_reserved, unit,
 313         total_committed, unit);
 314 
 315       if (type == mtClass) {
 316         _output->print_cr("%27s (classes #%d)", " ", _num_of_classes);
 317       } else if (type == mtThread) {
 318         _output->print_cr("%27s (thread #%d)", " ", _num_of_threads);
 319         _output->print_cr("%27s (stack: reserved=%d%s, committed=%d%s)", " ",
 320           _thread_stack_reserved, unit, _thread_stack_committed, unit);
 321       }
 322 
 323       if (malloc_amt > 0) {
 324         if (type != mtChunk) {
 325           _output->print_cr("%27s (malloc=%d%s, #%d)", " ", malloc_amt, unit,
 326             malloc_count);
 327         } else {
 328           _output->print_cr("%27s (malloc=%d%s)", " ", malloc_amt, unit);
 329         }
 330       }
 331 
 332       if (reserved_amt > 0) {
 333         _output->print_cr("%27s (mmap: reserved=%d%s, committed=%d%s)",
 334           " ", reserved_amt, unit, committed_amt, unit);
 335       }
 336 
 337       if (arena_amt > 0) {
 338         _output->print_cr("%27s (arena=%d%s, #%d)", " ", arena_amt, unit, arena_count);
 339       }
 340 
 341       _output->print_cr(" ");
 342     }
 343   }
 344 }
 345 
 346 void BaselineTTYOutputer::done_category_summary() {
 347   _output->print_cr(" ");
 348 }
 349 
 350 
 351 void BaselineTTYOutputer::start_virtual_memory_map() {
 352   _output->print_cr("Virtual memory map:");
 353 }
 354 
 355 void BaselineTTYOutputer::reserved_memory_region(MEMFLAGS type, address base, address end,
 356                                                  size_t size, address pc) {
 357   const char* unit = memory_unit(_scale);
 358   char buf[128];
 359   int  offset;
 360   _output->print_cr(" ");
 361   _output->print_cr("[" PTR_FORMAT " - " PTR_FORMAT "] reserved %d%s for %s", base, end, size, unit,
 362             MemBaseline::type2name(type));
 363   if (os::dll_address_to_function_name(pc, buf, sizeof(buf), &offset)) {
 364       _output->print_cr("\t\tfrom [%s+0x%x]", buf, offset);
 365   }
 366 }
 367 
 368 void BaselineTTYOutputer::committed_memory_region(address base, address end, size_t size, address pc) {
 369   const char* unit = memory_unit(_scale);
 370   char buf[128];
 371   int  offset;
 372   _output->print("\t[" PTR_FORMAT " - " PTR_FORMAT "] committed %d%s", base, end, size, unit);
 373   if (os::dll_address_to_function_name(pc, buf, sizeof(buf), &offset)) {
 374       _output->print_cr(" from [%s+0x%x]", buf, offset);
 375   }
 376 }
 377 
 378 void BaselineTTYOutputer::done_virtual_memory_map() {
 379   _output->print_cr(" ");
 380 }
 381 
 382 
 383 
 384 void BaselineTTYOutputer::start_callsite() {
 385   _output->print_cr("Details:");
 386   _output->print_cr(" ");
 387 }
 388 
 389 void BaselineTTYOutputer::done_callsite() {
 390   _output->print_cr(" ");
 391 }
 392 
 393 void BaselineTTYOutputer::malloc_callsite(address pc, size_t malloc_amt,
 394   size_t malloc_count) {
 395   if (malloc_amt > 0) {
 396     const char* unit = memory_unit(_scale);
 397     char buf[128];
 398     int  offset;
 399     if (pc == 0) {
 400       _output->print("[BOOTSTRAP]%18s", " ");
 401     } else if (os::dll_address_to_function_name(pc, buf, sizeof(buf), &offset)) {
 402       _output->print_cr("[" PTR_FORMAT "] %s+0x%x", pc, buf, offset);
 403       _output->print("%28s", " ");
 404     } else {
 405       _output->print("[" PTR_FORMAT "]%18s", pc, " ");
 406     }
 407 
 408     _output->print_cr("(malloc=%d%s #%d)", malloc_amt, unit, malloc_count);
 409     _output->print_cr(" ");
 410   }
 411 }
 412 
 413 void BaselineTTYOutputer::virtual_memory_callsite(address pc, size_t reserved_amt,
 414   size_t committed_amt) {
 415   if (reserved_amt > 0) {
 416     const char* unit = memory_unit(_scale);
 417     char buf[128];
 418     int  offset;
 419     if (pc == 0) {
 420       _output->print("[BOOTSTRAP]%18s", " ");
 421     } else if (os::dll_address_to_function_name(pc, buf, sizeof(buf), &offset)) {
 422       _output->print_cr("[" PTR_FORMAT "] %s+0x%x", pc, buf, offset);
 423       _output->print("%28s", " ");
 424     } else {
 425       _output->print("[" PTR_FORMAT "]%18s", pc, " ");
 426     }
 427 
 428     _output->print_cr("(mmap: reserved=%d%s, committed=%d%s)",
 429       reserved_amt, unit, committed_amt, unit);
 430     _output->print_cr(" ");
 431   }
 432 }
 433 
 434 void BaselineTTYOutputer::diff_total_usage(size_t total_reserved,
 435   size_t total_committed, int reserved_diff, int committed_diff) {
 436   const char* unit = memory_unit(_scale);
 437   _output->print_cr("Total:  reserved=%d%s  %+d%s, committed=%d%s %+d%s",
 438     total_reserved, unit, reserved_diff, unit, total_committed, unit,
 439     committed_diff, unit);
 440 }
 441 
 442 void BaselineTTYOutputer::diff_category_summary(MEMFLAGS type,
 443   size_t cur_reserved_amt, size_t cur_committed_amt,
 444   size_t cur_malloc_amt, size_t cur_malloc_count,
 445   size_t cur_arena_amt, size_t cur_arena_count,
 446   int reserved_diff, int committed_diff, int malloc_diff,
 447   int malloc_count_diff, int arena_diff, int arena_count_diff) {
 448 
 449   if (type == mtThreadStack) {
 450     assert(cur_malloc_amt == 0 && cur_malloc_count == 0 &&
 451       cur_arena_amt == 0, "Just check");
 452     _thread_stack_reserved = cur_reserved_amt;
 453     _thread_stack_committed = cur_committed_amt;
 454     _thread_stack_reserved_diff = reserved_diff;
 455     _thread_stack_committed_diff = committed_diff;
 456   } else {
 457     const char* unit = memory_unit(_scale);
 458     size_t total_reserved = (cur_reserved_amt + cur_malloc_amt + cur_arena_amt);
 459     // nothing to report in this category
 460     if (total_reserved == 0) {
 461       return;
 462     }
 463     int    diff_reserved = (reserved_diff + malloc_diff + arena_diff);
 464 
 465     // category summary
 466     _output->print("-%26s (reserved=%d%s", MemBaseline::type2name(type),
 467       total_reserved, unit);
 468 
 469     if (diff_reserved != 0) {
 470       _output->print(" %+d%s", diff_reserved, unit);
 471     }
 472 
 473     size_t total_committed = cur_committed_amt + cur_malloc_amt + cur_arena_amt;
 474     _output->print(", committed=%d%s", total_committed, unit);
 475 
 476     int total_committed_diff = committed_diff + malloc_diff + arena_diff;
 477     if (total_committed_diff != 0) {
 478       _output->print(" %+d%s", total_committed_diff, unit);
 479     }
 480 
 481     _output->print_cr(")");
 482 
 483     // special cases
 484     if (type == mtClass) {
 485       _output->print("%27s (classes #%d", " ", _num_of_classes);
 486       if (_num_of_classes_diff != 0) {
 487         _output->print(" %+d", _num_of_classes_diff);
 488       }
 489       _output->print_cr(")");
 490     } else if (type == mtThread) {
 491       // thread count
 492       _output->print("%27s (thread #%d", " ", _num_of_threads);
 493       if (_num_of_threads_diff != 0) {
 494         _output->print_cr(" %+d)", _num_of_threads_diff);
 495       } else {
 496         _output->print_cr(")");
 497       }
 498       _output->print("%27s (stack: reserved=%d%s", " ", _thread_stack_reserved, unit);
 499       if (_thread_stack_reserved_diff != 0) {
 500         _output->print(" %+d%s", _thread_stack_reserved_diff, unit);
 501       }
 502 
 503       _output->print(", committed=%d%s", _thread_stack_committed, unit);
 504       if (_thread_stack_committed_diff != 0) {
 505         _output->print(" %+d%s",_thread_stack_committed_diff, unit);
 506       }
 507 
 508       _output->print_cr(")");
 509     }
 510 
 511     // malloc'd memory
 512     if (cur_malloc_amt > 0) {
 513       _output->print("%27s (malloc=%d%s", " ", cur_malloc_amt, unit);
 514       if (malloc_diff != 0) {
 515         _output->print(" %+d%s", malloc_diff, unit);
 516       }
 517       if (type != mtChunk) {
 518         _output->print(", #%d", cur_malloc_count);
 519         if (malloc_count_diff) {
 520           _output->print(" %+d", malloc_count_diff);
 521         }
 522       }
 523       _output->print_cr(")");
 524     }
 525 
 526     // mmap'd memory
 527     if (cur_reserved_amt > 0) {
 528       _output->print("%27s (mmap: reserved=%d%s", " ", cur_reserved_amt, unit);
 529       if (reserved_diff != 0) {
 530         _output->print(" %+d%s", reserved_diff, unit);
 531       }
 532 
 533       _output->print(", committed=%d%s", cur_committed_amt, unit);
 534       if (committed_diff != 0) {
 535         _output->print(" %+d%s", committed_diff, unit);
 536       }
 537       _output->print_cr(")");
 538     }
 539 
 540     // arena memory
 541     if (cur_arena_amt > 0) {
 542       _output->print("%27s (arena=%d%s", " ", cur_arena_amt, unit);
 543       if (arena_diff != 0) {
 544         _output->print(" %+d%s", arena_diff, unit);
 545       }
 546       _output->print(", #%d", cur_arena_count);
 547       if (arena_count_diff != 0) {
 548         _output->print(" %+d", arena_count_diff);
 549       }
 550       _output->print_cr(")");
 551     }
 552 
 553     _output->print_cr(" ");
 554   }
 555 }
 556 
 557 void BaselineTTYOutputer::diff_malloc_callsite(address pc,
 558     size_t cur_malloc_amt, size_t cur_malloc_count,
 559     int malloc_diff, int malloc_count_diff) {
 560   if (malloc_diff != 0) {
 561     const char* unit = memory_unit(_scale);
 562     char buf[128];
 563     int  offset;
 564     if (pc == 0) {
 565       _output->print_cr("[BOOTSTRAP]%18s", " ");
 566     } else {
 567       if (os::dll_address_to_function_name(pc, buf, sizeof(buf), &offset)) {
 568         _output->print_cr("[" PTR_FORMAT "] %s+0x%x", pc, buf, offset);
 569         _output->print("%28s", " ");
 570       } else {
 571         _output->print("[" PTR_FORMAT "]%18s", pc, " ");
 572       }
 573     }
 574 
 575     _output->print("(malloc=%d%s", cur_malloc_amt, unit);
 576     if (malloc_diff != 0) {
 577       _output->print(" %+d%s", malloc_diff, unit);
 578     }
 579     _output->print(", #%d", cur_malloc_count);
 580     if (malloc_count_diff != 0) {
 581       _output->print(" %+d", malloc_count_diff);
 582     }
 583     _output->print_cr(")");
 584     _output->print_cr(" ");
 585   }
 586 }
 587 
 588 void BaselineTTYOutputer::diff_virtual_memory_callsite(address pc,
 589     size_t cur_reserved_amt, size_t cur_committed_amt,
 590     int reserved_diff, int committed_diff) {
 591   if (reserved_diff != 0 || committed_diff != 0) {
 592     const char* unit = memory_unit(_scale);
 593     char buf[64];
 594     int  offset;
 595     if (pc == 0) {
 596       _output->print_cr("[BOOSTRAP]%18s", " ");
 597     } else {
 598       if (os::dll_address_to_function_name(pc, buf, sizeof(buf), &offset)) {
 599         _output->print_cr("[" PTR_FORMAT "] %s+0x%x", pc, buf, offset);
 600         _output->print("%28s", " ");
 601       } else {
 602         _output->print("[" PTR_FORMAT "]%18s", pc, " ");
 603       }
 604     }
 605 
 606     _output->print("(mmap: reserved=%d%s", cur_reserved_amt, unit);
 607     if (reserved_diff != 0) {
 608       _output->print(" %+d%s", reserved_diff, unit);
 609     }
 610     _output->print(", committed=%d%s", cur_committed_amt, unit);
 611     if (committed_diff != 0) {
 612       _output->print(" %+d%s", committed_diff, unit);
 613     }
 614     _output->print_cr(")");
 615     _output->print_cr(" ");
 616   }
 617 }