< prev index next >

src/share/vm/services/memReporter.cpp

Print this page
rev 9024 : 8218558: NMT stack traces in output should show mt component for virtual memory allocations
Reviewed-by: shade, stuefe, coleenp
   1 /*
   2  * Copyright (c) 2012, 2017, 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  *


 188 
 189   report_malloc_sites();
 190   report_virtual_memory_allocation_sites();
 191 }
 192 
 193 void MemDetailReporter::report_malloc_sites() {
 194   MallocSiteIterator         malloc_itr = _baseline.malloc_sites(MemBaseline::by_size);
 195   if (malloc_itr.is_empty()) return;
 196 
 197   outputStream* out = output();
 198 
 199   const MallocSite* malloc_site;
 200   while ((malloc_site = malloc_itr.next()) != NULL) {
 201     // Don't report if size is too small
 202     if (amount_in_current_scale(malloc_site->size()) == 0)
 203       continue;
 204 
 205     const NativeCallStack* stack = malloc_site->call_stack();
 206     stack->print_on(out);
 207     out->print("%29s", " ");
 208     MEMFLAGS flag = malloc_site->flags();
 209     assert((flag >= 0 && flag < (int)mt_number_of_types) && flag != mtNone,
 210       "Must have a valid memory type");
 211     print_malloc(malloc_site->size(), malloc_site->count(),flag);
 212     out->print_cr("\n");
 213   }
 214 }
 215 
 216 void MemDetailReporter::report_virtual_memory_allocation_sites()  {
 217   VirtualMemorySiteIterator  virtual_memory_itr =
 218     _baseline.virtual_memory_sites(MemBaseline::by_size);
 219 
 220   if (virtual_memory_itr.is_empty()) return;
 221 
 222   outputStream* out = output();
 223   const VirtualMemoryAllocationSite*  virtual_memory_site;
 224 
 225   while ((virtual_memory_site = virtual_memory_itr.next()) != NULL) {
 226     // Don't report if size is too small
 227     if (amount_in_current_scale(virtual_memory_site->reserved()) == 0)
 228       continue;
 229 
 230     const NativeCallStack* stack = virtual_memory_site->call_stack();
 231     stack->print_on(out);
 232     out->print("%28s (", " ");
 233     print_total(virtual_memory_site->reserved(), virtual_memory_site->committed());




 234     out->print_cr(")\n");
 235   }
 236 }
 237 
 238 
 239 void MemDetailReporter::report_virtual_memory_map() {
 240   // Virtual memory map always in base address order
 241   VirtualMemoryAllocationIterator itr = _baseline.virtual_memory_allocations();
 242   const ReservedMemoryRegion* rgn;
 243 
 244   output()->print_cr("Virtual memory map:");
 245   while ((rgn = itr.next()) != NULL) {
 246     report_virtual_memory_region(rgn);
 247   }
 248 }
 249 
 250 void MemDetailReporter::report_virtual_memory_region(const ReservedMemoryRegion* reserved_rgn) {
 251   assert(reserved_rgn != NULL, "NULL pointer");
 252 
 253   // Don't report if size is too small


 545     } else {
 546       int compVal = current_site->call_stack()->compare(*early_site->call_stack());
 547       if (compVal < 0) {
 548         new_virtual_memory_site(current_site);
 549         current_site = current_itr.next();
 550       } else if (compVal > 0) {
 551         old_virtual_memory_site(early_site);
 552         early_site = early_itr.next();
 553       } else {
 554         diff_virtual_memory_site(early_site, current_site);
 555         early_site   = early_itr.next();
 556         current_site = current_itr.next();
 557       }
 558     }
 559   }
 560 }
 561 
 562 
 563 void MemDetailDiffReporter::new_malloc_site(const MallocSite* malloc_site) const {
 564   diff_malloc_site(malloc_site->call_stack(), malloc_site->size(), malloc_site->count(),
 565     0, 0, malloc_site->flags());
 566 }
 567 
 568 void MemDetailDiffReporter::old_malloc_site(const MallocSite* malloc_site) const {
 569   diff_malloc_site(malloc_site->call_stack(), 0, 0, malloc_site->size(),
 570     malloc_site->count(), malloc_site->flags());
 571 }
 572 
 573 void MemDetailDiffReporter::diff_malloc_site(const MallocSite* early,
 574   const MallocSite* current)  const {
 575   if (early->flags() != current->flags()) {
 576     // If malloc site type changed, treat it as deallocation of old type and
 577     // allocation of new type.
 578     old_malloc_site(early);
 579     new_malloc_site(current);
 580   } else {
 581     diff_malloc_site(current->call_stack(), current->size(), current->count(),
 582       early->size(), early->count(), early->flags());
 583   }
 584 }
 585 
 586 void MemDetailDiffReporter::diff_malloc_site(const NativeCallStack* stack, size_t current_size,
 587   size_t current_count, size_t early_size, size_t early_count, MEMFLAGS flags) const {
 588   outputStream* out = output();
 589 
 590   assert(stack != NULL, "NULL stack");
 591 
 592   if (diff_in_current_scale(current_size, early_size) == 0) {
 593       return;
 594   }
 595 
 596   stack->print_on(out);
 597   out->print("%28s (", " ");
 598   print_malloc_diff(current_size, current_count,
 599     early_size, early_count, flags);
 600 
 601   out->print_cr(")\n");
 602 }
 603 
 604 
 605 void MemDetailDiffReporter::new_virtual_memory_site(const VirtualMemoryAllocationSite* site) const {
 606   diff_virtual_memory_site(site->call_stack(), site->reserved(), site->committed(), 0, 0);
 607 }
 608 
 609 void MemDetailDiffReporter::old_virtual_memory_site(const VirtualMemoryAllocationSite* site) const {
 610   diff_virtual_memory_site(site->call_stack(), 0, 0, site->reserved(), site->committed());
 611 }
 612 
 613 void MemDetailDiffReporter::diff_virtual_memory_site(const VirtualMemoryAllocationSite* early,
 614   const VirtualMemoryAllocationSite* current) const {

 615   diff_virtual_memory_site(current->call_stack(), current->reserved(), current->committed(),
 616     early->reserved(), early->committed());
 617 }
 618 
 619 void MemDetailDiffReporter::diff_virtual_memory_site(const NativeCallStack* stack, size_t current_reserved,
 620   size_t current_committed, size_t early_reserved, size_t early_committed) const  {
 621   outputStream* out = output();
 622 
 623   // no change
 624   if (diff_in_current_scale(current_reserved, early_reserved) == 0 &&
 625       diff_in_current_scale(current_committed, early_committed) == 0) {
 626     return;
 627   }
 628 
 629   stack->print_on(out);
 630   out->print("%28s (mmap: ", " ");
 631   print_virtual_memory_diff(current_reserved, current_committed,
 632     early_reserved, early_committed);




 633 
 634   out->print_cr(")\n");
 635  }
 636 
   1 /*
   2  * Copyright (c) 2012, 2019, 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  *


 188 
 189   report_malloc_sites();
 190   report_virtual_memory_allocation_sites();
 191 }
 192 
 193 void MemDetailReporter::report_malloc_sites() {
 194   MallocSiteIterator         malloc_itr = _baseline.malloc_sites(MemBaseline::by_size);
 195   if (malloc_itr.is_empty()) return;
 196 
 197   outputStream* out = output();
 198 
 199   const MallocSite* malloc_site;
 200   while ((malloc_site = malloc_itr.next()) != NULL) {
 201     // Don't report if size is too small
 202     if (amount_in_current_scale(malloc_site->size()) == 0)
 203       continue;
 204 
 205     const NativeCallStack* stack = malloc_site->call_stack();
 206     stack->print_on(out);
 207     out->print("%29s", " ");
 208     MEMFLAGS flag = malloc_site->flag();
 209     assert((flag >= 0 && flag < (int)mt_number_of_types) && flag != mtNone,
 210       "Must have a valid memory type");
 211     print_malloc(malloc_site->size(), malloc_site->count(),flag);
 212     out->print_cr("\n");
 213   }
 214 }
 215 
 216 void MemDetailReporter::report_virtual_memory_allocation_sites()  {
 217   VirtualMemorySiteIterator  virtual_memory_itr =
 218     _baseline.virtual_memory_sites(MemBaseline::by_size);
 219 
 220   if (virtual_memory_itr.is_empty()) return;
 221 
 222   outputStream* out = output();
 223   const VirtualMemoryAllocationSite*  virtual_memory_site;
 224 
 225   while ((virtual_memory_site = virtual_memory_itr.next()) != NULL) {
 226     // Don't report if size is too small
 227     if (amount_in_current_scale(virtual_memory_site->reserved()) == 0)
 228       continue;
 229 
 230     const NativeCallStack* stack = virtual_memory_site->call_stack();
 231     stack->print_on(out);
 232     out->print("%28s (", " ");
 233     print_total(virtual_memory_site->reserved(), virtual_memory_site->committed());
 234     MEMFLAGS flag = virtual_memory_site->flag();
 235     if (flag != mtNone) {
 236       out->print(" Type=%s", NMTUtil::flag_to_name(flag));
 237     }
 238     out->print_cr(")\n");
 239   }
 240 }
 241 
 242 
 243 void MemDetailReporter::report_virtual_memory_map() {
 244   // Virtual memory map always in base address order
 245   VirtualMemoryAllocationIterator itr = _baseline.virtual_memory_allocations();
 246   const ReservedMemoryRegion* rgn;
 247 
 248   output()->print_cr("Virtual memory map:");
 249   while ((rgn = itr.next()) != NULL) {
 250     report_virtual_memory_region(rgn);
 251   }
 252 }
 253 
 254 void MemDetailReporter::report_virtual_memory_region(const ReservedMemoryRegion* reserved_rgn) {
 255   assert(reserved_rgn != NULL, "NULL pointer");
 256 
 257   // Don't report if size is too small


 549     } else {
 550       int compVal = current_site->call_stack()->compare(*early_site->call_stack());
 551       if (compVal < 0) {
 552         new_virtual_memory_site(current_site);
 553         current_site = current_itr.next();
 554       } else if (compVal > 0) {
 555         old_virtual_memory_site(early_site);
 556         early_site = early_itr.next();
 557       } else {
 558         diff_virtual_memory_site(early_site, current_site);
 559         early_site   = early_itr.next();
 560         current_site = current_itr.next();
 561       }
 562     }
 563   }
 564 }
 565 
 566 
 567 void MemDetailDiffReporter::new_malloc_site(const MallocSite* malloc_site) const {
 568   diff_malloc_site(malloc_site->call_stack(), malloc_site->size(), malloc_site->count(),
 569     0, 0, malloc_site->flag());
 570 }
 571 
 572 void MemDetailDiffReporter::old_malloc_site(const MallocSite* malloc_site) const {
 573   diff_malloc_site(malloc_site->call_stack(), 0, 0, malloc_site->size(),
 574     malloc_site->count(), malloc_site->flag());
 575 }
 576 
 577 void MemDetailDiffReporter::diff_malloc_site(const MallocSite* early,
 578   const MallocSite* current)  const {
 579   if (early->flag() != current->flag()) {
 580     // If malloc site type changed, treat it as deallocation of old type and
 581     // allocation of new type.
 582     old_malloc_site(early);
 583     new_malloc_site(current);
 584   } else {
 585     diff_malloc_site(current->call_stack(), current->size(), current->count(),
 586       early->size(), early->count(), early->flag());
 587   }
 588 }
 589 
 590 void MemDetailDiffReporter::diff_malloc_site(const NativeCallStack* stack, size_t current_size,
 591   size_t current_count, size_t early_size, size_t early_count, MEMFLAGS flags) const {
 592   outputStream* out = output();
 593 
 594   assert(stack != NULL, "NULL stack");
 595 
 596   if (diff_in_current_scale(current_size, early_size) == 0) {
 597       return;
 598   }
 599 
 600   stack->print_on(out);
 601   out->print("%28s (", " ");
 602   print_malloc_diff(current_size, current_count,
 603     early_size, early_count, flags);
 604 
 605   out->print_cr(")\n");
 606 }
 607 
 608 
 609 void MemDetailDiffReporter::new_virtual_memory_site(const VirtualMemoryAllocationSite* site) const {
 610   diff_virtual_memory_site(site->call_stack(), site->reserved(), site->committed(), 0, 0, site->flag());
 611 }
 612 
 613 void MemDetailDiffReporter::old_virtual_memory_site(const VirtualMemoryAllocationSite* site) const {
 614   diff_virtual_memory_site(site->call_stack(), 0, 0, site->reserved(), site->committed(), site->flag());
 615 }
 616 
 617 void MemDetailDiffReporter::diff_virtual_memory_site(const VirtualMemoryAllocationSite* early,
 618   const VirtualMemoryAllocationSite* current) const {
 619   assert(early->flag() == current->flag(), "Should be the same");
 620   diff_virtual_memory_site(current->call_stack(), current->reserved(), current->committed(),
 621     early->reserved(), early->committed(), current->flag());
 622 }
 623 
 624 void MemDetailDiffReporter::diff_virtual_memory_site(const NativeCallStack* stack, size_t current_reserved,
 625   size_t current_committed, size_t early_reserved, size_t early_committed, MEMFLAGS flag) const  {
 626   outputStream* out = output();
 627 
 628   // no change
 629   if (diff_in_current_scale(current_reserved, early_reserved) == 0 &&
 630       diff_in_current_scale(current_committed, early_committed) == 0) {
 631     return;
 632   }
 633 
 634   stack->print_on(out);
 635   out->print("%28s (mmap: ", " ");
 636   print_virtual_memory_diff(current_reserved, current_committed,
 637     early_reserved, early_committed);
 638 
 639   if (flag != mtNone) {
 640     out->print(" Type=%s", NMTUtil::flag_to_name(flag));
 641   }
 642 
 643   out->print_cr(")\n");
 644  }
 645 
< prev index next >