src/hotspot/share/services/memReporter.hpp
author dcubed
Wed, 18 Sep 2019 20:49:13 -0400
changeset 58223 778fc2dcbdaa
parent 53685 df83034c9275
child 58063 bdf136b8ae0e
permissions -rw-r--r--
8231210: [BACKOUT] JDK-8207266 ThreadMXBean::getThreadAllocatedBytes() can be quicker for self thread Reviewed-by: phh, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 48884
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
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 48884
diff changeset
    25
#ifndef SHARE_SERVICES_MEMREPORTER_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 48884
diff changeset
    26
#define SHARE_SERVICES_MEMREPORTER_HPP
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    27
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    28
#if INCLUDE_NMT
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    29
47553
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
    30
#include "memory/metaspace.hpp"
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    31
#include "oops/instanceKlass.hpp"
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    32
#include "services/memBaseline.hpp"
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    33
#include "services/nmtCommon.hpp"
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    34
#include "services/mallocTracker.hpp"
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    35
#include "services/virtualMemoryTracker.hpp"
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13195
diff changeset
    36
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    37
/*
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    38
 * Base class that provides helpers
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    39
*/
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    40
class MemReporterBase : public StackObj {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    41
 private:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    42
  size_t        _scale;  // report in this scale
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    43
  outputStream* _output; // destination
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    44
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    45
 public:
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    46
  MemReporterBase(outputStream* out = NULL, size_t scale = K)
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    47
    : _scale(scale) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    48
    _output = (out == NULL) ? tty : out;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    49
  }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    50
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    51
 protected:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    52
  inline outputStream* output() const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    53
    return _output;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    54
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    55
  // Current reporting scale
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    56
  inline const char* current_scale() const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    57
    return NMTUtil::scale_name(_scale);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    58
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    59
  // Convert memory amount in bytes to current reporting scale
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    60
  inline size_t amount_in_current_scale(size_t amount) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    61
    return NMTUtil::amount_in_scale(amount, _scale);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    62
  }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    63
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    64
  // Convert diff amount in bytes to current reporting scale
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    65
  inline long diff_in_current_scale(size_t s1, size_t s2) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    66
    long amount = (long)(s1 - s2);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    67
    long scale = (long)_scale;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    68
    amount = (amount > 0) ? (amount + scale / 2) : (amount - scale / 2);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    69
    return amount / scale;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    70
  }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    71
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    72
  // Helper functions
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    73
  // Calculate total reserved and committed amount
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    74
  size_t reserved_total(const MallocMemory* malloc, const VirtualMemory* vm) const;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    75
  size_t committed_total(const MallocMemory* malloc, const VirtualMemory* vm) const;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    76
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    77
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    78
  // Print summary total, malloc and virtual memory
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    79
  void print_total(size_t reserved, size_t committed) const;
