src/hotspot/share/services/virtualMemoryTracker.cpp
author egahlin
Mon, 08 Jul 2019 18:11:26 +0200
branchJEP-349-branch
changeset 57459 df39f8d8f4d6
parent 54292 c31faeacf00a
child 58063 bdf136b8ae0e
child 59119 7bdc4f073c7f
permissions -rw-r--r--
Make stream more responsive
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
     1
/*
54292
c31faeacf00a 8204552: NMT: Separate thread stack tracking from virtual memory tracking
zgu
parents: 49980
diff changeset
     2
 * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
     4
 *
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
     8
 *
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    13
 * accompanied this code).
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    14
 *
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    18
 *
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    21
 * questions.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    22
 *
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    23
 */
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    24
#include "precompiled.hpp"
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    25
49968
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
    26
#include "logging/log.hpp"
47553
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
    27
#include "memory/metaspace.hpp"
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 38935
diff changeset
    28
#include "runtime/atomic.hpp"
38935
f7427b0e0d7c 8138705: Kitchen sink stress test fails
mockner
parents: 35483
diff changeset
    29
#include "runtime/os.hpp"
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    30
#include "runtime/threadCritical.hpp"
38935
f7427b0e0d7c 8138705: Kitchen sink stress test fails
mockner
parents: 35483
diff changeset
    31
#include "services/memTracker.hpp"
54292
c31faeacf00a 8204552: NMT: Separate thread stack tracking from virtual memory tracking
zgu
parents: 49980
diff changeset
    32
#include "services/threadStackTracker.hpp"
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    33
#include "services/virtualMemoryTracker.hpp"
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    34
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    35
size_t VirtualMemorySummary::_snapshot[CALC_OBJ_SIZE_IN_TYPE(VirtualMemorySnapshot, size_t)];
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    36
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    37
void VirtualMemorySummary::initialize() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    38
  assert(sizeof(_snapshot) >= sizeof(VirtualMemorySnapshot), "Sanity Check");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    39
  // Use placement operator new to initialize static data area.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    40
  ::new ((void*)_snapshot) VirtualMemorySnapshot();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    41
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    42
49968
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
    43
void VirtualMemorySummary::snapshot(VirtualMemorySnapshot* s) {
54292
c31faeacf00a 8204552: NMT: Separate thread stack tracking from virtual memory tracking
zgu
parents: 49980
diff changeset
    44
  // Only if thread stack is backed by virtual memory
c31faeacf00a 8204552: NMT: Separate thread stack tracking from virtual memory tracking
zgu
parents: 49980
diff changeset
    45
  if (ThreadStackTracker::track_as_vm()) {
c31faeacf00a 8204552: NMT: Separate thread stack tracking from virtual memory tracking
zgu
parents: 49980
diff changeset
    46
    // Snapshot current thread stacks
c31faeacf00a 8204552: NMT: Separate thread stack tracking from virtual memory tracking
zgu
parents: 49980
diff changeset
    47
    VirtualMemoryTracker::snapshot_thread_stacks();
c31faeacf00a 8204552: NMT: Separate thread stack tracking from virtual memory tracking
zgu
parents: 49980
diff changeset
    48
    as_snapshot()->copy_to(s);
c31faeacf00a 8204552: NMT: Separate thread stack tracking from virtual memory tracking
zgu
parents: 49980
diff changeset
    49
  }
49968
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
    50
}
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
    51
26136
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
    52
