src/share/vm/services/memReporter.cpp

Tue, 25 Jun 2013 17:22:04 -0400

author
zgu
date
Tue, 25 Jun 2013 17:22:04 -0400
changeset 5325
8cff1de240de
parent 5270
cd2118b62475
child 6198
55fb97c4c58d
permissions
-rw-r--r--

8017478: Kitchensink crashed with SIGSEGV in BaselineReporter::diff_callsites
Summary: Fixed possible NULL pointer that caused SIGSEGV
Reviewed-by: coleenp, acorn, ctornqvi

     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"
    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 }
    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()));
    49   _outputer.num_of_classes(baseline.number_of_classes());
    50   _outputer.num_of_threads(baseline.number_of_threads());
    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 }
    60 void BaselineReporter::report_summaries(const MemBaseline& baseline) {
    61   _outputer.start_category_summary();
    62   MEMFLAGS type;
    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   }
    75   _outputer.done_category_summary();
    76 }
    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   }
    94   _outputer.done_virtual_memory_map();
    95 }
    97 void BaselineReporter::report_callsites(const MemBaseline& baseline) {
    98   _outputer.start_callsite();
    99   MemBaseline* pBL = const_cast<MemBaseline*>(&baseline);
   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);
   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   }
   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 }
   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();
   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())));
   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()));
   145   diff_summaries(cur, prev);
   146   if (!summary_only && MemTracker::track_callsite()) {
   147     diff_callsites(cur, prev);
   148   }
   149   _outputer.done();
   150 }
   152 void BaselineReporter::diff_summaries(const MemBaseline& cur, const MemBaseline& prev) {
   153   _outputer.start_category_summary();
   154   MEMFLAGS type;
   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   }
   173   _outputer.done_category_summary();
   174 }
   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);
   181   // walk malloc callsites
   182   MemPointerArrayIteratorImpl cur_malloc_itr(pBL_cur->_malloc_cs);
   183   MemPointerArrayIteratorImpl prev_malloc_itr(pBL_prev->_malloc_cs);
   185   MallocCallsitePointer*      cur_malloc_callsite =
   186                   (MallocCallsitePointer*)cur_malloc_itr.current();
   187   MallocCallsitePointer*      prev_malloc_callsite =
   188                   (MallocCallsitePointer*)prev_malloc_itr.current();
   190   while (cur_malloc_callsite != NULL || prev_malloc_callsite != NULL) {
   191     if (prev_malloc_callsite == NULL) {
   192       assert(cur_malloc_callsite != NULL, "sanity check");
   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       assert(prev_malloc_callsite != NULL, "Sanity check");
   202       // this callsite is already gone
   203       _outputer.diff_malloc_callsite(prev_malloc_callsite->addr(),
   204         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 {
   209       assert(cur_malloc_callsite  != NULL,  "Sanity check");
   210       assert(prev_malloc_callsite != NULL,  "Sanity check");
   211       if (cur_malloc_callsite->addr() < prev_malloc_callsite->addr()) {
   212         // this is a new callsite
   213         _outputer.diff_malloc_callsite(cur_malloc_callsite->addr(),
   214           amount_in_current_scale(cur_malloc_callsite->amount()),
   215           cur_malloc_callsite->count(),
   216           diff_in_current_scale(cur_malloc_callsite->amount(), 0),
   217           diff(cur_malloc_callsite->count(), 0));
   218           cur_malloc_callsite = (MallocCallsitePointer*)cur_malloc_itr.next();
   219       } else if (cur_malloc_callsite->addr() > prev_malloc_callsite->addr()) {
   220         // this callsite is already gone
   221         _outputer.diff_malloc_callsite(prev_malloc_callsite->addr(),
   222           0, 0,
   223           diff_in_current_scale(0, prev_malloc_callsite->amount()),
   224           diff(0, prev_malloc_callsite->count()));
   225         prev_malloc_callsite = (MallocCallsitePointer*)prev_malloc_itr.next();
   226       } else {
   227         // the same callsite
   228         _outputer.diff_malloc_callsite(cur_malloc_callsite->addr(),
   229           amount_in_current_scale(cur_malloc_callsite->amount()),
   230           cur_malloc_callsite->count(),
   231           diff_in_current_scale(cur_malloc_callsite->amount(), prev_malloc_callsite->amount()),
   232           diff(cur_malloc_callsite->count(), prev_malloc_callsite->count()));
   233         cur_malloc_callsite = (MallocCallsitePointer*)cur_malloc_itr.next();
   234         prev_malloc_callsite = (MallocCallsitePointer*)prev_malloc_itr.next();
   235       }
   236     }
   237   }
   239   // walk virtual memory callsite
   240   MemPointerArrayIteratorImpl cur_vm_itr(pBL_cur->_vm_cs);
   241   MemPointerArrayIteratorImpl prev_vm_itr(pBL_prev->_vm_cs);
   242   VMCallsitePointer*          cur_vm_callsite = (VMCallsitePointer*)cur_vm_itr.current();
   243   VMCallsitePointer*          prev_vm_callsite = (VMCallsitePointer*)prev_vm_itr.current();
   244   while (cur_vm_callsite != NULL || prev_vm_callsite != NULL) {
   245     if (prev_vm_callsite == NULL || cur_vm_callsite->addr() < prev_vm_callsite->addr()) {
   246       // this is a new callsite
   247       _outputer.diff_virtual_memory_callsite(cur_vm_callsite->addr(),
   248         amount_in_current_scale(cur_vm_callsite->reserved_amount()),
   249         amount_in_current_scale(cur_vm_callsite->committed_amount()),
   250         diff_in_current_scale(cur_vm_callsite->reserved_amount(), 0),
   251         diff_in_current_scale(cur_vm_callsite->committed_amount(), 0));
   252       cur_vm_callsite = (VMCallsitePointer*)cur_vm_itr.next();
   253     } else if (cur_vm_callsite == NULL || cur_vm_callsite->addr() > prev_vm_callsite->addr()) {
   254       // this callsite is already gone
   255       _outputer.diff_virtual_memory_callsite(prev_vm_callsite->addr(),
   256         amount_in_current_scale(0),
   257         amount_in_current_scale(0),
   258         diff_in_current_scale(0, prev_vm_callsite->reserved_amount()),
   259         diff_in_current_scale(0, prev_vm_callsite->committed_amount()));
   260       prev_vm_callsite = (VMCallsitePointer*)prev_vm_itr.next();
   261     } else { // the same callsite
   262       _outputer.diff_virtual_memory_callsite(cur_vm_callsite->addr(),
   263         amount_in_current_scale(cur_vm_callsite->reserved_amount()),
   264         amount_in_current_scale(cur_vm_callsite->committed_amount()),
   265         diff_in_current_scale(cur_vm_callsite->reserved_amount(), prev_vm_callsite->reserved_amount()),
   266         diff_in_current_scale(cur_vm_callsite->committed_amount(), prev_vm_callsite->committed_amount()));
   267       cur_vm_callsite  = (VMCallsitePointer*)cur_vm_itr.next();
   268       prev_vm_callsite = (VMCallsitePointer*)prev_vm_itr.next();
   269     }
   270   }
   272   _outputer.done_callsite();
   273 }
   275 size_t BaselineReporter::amount_in_current_scale(size_t amt) const {
   276   return (size_t)(((float)amt/(float)_scale) + 0.5);
   277 }
   279 int BaselineReporter::diff_in_current_scale(size_t value1, size_t value2) const {
   280   return (int)(((float)value1 - (float)value2)/((float)_scale) + 0.5);
   281 }
   283 int BaselineReporter::diff(size_t value1, size_t value2) const {
   284   return ((int)value1 - (int)value2);
   285 }
   287 void BaselineTTYOutputer::start(size_t scale, bool report_diff) {
   288   _scale = scale;
   289   _output->print_cr(" ");
   290   _output->print_cr("Native Memory Tracking:");
   291   _output->print_cr(" ");
   292 }
   294 void BaselineTTYOutputer::done() {
   296 }
   298 void BaselineTTYOutputer::total_usage(size_t total_reserved, size_t total_committed) {
   299   const char* unit = memory_unit(_scale);
   300   _output->print_cr("Total:  reserved=%d%s,  committed=%d%s",
   301     total_reserved, unit, total_committed, unit);
   302 }
   304 void BaselineTTYOutputer::start_category_summary() {
   305   _output->print_cr(" ");
   306 }
   308 /**
   309  * report a summary of memory type
   310  */
   311 void BaselineTTYOutputer::category_summary(MEMFLAGS type,
   312   size_t reserved_amt, size_t committed_amt, size_t malloc_amt,
   313   size_t malloc_count, size_t arena_amt, size_t arena_count) {
   315   // we report mtThreadStack under mtThread category
   316   if (type == mtThreadStack) {
   317     assert(malloc_amt == 0 && malloc_count == 0 && arena_amt == 0,
   318       "Just check");
   319     _thread_stack_reserved = reserved_amt;
   320     _thread_stack_committed = committed_amt;
   321   } else {
   322     const char* unit = memory_unit(_scale);
   323     size_t total_reserved = (reserved_amt + malloc_amt + arena_amt);
   324     size_t total_committed = (committed_amt + malloc_amt + arena_amt);
   325     if (type == mtThread) {
   326       total_reserved += _thread_stack_reserved;
   327       total_committed += _thread_stack_committed;
   328     }
   330     if (total_reserved > 0) {
   331       _output->print_cr("-%26s (reserved=%d%s, committed=%d%s)",
   332         MemBaseline::type2name(type), total_reserved, unit,
   333         total_committed, unit);
   335       if (type == mtClass) {
   336         _output->print_cr("%27s (classes #%d)", " ", _num_of_classes);
   337       } else if (type == mtThread) {
   338         _output->print_cr("%27s (thread #%d)", " ", _num_of_threads);
   339         _output->print_cr("%27s (stack: reserved=%d%s, committed=%d%s)", " ",
   340           _thread_stack_reserved, unit, _thread_stack_committed, unit);
   341       }
   343       if (malloc_amt > 0) {
   344         if (type != mtChunk) {
   345           _output->print_cr("%27s (malloc=%d%s, #%d)", " ", malloc_amt, unit,
   346             malloc_count);
   347         } else {
   348           _output->print_cr("%27s (malloc=%d%s)", " ", malloc_amt, unit);
   349         }
   350       }
   352       if (reserved_amt > 0) {
   353         _output->print_cr("%27s (mmap: reserved=%d%s, committed=%d%s)",
   354           " ", reserved_amt, unit, committed_amt, unit);
   355       }
   357       if (arena_amt > 0) {
   358         _output->print_cr("%27s (arena=%d%s, #%d)", " ", arena_amt, unit, arena_count);
   359       }
   361       _output->print_cr(" ");
   362     }
   363   }
   364 }
   366 void BaselineTTYOutputer::done_category_summary() {
   367   _output->print_cr(" ");
   368 }
   371 void BaselineTTYOutputer::start_virtual_memory_map() {
   372   _output->print_cr("Virtual memory map:");
   373 }
   375 void BaselineTTYOutputer::reserved_memory_region(MEMFLAGS type, address base, address end,
   376                                                  size_t size, address pc) {
   377   const char* unit = memory_unit(_scale);
   378   char buf[128];
   379   int  offset;
   380   _output->print_cr(" ");
   381   _output->print_cr("[" PTR_FORMAT " - " PTR_FORMAT "] reserved %d%s for %s", base, end, size, unit,
   382             MemBaseline::type2name(type));
   383   if (os::dll_address_to_function_name(pc, buf, sizeof(buf), &offset)) {
   384       _output->print_cr("\t\tfrom [%s+0x%x]", buf, offset);
   385   }
   386 }
   388 void BaselineTTYOutputer::committed_memory_region(address base, address end, size_t size, address pc) {
   389   const char* unit = memory_unit(_scale);
   390   char buf[128];
   391   int  offset;
   392   _output->print("\t[" PTR_FORMAT " - " PTR_FORMAT "] committed %d%s", base, end, size, unit);
   393   if (os::dll_address_to_function_name(pc, buf, sizeof(buf), &offset)) {
   394       _output->print_cr(" from [%s+0x%x]", buf, offset);
   395   }
   396 }
   398 void BaselineTTYOutputer::done_virtual_memory_map() {
   399   _output->print_cr(" ");
   400 }
   404 void BaselineTTYOutputer::start_callsite() {
   405   _output->print_cr("Details:");
   406   _output->print_cr(" ");
   407 }
   409 void BaselineTTYOutputer::done_callsite() {
   410   _output->print_cr(" ");
   411 }
   413 void BaselineTTYOutputer::malloc_callsite(address pc, size_t malloc_amt,
   414   size_t malloc_count) {
   415   if (malloc_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     }
   428     _output->print_cr("(malloc=%d%s #%d)", malloc_amt, unit, malloc_count);
   429     _output->print_cr(" ");
   430   }
   431 }
   433 void BaselineTTYOutputer::virtual_memory_callsite(address pc, size_t reserved_amt,
   434   size_t committed_amt) {
   435   if (reserved_amt > 0) {
   436     const char* unit = memory_unit(_scale);
   437     char buf[128];
   438     int  offset;
   439     if (pc == 0) {
   440       _output->print("[BOOTSTRAP]%18s", " ");
   441     } else if (os::dll_address_to_function_name(pc, buf, sizeof(buf), &offset)) {
   442       _output->print_cr("[" PTR_FORMAT "] %s+0x%x", pc, buf, offset);
   443       _output->print("%28s", " ");
   444     } else {
   445       _output->print("[" PTR_FORMAT "]%18s", pc, " ");
   446     }
   448     _output->print_cr("(mmap: reserved=%d%s, committed=%d%s)",
   449       reserved_amt, unit, committed_amt, unit);
   450     _output->print_cr(" ");
   451   }
   452 }
   454 void BaselineTTYOutputer::diff_total_usage(size_t total_reserved,
   455   size_t total_committed, int reserved_diff, int committed_diff) {
   456   const char* unit = memory_unit(_scale);
   457   _output->print_cr("Total:  reserved=%d%s  %+d%s, committed=%d%s %+d%s",
   458     total_reserved, unit, reserved_diff, unit, total_committed, unit,
   459     committed_diff, unit);
   460 }
   462 void BaselineTTYOutputer::diff_category_summary(MEMFLAGS type,
   463   size_t cur_reserved_amt, size_t cur_committed_amt,
   464   size_t cur_malloc_amt, size_t cur_malloc_count,
   465   size_t cur_arena_amt, size_t cur_arena_count,
   466   int reserved_diff, int committed_diff, int malloc_diff,
   467   int malloc_count_diff, int arena_diff, int arena_count_diff) {
   469   if (type == mtThreadStack) {
   470     assert(cur_malloc_amt == 0 && cur_malloc_count == 0 &&
   471       cur_arena_amt == 0, "Just check");
   472     _thread_stack_reserved = cur_reserved_amt;
   473     _thread_stack_committed = cur_committed_amt;
   474     _thread_stack_reserved_diff = reserved_diff;
   475     _thread_stack_committed_diff = committed_diff;
   476   } else {
   477     const char* unit = memory_unit(_scale);
   478     size_t total_reserved = (cur_reserved_amt + cur_malloc_amt + cur_arena_amt);
   479     // nothing to report in this category
   480     if (total_reserved == 0) {
   481       return;
   482     }
   483     int    diff_reserved = (reserved_diff + malloc_diff + arena_diff);
   485     // category summary
   486     _output->print("-%26s (reserved=%d%s", MemBaseline::type2name(type),
   487       total_reserved, unit);
   489     if (diff_reserved != 0) {
   490       _output->print(" %+d%s", diff_reserved, unit);
   491     }
   493     size_t total_committed = cur_committed_amt + cur_malloc_amt + cur_arena_amt;
   494     _output->print(", committed=%d%s", total_committed, unit);
   496     int total_committed_diff = committed_diff + malloc_diff + arena_diff;
   497     if (total_committed_diff != 0) {
   498       _output->print(" %+d%s", total_committed_diff, unit);
   499     }
   501     _output->print_cr(")");
   503     // special cases
   504     if (type == mtClass) {
   505       _output->print("%27s (classes #%d", " ", _num_of_classes);
   506       if (_num_of_classes_diff != 0) {
   507         _output->print(" %+d", _num_of_classes_diff);
   508       }
   509       _output->print_cr(")");
   510     } else if (type == mtThread) {
   511       // thread count
   512       _output->print("%27s (thread #%d", " ", _num_of_threads);
   513       if (_num_of_threads_diff != 0) {
   514         _output->print_cr(" %+d)", _num_of_threads_diff);
   515       } else {
   516         _output->print_cr(")");
   517       }
   518       _output->print("%27s (stack: reserved=%d%s", " ", _thread_stack_reserved, unit);
   519       if (_thread_stack_reserved_diff != 0) {
   520         _output->print(" %+d%s", _thread_stack_reserved_diff, unit);
   521       }
   523       _output->print(", committed=%d%s", _thread_stack_committed, unit);
   524       if (_thread_stack_committed_diff != 0) {
   525         _output->print(" %+d%s",_thread_stack_committed_diff, unit);
   526       }
   528       _output->print_cr(")");
   529     }
   531     // malloc'd memory
   532     if (cur_malloc_amt > 0) {
   533       _output->print("%27s (malloc=%d%s", " ", cur_malloc_amt, unit);
   534       if (malloc_diff != 0) {
   535         _output->print(" %+d%s", malloc_diff, unit);
   536       }
   537       if (type != mtChunk) {
   538         _output->print(", #%d", cur_malloc_count);
   539         if (malloc_count_diff) {
   540           _output->print(" %+d", malloc_count_diff);
   541         }
   542       }
   543       _output->print_cr(")");
   544     }
   546     // mmap'd memory
   547     if (cur_reserved_amt > 0) {
   548       _output->print("%27s (mmap: reserved=%d%s", " ", cur_reserved_amt, unit);
   549       if (reserved_diff != 0) {
   550         _output->print(" %+d%s", reserved_diff, unit);
   551       }
   553       _output->print(", committed=%d%s", cur_committed_amt, unit);
   554       if (committed_diff != 0) {
   555         _output->print(" %+d%s", committed_diff, unit);
   556       }
   557       _output->print_cr(")");
   558     }
   560     // arena memory
   561     if (cur_arena_amt > 0) {
   562       _output->print("%27s (arena=%d%s", " ", cur_arena_amt, unit);
   563       if (arena_diff != 0) {
   564         _output->print(" %+d%s", arena_diff, unit);
   565       }
   566       _output->print(", #%d", cur_arena_count);
   567       if (arena_count_diff != 0) {
   568         _output->print(" %+d", arena_count_diff);
   569       }
   570       _output->print_cr(")");
   571     }
   573     _output->print_cr(" ");
   574   }
   575 }
   577 void BaselineTTYOutputer::diff_malloc_callsite(address pc,
   578     size_t cur_malloc_amt, size_t cur_malloc_count,
   579     int malloc_diff, int malloc_count_diff) {
   580   if (malloc_diff != 0) {
   581     const char* unit = memory_unit(_scale);
   582     char buf[128];
   583     int  offset;
   584     if (pc == 0) {
   585       _output->print_cr("[BOOTSTRAP]%18s", " ");
   586     } else {
   587       if (os::dll_address_to_function_name(pc, buf, sizeof(buf), &offset)) {
   588         _output->print_cr("[" PTR_FORMAT "] %s+0x%x", pc, buf, offset);
   589         _output->print("%28s", " ");
   590       } else {
   591         _output->print("[" PTR_FORMAT "]%18s", pc, " ");
   592       }
   593     }
   595     _output->print("(malloc=%d%s", cur_malloc_amt, unit);
   596     if (malloc_diff != 0) {
   597       _output->print(" %+d%s", malloc_diff, unit);
   598     }
   599     _output->print(", #%d", cur_malloc_count);
   600     if (malloc_count_diff != 0) {
   601       _output->print(" %+d", malloc_count_diff);
   602     }
   603     _output->print_cr(")");
   604     _output->print_cr(" ");
   605   }
   606 }
   608 void BaselineTTYOutputer::diff_virtual_memory_callsite(address pc,
   609     size_t cur_reserved_amt, size_t cur_committed_amt,
   610     int reserved_diff, int committed_diff) {
   611   if (reserved_diff != 0 || committed_diff != 0) {
   612     const char* unit = memory_unit(_scale);
   613     char buf[64];
   614     int  offset;
   615     if (pc == 0) {
   616       _output->print_cr("[BOOSTRAP]%18s", " ");
   617     } else {
   618       if (os::dll_address_to_function_name(pc, buf, sizeof(buf), &offset)) {
   619         _output->print_cr("[" PTR_FORMAT "] %s+0x%x", pc, buf, offset);
   620         _output->print("%28s", " ");
   621       } else {
   622         _output->print("[" PTR_FORMAT "]%18s", pc, " ");
   623       }
   624     }
   626     _output->print("(mmap: reserved=%d%s", cur_reserved_amt, unit);
   627     if (reserved_diff != 0) {
   628       _output->print(" %+d%s", reserved_diff, unit);
   629     }
   630     _output->print(", committed=%d%s", cur_committed_amt, unit);
   631     if (committed_diff != 0) {
   632       _output->print(" %+d%s", committed_diff, unit);
   633     }
   634     _output->print_cr(")");
   635     _output->print_cr(" ");
   636   }
   637 }

mercurial