hotspot/src/share/vm/services/memReporter.cpp
author zgu
Thu, 07 Aug 2014 12:18:58 -0700
changeset 25946 1572c9f03fb9
parent 24424 2658d7834c6e
child 46489 40abcea5a9d5
permissions -rw-r--r--
8046598: Scalable Native memory tracking development Summary: Enhance scalability of native memory tracking Reviewed-by: coleenp, ctornqvi, gtriantafill
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
     1
/*
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22234
diff changeset
     2
 * Copyright (c) 2012, 2014, 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
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    46
void MemReporterBase::print_malloc(size_t amount, size_t count) const {
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();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    49
  out->print("(malloc=" SIZE_FORMAT "%s",
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    50
    amount_in_current_scale(amount), scale);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    51
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    52
  if (count > 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    53
    out->print(" #" SIZE_FORMAT "", count);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    54
  }
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22234
diff changeset
    55
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    56
  out->print(")");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    57
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    58
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    59
void MemReporterBase::print_virtual_memory(size_t reserved, size_t committed) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    60
  const char* scale = current_scale();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    61
  output()->print("(mmap: reserved=" SIZE_FORMAT "%s, committed=" SIZE_FORMAT "%s)",
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    62
    amount_in_current_scale(reserved), scale, amount_in_current_scale(committed), scale);
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
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    65
void MemReporterBase::print_malloc_line(size_t amount, size_t count) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    66
  output()->print("%28s", " ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    67
  print_malloc(amount, count);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    68
  output()->print_cr(" ");
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
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    71
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
    72
  output()->print("%28s", " ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    73
  print_virtual_memory(reserved, committed);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    74
  output()->print_cr(" ");
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
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    77
void MemReporterBase::print_arena_line(size_t amount, size_t count) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    78
  const char* scale = current_scale();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    79
  output()->print_cr("%27s (arena=" SIZE_FORMAT "%s #" SIZE_FORMAT ")", " ",
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    80
    amount_in_current_scale(amount), scale, count);
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
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    83
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
    84
  const char* scale = current_scale();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    85
  output()->print("[" PTR_FORMAT " - " PTR_FORMAT "] %s " SIZE_FORMAT "%s",
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    86
    p2i(base), p2i(base + size), type, amount_in_current_scale(size), scale);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    87
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    88
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    89
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    90
void MemSummaryReporter::report() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    91
  const char* scale = current_scale();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    92
  outputStream* out = output();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    93
  size_t total_reserved_amount = _malloc_snapshot->total() +
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    94
    _vm_snapshot->total_reserved();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    95
  size_t total_committed_amount = _malloc_snapshot->total() +
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    96
    _vm_snapshot->total_committed();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    97
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    98
  // Overall total
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
    99
  out->print_cr("\nNative Memory Tracking:\n");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   100
  out->print("Total: ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   101
  print_total(total_reserved_amount, total_committed_amount);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   102
  out->print("\n");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   103
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   104
  // Summary by memory type
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   105
  for (int index = 0; index < mt_number_of_types; index ++) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   106
    MEMFLAGS flag = NMTUtil::index_to_flag(index);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   107
    // thread stack is reported as part of thread category
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   108
    if (flag == mtThreadStack) continue;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   109
    MallocMemory* malloc_memory = _malloc_snapshot->by_type(flag);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   110
    VirtualMemory* virtual_memory = _vm_snapshot->by_type(flag);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   111
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   112
    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
   113
  }
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13195
diff changeset
   114
}
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13195
diff changeset
   115
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   116
void MemSummaryReporter::report_summary_of_type(MEMFLAGS flag,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   117
  MallocMemory*  malloc_memory, VirtualMemory* virtual_memory) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   118
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   119
  size_t reserved_amount  = reserved_total (malloc_memory, virtual_memory);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   120
  size_t committed_amount = committed_total(malloc_memory, virtual_memory);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   121
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   122
  // Count thread's native stack in "Thread" category
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   123
  if (flag == mtThread) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   124
    const VirtualMemory* thread_stack_usage =
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   125
      (const VirtualMemory*)_vm_snapshot->by_type(mtThreadStack);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   126
    reserved_amount  += thread_stack_usage->reserved();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   127
    committed_amount += thread_stack_usage->committed();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   128
  } else if (flag == mtNMT) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   129
    // Count malloc headers in "NMT" category
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   130
    reserved_amount  += _malloc_snapshot->malloc_overhead()->size();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   131
    committed_amount += _malloc_snapshot->malloc_overhead()->size();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   132
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   133
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   134
  if (amount_in_current_scale(reserved_amount) > 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   135
    outputStream* out   = output();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   136
    const char*   scale = current_scale();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   137
    out->print("-%26s (", NMTUtil::flag_to_name(flag));
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   138
    print_total(reserved_amount, committed_amount);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   139
    out->print_cr(")");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   140
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   141
    if (flag == mtClass) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   142
      // report class count
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   143
      out->print_cr("%27s (classes #" SIZE_FORMAT ")", " ", _class_count);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   144
    } else if (flag == mtThread) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   145
      // report thread count
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   146
      out->print_cr("%27s (thread #" SIZE_FORMAT ")", " ", _malloc_snapshot->thread_count());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   147
      const VirtualMemory* thread_stack_usage =
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   148
       _vm_snapshot->by_type(mtThreadStack);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   149
      out->print("%27s (stack: ", " ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   150
      print_total(thread_stack_usage->reserved(), thread_stack_usage->committed());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   151
      out->print_cr(")");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   152
    }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   153
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   154
     // report malloc'd memory
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   155
    if (amount_in_current_scale(malloc_memory->malloc_size()) > 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   156
      // 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
   157
      size_t count = (flag == mtChunk) ? 0 : malloc_memory->malloc_count();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   158
      print_malloc_line(malloc_memory->malloc_size(), count);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   159
    }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   160
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   161
    if (amount_in_current_scale(virtual_memory->reserved()) > 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   162
      print_virtual_memory_line(virtual_memory->reserved(), virtual_memory->committed());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   163
    }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   164
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   165
    if (amount_in_current_scale(malloc_memory->arena_size()) > 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   166
      print_arena_line(malloc_memory->arena_size(), malloc_memory->arena_count());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   167
    }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   168
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   169
    if (flag == mtNMT &&
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   170
      amount_in_current_scale(_malloc_snapshot->malloc_overhead()->size()) > 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   171
      out->print_cr("%27s (tracking overhead=" SIZE_FORMAT "%s)", " ",
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   172
        amount_in_current_scale(_malloc_snapshot->malloc_overhead()->size()), scale);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   173
    }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   174
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   175
    out->print_cr(" ");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   176
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   177
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   178
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   179
void MemDetailReporter::report_detail() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   180
  // Start detail report
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   181
  outputStream* out = output();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   182
  out->print_cr("Details:\n");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   183
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   184
  report_malloc_sites();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   185
  report_virtual_memory_allocation_sites();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   186
}
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
void MemDetailReporter::report_malloc_sites() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   189
  MallocSiteIterator         malloc_itr = _baseline.malloc_sites(MemBaseline::by_size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   190
  if (malloc_itr.is_empty()) return;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   191
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   192
  outputStream* out = output();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   193
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   194
  const MallocSite* malloc_site;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   195
  while ((malloc_site = malloc_itr.next()) != NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   196
    // Don't report if size is too small
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   197
    if (amount_in_current_scale(malloc_site->size()) == 0)
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   198
      continue;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   199
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   200
    const NativeCallStack* stack = malloc_site->call_stack();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   201
    stack->print_on(out);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   202
    out->print("%29s", " ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   203
    print_malloc(malloc_site->size(), malloc_site->count());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   204
    out->print_cr("\n");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   205
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   206
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   207
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   208
void MemDetailReporter::report_virtual_memory_allocation_sites()  {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   209
  VirtualMemorySiteIterator  virtual_memory_itr =
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   210
    _baseline.virtual_memory_sites(MemBaseline::by_size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   211
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   212
  if (virtual_memory_itr.is_empty()) return;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   213
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   214
  outputStream* out = output();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   215
  const VirtualMemoryAllocationSite*  virtual_memory_site;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   216
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   217
  while ((virtual_memory_site = virtual_memory_itr.next()) != NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   218
    // Don't report if size is too small
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   219
    if (amount_in_current_scale(virtual_memory_site->reserved()) == 0)
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   220
      continue;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   221
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   222
    const NativeCallStack* stack = virtual_memory_site->call_stack();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   223
    stack->print_on(out);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   224
    out->print("%28s (", " ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   225
    print_total(virtual_memory_site->reserved(), virtual_memory_site->committed());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   226
    out->print_cr(")\n");
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
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   229
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   230
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   231
void MemDetailReporter::report_virtual_memory_map() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   232
  // Virtual memory map always in base address order
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   233
  VirtualMemoryAllocationIterator itr = _baseline.virtual_memory_allocations();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   234
  const ReservedMemoryRegion* rgn;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   235
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   236
  output()->print_cr("Virtual memory map:");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   237
  while ((rgn = itr.next()) != NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   238
    report_virtual_memory_region(rgn);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   239
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   240
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   241
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   242
void MemDetailReporter::report_virtual_memory_region(const ReservedMemoryRegion* reserved_rgn) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   243
  assert(reserved_rgn != NULL, "NULL pointer");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   244
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   245
  // Don't report if size is too small
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   246
  if (amount_in_current_scale(reserved_rgn->size()) == 0) return;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   247
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   248
  outputStream* out = output();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   249
  const char* scale = current_scale();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   250
  const NativeCallStack*  stack = reserved_rgn->call_stack();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   251
  bool all_committed = reserved_rgn->all_committed();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   252
  const char* region_type = (all_committed ? "reserved and committed" : "reserved");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   253
  out->print_cr(" ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   254
  print_virtual_memory_region(region_type, reserved_rgn->base(), reserved_rgn->size());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   255
  out->print(" for %s", NMTUtil::flag_to_name(reserved_rgn->flag()));
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   256
  if (stack->is_empty()) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   257
    out->print_cr(" ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   258
  } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   259
    out->print_cr(" from");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   260
    stack->print_on(out, 4);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   261
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   262
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   263
  if (all_committed) return;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   264
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   265
  CommittedRegionIterator itr = reserved_rgn->iterate_committed_regions();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   266
  const CommittedMemoryRegion* committed_rgn;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   267
  while ((committed_rgn = itr.next()) != NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   268
    // Don't report if size is too small
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   269
    if (amount_in_current_scale(committed_rgn->size()) == 0) continue;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   270
    stack = committed_rgn->call_stack();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   271
    out->print("\n\t");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   272
    print_virtual_memory_region("committed", committed_rgn->base(), committed_rgn->size());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   273
    if (stack->is_empty()) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   274
      out->print_cr(" ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   275
    } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   276
      out->print_cr(" from");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   277
      stack->print_on(out, 12);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   278
    }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   279
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   280
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   281
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   282
void MemSummaryDiffReporter::report_diff() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   283
  const char* scale = current_scale();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   284
  outputStream* out = output();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   285
  out->print_cr("\nNative Memory Tracking:\n");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   286
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   287
  // Overall diff
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   288
  out->print("Total: ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   289
  print_virtual_memory_diff(_current_baseline.total_reserved_memory(),
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   290
    _current_baseline.total_committed_memory(), _early_baseline.total_reserved_memory(),
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   291
    _early_baseline.total_committed_memory());
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13195
diff changeset
   292
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   293
  out->print_cr("\n");
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13195
diff changeset
   294
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   295
  // Summary diff by memory type
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   296
  for (int index = 0; index < mt_number_of_types; index ++) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   297
    MEMFLAGS flag = NMTUtil::index_to_flag(index);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   298
    // thread stack is reported as part of thread category
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   299
    if (flag == mtThreadStack) continue;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   300
    diff_summary_of_type(flag, _early_baseline.malloc_memory(flag),
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   301
      _early_baseline.virtual_memory(flag), _current_baseline.malloc_memory(flag),
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   302
      _current_baseline.virtual_memory(flag));
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13195
diff changeset
   303
  }
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13195
diff changeset
   304
}
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13195
diff changeset
   305
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   306
void MemSummaryDiffReporter::print_malloc_diff(size_t current_amount, size_t current_count,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   307
    size_t early_amount, size_t early_count) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   308
  const char* scale = current_scale();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   309
  outputStream* out = output();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   310
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   311
  out->print("malloc=" SIZE_FORMAT "%s", amount_in_current_scale(current_amount), scale);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   312
  long amount_diff = diff_in_current_scale(current_amount, early_amount);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   313
  if (amount_diff != 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   314
    out->print(" %+ld%s", amount_diff, scale);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   315
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   316
  if (current_count > 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   317
    out->print(" #" SIZE_FORMAT "", current_count);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   318
    if (current_count != early_count) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   319
      out->print(" %+d", (int)(current_count - early_count));
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   320
    }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   321
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   322
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   323
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   324
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
   325
  size_t early_amount, size_t early_count) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   326
  const char* scale = current_scale();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   327
  outputStream* out = output();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   328
  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
   329
  if (diff_in_current_scale(current_amount, early_amount) != 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   330
    out->print(" %+ld", diff_in_current_scale(current_amount, early_amount));
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   331
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   332
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   333
  out->print(" #" SIZE_FORMAT "", current_count);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   334
  if (current_count != early_count) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   335
    out->print(" %+d", (int)(current_count - early_count));
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   336
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   337
}
13195
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::print_virtual_memory_diff(size_t current_reserved, size_t current_committed,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   340
    size_t early_reserved, size_t early_committed) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   341
  const char* scale = current_scale();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   342
  outputStream* out = output();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   343
  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
   344
  long reserved_diff = diff_in_current_scale(current_reserved, early_reserved);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   345
  if (reserved_diff != 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   346
    out->print(" %+ld%s", reserved_diff, scale);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   347
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   348
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   349
  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
   350
  long committed_diff = diff_in_current_scale(current_committed, early_committed);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   351
  if (committed_diff != 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   352
    out->print(" %+ld%s", committed_diff, scale);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   353
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   354
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   355
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   356
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   357
void MemSummaryDiffReporter::diff_summary_of_type(MEMFLAGS flag, const MallocMemory* early_malloc,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   358
  const VirtualMemory* early_vm, const MallocMemory* current_malloc,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   359
  const VirtualMemory* current_vm) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   360
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   361
  outputStream* out = output();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   362
  const char* scale = current_scale();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   363
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   364
  // Total reserved and committed memory in current baseline
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   365
  size_t current_reserved_amount  = reserved_total (current_malloc, current_vm);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   366
  size_t current_committed_amount = committed_total(current_malloc, current_vm);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   367
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   368
  // Total reserved and committed memory in early baseline
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   369
  size_t early_reserved_amount  = reserved_total(early_malloc, early_vm);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   370
  size_t early_committed_amount = committed_total(early_malloc, early_vm);
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
  // Adjust virtual memory total
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   373
  if (flag == mtThread) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   374
    const VirtualMemory* early_thread_stack_usage =
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   375
      _early_baseline.virtual_memory(mtThreadStack);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   376
    const VirtualMemory* current_thread_stack_usage =
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   377
      _current_baseline.virtual_memory(mtThreadStack);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   378
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   379
    early_reserved_amount  += early_thread_stack_usage->reserved();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   380
    early_committed_amount += early_thread_stack_usage->committed();
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
    current_reserved_amount  += current_thread_stack_usage->reserved();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   383
    current_committed_amount += current_thread_stack_usage->committed();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   384
  } else if (flag == mtNMT) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   385
    early_reserved_amount  += _early_baseline.malloc_tracking_overhead();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   386
    early_committed_amount += _early_baseline.malloc_tracking_overhead();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   387
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   388
    current_reserved_amount  += _current_baseline.malloc_tracking_overhead();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   389
    current_committed_amount += _current_baseline.malloc_tracking_overhead();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   390
  }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   391
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   392
  if (amount_in_current_scale(current_reserved_amount) > 0 ||
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   393
      diff_in_current_scale(current_reserved_amount, early_reserved_amount) != 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   394
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   395
    // print summary line
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   396
    out->print("-%26s (", NMTUtil::flag_to_name(flag));
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   397
    print_virtual_memory_diff(current_reserved_amount, current_committed_amount,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   398
      early_reserved_amount, early_committed_amount);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   399
    out->print_cr(")");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   400
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   401
    // detail lines
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   402
    if (flag == mtClass) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   403
      // report class count
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   404
      out->print("%27s (classes #" SIZE_FORMAT "", " ", _current_baseline.class_count());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   405
      int class_count_diff = (int)(_current_baseline.class_count() -
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   406
        _early_baseline.class_count());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   407
      if (_current_baseline.class_count() != _early_baseline.class_count()) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   408
        out->print(" %+d", (int)(_current_baseline.class_count() - _early_baseline.class_count()));
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   409
      }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   410
      out->print_cr(")");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   411
    } else if (flag == mtThread) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   412
      // report thread count
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   413
      out->print("%27s (thread #" SIZE_FORMAT "", " ", _current_baseline.thread_count());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   414
      int thread_count_diff = (int)(_current_baseline.thread_count() -
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   415
          _early_baseline.thread_count());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   416
      if (thread_count_diff != 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   417
        out->print(" %+d", thread_count_diff);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   418
      }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   419
      out->print_cr(")");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   420
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   421
      // report thread stack
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   422
      const VirtualMemory* current_thread_stack =
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   423
          _current_baseline.virtual_memory(mtThreadStack);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   424
      const VirtualMemory* early_thread_stack =
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   425
        _early_baseline.virtual_memory(mtThreadStack);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   426
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   427
      out->print("%27s (stack: ", " ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   428
      print_virtual_memory_diff(current_thread_stack->reserved(), current_thread_stack->committed(),
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   429
        early_thread_stack->reserved(), early_thread_stack->committed());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   430
      out->print_cr(")");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   431
    }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   432
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   433
    // Report malloc'd memory
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   434
    size_t current_malloc_amount = current_malloc->malloc_size();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   435
    size_t early_malloc_amount   = early_malloc->malloc_size();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   436
    if (amount_in_current_scale(current_malloc_amount) > 0 ||
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   437
        diff_in_current_scale(current_malloc_amount, early_malloc_amount) != 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   438
      out->print("%28s(", " ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   439
      print_malloc_diff(current_malloc_amount, (flag == mtChunk) ? 0 : current_malloc->malloc_count(),
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   440
        early_malloc_amount, early_malloc->malloc_count());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   441
      out->print_cr(")");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   442
    }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   443
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   444
    // Report virtual memory
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   445
    if (amount_in_current_scale(current_vm->reserved()) > 0 ||
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   446
        diff_in_current_scale(current_vm->reserved(), early_vm->reserved()) != 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   447
      out->print("%27s (mmap: ", " ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   448
      print_virtual_memory_diff(current_vm->reserved(), current_vm->committed(),
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   449
        early_vm->reserved(), early_vm->committed());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   450
      out->print_cr(")");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   451
    }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   452
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   453
    // Report arena memory
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   454
    if (amount_in_current_scale(current_malloc->arena_size()) > 0 ||
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   455
        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
   456
      out->print("%28s(", " ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   457
      print_arena_diff(current_malloc->arena_size(), current_malloc->arena_count(),
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   458
        early_malloc->arena_size(), early_malloc->arena_count());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   459
      out->print_cr(")");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   460
    }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   461
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   462
    // Report native memory tracking overhead
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   463
    if (flag == mtNMT) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   464
      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
   465
      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
   466
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   467
      out->print("%27s (tracking overhead=" SIZE_FORMAT "%s", " ",
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   468
        amount_in_current_scale(_current_baseline.malloc_tracking_overhead()), scale);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   469
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   470
      long overhead_diff = diff_in_current_scale(_current_baseline.malloc_tracking_overhead(),
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   471
           _early_baseline.malloc_tracking_overhead());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   472
      if (overhead_diff != 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   473
        out->print(" %+ld%s", overhead_diff, scale);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   474
      }
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   475
      out->print_cr(")");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   476
    }
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   477
    out->print_cr(" ");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   478
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   479
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   480
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   481
void MemDetailDiffReporter::report_diff() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   482
  MemSummaryDiffReporter::report_diff();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   483
  diff_malloc_sites();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   484
  diff_virtual_memory_sites();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   485
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   486
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   487
void MemDetailDiffReporter::diff_malloc_sites() const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   488
  MallocSiteIterator early_itr = _early_baseline.malloc_sites(MemBaseline::by_site);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   489
  MallocSiteIterator current_itr = _current_baseline.malloc_sites(MemBaseline::by_site);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   490
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   491
  const MallocSite* early_site   = early_itr.next();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   492
  const MallocSite* current_site = current_itr.next();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   493
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   494
  while (early_site != NULL || current_site != NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   495
    if (early_site == NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   496
      new_malloc_site(current_site);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   497
      current_site = current_itr.next();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   498
    } else if (current_site == NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   499
      old_malloc_site(early_site);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   500
      early_site = early_itr.next();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   501
    } else {
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   502
      int compVal = current_site->call_stack()->compare(*early_site->call_stack());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   503
      if (compVal < 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   504
        new_malloc_site(current_site);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   505
        current_site = current_itr.next();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   506
      } else if (compVal > 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   507
        old_malloc_site(early_site);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   508
        early_site = early_itr.next();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   509
      } else {
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   510
        diff_malloc_site(early_site, current_site);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   511
        early_site   = early_itr.next();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   512
        current_site = current_itr.next();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   513
      }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   514
    }
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   515
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   516
}
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   517
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   518
void MemDetailDiffReporter::diff_virtual_memory_sites() const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   519
  VirtualMemorySiteIterator early_itr = _early_baseline.virtual_memory_sites(MemBaseline::by_site);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   520
  VirtualMemorySiteIterator current_itr = _current_baseline.virtual_memory_sites(MemBaseline::by_site);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   521
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   522
  const VirtualMemoryAllocationSite* early_site   = early_itr.next();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   523
  const VirtualMemoryAllocationSite* current_site = current_itr.next();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   524
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   525
  while (early_site != NULL || current_site != NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   526
    if (early_site == NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   527
      new_virtual_memory_site(current_site);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   528
      current_site = current_itr.next();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   529
    } else if (current_site == NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   530
      old_virtual_memory_site(early_site);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   531
      early_site = early_itr.next();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   532
    } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   533
      int compVal = current_site->call_stack()->compare(*early_site->call_stack());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   534
      if (compVal < 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   535
        new_virtual_memory_site(current_site);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   536
        current_site = current_itr.next();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   537
      } else if (compVal > 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   538
        old_virtual_memory_site(early_site);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   539
        early_site = early_itr.next();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   540
      } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   541
        diff_virtual_memory_site(early_site, current_site);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   542
        early_site   = early_itr.next();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   543
        current_site = current_itr.next();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   544
      }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   545
    }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   546
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   547
}
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
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   550
void MemDetailDiffReporter::new_malloc_site(const MallocSite* malloc_site) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   551
  diff_malloc_site(malloc_site->call_stack(), malloc_site->size(), malloc_site->count(),
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   552
    0, 0);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   553
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   554
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   555
void MemDetailDiffReporter::old_malloc_site(const MallocSite* malloc_site) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   556
  diff_malloc_site(malloc_site->call_stack(), 0, 0, malloc_site->size(),
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   557
    malloc_site->count());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   558
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   559
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   560
void MemDetailDiffReporter::diff_malloc_site(const MallocSite* early,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   561
  const MallocSite* current)  const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   562
  diff_malloc_site(current->call_stack(), current->size(), current->count(),
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   563
    early->size(), early->count());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   564
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   565
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   566
void MemDetailDiffReporter::diff_malloc_site(const NativeCallStack* stack, size_t current_size,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   567
  size_t current_count, size_t early_size, size_t early_count) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   568
  outputStream* out = output();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   569
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   570
  assert(stack != NULL, "NULL stack");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   571
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   572
  if (diff_in_current_scale(current_size, early_size) == 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   573
      return;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   574
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   575
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   576
  stack->print_on(out);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   577
  out->print("%28s (", " ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   578
  print_malloc_diff(current_size, current_count,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   579
    early_size, early_count);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   580
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   581
  out->print_cr(")\n");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   582
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   583
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   584
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   585
void MemDetailDiffReporter::new_virtual_memory_site(const VirtualMemoryAllocationSite* site) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   586
  diff_virtual_memory_site(site->call_stack(), site->reserved(), site->committed(), 0, 0);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   587
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   588
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   589
void MemDetailDiffReporter::old_virtual_memory_site(const VirtualMemoryAllocationSite* site) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   590
  diff_virtual_memory_site(site->call_stack(), 0, 0, site->reserved(), site->committed());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   591
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   592
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   593
void MemDetailDiffReporter::diff_virtual_memory_site(const VirtualMemoryAllocationSite* early,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   594
  const VirtualMemoryAllocationSite* current) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   595
  diff_virtual_memory_site(current->call_stack(), current->reserved(), current->committed(),
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   596
    early->reserved(), early->committed());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   597
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   598
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   599
void MemDetailDiffReporter::diff_virtual_memory_site(const NativeCallStack* stack, size_t current_reserved,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   600
  size_t current_committed, size_t early_reserved, size_t early_committed) const  {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   601
  outputStream* out = output();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   602
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   603
  // no change
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   604
  if (diff_in_current_scale(current_reserved, early_reserved) == 0 &&
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   605
      diff_in_current_scale(current_committed, early_committed) == 0) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   606
    return;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   607
  }
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   608
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   609
  stack->print_on(out);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   610
  out->print("%28s (mmap: ", " ");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   611
  print_virtual_memory_diff(current_reserved, current_committed,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   612
    early_reserved, early_committed);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   613
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   614
  out->print_cr(")\n");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   615
 }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 24424
diff changeset
   616