SortedLinkedList<ReservedMemoryRegion, compare_reserved_region_base>* VirtualMemoryTracker::_reserved_regions;
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    53
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    54
int compare_committed_region(const CommittedMemoryRegion& r1, const CommittedMemoryRegion& r2) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    55
  return r1.compare(r2);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    56
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    57
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    58
int compare_reserved_region_base(const ReservedMemoryRegion& r1, const ReservedMemoryRegion& r2) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    59
  return r1.compare(r2);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    60
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    61
49033
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    62
static bool is_mergeable_with(CommittedMemoryRegion* rgn, address addr, size_t size, const NativeCallStack& stack) {
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    63
  return rgn->adjacent_to(addr, size) && rgn->call_stack()->equals(stack);
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    64
}
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    65
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    66
static bool is_same_as(CommittedMemoryRegion* rgn, address addr, size_t size, const NativeCallStack& stack) {
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    67
  // It would have made sense to use rgn->equals(...), but equals returns true for overlapping regions.
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    68
  return rgn->same_region(addr, size) && rgn->call_stack()->equals(stack);
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    69
}
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    70
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    71
static LinkedListNode<CommittedMemoryRegion>* find_preceding_node_from(LinkedListNode<CommittedMemoryRegion>* from, address addr) {
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    72
  LinkedListNode<CommittedMemoryRegion>* preceding = NULL;
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    73
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    74
  for (LinkedListNode<CommittedMemoryRegion>* node = from; node != NULL; node = node->next()) {
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    75
    CommittedMemoryRegion* rgn = node->data();
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    76
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    77
    // We searched past the region start.
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    78
    if (rgn->end() > addr) {
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    79
      break;
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    80
    }
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    81
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    82
    preceding = node;
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    83
  }
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    84
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    85
  return preceding;
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    86
}
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    87
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    88
static bool try_merge_with(LinkedListNode<CommittedMemoryRegion>* node, address addr, size_t size, const NativeCallStack& stack) {
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    89
  if (node != NULL) {
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    90
    CommittedMemoryRegion* rgn = node->data();
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    91
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    92
    if (is_mergeable_with(rgn, addr, size, stack)) {
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    93
      rgn->expand_region(addr, size);
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    94
      return true;
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    95
    }
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    96
  }
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    97
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    98
  return false;
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
    99
}
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   100
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   101
static bool try_merge_with(LinkedListNode<CommittedMemoryRegion>* node, LinkedListNode<CommittedMemoryRegion>* other) {
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   102
  if (other == NULL) {
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   103
    return false;
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   104
  }
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   105
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   106
  CommittedMemoryRegion* rgn = other->data();
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   107
  return try_merge_with(node, rgn->base(), rgn->size(), *rgn->call_stack());
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   108
}
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   109
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   110
bool ReservedMemoryRegion::add_committed_region(address addr, size_t size, const NativeCallStack& stack) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   111
  assert(addr != NULL, "Invalid address");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   112
  assert(size > 0, "Invalid size");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   113
  assert(contain_region(addr, size), "Not contain this region");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   114
49033
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   115
  // Find the region that fully precedes the [addr, addr + size) region.
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   116
  LinkedListNode<CommittedMemoryRegion>* prev = find_preceding_node_from(_committed_regions.head(), addr);
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   117
  LinkedListNode<CommittedMemoryRegion>* next = (prev != NULL ? prev->next() : _committed_regions.head());
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   118
49033
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   119
  if (next != NULL) {
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   120
    // Ignore request if region already exists.
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   121
    if (is_same_as(next->data(), addr, size, stack)) {
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   122
      return true;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   123
    }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   124
49033
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   125
    // The new region is after prev, and either overlaps with the
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   126
    // next region (and maybe more regions), or overlaps with no region.
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   127
    if (next->data()->overlap_region(addr, size)) {
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   128
      // Remove _all_ overlapping regions, and parts of regions,
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   129
      // in preparation for the addition of this new region.
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   130
      remove_uncommitted_region(addr, size);
38935
f7427b0e0d7c 8138705: Kitchen sink stress test fails
mockner
parents: 35483
diff changeset
   131
49033
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   132
      // The remove could have split a region into two and created a
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   133
      // new prev region. Need to reset the prev and next pointers.
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   134
      prev = find_preceding_node_from((prev != NULL ? prev : _committed_regions.head()), addr);
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   135
      next = (prev != NULL ? prev->next() : _committed_regions.head());
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   136
    }
38935
f7427b0e0d7c 8138705: Kitchen sink stress test fails
mockner
parents: 35483
diff changeset
   137
  }
f7427b0e0d7c 8138705: Kitchen sink stress test fails
mockner
parents: 35483
diff changeset
   138
49033
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   139
  // At this point the previous overlapping regions have been
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   140
  // cleared, and the full region is guaranteed to be inserted.
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   141
  VirtualMemorySummary::record_committed_memory(size, flag());
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   142
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   143
  // Try to merge with prev and possibly next.
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   144
  if (try_merge_with(prev, addr, size, stack)) {
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   145
    if (try_merge_with(prev, next)) {
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   146
      // prev was expanded to contain the new region
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   147
      // and next, need to remove next from the list
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   148
      _committed_regions.remove_after(prev);
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   149
    }
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   150
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   151
    return true;
48818
ec4a84ba2aaf 8196372: [BACKOUT] NMT: add_committed_regions doesn't merge succeeding regions
jwilhelm
parents: 48815
diff changeset
   152
  }
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   153
49033
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   154
  // Didn't merge with prev, try with next.
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   155
  if (try_merge_with(next, addr, size, stack)) {
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   156
    return true;
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   157
  }
