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