46489
40abcea5a9d5 8139673: NMT stack traces in output should show mtcomponent
zgu
parents: 27162
diff changeset
    80
  void print_malloc(size_t amount, size_t count, MEMFLAGS flag = mtNone) const;
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    81
  void print_virtual_memory(size_t reserved, size_t committed) const;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    82
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    83
  void print_malloc_line(size_t amount, size_t count) const;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    84
  void print_virtual_memory_line(size_t reserved, size_t committed) const;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    85
  void print_arena_line(size_t amount, size_t count) const;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    86
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    87
  void print_virtual_memory_region(const char* type, address base, size_t size) const;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    88
};
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    89
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    90
/*
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    91
 * The class is for generating summary tracking report.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    92
 */
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    93
class MemSummaryReporter : public MemReporterBase {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    94
 private:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    95
  MallocMemorySnapshot*   _malloc_snapshot;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
    96
  VirtualMemorySnapshot*  _vm_snapshot;
48884
7e17b00dc245 8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents: 48874
diff changeset
    97
  size_t                  _instance_class_count;
7e17b00dc245 8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents: 48874
diff changeset
    98
  size_t                  _array_class_count;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    99
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   100
 public:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   101
  // This constructor is for normal reporting from a recent baseline.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   102
  MemSummaryReporter(MemBaseline& baseline, outputStream* output,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   103
    size_t scale = K) : MemReporterBase(output, scale),
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   104
    _malloc_snapshot(baseline.malloc_memory_snapshot()),
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   105
    _vm_snapshot(baseline.virtual_memory_snapshot()),
48884
7e17b00dc245 8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents: 48874
diff changeset
   106
    _instance_class_count(baseline.instance_class_count()),
7e17b00dc245 8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents: 48874
diff changeset
   107
    _array_class_count(baseline.array_class_count()) { }
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13975
diff changeset
   108
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   109
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   110
  // Generate summary report
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   111
  virtual void report();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   112
 private:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   113
  // Report summary for each memory type
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   114
  void report_summary_of_type(MEMFLAGS type, MallocMemory* malloc_memory,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   115
    VirtualMemory* virtual_memory);
47553
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   116
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   117
  void report_metadata(Metaspace::MetadataType type) const;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   118
};
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   119
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   120
/*
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   121
 * The class is for generating detail tracking report.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   122
 */
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   123
class MemDetailReporter : public MemSummaryReporter {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   124
 private:
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   125
  MemBaseline&   _baseline;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   126
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   127
 public:
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   128
  MemDetailReporter(MemBaseline& baseline, outputStream* output, size_t scale = K) :
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   129
    MemSummaryReporter(baseline, output, scale),
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   130
     _baseline(baseline) { }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   131
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   132
  // Generate detail report.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   133
  // The report contains summary and detail sections.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   134
  virtual void report() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   135
    MemSummaryReporter::report();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   136
    report_virtual_memory_map();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   137
    report_detail();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   138
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   139
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   140
 private:
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   141
  // Report detail tracking data.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   142
  void report_detail();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   143
  // Report virtual memory map
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   144
  void report_virtual_memory_map();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   145
  // Report malloc allocation sites
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   146
  void report_malloc_sites();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   147
  // Report virtual memory reservation sites
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   148
  void report_virtual_memory_allocation_sites();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   149
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   150
  // Report a virtual memory region
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   151
  void report_virtual_memory_region(const ReservedMemoryRegion* rgn);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   152
};
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   153
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   154
/*
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   155
 * The class is for generating summary comparison report.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   156
 * It compares current memory baseline against an early baseline.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   157
 */
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   158
class MemSummaryDiffReporter : public MemReporterBase {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   159
 protected:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   160
  MemBaseline&      _early_baseline;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   161
  MemBaseline&      _current_baseline;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   162
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   163
 public:
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   164
  MemSummaryDiffReporter(MemBaseline& early_baseline, MemBaseline& current_baseline,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   165
    outputStream* output, size_t scale = K) : MemReporterBase(output, scale),
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   166
    _early_baseline(early_baseline), _current_baseline(current_baseline) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   167
    assert(early_baseline.baseline_type()   != MemBaseline::Not_baselined, "Not baselined");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   168
    assert(current_baseline.baseline_type() != MemBaseline::Not_baselined, "Not baselined");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   169
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   170
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   171
  // Generate summary comparison report
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   172
  virtual void report_diff();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   173
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   174
 private:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   175
  // report the comparison of each memory type
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   176
  void diff_summary_of_type(MEMFLAGS type,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   177
    const MallocMemory* early_malloc, const VirtualMemory* early_vm,
47553
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   178
    const MetaspaceSnapshot* early_ms,
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   179
    const MallocMemory* current_malloc, const VirtualMemory* current_vm,
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   180
    const MetaspaceSnapshot* current_ms) const;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   181
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   182
 protected:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   183
  void 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
   184
    size_t early_amount, size_t early_count, MEMFLAGS flags) const;
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   185
  void print_virtual_memory_diff(size_t current_reserved, size_t current_committed,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   186
    size_t early_reserved, size_t early_committed) const;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   187
  void print_arena_diff(size_t current_amount, size_t current_count,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   188
    size_t early_amount, size_t early_count) const;
47553
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   189
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   190
  void print_metaspace_diff(const MetaspaceSnapshot* current_ms,
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   191
                            const MetaspaceSnapshot* early_ms) const;
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   192
  void print_metaspace_diff(Metaspace::MetadataType type,
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   193
    const MetaspaceSnapshot* current_ms, const MetaspaceSnapshot* early_ms) const;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   194
};
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   195
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   196
/*
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   197
 * The class is for generating detail comparison report.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   198
 * It compares current memory baseline against an early baseline,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   199
 * both baselines have to be detail baseline.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   200
 */
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   201
class MemDetailDiffReporter : public MemSummaryDiffReporter {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   202
 public:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   203
  MemDetailDiffReporter(MemBaseline& early_baseline, MemBaseline& current_baseline,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   204
    outputStream* output, size_t scale = K) :
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   205
    MemSummaryDiffReporter(early_baseline, current_baseline, output, scale) { }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   206
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   207
  // Generate detail comparison report
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   208
  virtual void report_diff();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   209
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   210
  // Malloc allocation site comparison
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   211
  void diff_malloc_sites() const;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   212
  // Virutal memory reservation site comparison
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   213
  void diff_virtual_memory_sites() const;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   214
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   215
  // New malloc allocation site in recent baseline
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   216
  void new_malloc_site (const MallocSite* site) const;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   217
  // The malloc allocation site is not in recent baseline
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   218
  void old_malloc_site (const MallocSite* site) const;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   219
  // Compare malloc allocation site, it is in both baselines
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   220
  void diff_malloc_site(const MallocSite* early, const MallocSite* current)  const;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   221
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   222
  // New virtual memory allocation site in recent baseline
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   223
  void new_virtual_memory_site (const VirtualMemoryAllocationSite* callsite) const;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   224
  // The virtual memory allocation site is not in recent baseline
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   225
  void old_virtual_memory_site (const VirtualMemoryAllocationSite* callsite) const;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   226
  // Compare virtual memory allocation site, it is in both baseline
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   227
  void diff_virtual_memory_site(const VirtualMemoryAllocationSite* early,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   228
                                const VirtualMemoryAllocationSite* current)  const;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   229
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   230
  void 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
   231
    size_t currrent_count, size_t early_size, size_t early_count, MEMFLAGS flags) const;
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22234
diff changeset
   232
  void 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: 53244
diff changeset
   233
    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: 22234
diff changeset
   234
};
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   235
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13195
diff changeset
   236
#endif // INCLUDE_NMT
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13195
diff changeset
   237
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 48884
diff changeset
   238
#endif // SHARE_SERVICES_MEMREPORTER_HPP