49033
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   158
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   159
  // Couldn't merge with any regions - create a new region.
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   160
  return add_committed_region(CommittedMemoryRegion(addr, size, stack));
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   161
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   162
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   163
bool ReservedMemoryRegion::remove_uncommitted_region(LinkedListNode<CommittedMemoryRegion>* node,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   164
  address addr, size_t size) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   165
  assert(addr != NULL, "Invalid address");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   166
  assert(size > 0, "Invalid size");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   167
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   168
  CommittedMemoryRegion* rgn = node->data();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   169
  assert(rgn->contain_region(addr, size), "Has to be contained");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   170
  assert(!rgn->same_region(addr, size), "Can not be the same region");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   171
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   172
  if (rgn->base() == addr ||
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   173
      rgn->end() == addr + size) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   174
    rgn->exclude_region(addr, size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   175
    return true;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   176
  } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   177
    // split this region
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   178
    address top =rgn->end();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   179
    // use this region for lower part
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   180
    size_t exclude_size = rgn->end() - addr;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   181
    rgn->exclude_region(addr, exclude_size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   182
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   183
    // higher part
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   184
    address high_base = addr + size;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   185
    size_t  high_size = top - high_base;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   186
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   187
    CommittedMemoryRegion high_rgn(high_base, high_size, *rgn->call_stack());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   188
    LinkedListNode<CommittedMemoryRegion>* high_node = _committed_regions.add(high_rgn);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   189
    assert(high_node == NULL || node->next() == high_node, "Should be right after");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   190
    return (high_node != NULL);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   191
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   192
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   193
  return false;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   194
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   195
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   196
bool ReservedMemoryRegion::remove_uncommitted_region(address addr, size_t sz) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   197
  assert(addr != NULL, "Invalid address");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   198
  assert(sz > 0, "Invalid size");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   199
49033
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   200
  CommittedMemoryRegion del_rgn(addr, sz, *call_stack());
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   201
  address end = addr + sz;
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   202
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   203
  LinkedListNode<CommittedMemoryRegion>* head = _committed_regions.head();
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   204
  LinkedListNode<CommittedMemoryRegion>* prev = NULL;
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   205
  CommittedMemoryRegion* crgn;
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   206
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   207
  while (head != NULL) {
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   208
    crgn = head->data();
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   209
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   210
    if (crgn->same_region(addr, sz)) {
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   211
      VirtualMemorySummary::record_uncommitted_memory(crgn->size(), flag());
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   212
      _committed_regions.remove_after(prev);
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   213
      return true;
49033
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   214
    }
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   215
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   216
    // del_rgn contains crgn
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   217
    if (del_rgn.contain_region(crgn->base(), crgn->size())) {
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   218
      VirtualMemorySummary::record_uncommitted_memory(crgn->size(), flag());
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   219
      head = head->next();
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   220
      _committed_regions.remove_after(prev);
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   221
      continue;  // don't update head or prev
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   222
    }
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   223
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   224
    // Found addr in the current crgn. There are 2 subcases:
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   225
    if (crgn->contain_address(addr)) {
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   226
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   227
      // (1) Found addr+size in current crgn as well. (del_rgn is contained in crgn)
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   228
      if (crgn->contain_address(end - 1)) {
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   229
        VirtualMemorySummary::record_uncommitted_memory(sz, flag());
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   230
        return remove_uncommitted_region(head, addr, sz); // done!
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   231
      } else {
49033
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   232
        // (2) Did not find del_rgn's end in crgn.
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   233
        size_t size = crgn->end() - del_rgn.base();
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   234
        crgn->exclude_region(addr, size);
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   235
        VirtualMemorySummary::record_uncommitted_memory(size, flag());
38935
f7427b0e0d7c 8138705: Kitchen sink stress test fails
mockner
parents: 35483
diff changeset
   236
      }
f7427b0e0d7c 8138705: Kitchen sink stress test fails
mockner
parents: 35483
diff changeset
   237
49033
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   238
    } else if (crgn->contain_address(end - 1)) {
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   239
      // Found del_rgn's end, but not its base addr.
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   240
      size_t size = del_rgn.end() - crgn->base();
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   241
      crgn->exclude_region(crgn->base(), size);
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   242
      VirtualMemorySummary::record_uncommitted_memory(size, flag());
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   243
      return true;  // should be done if the list is sorted properly!
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   244
    }
38935
f7427b0e0d7c 8138705: Kitchen sink stress test fails
mockner
parents: 35483
diff changeset
   245
49033
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   246
    prev = head;
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   247
    head = head->next();
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   248
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   249
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   250
  return true;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   251
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   252
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   253
void ReservedMemoryRegion::move_committed_regions(address addr, ReservedMemoryRegion& rgn) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   254
  assert(addr != NULL, "Invalid address");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   255
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   256
  // split committed regions
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   257
  LinkedListNode<CommittedMemoryRegion>* head =
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   258
    _committed_regions.head();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   259
  LinkedListNode<CommittedMemoryRegion>* prev = NULL;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   260
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   261
  while (head != NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   262
    if (head->data()->base() >= addr) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   263
      break;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   264
    }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   265
    prev = head;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   266
    head = head->next();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   267
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   268
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   269
  if (head != NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   270
    if (prev != NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   271
      prev->set_next(head->next());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   272
    } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   273
      _committed_regions.set_head(NULL);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   274
    }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   275
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   276
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   277
  rgn._committed_regions.set_head(head);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   278
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   279
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   280
size_t ReservedMemoryRegion::committed_size() const {
49033
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   281
  size_t committed = 0;
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   282
  LinkedListNode<CommittedMemoryRegion>* head =
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   283
    _committed_regions.head();
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   284
  while (head != NULL) {
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   285
    committed += head->data()->size();
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   286
    head = head->next();
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   287
  }
49033
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   288
  return committed;
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   289
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   290
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   291
void ReservedMemoryRegion::set_flag(MEMFLAGS f) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   292
  assert((flag() == mtNone || flag() == f), "Overwrite memory type");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   293
  if (flag() != f) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   294
    VirtualMemorySummary::move_reserved_memory(flag(), f, size());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   295
    VirtualMemorySummary::move_committed_memory(flag(), f, committed_size());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   296
    _flag = f;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   297
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   298
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   299
49968
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   300
address ReservedMemoryRegion::thread_stack_uncommitted_bottom() const {
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   301
  assert(flag() == mtThreadStack, "Only for thread stack");
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   302
  LinkedListNode<CommittedMemoryRegion>* head = _committed_regions.head();
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   303
  address bottom = base();
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   304
  address top = base() + size();
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   305
  while (head != NULL) {
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   306
    address committed_top = head->data()->base() + head->data()->size();
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   307
    if (committed_top < top) {
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   308
      // committed stack guard pages, skip them
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   309
      bottom = head->data()->base() + head->data()->size();
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   310
      head = head->next();
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   311
    } else {
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   312
      assert(top == committed_top, "Sanity");
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   313
      break;
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   314
    }
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   315
  }
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   316
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   317
  return bottom;
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   318
}
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   319
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   320
bool VirtualMemoryTracker::initialize(NMT_TrackingLevel level) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   321
  if (level >= NMT_summary) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   322
    VirtualMemorySummary::initialize();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   323
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   324
  return true;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   325
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   326
26136
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   327
bool VirtualMemoryTracker::late_initialize(NMT_TrackingLevel level) {
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   328
  if (level >= NMT_summary) {
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   329
    _reserved_regions = new (std::nothrow, ResourceObj::C_HEAP, mtNMT)
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   330
      SortedLinkedList<ReservedMemoryRegion, compare_reserved_region_base>();
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   331
    return (_reserved_regions != NULL);
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   332
  }
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   333
  return true;
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   334
}
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   335
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   336
bool VirtualMemoryTracker::add_reserved_region(address base_addr, size_t size,
49033
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   337
    const NativeCallStack& stack, MEMFLAGS flag) {
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   338
  assert(base_addr != NULL, "Invalid address");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   339
  assert(size > 0, "Invalid size");
26136
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   340
  assert(_reserved_regions != NULL, "Sanity check");
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   341
  ReservedMemoryRegion  rgn(base_addr, size, stack, flag);
26136
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   342
  ReservedMemoryRegion* reserved_rgn = _reserved_regions->find(rgn);
49033
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   343
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   344
  if (reserved_rgn == NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   345
    VirtualMemorySummary::record_reserved_memory(size, flag);
49033
3acc342c0738 8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents: 48818
diff changeset
   346
    return _reserved_regions->add(rgn) != NULL;
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   347
  } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   348
    if (reserved_rgn->same_region(base_addr, size)) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   349
      reserved_rgn->set_call_stack(stack);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   350
      reserved_rgn->set_flag(flag);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   351
      return true;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   352
    } else if (reserved_rgn->adjacent_to(base_addr, size)) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   353
      VirtualMemorySummary::record_reserved_memory(size, flag);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   354
      reserved_rgn->expand_region(base_addr, size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   355
      reserved_rgn->set_call_stack(stack);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   356
      return true;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   357
    } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   358
      // Overlapped reservation.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   359
      // It can happen when the regions are thread stacks, as JNI
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   360
      // thread does not detach from VM before exits, and leads to
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   361
      // leak JavaThread object
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   362
      if (reserved_rgn->flag() == mtThreadStack) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   363
        guarantee(!CheckJNICalls, "Attached JNI thread exited without being detached");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   364
        // Overwrite with new region
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   365
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   366
        // Release old region
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   367
        VirtualMemorySummary::record_uncommitted_memory(reserved_rgn->committed_size(), reserved_rgn->flag());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   368
        VirtualMemorySummary::record_released_memory(reserved_rgn->size(), reserved_rgn->flag());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   369
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   370
        // Add new region
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   371
        VirtualMemorySummary::record_reserved_memory(rgn.size(), flag);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   372
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   373
        *reserved_rgn = rgn;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   374
        return true;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   375
      }
26146
ce3202564442 8055061: assert at share/vm/services/virtualMemoryTracker.cpp:332 Error: ShouldNotReachHere() when running NMT tests
zgu
parents: 26136
diff changeset
   376
ce3202564442 8055061: assert at share/vm/services/virtualMemoryTracker.cpp:332 Error: ShouldNotReachHere() when running NMT tests
zgu
parents: 26136
diff changeset
   377
      // CDS mapping region.
ce3202564442 8055061: assert at share/vm/services/virtualMemoryTracker.cpp:332 Error: ShouldNotReachHere() when running NMT tests
zgu
parents: 26136
diff changeset
   378
      // CDS reserves the whole region for mapping CDS archive, then maps each section into the region.
ce3202564442 8055061: assert at share/vm/services/virtualMemoryTracker.cpp:332 Error: ShouldNotReachHere() when running NMT tests
zgu
parents: 26136
diff changeset
   379
      // NMT reports CDS as a whole.
ce3202564442 8055061: assert at share/vm/services/virtualMemoryTracker.cpp:332 Error: ShouldNotReachHere() when running NMT tests
zgu
parents: 26136
diff changeset
   380
      if (reserved_rgn->flag() == mtClassShared) {
ce3202564442 8055061: assert at share/vm/services/virtualMemoryTracker.cpp:332 Error: ShouldNotReachHere() when running NMT tests
zgu
parents: 26136
diff changeset
   381
        assert(reserved_rgn->contain_region(base_addr, size), "Reserved CDS region should contain this mapping region");
ce3202564442 8055061: assert at share/vm/services/virtualMemoryTracker.cpp:332 Error: ShouldNotReachHere() when running NMT tests
zgu
parents: 26136
diff changeset
   382
        return true;
ce3202564442 8055061: assert at share/vm/services/virtualMemoryTracker.cpp:332 Error: ShouldNotReachHere() when running NMT tests
zgu
parents: 26136
diff changeset
   383
      }
ce3202564442 8055061: assert at share/vm/services/virtualMemoryTracker.cpp:332 Error: ShouldNotReachHere() when running NMT tests
zgu
parents: 26136
diff changeset
   384
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 27162
diff changeset
   385
      // Mapped CDS string region.
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 27162
diff changeset
   386
      // The string region(s) is part of the java heap.
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 27162
diff changeset
   387
      if (reserved_rgn->flag() == mtJavaHeap) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 27162
diff changeset
   388
        assert(reserved_rgn->contain_region(base_addr, size), "Reserved heap region should contain this mapping region");
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 27162
diff changeset
   389
        return true;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 27162
diff changeset
   390
      }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 27162
diff changeset
   391
26146
ce3202564442 8055061: assert at share/vm/services/virtualMemoryTracker.cpp:332 Error: ShouldNotReachHere() when running NMT tests
zgu
parents: 26136
diff changeset
   392
      ShouldNotReachHere();
ce3202564442 8055061: assert at share/vm/services/virtualMemoryTracker.cpp:332 Error: ShouldNotReachHere() when running NMT tests
zgu
parents: 26136
diff changeset
   393
      return false;
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   394
    }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   395
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   396
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   397
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   398
void VirtualMemoryTracker::set_reserved_region_type(address addr, MEMFLAGS flag) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   399
  assert(addr != NULL, "Invalid address");
