hotspot/src/share/vm/services/virtualMemoryTracker.hpp
author zgu
Thu, 07 Aug 2014 12:18:58 -0700
changeset 25946 1572c9f03fb9
child 26136 254c226e4402
child 26144 35e11b657728
permissions -rw-r--r--
8046598: Scalable Native memory tracking development Summary: Enhance scalability of native memory tracking Reviewed-by: coleenp, ctornqvi, gtriantafill
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
  void reset() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    66
    _reserved  = 0;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    67
    _committed = 0;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    68
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    69
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    70
  inline size_t reserved()  const { return _reserved;  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    71
  inline size_t committed() const { return _committed; }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    72
};
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    73
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    74
// Virtual memory allocation site, keeps track where the virtual memory is reserved.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    75
class VirtualMemoryAllocationSite : public AllocationSite<VirtualMemory> {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    76
 public:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    77
  VirtualMemoryAllocationSite(const NativeCallStack& stack) :
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    78
    AllocationSite<VirtualMemory>(stack) { }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    79
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    80
  inline void reserve_memory(size_t sz)  { data()->reserve_memory(sz);  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    81
  inline void commit_memory (size_t sz)  { data()->commit_memory(sz);   }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    82
  inline void uncommit_memory(size_t sz) { data()->uncommit_memory(sz); }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    83
  inline void release_memory(size_t sz)  { data()->release_memory(sz);  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    84
  inline size_t reserved() const  { return peek()->reserved(); }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    85
  inline size_t committed() const { return peek()->committed(); }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    86
};
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    87
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    88
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
// This class represents a snapshot of virtual memory at a given time.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    91
// The latest snapshot is saved in a static area.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    92
class VirtualMemorySnapshot : public ResourceObj {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    93
  friend class VirtualMemorySummary;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    94
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    95
 private:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    96
  VirtualMemory  _virtual_memory[mt_number_of_types];
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    97
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    98
 public:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
    99
  inline VirtualMemory* by_type(MEMFLAGS flag) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   100
    int index = NMTUtil::flag_to_index(flag);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   101
    return &_virtual_memory[index];
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   102
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   103
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   104
  inline VirtualMemory* by_index(int index) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   105
    assert(index >= 0, "Index out of bound");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   106
    assert(index < mt_number_of_types, "Index out of bound");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   107
    return &_virtual_memory[index];
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   108
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   109
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   110
  inline size_t total_reserved() const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   111
    size_t amount = 0;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   112
    for (int index = 0; index < mt_number_of_types; index ++) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   113
      amount += _virtual_memory[index].reserved();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   114
    }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   115
    return amount;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   116
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   117
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   118
  inline size_t total_committed() const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   119
    size_t amount = 0;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   120
    for (int index = 0; index < mt_number_of_types; index ++) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   121
      amount += _virtual_memory[index].committed();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   122
    }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   123
    return amount;
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
  inline void reset() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   127
    for (int index = 0; index < mt_number_of_types; index ++) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   128
      _virtual_memory[index].reset();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   129
    }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   130
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   131
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   132
  void copy_to(VirtualMemorySnapshot* s) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   133
    for (int index = 0; index < mt_number_of_types; index ++) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   134
      s->_virtual_memory[index] = _virtual_memory[index];
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   135
    }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   136
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   137
};
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   138
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   139
class VirtualMemorySummary : AllStatic {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   140
 public:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   141
  static void initialize();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   142
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   143
  static inline void record_reserved_memory(size_t size, MEMFLAGS flag) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   144
    as_snapshot()->by_type(flag)->reserve_memory(size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   145
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   146
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   147
  static inline void record_committed_memory(size_t size, MEMFLAGS flag) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   148
    as_snapshot()->by_type(flag)->commit_memory(size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   149
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   150
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   151
  static inline void record_uncommitted_memory(size_t size, MEMFLAGS flag) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   152
    as_snapshot()->by_type(flag)->uncommit_memory(size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   153
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   154
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   155
  static inline void record_released_memory(size_t size, MEMFLAGS flag) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   156
    as_snapshot()->by_type(flag)->release_memory(size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   157
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   158
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   159
  // Move virtual memory from one memory type to another.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   160
  // 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
   161
  // 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
   162
  // type to specified memory type.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   163
  static inline void move_reserved_memory(MEMFLAGS from, MEMFLAGS to, size_t size) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   164
    as_snapshot()->by_type(from)->release_memory(size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   165
    as_snapshot()->by_type(to)->reserve_memory(size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   166
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   167
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   168
  static inline void move_committed_memory(MEMFLAGS from, MEMFLAGS to, size_t size) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   169
    as_snapshot()->by_type(from)->uncommit_memory(size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   170
    as_snapshot()->by_type(to)->commit_memory(size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   171
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   172
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   173
  static inline void snapshot(VirtualMemorySnapshot* s) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   174
    as_snapshot()->copy_to(s);
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
  static inline void reset() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   178
    as_snapshot()->reset();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   179
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   180
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   181
  static VirtualMemorySnapshot* as_snapshot() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   182
    return (VirtualMemorySnapshot*)_snapshot;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   183
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   184
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   185
 private:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   186
  static size_t _snapshot[CALC_OBJ_SIZE_IN_TYPE(VirtualMemorySnapshot, size_t)];
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   187
};
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   188
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
/*
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   192
 * A virtual memory region
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   193
 */
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   194
class VirtualMemoryRegion VALUE_OBJ_CLASS_SPEC {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   195
 private:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   196
  address      _base_address;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   197
  size_t       _size;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   198
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   199
 public:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   200
  VirtualMemoryRegion(address addr, size_t size) :
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   201
    _base_address(addr), _size(size) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   202
     assert(addr != NULL, "Invalid address");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   203
     assert(size > 0, "Invalid size");
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 address base() const { return _base_address;   }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   207
  inline address end()  const { return base() + size(); }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   208
  inline size_t  size() const { return _size;           }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   209
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   210
  inline bool is_empty() const { return size() == 0; }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   211
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   212
  inline bool contain_address(address addr) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   213
    return (addr >= base() && addr < end());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   214
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   215
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   216
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   217
  inline bool contain_region(address addr, size_t size) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   218
    return contain_address(addr) && contain_address(addr + size - 1);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   219
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   220
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   221
  inline bool same_region(address addr, size_t sz) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   222
    return (addr == base() && sz == size());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   223
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   224
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   225
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   226
  inline bool overlap_region(address addr, size_t sz) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   227
    VirtualMemoryRegion rgn(addr, sz);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   228
    return contain_address(addr) ||
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   229
           contain_address(addr + sz - 1) ||
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   230
           rgn.contain_address(base()) ||
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   231
           rgn.contain_address(end() - 1);
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
  inline bool adjacent_to(address addr, size_t sz) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   235
    return (addr == end() || (addr + sz) == base());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   236
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   237
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   238
  void exclude_region(address addr, size_t sz) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   239
    assert(contain_region(addr, sz), "Not containment");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   240
    assert(addr == base() || addr + sz == end(), "Can not exclude from middle");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   241
    size_t new_size = size() - sz;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   242
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   243
    if (addr == base()) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   244
      set_base(addr + sz);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   245
    }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   246
    set_size(new_size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   247
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   248
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   249
  void expand_region(address addr, size_t sz) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   250
    assert(adjacent_to(addr, sz), "Not adjacent regions");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   251
    if (base() == addr + sz) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   252
      set_base(addr);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   253
    }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   254
    set_size(size() + sz);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   255
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   256
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   257
 protected:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   258
  void set_base(address base) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   259
    assert(base != NULL, "Sanity check");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   260
    _base_address = base;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   261
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   262
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   263
  void set_size(size_t  size) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   264
    assert(size > 0, "Sanity check");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   265
    _size = size;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   266
  }
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
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   270
class CommittedMemoryRegion : public VirtualMemoryRegion {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   271
 private:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   272
  NativeCallStack  _stack;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   273
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   274
 public:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   275
  CommittedMemoryRegion(address addr, size_t size, const NativeCallStack& stack) :
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   276
    VirtualMemoryRegion(addr, size), _stack(stack) { }
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 int compare(const CommittedMemoryRegion& rgn) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   279
    if (overlap_region(rgn.base(), rgn.size()) ||
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   280
        adjacent_to   (rgn.base(), rgn.size())) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   281
      return 0;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   282
    } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   283
      if (base() == rgn.base()) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   284
        return 0;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   285
      } else if (base() > rgn.base()) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   286
        return 1;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   287
      } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   288
        return -1;
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
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   292
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   293
  inline bool equals(const CommittedMemoryRegion& rgn) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   294
    return compare(rgn) == 0;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   295
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   296
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   297
  inline void set_call_stack(const NativeCallStack& stack) { _stack = stack; }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   298
  inline const NativeCallStack* call_stack() const         { return &_stack; }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   299
};
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   300
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   301
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   302
typedef LinkedListIterator<CommittedMemoryRegion> CommittedRegionIterator;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   303
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   304
int compare_committed_region(const CommittedMemoryRegion&, const CommittedMemoryRegion&);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   305
class ReservedMemoryRegion : public VirtualMemoryRegion {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   306
 private:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   307
  SortedLinkedList<CommittedMemoryRegion, compare_committed_region>
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   308
    _committed_regions;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   309
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   310
  NativeCallStack  _stack;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   311
  MEMFLAGS         _flag;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   312
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   313
  bool             _all_committed;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   314
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   315
 public:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   316
  ReservedMemoryRegion(address base, size_t size, const NativeCallStack& stack,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   317
    MEMFLAGS flag = mtNone) :
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   318
    VirtualMemoryRegion(base, size), _stack(stack), _flag(flag),
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   319
    _all_committed(false) { }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   320
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   321
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   322
  ReservedMemoryRegion(address base, size_t size) :
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   323
    VirtualMemoryRegion(base, size), _stack(emptyStack), _flag(mtNone),
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   324
    _all_committed(false) { }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   325
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   326
  // Copy constructor
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   327
  ReservedMemoryRegion(const ReservedMemoryRegion& rr) :
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   328
    VirtualMemoryRegion(rr.base(), rr.size()) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   329
    *this = rr;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   330
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   331
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   332
  inline void  set_call_stack(const NativeCallStack& stack) { _stack = stack; }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   333
  inline const NativeCallStack* call_stack() const          { return &_stack;  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   334
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   335
  void  set_flag(MEMFLAGS flag);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   336
  inline MEMFLAGS flag() const            { return _flag;  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   337
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   338
  inline int compare(const ReservedMemoryRegion& rgn) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   339
    if (overlap_region(rgn.base(), rgn.size())) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   340
      return 0;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   341
    } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   342
      if (base() == rgn.base()) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   343
        return 0;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   344
      } else if (base() > rgn.base()) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   345
        return 1;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   346
      } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   347
        return -1;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   348
      }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   349
    }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   350
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   351
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   352
  inline bool equals(const ReservedMemoryRegion& rgn) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   353
    return compare(rgn) == 0;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   354
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   355
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   356
  bool    add_committed_region(address addr, size_t size, const NativeCallStack& stack);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   357
  bool    remove_uncommitted_region(address addr, size_t size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   358
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   359
  size_t  committed_size() const;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   360
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   361
  // move committed regions that higher than specified address to
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   362
  // the new region
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   363
  void    move_committed_regions(address addr, ReservedMemoryRegion& rgn);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   364
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   365
  inline bool all_committed() const { return _all_committed; }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   366
  void        set_all_committed(bool b);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   367
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   368
  CommittedRegionIterator iterate_committed_regions() const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   369
    return CommittedRegionIterator(_committed_regions.head());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   370
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   371
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   372
  ReservedMemoryRegion& operator= (const ReservedMemoryRegion& other) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   373
    set_base(other.base());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   374
    set_size(other.size());
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   375
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   376
    _stack =         *other.call_stack();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   377
    _flag  =         other.flag();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   378
    _all_committed = other.all_committed();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   379
    if (other.all_committed()) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   380
      set_all_committed(true);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   381
    } else {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   382
      CommittedRegionIterator itr = other.iterate_committed_regions();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   383
      const CommittedMemoryRegion* rgn = itr.next();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   384
      while (rgn != NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   385
        _committed_regions.add(*rgn);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   386
        rgn = itr.next();
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
    return *this;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   390
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   391
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   392
 private:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   393
  // The committed region contains the uncommitted region, subtract the uncommitted
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   394
  // region from this committed region
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   395
  bool remove_uncommitted_region(LinkedListNode<CommittedMemoryRegion>* node,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   396
    address addr, size_t sz);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   397
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   398
  bool add_committed_region(const CommittedMemoryRegion& rgn) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   399
    assert(rgn.base() != NULL, "Invalid base address");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   400
    assert(size() > 0, "Invalid size");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   401
    return _committed_regions.add(rgn) != NULL;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   402
  }
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   403
};
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   404
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   405
int compare_reserved_region_base(const ReservedMemoryRegion& r1, const ReservedMemoryRegion& r2);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   406
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   407
class VirtualMemoryWalker : public StackObj {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   408
 public:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   409
   virtual bool do_allocation_site(const ReservedMemoryRegion* rgn) { return false; }
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
// Main class called from MemTracker to track virtual memory allocations, commits and releases.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   413
class VirtualMemoryTracker : AllStatic {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   414
 public:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   415
  static bool initialize(NMT_TrackingLevel level);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   416
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   417
  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
   418
    MEMFLAGS flag = mtNone, bool all_committed = false);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   419
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   420
  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
   421
  static bool remove_uncommitted_region (address base_addr, size_t size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   422
  static bool remove_released_region    (address base_addr, size_t size);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   423
  static void set_reserved_region_type  (address addr, MEMFLAGS flag);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   424
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   425
  // Walk virtual memory data structure for creating baseline, etc.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   426
  static bool walk_virtual_memory(VirtualMemoryWalker* walker);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   427
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   428
  static bool transition(NMT_TrackingLevel from, NMT_TrackingLevel to);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   429
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   430
 private:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   431
  static SortedLinkedList<ReservedMemoryRegion, compare_reserved_region_base> _reserved_regions;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   432
};
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   433
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   434
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   435
#endif // INCLUDE_NMT
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   436
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents:
diff changeset
   437
#endif // SHARE_VM_SERVICES_VIRTUAL_MEMORY_TRACKER_HPP