src/hotspot/share/services/memBaseline.cpp
author zgu
Thu, 08 Feb 2018 13:21:22 -0500
changeset 48884 7e17b00dc245
parent 48874 f09fdaad7321
child 51959 db0c3952de52
permissions -rw-r--r--
8196923: [REDO] NMT: Report array class count in NMT summary Summary: Added instance and array class counters in NMT summary report Reviewed-by: minqi, stuefe, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
     1
/*
48884
7e17b00dc245 8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents: 48874
diff changeset
     2
 * Copyright (c) 2012, 2018, 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: 18693
diff changeset
    25
48884
7e17b00dc245 8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents: 48874
diff changeset
    26
#include "classfile/classLoaderData.inline.hpp"
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    27
#include "memory/allocation.hpp"
17074
d660347efb98 8011218: Kitchensink hanged, likely NMT is to blame
zgu
parents: 15452
diff changeset
    28
#include "runtime/safepoint.hpp"
d660347efb98 8011218: Kitchensink hanged, likely NMT is to blame
zgu
parents: 15452
diff changeset
    29
#include "runtime/thread.inline.hpp"
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    30
#include "services/memBaseline.hpp"
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    31
#include "services/memTracker.hpp"
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    32
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    33
/*
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    34
 * Sizes are sorted in descenting order for reporting
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    35
 */
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    36
int compare_malloc_size(const MallocSite& s1, const MallocSite& s2) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    37
  if (s1.size() == s2.size()) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    38
    return 0;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    39
  } else if (s1.size() > s2.size()) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    40
    return -1;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    41
  } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    42
    return 1;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    43
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    44
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    45
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    46
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    47
int compare_virtual_memory_size(const VirtualMemoryAllocationSite& s1,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    48
  const VirtualMemoryAllocationSite& s2) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    49
  if (s1.reserved() == s2.reserved()) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    50
    return 0;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    51
  } else if (s1.reserved() > s2.reserved()) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    52
    return -1;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    53
  } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    54
    return 1;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    55
  }
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    56
}
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    57
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    58
// Sort into allocation site addresses order for baseline comparison
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    59
int compare_malloc_site(const MallocSite& s1, const MallocSite& s2) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    60
  return s1.call_stack()->compare(*s2.call_stack());
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    61
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    62
46711
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 26288
diff changeset
    63
// Sort into allocation site addresses and memory type order for baseline comparison
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 26288
diff changeset
    64
int compare_malloc_site_and_type(const MallocSite& s1, const MallocSite& s2) {
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 26288
diff changeset
    65
  int res = compare_malloc_site(s1, s2);
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 26288
diff changeset
    66
  if (res == 0) {
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 26288
diff changeset
    67
    res = (int)(s1.flags() - s2.flags());
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 26288
diff changeset
    68
  }
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 26288
diff changeset
    69
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 26288
diff changeset
    70
  return res;
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 26288
diff changeset
    71
}
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    72
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    73
int compare_virtual_memory_site(const VirtualMemoryAllocationSite& s1,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    74
  const VirtualMemoryAllocationSite& s2) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    75
  return s1.call_stack()->compare(*s2.call_stack());
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: 18693
diff changeset
    78