26136
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   400
  assert(_reserved_regions != NULL, "Sanity check");
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   401
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   402
  ReservedMemoryRegion   rgn(addr, 1);
26136
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   403
  ReservedMemoryRegion*  reserved_rgn = _reserved_regions->find(rgn);
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   404
  if (reserved_rgn != NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   405
    assert(reserved_rgn->contain_address(addr), "Containment");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   406
    if (reserved_rgn->flag() != flag) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   407
      assert(reserved_rgn->flag() == mtNone, "Overwrite memory type");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   408
      reserved_rgn->set_flag(flag);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   409
    }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   410
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   411
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   412
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   413
bool VirtualMemoryTracker::add_committed_region(address addr, size_t size,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   414
  const NativeCallStack& stack) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   415
  assert(addr != NULL, "Invalid address");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   416
  assert(size > 0, "Invalid size");
26136
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   417
  assert(_reserved_regions != NULL, "Sanity check");
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   418
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   419
  ReservedMemoryRegion  rgn(addr, size);
26136
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   420
  ReservedMemoryRegion* reserved_rgn = _reserved_regions->find(rgn);
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   421
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   422
  assert(reserved_rgn != NULL, "No reserved region");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   423
  assert(reserved_rgn->contain_region(addr, size), "Not completely contained");
