src/hotspot/share/services/memReporter.cpp
author zgu
Thu, 07 Feb 2019 14:29:17 -0500
changeset 53685 df83034c9275
parent 49980 57dd7b4ba338
child 53709 2b64ebacce93
permissions -rw-r--r--
8218558: NMT stack traces in output should show mt component for virtual memory allocations Reviewed-by: shade, stuefe, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
     1
/*
53685
df83034c9275 8218558: NMT stack traces in output should show mt component for virtual memory allocations
zgu
parents: 49980
diff changeset
     2
 * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
     4
 *
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
     7
 * published by the Free Software Foundation.
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
     8
 *
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    13
 * accompanied this code).
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    14
 *
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    18
 *
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    21
 * questions.
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    22
 *
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    23
 */
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    24
#include "precompiled.hpp"
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    25
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    26
#include "memory/allocation.hpp"
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    27
#include "services/mallocTracker.hpp"
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    28
#include "services/memReporter.hpp"
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    29
#include "services/virtualMemoryTracker.hpp"
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    30
#include "utilities/globalDefinitions.hpp"
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    31
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    32
size_t MemReporterBase::reserved_total(const MallocMemory* malloc, const VirtualMemory* vm) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    33
  return malloc->malloc_size() + malloc->arena_size() + vm->reserved();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    34
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    35
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    36
size_t MemReporterBase::committed_total(const MallocMemory* malloc, const VirtualMemory* vm) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    37
  return malloc->malloc_size() + malloc->arena_size() + vm->committed();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    38
}
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    39
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    40
void MemReporterBase::print_total(size_t reserved, size_t committed) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    41
  const char* scale = current_scale();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    42
  output()->print("reserved=" SIZE_FORMAT "%s, committed=" SIZE_FORMAT "%s",
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    43
    amount_in_current_scale(reserved), scale, amount_in_current_scale(committed), scale);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    44
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    45
46489
40abcea5a9d5 8139673: NMT stack traces in output should show mtcomponent
zgu
parents: 25946
diff changeset
    46