/*
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    79
 * Walker to walk malloc allocation site table
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    80
 */
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    81
class MallocAllocationSiteWalker : public MallocSiteWalker {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    82
 private:
26288
631bf42cf7c2 8054546: NMT2 leaks memory
zgu
parents: 25946
diff changeset
    83
  SortedLinkedList<MallocSite, compare_malloc_size> _malloc_sites;
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    84
  size_t         _count;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    85
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    86
  // Entries in MallocSiteTable with size = 0 and count = 0,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    87
  // when the malloc site is not longer there.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    88
 public:
26288
631bf42cf7c2 8054546: NMT2 leaks memory
zgu
parents: 25946
diff changeset
    89
  MallocAllocationSiteWalker() : _count(0) { }
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    90
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    91
  inline size_t count() const { return _count; }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    92
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    93
  LinkedList<MallocSite>* malloc_sites() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    94
    return &_malloc_sites;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    95
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    96
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    97
  bool do_malloc_site(const MallocSite* site) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    98
    if (site->size() >= MemBaseline::SIZE_THRESHOLD) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
    99
      if (_malloc_sites.add(*site) != NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   100
        _count++;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   101
        return true;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   102
      } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   103
        return false;  // OOM
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   104
      }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   105
    } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   106
      // malloc site does not meet threshold, ignore and continue
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   107
      return true;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   108
    }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   109
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   110
};
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   111
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   112
// Compare virtual memory region's base address
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   113
int compare_virtual_memory_base(const ReservedMemoryRegion& r1, const ReservedMemoryRegion& r2) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   114
  return r1.compare(r2);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   115
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   116
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   117
// Walk all virtual memory regions for baselining
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   118
class VirtualMemoryAllocationWalker : public VirtualMemoryWalker {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   119
 private:
26288
631bf42cf7c2 8054546: NMT2 leaks memory
zgu
parents: 25946
diff changeset
   120
  SortedLinkedList<ReservedMemoryRegion, compare_virtual_memory_base>
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   121
                _virtual_memory_regions;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   122
  size_t        _count;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   123
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   124
 public:
26288
631bf42cf7c2 8054546: NMT2 leaks memory
zgu
parents: 25946
diff changeset
   125
  VirtualMemoryAllocationWalker() : _count(0) { }
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   126
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   127
  bool do_allocation_site(const ReservedMemoryRegion* rgn)  {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   128
    if (rgn->size() >= MemBaseline::SIZE_THRESHOLD) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   129
      if (_virtual_memory_regions.add(*rgn) != NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   130
        _count ++;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   131
        return true;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   132
      } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   133
        return false;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   134
      }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   135
    }
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   136
    return true;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   137
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   138
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   139
  LinkedList<ReservedMemoryRegion>* virtual_memory_allocations() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   140
    return &_virtual_memory_regions;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   141
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   142
};
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   143
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   144
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   145
bool MemBaseline::baseline_summary() {
26288
631bf42cf7c2 8054546: NMT2 leaks memory
zgu
parents: 25946
diff changeset
   146
  MallocMemorySummary::snapshot(&_malloc_memory_snapshot);
631bf42cf7c2 8054546: NMT2 leaks memory
zgu
parents: 25946
diff changeset
   147
  VirtualMemorySummary::snapshot(&_virtual_memory_snapshot);
47553
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   148
  MetaspaceSnapshot::snapshot(_metaspace_snapshot);
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   149
  return true;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   150
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   151
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   152
bool MemBaseline::baseline_allocation_sites() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   153
  // Malloc allocation sites
26288
631bf42cf7c2 8054546: NMT2 leaks memory
zgu
parents: 25946
diff changeset
   154
  MallocAllocationSiteWalker malloc_walker;
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   155
  if (!MallocSiteTable::walk_malloc_site(&malloc_walker)) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   156
    return false;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   157
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   158
26288
631bf42cf7c2 8054546: NMT2 leaks memory
zgu
parents: 25946
diff changeset
   159
  _malloc_sites.move(malloc_walker.malloc_sites());
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   160
  // The malloc sites are collected in size order
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   161
  _malloc_sites_order = by_size;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   162
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   163
  // Virtual memory allocation sites
26288
631bf42cf7c2 8054546: NMT2 leaks memory
zgu
parents: 25946
diff changeset
   164
  VirtualMemoryAllocationWalker virtual_memory_walker;
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   165
  if (!VirtualMemoryTracker::walk_virtual_memory(&virtual_memory_walker)) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   166
    return false;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   167
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   168
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   169
  // Virtual memory allocations are collected in call stack order
26288
631bf42cf7c2 8054546: NMT2 leaks memory
zgu
parents: 25946
diff changeset
   170
  _virtual_memory_allocations.move(virtual_memory_walker.virtual_memory_allocations());
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   171
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   172
  if (!aggregate_virtual_memory_allocation_sites()) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   173
    return false;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   174
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   175
  // Virtual memory allocation sites are aggregrated in call stack order
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   176
  _virtual_memory_sites_order = by_address;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   177
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   178
  return true;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   179
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   180
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   181
bool MemBaseline::baseline(bool summaryOnly) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   182
  reset();
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13195
diff changeset
   183
48884
7e17b00dc245 8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents: 48874
diff changeset
   184
  _instance_class_count = ClassLoaderDataGraph::num_instance_classes();
7e17b00dc245 8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents: 48874
diff changeset
   185
  _array_class_count = ClassLoaderDataGraph::num_array_classes();
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13195
diff changeset
   186
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   187
  if (!baseline_summary()) {
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13195
diff changeset
   188
    return false;
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13195
diff changeset
   189
  }
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13195
diff changeset
   190
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   191
  _baseline_type = Summary_baselined;
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13195
diff changeset
   192
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   193
  // baseline details
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   194
  if (!summaryOnly &&
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   195
      MemTracker::tracking_level() == NMT_detail) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   196
    baseline_allocation_sites();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   197
    _baseline_type = Detail_baselined;
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13195
diff changeset
   198
  }
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13195
diff changeset
   199
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   200
  return true;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   201
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   202
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   203
int compare_allocation_site(const VirtualMemoryAllocationSite& s1,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   204
  const VirtualMemoryAllocationSite& s2) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   205
  return s1.call_stack()->compare(*s2.call_stack());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   206
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   207
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   208
bool MemBaseline::aggregate_virtual_memory_allocation_sites() {
26288
631bf42cf7c2 8054546: NMT2 leaks memory
zgu
parents: 25946
diff changeset
   209
  SortedLinkedList<VirtualMemoryAllocationSite, compare_allocation_site> allocation_sites;
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   210
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   211
  VirtualMemoryAllocationIterator itr = virtual_memory_allocations();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   212
  const ReservedMemoryRegion* rgn;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   213
  VirtualMemoryAllocationSite* site;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   214
  while ((rgn = itr.next()) != NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   215
    VirtualMemoryAllocationSite tmp(*rgn->call_stack());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   216
    site = allocation_sites.find(tmp);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   217
    if (site == NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   218
      LinkedListNode<VirtualMemoryAllocationSite>* node =
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   219
        allocation_sites.add(tmp);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   220
      if (node == NULL) return false;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   221
      site = node->data();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   222
    }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   223
    site->reserve_memory(rgn->size());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   224
    site->commit_memory(rgn->committed_size());
17074
d660347efb98 8011218: Kitchensink hanged, likely NMT is to blame
zgu
parents: 15452
diff changeset
   225
  }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   226
26288
631bf42cf7c2 8054546: NMT2 leaks memory
zgu
parents: 25946
diff changeset
   227
  _virtual_memory_sites.move(&allocation_sites);
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   228
  return true;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   229
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   230
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   231
MallocSiteIterator MemBaseline::malloc_sites(SortingOrder order) {
26288
631bf42cf7c2 8054546: NMT2 leaks memory
zgu
parents: 25946
diff changeset
   232
  assert(!_malloc_sites.is_empty(), "Not detail baseline");
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   233
  switch(order) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   234
    case by_size:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   235
      malloc_sites_to_size_order();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   236
      break;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   237
    case by_site:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   238
      malloc_sites_to_allocation_site_order();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   239
      break;
46711
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 26288
diff changeset
   240
    case by_site_and_type:
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 26288
diff changeset
   241
      malloc_sites_to_allocation_site_and_type_order();
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 26288
diff changeset
   242
      break;
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   243
    case by_address:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   244
    default:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   245
      ShouldNotReachHere();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   246
  }
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   247
  return MallocSiteIterator(_malloc_sites.head());
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   248
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   249
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   250
VirtualMemorySiteIterator MemBaseline::virtual_memory_sites(SortingOrder order) {
26288
631bf42cf7c2 8054546: NMT2 leaks memory
zgu
parents: 25946
diff changeset
   251
  assert(!_virtual_memory_sites.is_empty(), "Not detail baseline");
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   252
  switch(order) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   253
    case by_size:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   254
      virtual_memory_sites_to_size_order();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   255
      break;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   256
    case by_site:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   257
      virtual_memory_sites_to_reservation_site_order();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   258
      break;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   259
    case by_address:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   260
    default:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   261
      ShouldNotReachHere();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   262
  }
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   263
  return VirtualMemorySiteIterator(_virtual_memory_sites.head());
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   264
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   265
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   266
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   267
// Sorting allocations sites in different orders
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   268
void MemBaseline::malloc_sites_to_size_order() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   269
  if (_malloc_sites_order != by_size) {
26288
631bf42cf7c2 8054546: NMT2 leaks memory
zgu
parents: 25946
diff changeset
   270
    SortedLinkedList<MallocSite, compare_malloc_size> tmp;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   271
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   272
    // Add malloc sites to sorted linked list to sort into size order
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   273
    tmp.move(&_malloc_sites);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   274
    _malloc_sites.set_head(tmp.head());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   275
    tmp.set_head(NULL);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   276
    _malloc_sites_order = by_size;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   277
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   278
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   279
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   280
void MemBaseline::malloc_sites_to_allocation_site_order() {
46711
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 26288
diff changeset
   281
  if (_malloc_sites_order != by_site && _malloc_sites_order != by_site_and_type) {
26288
631bf42cf7c2 8054546: NMT2 leaks memory
zgu
parents: 25946
diff changeset
   282
    SortedLinkedList<MallocSite, compare_malloc_site> tmp;
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   283
    // Add malloc sites to sorted linked list to sort into site (address) order
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   284
    tmp.move(&_malloc_sites);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   285
    _malloc_sites.set_head(tmp.head());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   286
    tmp.set_head(NULL);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   287
    _malloc_sites_order = by_site;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   288
  }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   289
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   290
46711
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 26288
diff changeset
   291
void MemBaseline::malloc_sites_to_allocation_site_and_type_order() {
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 26288
diff changeset
   292
  if (_malloc_sites_order != by_site_and_type) {
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 26288
diff changeset
   293
    SortedLinkedList<MallocSite, compare_malloc_site_and_type> tmp;
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 26288
diff changeset
   294
    // Add malloc sites to sorted linked list to sort into site (address) order
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 26288
diff changeset
   295
    tmp.move(&_malloc_sites);
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 26288
diff changeset
   296
    _malloc_sites.set_head(tmp.head());
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 26288
diff changeset
   297
    tmp.set_head(NULL);
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 26288
diff changeset
   298
    _malloc_sites_order = by_site_and_type;
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 26288
diff changeset
   299
  }
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 26288
diff changeset
   300
}
0ccef2260315 8184991: NMT detail diff should take memory type into account
zgu
parents: 26288
diff changeset
   301
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   302
void MemBaseline::virtual_memory_sites_to_size_order() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   303
  if (_virtual_memory_sites_order != by_size) {
26288
631bf42cf7c2 8054546: NMT2 leaks memory
zgu
parents: 25946
diff changeset
   304
    SortedLinkedList<VirtualMemoryAllocationSite, compare_virtual_memory_size> tmp;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   305
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   306
    tmp.move(&_virtual_memory_sites);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   307
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   308
    _virtual_memory_sites.set_head(tmp.head());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   309
    tmp.set_head(NULL);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   310
    _virtual_memory_sites_order = by_size;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   311
  }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   312
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   313
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   314
void MemBaseline::virtual_memory_sites_to_reservation_site_order() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   315
  if (_virtual_memory_sites_order != by_size) {
26288
631bf42cf7c2 8054546: NMT2 leaks memory
zgu
parents: 25946
diff changeset
   316
    SortedLinkedList<VirtualMemoryAllocationSite, compare_virtual_memory_site> tmp;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   317
26288
631bf42cf7c2 8054546: NMT2 leaks memory
zgu
parents: 25946
diff changeset
   318
    tmp.move(&_virtual_memory_sites);
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   319
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   320
    _virtual_memory_sites.set_head(tmp.head());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   321
    tmp.set_head(NULL);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   322
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   323
    _virtual_memory_sites_order = by_size;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 18693
diff changeset
   324
  }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   325
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   326