38935
f7427b0e0d7c 8138705: Kitchen sink stress test fails
mockner
parents: 35483
diff changeset
   424
  bool result = reserved_rgn->add_committed_region(addr, size, stack);
f7427b0e0d7c 8138705: Kitchen sink stress test fails
mockner
parents: 35483
diff changeset
   425
  return result;
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   426
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   427
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   428
bool VirtualMemoryTracker::remove_uncommitted_region(address addr, size_t size) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   429
  assert(addr != NULL, "Invalid address");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   430
  assert(size > 0, "Invalid size");
26136
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   431
  assert(_reserved_regions != NULL, "Sanity check");
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   432
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   433
  ReservedMemoryRegion  rgn(addr, size);
26136
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   434
  ReservedMemoryRegion* reserved_rgn = _reserved_regions->find(rgn);
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   435
  assert(reserved_rgn != NULL, "No reserved region");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   436
  assert(reserved_rgn->contain_region(addr, size), "Not completely contained");
38935
f7427b0e0d7c 8138705: Kitchen sink stress test fails
mockner
parents: 35483
diff changeset
   437
  bool result = reserved_rgn->remove_uncommitted_region(addr, size);
f7427b0e0d7c 8138705: Kitchen sink stress test fails
mockner
parents: 35483
diff changeset
   438
  return result;
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   439
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   440
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   441
bool VirtualMemoryTracker::remove_released_region(address addr, size_t size) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   442
  assert(addr != NULL, "Invalid address");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   443
  assert(size > 0, "Invalid size");