void MemReporterBase::print_malloc(size_t amount, size_t count, MEMFLAGS flag) const {
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    47
  const char* scale = current_scale();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    48
  outputStream* out = output();
46489
40abcea5a9d5 8139673: NMT stack traces in output should show mtcomponent
zgu
parents: 25946
diff changeset
    49
  if (flag != mtNone) {
40abcea5a9d5 8139673: NMT stack traces in output should show mtcomponent
zgu
parents: 25946
diff changeset
    50
    out->print("(malloc=" SIZE_FORMAT "%s type=%s",
40abcea5a9d5 8139673: NMT stack traces in output should show mtcomponent
zgu
parents: 25946
diff changeset
    51
      amount_in_current_scale(amount), scale, NMTUtil::flag_to_name(flag));
40abcea5a9d5 8139673: NMT stack traces in output should show mtcomponent
zgu
parents: 25946
diff changeset
    52
  } else {
40abcea5a9d5 8139673: NMT stack traces in output should show mtcomponent
zgu
parents: 25946
diff changeset
    53
    out->print("(malloc=" SIZE_FORMAT "%s",
40abcea5a9d5 8139673: NMT stack traces in output should show mtcomponent
zgu
parents: 25946
diff changeset
    54
      amount_in_current_scale(amount), scale);
40abcea5a9d5 8139673: NMT stack traces in output should show mtcomponent
zgu
parents: 25946
diff changeset
    55
  }
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    56
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    57
  if (count > 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    58
    out->print(" #" SIZE_FORMAT "", count);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    59
  }
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22234
diff changeset
    60
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    61
  out->print(")");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    62
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    63
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    64
void MemReporterBase::print_virtual_memory(size_t reserved, size_t committed) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    65
  const char* scale = current_scale();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    66
  output()->print("(mmap: reserved=" SIZE_FORMAT "%s, committed=" SIZE_FORMAT "%s)",
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    67
    amount_in_current_scale(reserved), scale, amount_in_current_scale(committed), scale);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    68
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    69
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    70
void MemReporterBase::print_malloc_line(size_t amount, size_t count) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    71
  output()->print("%28s", " ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    72
  print_malloc(amount, count);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    73
  output()->print_cr(" ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    74
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    75
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    76
void MemReporterBase::print_virtual_memory_line(size_t reserved, size_t committed) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    77
  output()->print("%28s", " ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    78
  print_virtual_memory(reserved, committed);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    79
  output()->print_cr(" ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    80
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    81
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    82
void MemReporterBase::print_arena_line(size_t amount, size_t count) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    83
  const char* scale = current_scale();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    84
  output()->print_cr("%27s (arena=" SIZE_FORMAT "%s #" SIZE_FORMAT ")", " ",
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    85
    amount_in_current_scale(amount), scale, count);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    86
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    87
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    88
void MemReporterBase::print_virtual_memory_region(const char* type, address base, size_t size) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    89
  const char* scale = current_scale();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    90
  output()->print("[" PTR_FORMAT " - " PTR_FORMAT "] %s " SIZE_FORMAT "%s",
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    91
    p2i(base), p2i(base + size), type, amount_in_current_scale(size), scale);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    92
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    93
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    94
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    95
void MemSummaryReporter::report() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    96
  const char* scale = current_scale();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    97
  outputStream* out = output();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    98
  size_t total_reserved_amount = _malloc_snapshot->total() +
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    99
    _vm_snapshot->total_reserved();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   100
  size_t total_committed_amount = _malloc_snapshot->total() +
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   101
    _vm_snapshot->total_committed();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   102
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   103
  // Overall total
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   104
  out->print_cr("\nNative Memory Tracking:\n");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   105
  out->print("Total: ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   106
  print_total(total_reserved_amount, total_committed_amount);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   107
  out->print("\n");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   108
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   109
  // Summary by memory type
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   110
  for (int index = 0; index < mt_number_of_types; index ++) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   111
    MEMFLAGS flag = NMTUtil::index_to_flag(index);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   112
    // thread stack is reported as part of thread category
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   113
    if (flag == mtThreadStack) continue;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   114
    MallocMemory* malloc_memory = _malloc_snapshot->by_type(flag);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   115
    VirtualMemory* virtual_memory = _vm_snapshot->by_type(flag);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   116
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   117
    report_summary_of_type(flag, malloc_memory, virtual_memory);
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13195
diff changeset
   118
  }
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13195
diff changeset
   119
}
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13195
diff changeset
   120
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   121
void MemSummaryReporter::report_summary_of_type(MEMFLAGS flag,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   122
  MallocMemory*  malloc_memory, VirtualMemory* virtual_memory) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   123
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   124
  size_t reserved_amount  = reserved_total (malloc_memory, virtual_memory);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   125
  size_t committed_amount = committed_total(malloc_memory, virtual_memory);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   126
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   127
  // Count thread's native stack in "Thread" category
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   128
  if (flag == mtThread) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   129
    const VirtualMemory* thread_stack_usage =
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   130
      (const VirtualMemory*)_vm_snapshot->by_type(mtThreadStack);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   131
    reserved_amount  += thread_stack_usage->reserved();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   132
    committed_amount += thread_stack_usage->committed();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   133
  } else if (flag == mtNMT) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   134
    // Count malloc headers in "NMT" category
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   135
    reserved_amount  += _malloc_snapshot->malloc_overhead()->size();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   136
    committed_amount += _malloc_snapshot->malloc_overhead()->size();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   137
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   138
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   139
  if (amount_in_current_scale(reserved_amount) > 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   140
    outputStream* out   = output();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   141
    const char*   scale = current_scale();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   142
    out->print("-%26s (", NMTUtil::flag_to_name(flag));
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   143
    print_total(reserved_amount, committed_amount);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   144
    out->print_cr(")");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   145
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   146
    if (flag == mtClass) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   147
      // report class count
48884
7e17b00dc245 8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents: 48874
diff changeset
   148
      out->print_cr("%27s (classes #" SIZE_FORMAT ")",
7e17b00dc245 8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents: 48874
diff changeset
   149
        " ", (_instance_class_count + _array_class_count));
7e17b00dc245 8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents: 48874
diff changeset
   150
      out->print_cr("%27s (  instance classes #" SIZE_FORMAT ", array classes #" SIZE_FORMAT ")",
7e17b00dc245 8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents: 48874
diff changeset
   151
        " ", _instance_class_count, _array_class_count);
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   152
    } else if (flag == mtThread) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   153
      // report thread count
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   154
      out->print_cr("%27s (thread #" SIZE_FORMAT ")", " ", _malloc_snapshot->thread_count());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   155
      const VirtualMemory* thread_stack_usage =
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   156
       _vm_snapshot->by_type(mtThreadStack);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   157
      out->print("%27s (stack: ", " ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   158
      print_total(thread_stack_usage->reserved(), thread_stack_usage->committed());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   159
      out->print_cr(")");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   160
    }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   161
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   162
     // report malloc'd memory
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   163
    if (amount_in_current_scale(malloc_memory->malloc_size()) > 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   164
      // We don't know how many arena chunks are in used, so don't report the count
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   165
      size_t count = (flag == mtChunk) ? 0 : malloc_memory->malloc_count();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   166
      print_malloc_line(malloc_memory->malloc_size(), count);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   167
    }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   168
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   169
    if (amount_in_current_scale(virtual_memory->reserved()) > 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   170
      print_virtual_memory_line(virtual_memory->reserved(), virtual_memory->committed());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   171
    }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   172
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   173
    if (amount_in_current_scale(malloc_memory->arena_size()) > 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   174
      print_arena_line(malloc_memory->arena_size(), malloc_memory->arena_count());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   175
    }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   176
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   177
    if (flag == mtNMT &&
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   178
      amount_in_current_scale(_malloc_snapshot->malloc_overhead()->size()) > 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   179
      out->print_cr("%27s (tracking overhead=" SIZE_FORMAT "%s)", " ",
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   180
        amount_in_current_scale(_malloc_snapshot->malloc_overhead()->size()), scale);
47553
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   181
    } else if (flag == mtClass) {
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   182
      // Metadata information
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   183
      report_metadata(Metaspace::NonClassType);
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   184
      if (Metaspace::using_class_space()) {
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   185
        report_metadata(Metaspace::ClassType);
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   186
      }
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   187
    }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   188
    out->print_cr(" ");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   189
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   190
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   191
47553
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   192
void MemSummaryReporter::report_metadata(Metaspace::MetadataType type) const {
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   193
  assert(type == Metaspace::NonClassType || type == Metaspace::ClassType,
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   194
    "Invalid metadata type");
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   195
  const char* name = (type == Metaspace::NonClassType) ?
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   196
    "Metadata:   " : "Class space:";
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   197
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   198
  outputStream* out = output();
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   199
  const char* scale = current_scale();
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49033
diff changeset
   200
  size_t committed   = MetaspaceUtils::committed_bytes(type);
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49033
diff changeset
   201
  size_t used = MetaspaceUtils::used_bytes(type);
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49033
diff changeset
   202
  size_t free = (MetaspaceUtils::capacity_bytes(type) - used)
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49033
diff changeset
   203
              + MetaspaceUtils::free_chunks_total_bytes(type)
49980
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents: 49389
diff changeset
   204
              + MetaspaceUtils::free_in_vs_bytes(type);
47553
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   205
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   206
  assert(committed >= used + free, "Sanity");
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   207
  size_t waste = committed - (used + free);
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   208
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   209
  out->print_cr("%27s (  %s)", " ", name);
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   210
  out->print("%27s (    ", " ");
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49033
diff changeset
   211
  print_total(MetaspaceUtils::reserved_bytes(type), committed);
47553
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   212
  out->print_cr(")");
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   213
  out->print_cr("%27s (    used=" SIZE_FORMAT "%s)", " ", amount_in_current_scale(used), scale);
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   214
  out->print_cr("%27s (    free=" SIZE_FORMAT "%s)", " ", amount_in_current_scale(free), scale);
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   215
  out->print_cr("%27s (    waste=" SIZE_FORMAT "%s =%2.2f%%)", " ", amount_in_current_scale(waste),
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   216
    scale, ((float)waste * 100)/committed);
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   217
}
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   218
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   219
void MemDetailReporter::report_detail() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   220
  // Start detail report
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   221
  outputStream* out = output();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   222
  out->print_cr("Details:\n");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   223
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   224
  report_malloc_sites();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   225
  report_virtual_memory_allocation_sites();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   226
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   227
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   228
void MemDetailReporter::report_malloc_sites() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   229
  MallocSiteIterator         malloc_itr = _baseline.malloc_sites(MemBaseline::by_size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   230
  if (malloc_itr.is_empty()) return;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   231
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   232
  outputStream* out = output();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   233
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   234
  const MallocSite* malloc_site;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   235
  while ((malloc_site = malloc_itr.next()) != NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   236
    // Don't report if size is too small
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   237
    if (amount_in_current_scale(malloc_site->size()) == 0)
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   238
      continue;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   239
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   240
    const NativeCallStack* stack = malloc_site->call_stack();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   241
    stack->print_on(out);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   242
    out->print("%29s", " ");
53685
df83034c9275 8218558: NMT stack traces in output should show mt component for virtual memory allocations
zgu
parents: 49980
diff changeset
   243
    MEMFLAGS flag = malloc_site->flag();
46489
40abcea5a9d5 8139673: NMT stack traces in output should show mtcomponent
zgu
parents: 25946
diff changeset
   244
    assert((flag >= 0 && flag < (int)mt_number_of_types) && flag != mtNone,
40abcea5a9d5 8139673: NMT stack traces in output should show mtcomponent
zgu
parents: 25946
diff changeset
   245
      "Must have a valid memory type");
40abcea5a9d5 8139673: NMT stack traces in output should show mtcomponent
zgu
parents: 25946
diff changeset
   246
    print_malloc(malloc_site->size(), malloc_site->count(),flag);
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   247
    out->print_cr("\n");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   248
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   249
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   250
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   251
void MemDetailReporter::report_virtual_memory_allocation_sites()  {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   252
  VirtualMemorySiteIterator  virtual_memory_itr =
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   253
    _baseline.virtual_memory_sites(MemBaseline::by_size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   254
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   255
  if (virtual_memory_itr.is_empty()) return;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   256
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   257
  outputStream* out = output();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   258
  const VirtualMemoryAllocationSite*  virtual_memory_site;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   259
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   260
  while ((virtual_memory_site = virtual_memory_itr.next()) != NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   261
    // Don't report if size is too small
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   262
    if (amount_in_current_scale(virtual_memory_site->reserved()) == 0)
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   263
      continue;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   264
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   265
    const NativeCallStack* stack = virtual_memory_site->call_stack();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   266
    stack->print_on(out);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   267
    out->print("%28s (", " ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   268
    print_total(virtual_memory_site->reserved(), virtual_memory_site->committed());
53685
df83034c9275 8218558: NMT stack traces in output should show mt component for virtual memory allocations
zgu
parents: 49980
diff changeset
   269
    MEMFLAGS flag = virtual_memory_site->flag();
df83034c9275 8218558: NMT stack traces in output should show mt component for virtual memory allocations
zgu
parents: 49980
diff changeset
   270
    if (flag != mtNone) {
df83034c9275 8218558: NMT stack traces in output should show mt component for virtual memory allocations
zgu
parents: 49980
diff changeset
   271
      out->print(" Type=%s", NMTUtil::flag_to_name(flag));
df83034c9275 8218558: NMT stack traces in output should show mt component for virtual memory allocations
zgu
parents: 49980
diff changeset
   272
    }
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   273
    out->print_cr(")\n");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   274
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   275
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   276
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   277
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   278
void MemDetailReporter::report_virtual_memory_map() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   279
  // Virtual memory map always in base address order
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   280
  VirtualMemoryAllocationIterator itr = _baseline.virtual_memory_allocations();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   281
  const ReservedMemoryRegion* rgn;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   282
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   283
  output()->print_cr("Virtual memory map:");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   284
  while ((rgn = itr.next()) != NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   285
    report_virtual_memory_region(rgn);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   286
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   287
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   288
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   289
void MemDetailReporter::report_virtual_memory_region(const ReservedMemoryRegion* reserved_rgn) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   290
  assert(reserved_rgn != NULL, "NULL pointer");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   291
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   292
  // Don't report if size is too small
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   293
  if (amount_in_current_scale(reserved_rgn->size()) == 0) return;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   294
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   295
  outputStream* out = output();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   296
  const char* scale = current_scale();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   297
  const NativeCallStack*  stack = reserved_rgn->call_stack();
49033
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48884
diff changeset
   298
  bool all_committed = reserved_rgn->size() == reserved_rgn->committed_size();
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   299
  const char* region_type = (all_committed ? "reserved and committed" : "reserved");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   300
  out->print_cr(" ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   301
  print_virtual_memory_region(region_type, reserved_rgn->base(), reserved_rgn->size());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   302
  out->print(" for %s", NMTUtil::flag_to_name(reserved_rgn->flag()));
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   303
  if (stack->is_empty()) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   304
    out->print_cr(" ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   305
  } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   306
    out->print_cr(" from");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   307
    stack->print_on(out, 4);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   308
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   309
49033
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48884
diff changeset
   310
  if (all_committed) {
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48884
diff changeset
   311
    CommittedRegionIterator itr = reserved_rgn->iterate_committed_regions();
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48884
diff changeset
   312
    const CommittedMemoryRegion* committed_rgn = itr.next();
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48884
diff changeset
   313
    if (committed_rgn->size() == reserved_rgn->size() && committed_rgn->call_stack()->equals(*stack)) {
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48884
diff changeset
   314
      // One region spanning the entire reserved region, with the same stack trace.
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48884
diff changeset
   315
      // Don't print this regions because the "reserved and committed" line above
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48884
diff changeset
   316
      // already indicates that the region is comitted.
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48884
diff changeset
   317
      assert(itr.next() == NULL, "Unexpectedly more than one regions");
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48884
diff changeset
   318
      return;
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48884
diff changeset
   319
    }
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48884
diff changeset
   320
  }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   321
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   322
  CommittedRegionIterator itr = reserved_rgn->iterate_committed_regions();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   323
  const CommittedMemoryRegion* committed_rgn;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   324
  while ((committed_rgn = itr.next()) != NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   325
    // Don't report if size is too small
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   326
    if (amount_in_current_scale(committed_rgn->size()) == 0) continue;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   327
    stack = committed_rgn->call_stack();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   328
    out->print("\n\t");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   329
    print_virtual_memory_region("committed", committed_rgn->base(), committed_rgn->size());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   330
    if (stack->is_empty()) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   331
      out->print_cr(" ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   332
    } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   333
      out->print_cr(" from");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   334
      stack->print_on(out, 12);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   335
    }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   336
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   337
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   338
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   339
void MemSummaryDiffReporter::report_diff() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   340
  const char* scale = current_scale();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   341
  outputStream* out = output();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   342
  out->print_cr("\nNative Memory Tracking:\n");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   343
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   344
  // Overall diff
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   345
  out->print("Total: ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   346
  print_virtual_memory_diff(_current_baseline.total_reserved_memory(),
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   347
    _current_baseline.total_committed_memory(), _early_baseline.total_reserved_memory(),
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   348
    _early_baseline.total_committed_memory());
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13195
diff changeset
   349
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   350
  out->print_cr("\n");
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13195
diff changeset
   351
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   352
  // Summary diff by memory type
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   353
  for (int index = 0; index < mt_number_of_types; index ++) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   354
    MEMFLAGS flag = NMTUtil::index_to_flag(index);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   355
    // thread stack is reported as part of thread category
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   356
    if (flag == mtThreadStack) continue;
47553
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   357
    diff_summary_of_type(flag,
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   358
      _early_baseline.malloc_memory(flag),
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   359
      _early_baseline.virtual_memory(flag),
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   360
      _early_baseline.metaspace_snapshot(),
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   361
      _current_baseline.malloc_memory(flag),
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   362
      _current_baseline.virtual_memory(flag),
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   363
      _current_baseline.metaspace_snapshot());
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13195
diff changeset
   364
  }
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13195
diff changeset
   365
}
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13195
diff changeset
   366
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   367
void MemSummaryDiffReporter::print_malloc_diff(size_t current_amount, size_t current_count,
46711
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 46489
diff changeset
   368
    size_t early_amount, size_t early_count, MEMFLAGS flags) const {
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   369
  const char* scale = current_scale();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   370
  outputStream* out = output();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   371
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   372
  out->print("malloc=" SIZE_FORMAT "%s", amount_in_current_scale(current_amount), scale);
46711
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 46489
diff changeset
   373
  // Report type only if it is valid
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 46489
diff changeset
   374
  if (flags != mtNone) {
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 46489
diff changeset
   375
    out->print(" type=%s", NMTUtil::flag_to_name(flags));
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 46489
diff changeset
   376
  }
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 46489
diff changeset
   377
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   378
  long amount_diff = diff_in_current_scale(current_amount, early_amount);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   379
  if (amount_diff != 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   380
    out->print(" %+ld%s", amount_diff, scale);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   381
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   382
  if (current_count > 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   383
    out->print(" #" SIZE_FORMAT "", current_count);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   384
    if (current_count != early_count) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   385
      out->print(" %+d", (int)(current_count - early_count));
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   386
    }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   387
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   388
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   389
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   390
void MemSummaryDiffReporter::print_arena_diff(size_t current_amount, size_t current_count,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   391
  size_t early_amount, size_t early_count) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   392
  const char* scale = current_scale();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   393
  outputStream* out = output();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   394
  out->print("arena=" SIZE_FORMAT "%s", amount_in_current_scale(current_amount), scale);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   395
  if (diff_in_current_scale(current_amount, early_amount) != 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   396
    out->print(" %+ld", diff_in_current_scale(current_amount, early_amount));
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   397
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   398
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   399
  out->print(" #" SIZE_FORMAT "", current_count);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   400
  if (current_count != early_count) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   401
    out->print(" %+d", (int)(current_count - early_count));
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   402
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   403
}
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   404
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   405
void MemSummaryDiffReporter::print_virtual_memory_diff(size_t current_reserved, size_t current_committed,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   406
    size_t early_reserved, size_t early_committed) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   407
  const char* scale = current_scale();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   408
  outputStream* out = output();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   409
  out->print("reserved=" SIZE_FORMAT "%s", amount_in_current_scale(current_reserved), scale);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   410
  long reserved_diff = diff_in_current_scale(current_reserved, early_reserved);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   411
  if (reserved_diff != 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   412
    out->print(" %+ld%s", reserved_diff, scale);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   413
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   414
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   415
  out->print(", committed=" SIZE_FORMAT "%s", amount_in_current_scale(current_committed), scale);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   416
  long committed_diff = diff_in_current_scale(current_committed, early_committed);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   417
  if (committed_diff != 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   418
    out->print(" %+ld%s", committed_diff, scale);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   419
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   420
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   421
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   422
47553
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   423
void MemSummaryDiffReporter::diff_summary_of_type(MEMFLAGS flag,
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   424
  const MallocMemory* early_malloc, const VirtualMemory* early_vm,
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   425
  const MetaspaceSnapshot* early_ms,
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   426
  const MallocMemory* current_malloc, const VirtualMemory* current_vm,
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   427
  const MetaspaceSnapshot* current_ms) const {
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   428
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   429
  outputStream* out = output();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   430
  const char* scale = current_scale();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   431
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   432
  // Total reserved and committed memory in current baseline
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   433
  size_t current_reserved_amount  = reserved_total (current_malloc, current_vm);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   434
  size_t current_committed_amount = committed_total(current_malloc, current_vm);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   435
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   436
  // Total reserved and committed memory in early baseline
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   437
  size_t early_reserved_amount  = reserved_total(early_malloc, early_vm);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   438
  size_t early_committed_amount = committed_total(early_malloc, early_vm);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   439
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   440
  // Adjust virtual memory total
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   441
  if (flag == mtThread) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   442
    const VirtualMemory* early_thread_stack_usage =
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   443
      _early_baseline.virtual_memory(mtThreadStack);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   444
    const VirtualMemory* current_thread_stack_usage =
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   445
      _current_baseline.virtual_memory(mtThreadStack);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   446
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   447
    early_reserved_amount  += early_thread_stack_usage->reserved();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   448
    early_committed_amount += early_thread_stack_usage->committed();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   449
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   450
    current_reserved_amount  += current_thread_stack_usage->reserved();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   451
    current_committed_amount += current_thread_stack_usage->committed();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   452
  } else if (flag == mtNMT) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   453
    early_reserved_amount  += _early_baseline.malloc_tracking_overhead();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   454
    early_committed_amount += _early_baseline.malloc_tracking_overhead();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   455
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   456
    current_reserved_amount  += _current_baseline.malloc_tracking_overhead();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   457
    current_committed_amount += _current_baseline.malloc_tracking_overhead();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   458
  }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   459
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   460
  if (amount_in_current_scale(current_reserved_amount) > 0 ||
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   461
      diff_in_current_scale(current_reserved_amount, early_reserved_amount) != 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   462
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   463
    // print summary line
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   464
    out->print("-%26s (", NMTUtil::flag_to_name(flag));
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   465
    print_virtual_memory_diff(current_reserved_amount, current_committed_amount,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   466
      early_reserved_amount, early_committed_amount);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   467
    out->print_cr(")");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   468
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   469
    // detail lines
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   470
    if (flag == mtClass) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   471
      // report class count
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   472
      out->print("%27s (classes #" SIZE_FORMAT "", " ", _current_baseline.class_count());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   473
      int class_count_diff = (int)(_current_baseline.class_count() -
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   474
        _early_baseline.class_count());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   475
      if (_current_baseline.class_count() != _early_baseline.class_count()) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   476
        out->print(" %+d", (int)(_current_baseline.class_count() - _early_baseline.class_count()));
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   477
      }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   478
      out->print_cr(")");
48884
7e17b00dc245 8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents: 48874
diff changeset
   479
7e17b00dc245 8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents: 48874
diff changeset
   480
      out->print("%27s (  instance classes #" SIZE_FORMAT, " ", _current_baseline.instance_class_count());
7e17b00dc245 8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents: 48874
diff changeset
   481
      if (_current_baseline.instance_class_count() != _early_baseline.instance_class_count()) {
7e17b00dc245 8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents: 48874
diff changeset
   482
        out->print(" %+d", (int)(_current_baseline.instance_class_count() - _early_baseline.instance_class_count()));
7e17b00dc245 8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents: 48874
diff changeset
   483
      }
7e17b00dc245 8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents: 48874
diff changeset
   484
      out->print(", array classes #" SIZE_FORMAT, _current_baseline.array_class_count());
7e17b00dc245 8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents: 48874
diff changeset
   485
      if (_current_baseline.array_class_count() != _early_baseline.array_class_count()) {
7e17b00dc245 8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents: 48874
diff changeset
   486
        out->print(" %+d", (int)(_current_baseline.array_class_count() - _early_baseline.array_class_count()));
7e17b00dc245 8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents: 48874
diff changeset
   487
      }
7e17b00dc245 8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents: 48874
diff changeset
   488
      out->print_cr(")");
7e17b00dc245 8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents: 48874
diff changeset
   489
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   490
    } else if (flag == mtThread) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   491
      // report thread count
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   492
      out->print("%27s (thread #" SIZE_FORMAT "", " ", _current_baseline.thread_count());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   493
      int thread_count_diff = (int)(_current_baseline.thread_count() -
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   494
          _early_baseline.thread_count());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   495
      if (thread_count_diff != 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   496
        out->print(" %+d", thread_count_diff);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   497
      }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   498
      out->print_cr(")");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   499
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   500
      // report thread stack
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   501
      const VirtualMemory* current_thread_stack =
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   502
          _current_baseline.virtual_memory(mtThreadStack);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   503
      const VirtualMemory* early_thread_stack =
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   504
        _early_baseline.virtual_memory(mtThreadStack);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   505
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   506
      out->print("%27s (stack: ", " ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   507
      print_virtual_memory_diff(current_thread_stack->reserved(), current_thread_stack->committed(),
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   508
        early_thread_stack->reserved(), early_thread_stack->committed());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   509
      out->print_cr(")");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   510
    }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   511
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   512
    // Report malloc'd memory
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   513
    size_t current_malloc_amount = current_malloc->malloc_size();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   514
    size_t early_malloc_amount   = early_malloc->malloc_size();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   515
    if (amount_in_current_scale(current_malloc_amount) > 0 ||
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   516
        diff_in_current_scale(current_malloc_amount, early_malloc_amount) != 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   517
      out->print("%28s(", " ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   518
      print_malloc_diff(current_malloc_amount, (flag == mtChunk) ? 0 : current_malloc->malloc_count(),
46711
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 46489
diff changeset
   519
        early_malloc_amount, early_malloc->malloc_count(), mtNone);
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   520
      out->print_cr(")");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   521
    }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   522
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   523
    // Report virtual memory
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   524
    if (amount_in_current_scale(current_vm->reserved()) > 0 ||
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   525
        diff_in_current_scale(current_vm->reserved(), early_vm->reserved()) != 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   526
      out->print("%27s (mmap: ", " ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   527
      print_virtual_memory_diff(current_vm->reserved(), current_vm->committed(),
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   528
        early_vm->reserved(), early_vm->committed());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   529
      out->print_cr(")");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   530
    }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   531
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   532
    // Report arena memory
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   533
    if (amount_in_current_scale(current_malloc->arena_size()) > 0 ||
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   534
        diff_in_current_scale(current_malloc->arena_size(), early_malloc->arena_size()) != 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   535
      out->print("%28s(", " ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   536
      print_arena_diff(current_malloc->arena_size(), current_malloc->arena_count(),
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   537
        early_malloc->arena_size(), early_malloc->arena_count());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   538
      out->print_cr(")");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   539
    }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   540
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   541
    // Report native memory tracking overhead
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   542
    if (flag == mtNMT) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   543
      size_t current_tracking_overhead = amount_in_current_scale(_current_baseline.malloc_tracking_overhead());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   544
      size_t early_tracking_overhead   = amount_in_current_scale(_early_baseline.malloc_tracking_overhead());
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   545
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   546
      out->print("%27s (tracking overhead=" SIZE_FORMAT "%s", " ",
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   547
        amount_in_current_scale(_current_baseline.malloc_tracking_overhead()), scale);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   548
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   549
      long overhead_diff = diff_in_current_scale(_current_baseline.malloc_tracking_overhead(),
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   550
           _early_baseline.malloc_tracking_overhead());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   551
      if (overhead_diff != 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   552
        out->print(" %+ld%s", overhead_diff, scale);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   553
      }
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   554
      out->print_cr(")");
47553
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   555
    } else if (flag == mtClass) {
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   556
      assert(current_ms != NULL && early_ms != NULL, "Sanity");
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   557
      print_metaspace_diff(current_ms, early_ms);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   558
    }
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   559
    out->print_cr(" ");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   560
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   561
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   562
47553
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   563
void MemSummaryDiffReporter::print_metaspace_diff(const MetaspaceSnapshot* current_ms,
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   564
                                                  const MetaspaceSnapshot* early_ms) const {
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   565
  print_metaspace_diff(Metaspace::NonClassType, current_ms, early_ms);
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   566
  if (Metaspace::using_class_space()) {
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   567
    print_metaspace_diff(Metaspace::ClassType, current_ms, early_ms);
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   568
  }
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   569
}
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   570
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   571
void MemSummaryDiffReporter::print_metaspace_diff(Metaspace::MetadataType type,
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   572
                                                  const MetaspaceSnapshot* current_ms,
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   573
                                                  const MetaspaceSnapshot* early_ms) const {
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   574
  const char* name = (type == Metaspace::NonClassType) ?
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   575
    "Metadata:   " : "Class space:";
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   576
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   577
  outputStream* out = output();
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   578
  const char* scale = current_scale();
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   579
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   580
  out->print_cr("%27s (  %s)", " ", name);
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   581
  out->print("%27s (    ", " ");
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   582
  print_virtual_memory_diff(current_ms->reserved_in_bytes(type),
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   583
                            current_ms->committed_in_bytes(type),
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   584
                            early_ms->reserved_in_bytes(type),
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   585
                            early_ms->committed_in_bytes(type));
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   586
  out->print_cr(")");
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   587
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   588
  long diff_used = diff_in_current_scale(current_ms->used_in_bytes(type),
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   589
                                         early_ms->used_in_bytes(type));
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   590
  long diff_free = diff_in_current_scale(current_ms->free_in_bytes(type),
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   591
                                         early_ms->free_in_bytes(type));
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   592
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   593
  size_t current_waste = current_ms->committed_in_bytes(type)
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   594
    - (current_ms->used_in_bytes(type) + current_ms->free_in_bytes(type));
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   595
  size_t early_waste = early_ms->committed_in_bytes(type)
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   596
    - (early_ms->used_in_bytes(type) + early_ms->free_in_bytes(type));
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   597
  long diff_waste = diff_in_current_scale(current_waste, early_waste);
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   598
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   599
  // Diff used
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   600
  out->print("%27s (    used=" SIZE_FORMAT "%s", " ",
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   601
    amount_in_current_scale(current_ms->used_in_bytes(type)), scale);
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   602
  if (diff_used != 0) {
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   603
    out->print(" %+ld%s", diff_used, scale);
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   604
  }
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   605
  out->print_cr(")");
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   606
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   607
  // Diff free
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   608
  out->print("%27s (    free=" SIZE_FORMAT "%s", " ",
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   609
    amount_in_current_scale(current_ms->free_in_bytes(type)), scale);
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   610
  if (diff_free != 0) {
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   611
    out->print(" %+ld%s", diff_free, scale);
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   612
  }
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   613
  out->print_cr(")");
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   614
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   615
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   616
  // Diff waste
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   617
  out->print("%27s (    waste=" SIZE_FORMAT "%s =%2.2f%%", " ",
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   618
    amount_in_current_scale(current_waste), scale,
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   619
    ((float)current_waste * 100) / current_ms->committed_in_bytes(type));
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   620
  if (diff_waste != 0) {
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   621
    out->print(" %+ld%s", diff_waste, scale);
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   622
  }
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   623
  out->print_cr(")");
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   624
}
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   625
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   626
void MemDetailDiffReporter::report_diff() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   627
  MemSummaryDiffReporter::report_diff();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   628
  diff_malloc_sites();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   629
  diff_virtual_memory_sites();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   630
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   631
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   632
void MemDetailDiffReporter::diff_malloc_sites() const {
46711
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 46489
diff changeset
   633
  MallocSiteIterator early_itr = _early_baseline.malloc_sites(MemBaseline::by_site_and_type);
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 46489
diff changeset
   634
  MallocSiteIterator current_itr = _current_baseline.malloc_sites(MemBaseline::by_site_and_type);
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   635
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   636
  const MallocSite* early_site   = early_itr.next();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   637
  const MallocSite* current_site = current_itr.next();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   638
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   639
  while (early_site != NULL || current_site != NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   640
    if (early_site == NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   641
      new_malloc_site(current_site);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   642
      current_site = current_itr.next();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   643
    } else if (current_site == NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   644
      old_malloc_site(early_site);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   645
      early_site = early_itr.next();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   646
    } else {
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   647
      int compVal = current_site->call_stack()->compare(*early_site->call_stack());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   648
      if (compVal < 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   649
        new_malloc_site(current_site);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   650
        current_site = current_itr.next();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   651
      } else if (compVal > 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   652
        old_malloc_site(early_site);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   653
        early_site = early_itr.next();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   654
      } else {
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   655
        diff_malloc_site(early_site, current_site);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   656
        early_site   = early_itr.next();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   657
        current_site = current_itr.next();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   658
      }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   659
    }
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   660
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   661
}
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   662
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   663
void MemDetailDiffReporter::diff_virtual_memory_sites() const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   664
  VirtualMemorySiteIterator early_itr = _early_baseline.virtual_memory_sites(MemBaseline::by_site);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   665
  VirtualMemorySiteIterator current_itr = _current_baseline.virtual_memory_sites(MemBaseline::by_site);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   666
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   667
  const VirtualMemoryAllocationSite* early_site   = early_itr.next();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   668
  const VirtualMemoryAllocationSite* current_site = current_itr.next();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   669
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   670
  while (early_site != NULL || current_site != NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   671
    if (early_site == NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   672
      new_virtual_memory_site(current_site);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   673
      current_site = current_itr.next();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   674
    } else if (current_site == NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   675
      old_virtual_memory_site(early_site);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   676
      early_site = early_itr.next();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   677
    } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   678
      int compVal = current_site->call_stack()->compare(*early_site->call_stack());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   679
      if (compVal < 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   680
        new_virtual_memory_site(current_site);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   681
        current_site = current_itr.next();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   682
      } else if (compVal > 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   683
        old_virtual_memory_site(early_site);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   684
        early_site = early_itr.next();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   685
      } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   686
        diff_virtual_memory_site(early_site, current_site);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   687
        early_site   = early_itr.next();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   688
        current_site = current_itr.next();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   689
      }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   690
    }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   691
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   692
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   693
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   694
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   695
void MemDetailDiffReporter::new_malloc_site(const MallocSite* malloc_site) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   696
  diff_malloc_site(malloc_site->call_stack(), malloc_site->size(), malloc_site->count(),
53685
df83034c9275 8218558: NMT stack traces in output should show mt component for virtual memory allocations
zgu
parents: 49980
diff changeset
   697
    0, 0, malloc_site->flag());
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   698
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   699
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   700
void MemDetailDiffReporter::old_malloc_site(const MallocSite* malloc_site) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   701
  diff_malloc_site(malloc_site->call_stack(), 0, 0, malloc_site->size(),
53685
df83034c9275 8218558: NMT stack traces in output should show mt component for virtual memory allocations
zgu
parents: 49980
diff changeset
   702
    malloc_site->count(), malloc_site->flag());
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   703
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   704
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   705
void MemDetailDiffReporter::diff_malloc_site(const MallocSite* early,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   706
  const MallocSite* current)  const {
53685
df83034c9275 8218558: NMT stack traces in output should show mt component for virtual memory allocations
zgu
parents: 49980
diff changeset
   707
  assert(early->flag() == current->flag(), "Must be the same memory type");
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   708
  diff_malloc_site(current->call_stack(), current->size(), current->count(),
53685
df83034c9275 8218558: NMT stack traces in output should show mt component for virtual memory allocations
zgu
parents: 49980
diff changeset
   709
    early->size(), early->count(), early->flag());
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   710
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   711
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   712
void MemDetailDiffReporter::diff_malloc_site(const NativeCallStack* stack, size_t current_size,
46711
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 46489
diff changeset
   713
  size_t current_count, size_t early_size, size_t early_count, MEMFLAGS flags) const {
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   714
  outputStream* out = output();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   715
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   716
  assert(stack != NULL, "NULL stack");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   717
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   718
  if (diff_in_current_scale(current_size, early_size) == 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   719
      return;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   720
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   721
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   722
  stack->print_on(out);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   723
  out->print("%28s (", " ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   724
  print_malloc_diff(current_size, current_count,
46711
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 46489
diff changeset
   725
    early_size, early_count, flags);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   726
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   727
  out->print_cr(")\n");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   728
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   729
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   730
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   731
void MemDetailDiffReporter::new_virtual_memory_site(const VirtualMemoryAllocationSite* site) const {
53685
df83034c9275 8218558: NMT stack traces in output should show mt component for virtual memory allocations
zgu
parents: 49980
diff changeset
   732
  diff_virtual_memory_site(site->call_stack(), site->reserved(), site->committed(), 0, 0, site->flag());
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   733
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   734
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   735
void MemDetailDiffReporter::old_virtual_memory_site(const VirtualMemoryAllocationSite* site) const {
53685
df83034c9275 8218558: NMT stack traces in output should show mt component for virtual memory allocations
zgu
parents: 49980
diff changeset
   736
  diff_virtual_memory_site(site->call_stack(), 0, 0, site->reserved(), site->committed(), site->flag());
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   737
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   738
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   739
void MemDetailDiffReporter::diff_virtual_memory_site(const VirtualMemoryAllocationSite* early,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   740
  const VirtualMemoryAllocationSite* current) const {
53685
df83034c9275 8218558: NMT stack traces in output should show mt component for virtual memory allocations
zgu
parents: 49980
diff changeset
   741
  assert(early->flag() == current->flag(), "Should be the same");
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   742
  diff_virtual_memory_site(current->call_stack(), current->reserved(), current->committed(),
53685
df83034c9275 8218558: NMT stack traces in output should show mt component for virtual memory allocations
zgu
parents: 49980
diff changeset
   743
    early->reserved(), early->committed(), current->flag());
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   744
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   745
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   746
void MemDetailDiffReporter::diff_virtual_memory_site(const NativeCallStack* stack, size_t current_reserved,
53685
df83034c9275 8218558: NMT stack traces in output should show mt component for virtual memory allocations
zgu
parents: 49980
diff changeset
   747
  size_t current_committed, size_t early_reserved, size_t early_committed, MEMFLAGS flag) const  {
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   748
  outputStream* out = output();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   749
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   750
  // no change
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   751
  if (diff_in_current_scale(current_reserved, early_reserved) == 0 &&
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   752
      diff_in_current_scale(current_committed, early_committed) == 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   753
    return;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   754
  }
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   755
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   756
  stack->print_on(out);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   757
  out->print("%28s (mmap: ", " ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   758
  print_virtual_memory_diff(current_reserved, current_committed,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   759
    early_reserved, early_committed);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   760
53685
df83034c9275 8218558: NMT stack traces in output should show mt component for virtual memory allocations
zgu
parents: 49980
diff changeset
   761
  if (flag != mtNone) {
df83034c9275 8218558: NMT stack traces in output should show mt component for virtual memory allocations
zgu
parents: 49980
diff changeset
   762
    out->print(" Type=%s", NMTUtil::flag_to_name(flag));
df83034c9275 8218558: NMT stack traces in output should show mt component for virtual memory allocations
zgu
parents: 49980
diff changeset
   763
  }
df83034c9275 8218558: NMT stack traces in output should show mt component for virtual memory allocations
zgu
parents: 49980
diff changeset
   764
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   765
  out->print_cr(")\n");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   766
 }