hotspot/src/share/vm/services/virtualMemoryTracker.hpp
author stefank
Fri, 13 Feb 2015 14:37:35 +0100
changeset 29081 c61eb4914428
parent 27162 0a4a7276949b
child 38935 f7427b0e0d7c
permissions -rw-r--r--
8072911: Remove includes of oop.inline.hpp from .hpp files Reviewed-by: brutisso, coleenp, jwilhelm, simonis, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
     1
/*
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
     2
 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
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
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    25
#ifndef SHARE_VM_SERVICES_VIRTUAL_MEMORY_TRACKER_HPP
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    26
#define SHARE_VM_SERVICES_VIRTUAL_MEMORY_TRACKER_HPP
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    27
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    28
#if INCLUDE_NMT
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    29
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    30
#include "memory/allocation.hpp"
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    31
#include "services/allocationSite.hpp"
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    32
#include "services/nmtCommon.hpp"
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    33
#include "utilities/linkedlist.hpp"
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    34
#include "utilities/nativeCallStack.hpp"
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    35
#include "utilities/ostream.hpp"
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    36
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    37
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    38
/*
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    39
 * Virtual memory counter
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    40
 */
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    41
class VirtualMemory VALUE_OBJ_CLASS_SPEC {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    42
 private:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    43
  size_t     _reserved;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    44
  size_t     _committed;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    45
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    46
 public:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    47
  VirtualMemory() : _reserved(0), _committed(0) { }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    48
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    49
  inline void reserve_memory(size_t sz) { _reserved += sz; }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    50
  inline void commit_memory (size_t sz) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    51
    _committed += sz;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    52
    assert(_committed <= _reserved, "Sanity check");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    53
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    54
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    55
  inline void release_memory (size_t sz) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    56
    assert(_reserved >= sz, "Negative amount");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    57
    _reserved -= sz;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    58
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    59
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    60
  inline void uncommit_memory(size_t sz) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    61
    assert(_committed >= sz, "Negative amount");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    62
    _committed -= sz;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    63
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    64
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    65
  inline size_t reserved()  const { return _reserved;  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    66
  inline size_t committed() const { return _committed; }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    67
};
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    68
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    69
// Virtual memory allocation site, keeps track where the virtual memory is reserved.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    70
class VirtualMemoryAllocationSite : public AllocationSite<VirtualMemory> {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    71
 public:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    72
  VirtualMemoryAllocationSite(const NativeCallStack& stack) :
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    73
    AllocationSite<VirtualMemory>(stack) { }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    74
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    75
  inline void reserve_memory(size_t sz)  { data()->reserve_memory(sz);  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    76
  inline void commit_memory (size_t sz)  { data()->commit_memory(sz);   }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    77
  inline void uncommit_memory(size_t sz) { data()->uncommit_memory(sz); }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    78
  inline void release_memory(size_t sz)  { data()->release_memory(sz);  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    79
  inline size_t reserved() const  { return peek()->reserved(); }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    80
  inline size_t committed() const { return peek()->committed(); }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    81
};
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    82
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    83
class VirtualMemorySummary;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    84
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    85
// This class represents a snapshot of virtual memory at a given time.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    86
// The latest snapshot is saved in a static area.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    87
class VirtualMemorySnapshot : public ResourceObj {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    88
  friend class VirtualMemorySummary;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    89
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    90
 private:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    91
  VirtualMemory  _virtual_memory[mt_number_of_types];
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    92
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    93
 public:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    94
  inline VirtualMemory* by_type(MEMFLAGS flag) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    95
    int index = NMTUtil::flag_to_index(flag);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    96
    return &_virtual_memory[index];
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    97
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    98
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    99
  inline VirtualMemory* by_index(int index) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   100
    assert(index >= 0, "Index out of bound");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   101
    assert(index < mt_number_of_types, "Index out of bound");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   102
    return &_virtual_memory[index];
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   103
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   104
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   105
  inline size_t total_reserved() const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   106
    size_t amount = 0;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   107
    for (int index = 0; index < mt_number_of_types; index ++) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   108
      amount += _virtual_memory[index].reserved();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   109
    }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   110
    return amount;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   111
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   112
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   113
  inline size_t total_committed() const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   114
    size_t amount = 0;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   115
    for (int index = 0; index < mt_number_of_types; index ++) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   116
      amount += _virtual_memory[index].committed();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   117
    }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   118
    return amount;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   119
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   120
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   121
  void copy_to(VirtualMemorySnapshot* s) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   122
    for (int index = 0; index < mt_number_of_types; index ++) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   123
      s->_virtual_memory[index] = _virtual_memory[index];
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   124
    }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   125
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   126
};
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   127
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   128
class VirtualMemorySummary : AllStatic {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   129
 public:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   130
  static void initialize();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   131
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   132
  static inline void record_reserved_memory(size_t size, MEMFLAGS flag) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   133
    as_snapshot()->by_type(flag)->reserve_memory(size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   134
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   135
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   136
  static inline void record_committed_memory(size_t size, MEMFLAGS flag) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   137
    as_snapshot()->by_type(flag)->commit_memory(size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   138
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   139
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   140
  static inline void record_uncommitted_memory(size_t size, MEMFLAGS flag) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   141
    as_snapshot()->by_type(flag)->uncommit_memory(size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   142
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   143
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   144
  static inline void record_released_memory(size_t size, MEMFLAGS flag) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   145
    as_snapshot()->by_type(flag)->release_memory(size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   146
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   147
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   148
  // Move virtual memory from one memory type to another.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   149
  // Virtual memory can be reserved before it is associated with a memory type, and tagged
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   150
  // as 'unknown'. Once the memory is tagged, the virtual memory will be moved from 'unknown'
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   151
  // type to specified memory type.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   152
  static inline void move_reserved_memory(MEMFLAGS from, MEMFLAGS to, size_t size) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   153
    as_snapshot()->by_type(from)->release_memory(size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   154
    as_snapshot()->by_type(to)->reserve_memory(size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   155
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   156
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   157
  static inline void move_committed_memory(MEMFLAGS from, MEMFLAGS to, size_t size) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   158
    as_snapshot()->by_type(from)->uncommit_memory(size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   159
    as_snapshot()->by_type(to)->commit_memory(size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   160
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   161
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   162
  static inline void snapshot(VirtualMemorySnapshot* s) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   163
    as_snapshot()->copy_to(s);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   164
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   165
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   166
  static VirtualMemorySnapshot* as_snapshot() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   167
    return (VirtualMemorySnapshot*)_snapshot;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   168
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   169
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   170
 private:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   171
  static size_t _snapshot[CALC_OBJ_SIZE_IN_TYPE(VirtualMemorySnapshot, size_t)];
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   172
};
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   173
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   174
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   175
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   176
/*
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   177
 * A virtual memory region
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   178
 */
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   179
class VirtualMemoryRegion VALUE_OBJ_CLASS_SPEC {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   180
 private:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   181
  address      _base_address;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   182
  size_t       _size;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   183
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   184
 public:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   185
  VirtualMemoryRegion(address addr, size_t size) :
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   186
    _base_address(addr), _size(size) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   187
     assert(addr != NULL, "Invalid address");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   188
     assert(size > 0, "Invalid size");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   189
   }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   190
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   191
  inline address base() const { return _base_address;   }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   192
  inline address end()  const { return base() + size(); }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   193
  inline size_t  size() const { return _size;           }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   194
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   195
  inline bool is_empty() const { return size() == 0; }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   196
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   197
  inline bool contain_address(address addr) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   198
    return (addr >= base() && addr < end());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   199
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   200
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   201
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   202
  inline bool contain_region(address addr, size_t size) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   203
    return contain_address(addr) && contain_address(addr + size - 1);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   204
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   205
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   206
  inline bool same_region(address addr, size_t sz) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   207
    return (addr == base() && sz == size());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   208
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   209
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   210
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   211
  inline bool overlap_region(address addr, size_t sz) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   212
    VirtualMemoryRegion rgn(addr, sz);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   213
    return contain_address(addr) ||
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   214
           contain_address(addr + sz - 1) ||
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   215
           rgn.contain_address(base()) ||
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   216
           rgn.contain_address(end() - 1);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   217
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   218
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   219
  inline bool adjacent_to(address addr, size_t sz) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   220
    return (addr == end() || (addr + sz) == base());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   221
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   222
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   223
  void exclude_region(address addr, size_t sz) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   224
    assert(contain_region(addr, sz), "Not containment");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   225
    assert(addr == base() || addr + sz == end(), "Can not exclude from middle");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   226
    size_t new_size = size() - sz;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   227
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   228
    if (addr == base()) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   229
      set_base(addr + sz);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   230
    }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   231
    set_size(new_size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   232
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   233
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   234
  void expand_region(address addr, size_t sz) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   235
    assert(adjacent_to(addr, sz), "Not adjacent regions");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   236
    if (base() == addr + sz) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   237
      set_base(addr);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   238
    }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   239
    set_size(size() + sz);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   240
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   241
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   242
 protected:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   243
  void set_base(address base) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   244
    assert(base != NULL, "Sanity check");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   245
    _base_address = base;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   246
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   247
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   248
  void set_size(size_t  size) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   249
    assert(size > 0, "Sanity check");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   250
    _size = size;
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
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   254
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   255
class CommittedMemoryRegion : public VirtualMemoryRegion {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   256
 private:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   257
  NativeCallStack  _stack;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   258
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   259
 public:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   260
  CommittedMemoryRegion(address addr, size_t size, const NativeCallStack& stack) :
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   261
    VirtualMemoryRegion(addr, size), _stack(stack) { }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   262
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   263
  inline int compare(const CommittedMemoryRegion& rgn) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   264
    if (overlap_region(rgn.base(), rgn.size()) ||
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   265
        adjacent_to   (rgn.base(), rgn.size())) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   266
      return 0;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   267
    } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   268
      if (base() == rgn.base()) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   269
        return 0;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   270
      } else if (base() > rgn.base()) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   271
        return 1;
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
        return -1;
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
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   278
  inline bool equals(const CommittedMemoryRegion& rgn) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   279
    return compare(rgn) == 0;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   280
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   281
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   282
  inline void set_call_stack(const NativeCallStack& stack) { _stack = stack; }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   283
  inline const NativeCallStack* call_stack() const         { return &_stack; }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   284
};
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   285
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   286
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   287
typedef LinkedListIterator<CommittedMemoryRegion> CommittedRegionIterator;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   288
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   289
int compare_committed_region(const CommittedMemoryRegion&, const CommittedMemoryRegion&);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   290
class ReservedMemoryRegion : public VirtualMemoryRegion {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   291
 private:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   292
  SortedLinkedList<CommittedMemoryRegion, compare_committed_region>
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   293
    _committed_regions;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   294
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   295
  NativeCallStack  _stack;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   296
  MEMFLAGS         _flag;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   297
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   298
  bool             _all_committed;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   299
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   300
 public:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   301
  ReservedMemoryRegion(address base, size_t size, const NativeCallStack& stack,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   302
    MEMFLAGS flag = mtNone) :
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   303
    VirtualMemoryRegion(base, size), _stack(stack), _flag(flag),
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   304
    _all_committed(false) { }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   305
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   306
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   307
  ReservedMemoryRegion(address base, size_t size) :
26144
35e11b657728 8055007: NMT2: emptyStack missing in minimal build
zgu
parents: 25946
diff changeset
   308
    VirtualMemoryRegion(base, size), _stack(NativeCallStack::EMPTY_STACK), _flag(mtNone),
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   309
    _all_committed(false) { }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   310
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   311
  // Copy constructor
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   312
  ReservedMemoryRegion(const ReservedMemoryRegion& rr) :
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   313
    VirtualMemoryRegion(rr.base(), rr.size()) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   314
    *this = rr;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   315
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   316
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   317
  inline void  set_call_stack(const NativeCallStack& stack) { _stack = stack; }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   318
  inline const NativeCallStack* call_stack() const          { return &_stack;  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   319
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   320
  void  set_flag(MEMFLAGS flag);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   321
  inline MEMFLAGS flag() const            { return _flag;  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   322
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   323
  inline int compare(const ReservedMemoryRegion& rgn) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   324
    if (overlap_region(rgn.base(), rgn.size())) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   325
      return 0;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   326
    } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   327
      if (base() == rgn.base()) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   328
        return 0;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   329
      } else if (base() > rgn.base()) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   330
        return 1;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   331
      } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   332
        return -1;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   333
      }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   334
    }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   335
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   336
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   337
  inline bool equals(const ReservedMemoryRegion& rgn) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   338
    return compare(rgn) == 0;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   339
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   340
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   341
  bool    add_committed_region(address addr, size_t size, const NativeCallStack& stack);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   342
  bool    remove_uncommitted_region(address addr, size_t size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   343
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   344
  size_t  committed_size() const;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   345
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   346
  // move committed regions that higher than specified address to
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   347
  // the new region
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   348
  void    move_committed_regions(address addr, ReservedMemoryRegion& rgn);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   349
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   350
  inline bool all_committed() const { return _all_committed; }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   351
  void        set_all_committed(bool b);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   352
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   353
  CommittedRegionIterator iterate_committed_regions() const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   354
    return CommittedRegionIterator(_committed_regions.head());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   355
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   356
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   357
  ReservedMemoryRegion& operator= (const ReservedMemoryRegion& other) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   358
    set_base(other.base());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   359
    set_size(other.size());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   360
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   361
    _stack =         *other.call_stack();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   362
    _flag  =         other.flag();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   363
    _all_committed = other.all_committed();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   364
    if (other.all_committed()) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   365
      set_all_committed(true);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   366
    } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   367
      CommittedRegionIterator itr = other.iterate_committed_regions();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   368
      const CommittedMemoryRegion* rgn = itr.next();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   369
      while (rgn != NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   370
        _committed_regions.add(*rgn);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   371
        rgn = itr.next();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   372
      }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   373
    }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   374
    return *this;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   375
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   376
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   377
 private:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   378
  // The committed region contains the uncommitted region, subtract the uncommitted
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   379
  // region from this committed region
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   380
  bool remove_uncommitted_region(LinkedListNode<CommittedMemoryRegion>* node,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   381
    address addr, size_t sz);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   382
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   383
  bool add_committed_region(const CommittedMemoryRegion& rgn) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   384
    assert(rgn.base() != NULL, "Invalid base address");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   385
    assert(size() > 0, "Invalid size");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   386
    return _committed_regions.add(rgn) != NULL;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   387
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   388
};
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   389
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   390
int compare_reserved_region_base(const ReservedMemoryRegion& r1, const ReservedMemoryRegion& r2);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   391
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   392
class VirtualMemoryWalker : public StackObj {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   393
 public:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   394
   virtual bool do_allocation_site(const ReservedMemoryRegion* rgn) { return false; }
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
// Main class called from MemTracker to track virtual memory allocations, commits and releases.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   398
class VirtualMemoryTracker : AllStatic {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   399
 public:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   400
  static bool initialize(NMT_TrackingLevel level);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   401
26136
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   402
  // Late phase initialization
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   403
  static bool late_initialize(NMT_TrackingLevel level);
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   404
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   405
  static bool add_reserved_region (address base_addr, size_t size, const NativeCallStack& stack,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   406
    MEMFLAGS flag = mtNone, bool all_committed = false);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   407
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   408
  static bool add_committed_region      (address base_addr, size_t size, const NativeCallStack& stack);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   409
  static bool remove_uncommitted_region (address base_addr, size_t size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   410
  static bool remove_released_region    (address base_addr, size_t size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   411
  static void set_reserved_region_type  (address addr, MEMFLAGS flag);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   412
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   413
  // Walk virtual memory data structure for creating baseline, etc.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   414
  static bool walk_virtual_memory(VirtualMemoryWalker* walker);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   415
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   416
  static bool transition(NMT_TrackingLevel from, NMT_TrackingLevel to);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   417
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   418
 private:
26136
254c226e4402 8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents: 25946
diff changeset
   419
  static SortedLinkedList<ReservedMemoryRegion, compare_reserved_region_base>* _reserved_regions;
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   420
};
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   421
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   422
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   423
#endif // INCLUDE_NMT
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   424
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   425
#endif // SHARE_VM_SERVICES_VIRTUAL_MEMORY_TRACKER_HPP