26136
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   444
  assert(_reserved_regions != NULL, "Sanity check");
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   445
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   446
  ReservedMemoryRegion  rgn(addr, size);
26136
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   447
  ReservedMemoryRegion* reserved_rgn = _reserved_regions->find(rgn);
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   448
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   449
  assert(reserved_rgn != NULL, "No reserved region");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   450
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   451
  // uncommit regions within the released region
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   452
  if (!reserved_rgn->remove_uncommitted_region(addr, size)) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   453
    return false;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   454
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   455
35483
d9cf65a7fd2d 8146523: VirtualMemoryTracker::remove_released_region double count unmapped CDS shared memory
jiangli
parents: 33127
diff changeset
   456
  if (reserved_rgn->flag() == mtClassShared &&
d9cf65a7fd2d 8146523: VirtualMemoryTracker::remove_released_region double count unmapped CDS shared memory
jiangli
parents: 33127
diff changeset
   457
      reserved_rgn->contain_region(addr, size) &&
d9cf65a7fd2d 8146523: VirtualMemoryTracker::remove_released_region double count unmapped CDS shared memory
jiangli
parents: 33127
diff changeset
   458
      !reserved_rgn->same_region(addr, size)) {
d9cf65a7fd2d 8146523: VirtualMemoryTracker::remove_released_region double count unmapped CDS shared memory
jiangli
parents: 33127
diff changeset
   459
    // This is an unmapped CDS region, which is part of the reserved shared
d9cf65a7fd2d 8146523: VirtualMemoryTracker::remove_released_region double count unmapped CDS shared memory
jiangli
parents: 33127
diff changeset
   460
    // memory region.
d9cf65a7fd2d 8146523: VirtualMemoryTracker::remove_released_region double count unmapped CDS shared memory
jiangli
parents: 33127
diff changeset
   461
    // See special handling in VirtualMemoryTracker::add_reserved_region also.
d9cf65a7fd2d 8146523: VirtualMemoryTracker::remove_released_region double count unmapped CDS shared memory
jiangli
parents: 33127
diff changeset
   462
    return true;
d9cf65a7fd2d 8146523: VirtualMemoryTracker::remove_released_region double count unmapped CDS shared memory
jiangli
parents: 33127
diff changeset
   463
  }
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   464
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   465
  VirtualMemorySummary::record_released_memory(size, reserved_rgn->flag());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   466
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   467
  if (reserved_rgn->same_region(addr, size)) {
26136
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   468
    return _reserved_regions->remove(rgn);
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   469
  } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   470
    assert(reserved_rgn->contain_region(addr, size), "Not completely contained");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   471
    if (reserved_rgn->base() == addr ||
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   472
        reserved_rgn->end() == addr + size) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   473
        reserved_rgn->exclude_region(addr, size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   474
      return true;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   475
    } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   476
      address top = reserved_rgn->end();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   477
      address high_base = addr + size;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   478
      ReservedMemoryRegion high_rgn(high_base, top - high_base,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   479
        *reserved_rgn->call_stack(), reserved_rgn->flag());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   480
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   481
      // use original region for lower region
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   482
      reserved_rgn->exclude_region(addr, top - addr);
26136
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   483
      LinkedListNode<ReservedMemoryRegion>* new_rgn = _reserved_regions->add(high_rgn);
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   484
      if (new_rgn == NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   485
        return false;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   486
      } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   487
        reserved_rgn->move_committed_regions(addr, *new_rgn->data());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   488
        return true;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   489
      }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   490
    }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   491
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   492
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   493
49968
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   494
// Iterate the range, find committed region within its bound.
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   495
class RegionIterator : public StackObj {
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   496
private:
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   497
  const address _start;
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   498
  const size_t  _size;
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   499
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   500
  address _current_start;
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   501
  size_t  _current_size;
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   502
public:
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   503
  RegionIterator(address start, size_t size) :
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   504
    _start(start), _size(size), _current_start(start), _current_size(size) {
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   505
  }
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   506
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   507
  // return true if committed region is found
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   508
  bool next_committed(address& start, size_t& size);
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   509
private:
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   510
  address end() const { return _start + _size; }
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   511
};
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   512
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   513
bool RegionIterator::next_committed(address& committed_start, size_t& committed_size) {
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   514
  if (end() <= _current_start) return false;
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   515
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   516
  const size_t page_sz = os::vm_page_size();
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   517
  assert(_current_start + _current_size == end(), "Must be");
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   518
  if (os::committed_in_range(_current_start, _current_size, committed_start, committed_size)) {
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   519
    assert(committed_start != NULL, "Must be");
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   520
    assert(committed_size > 0 && is_aligned(committed_size, os::vm_page_size()), "Must be");
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   521
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   522
    size_t remaining_size = (_current_start + _current_size) - (committed_start + committed_size);
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   523
    _current_start = committed_start + committed_size;
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   524
    _current_size = remaining_size;
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   525
    return true;
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   526
  } else {
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   527
    return false;
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   528
  }
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   529
}
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   530
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   531
// Walk all known thread stacks, snapshot their committed ranges.
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   532
class SnapshotThreadStackWalker : public VirtualMemoryWalker {
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   533
public:
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   534
  SnapshotThreadStackWalker() {}
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   535
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   536
  bool do_allocation_site(const ReservedMemoryRegion* rgn) {
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   537
    if (rgn->flag() == mtThreadStack) {
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   538
      address stack_bottom = rgn->thread_stack_uncommitted_bottom();
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   539
      address committed_start;
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   540
      size_t  committed_size;
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   541
      size_t stack_size = rgn->base() + rgn->size() - stack_bottom;
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   542
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   543
      ReservedMemoryRegion* region = const_cast<ReservedMemoryRegion*>(rgn);
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   544
      NativeCallStack ncs; // empty stack
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   545
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   546
      RegionIterator itr(stack_bottom, stack_size);
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   547
      DEBUG_ONLY(bool found_stack = false;)
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   548
      while (itr.next_committed(committed_start, committed_size)) {
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   549
        assert(committed_start != NULL, "Should not be null");
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   550
        assert(committed_size > 0, "Should not be 0");
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   551
        region->add_committed_region(committed_start, committed_size, ncs);
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   552
        DEBUG_ONLY(found_stack = true;)
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   553
      }
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   554
#ifdef ASSERT
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   555
      if (!found_stack) {
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   556
        log_debug(thread)("Thread exited without proper cleanup, may leak thread object");
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   557
      }
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   558
#endif
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   559
    }
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   560
    return true;
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   561
  }
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   562
};
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   563
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   564
void VirtualMemoryTracker::snapshot_thread_stacks() {
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   565
  SnapshotThreadStackWalker walker;
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   566
  walk_virtual_memory(&walker);
33a76b934213 8199067: [REDO] NMT: Enhance thread stack tracking
zgu
parents: 49389
diff changeset
   567
}
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   568
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   569
bool VirtualMemoryTracker::walk_virtual_memory(VirtualMemoryWalker* walker) {
26136
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   570
  assert(_reserved_regions != NULL, "Sanity check");
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   571
  ThreadCritical tc;
27162
0a4a7276949b 8059100: SIGSEGV VirtualMemoryTracker::remove_released_region
coleenp
parents: 26149
diff changeset
   572
  // Check that the _reserved_regions haven't been deleted.
0a4a7276949b 8059100: SIGSEGV VirtualMemoryTracker::remove_released_region
coleenp
parents: 26149
diff changeset
   573
  if (_reserved_regions != NULL) {
0a4a7276949b 8059100: SIGSEGV VirtualMemoryTracker::remove_released_region
coleenp
parents: 26149
diff changeset
   574
    LinkedListNode<ReservedMemoryRegion>* head = _reserved_regions->head();
0a4a7276949b 8059100: SIGSEGV VirtualMemoryTracker::remove_released_region
coleenp
parents: 26149
diff changeset
   575
    while (head != NULL) {
0a4a7276949b 8059100: SIGSEGV VirtualMemoryTracker::remove_released_region
coleenp
parents: 26149
diff changeset
   576
      const ReservedMemoryRegion* rgn = head->peek();
0a4a7276949b 8059100: SIGSEGV VirtualMemoryTracker::remove_released_region
coleenp
parents: 26149
diff changeset
   577
      if (!walker->do_allocation_site(rgn)) {
0a4a7276949b 8059100: SIGSEGV VirtualMemoryTracker::remove_released_region
coleenp
parents: 26149
diff changeset
   578
        return false;
0a4a7276949b 8059100: SIGSEGV VirtualMemoryTracker::remove_released_region
coleenp
parents: 26149
diff changeset
   579
      }
0a4a7276949b 8059100: SIGSEGV VirtualMemoryTracker::remove_released_region
coleenp
parents: 26149
diff changeset
   580
      head = head->next();
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   581
    }
27162
0a4a7276949b 8059100: SIGSEGV VirtualMemoryTracker::remove_released_region
coleenp
parents: 26149
diff changeset
   582
   }
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   583
  return true;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   584
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   585
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   586
// Transition virtual memory tracking level.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   587
bool VirtualMemoryTracker::transition(NMT_TrackingLevel from, NMT_TrackingLevel to) {
27162
0a4a7276949b 8059100: SIGSEGV VirtualMemoryTracker::remove_released_region
coleenp
parents: 26149
diff changeset
   588
  assert (from != NMT_minimal, "cannot convert from the lowest tracking level to anything");
0a4a7276949b 8059100: SIGSEGV VirtualMemoryTracker::remove_released_region
coleenp
parents: 26149
diff changeset
   589
  if (to == NMT_minimal) {
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   590
    assert(from == NMT_summary || from == NMT_detail, "Just check");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   591
    // Clean up virtual memory tracking data structures.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   592
    ThreadCritical tc;
27162
0a4a7276949b 8059100: SIGSEGV VirtualMemoryTracker::remove_released_region
coleenp
parents: 26149
diff changeset
   593
    // Check for potential race with other thread calling transition
26136
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   594
    if (_reserved_regions != NULL) {
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   595
      delete _reserved_regions;
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   596
      _reserved_regions = NULL;
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   597
    }
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   598
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   599
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   600
  return true;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   601
}
47553
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   602
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   603
// Metaspace Support
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   604
MetaspaceSnapshot::MetaspaceSnapshot() {
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   605
  for (int index = (int)Metaspace::ClassType; index < (int)Metaspace::MetadataTypeCount; index ++) {
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   606
    Metaspace::MetadataType type = (Metaspace::MetadataType)index;
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   607
    assert_valid_metadata_type(type);
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   608
    _reserved_in_bytes[type]  = 0;
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   609
    _committed_in_bytes[type] = 0;
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   610
    _used_in_bytes[type]      = 0;
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   611
    _free_in_bytes[type]      = 0;
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   612
  }
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   613
}
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   614
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   615
void MetaspaceSnapshot::snapshot(Metaspace::MetadataType type, MetaspaceSnapshot& mss) {
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   616
  assert_valid_metadata_type(type);
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   617
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49349
diff changeset
   618
  mss._reserved_in_bytes[type]   = MetaspaceUtils::reserved_bytes(type);
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49349
diff changeset
   619
  mss._committed_in_bytes[type]  = MetaspaceUtils::committed_bytes(type);
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49349
diff changeset
   620
  mss._used_in_bytes[type]       = MetaspaceUtils::used_bytes(type);
47553
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   621
49389
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49349
diff changeset
   622
  size_t free_in_bytes = (MetaspaceUtils::capacity_bytes(type) - MetaspaceUtils::used_bytes(type))
9ef2eee8ca7c 8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents: 49349
diff changeset
   623
                       + MetaspaceUtils::free_chunks_total_bytes(type)
49980
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents: 49968
diff changeset
   624
                       + MetaspaceUtils::free_in_vs_bytes(type);
47553
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   625
  mss._free_in_bytes[type] = free_in_bytes;
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   626
}
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   627
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   628
void MetaspaceSnapshot::snapshot(MetaspaceSnapshot& mss) {
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   629
  snapshot(Metaspace::ClassType, mss);
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   630
  if (Metaspace::using_class_space()) {
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   631
    snapshot(Metaspace::NonClassType, mss);
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   632
  }
5d20359dd938 8186770: NMT: Report metadata information in NMT summary
zgu
parents: 47216
diff changeset
   633
}