src/share/vm/services/memoryManager.hpp

Tue, 11 May 2010 14:35:43 -0700

author
prr
date
Tue, 11 May 2010 14:35:43 -0700
changeset 1840
fb57d4cf76c2
parent 1524
db0d5eba9d20
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6931180: Migration to recent versions of MS Platform SDK
6951582: Build problems on win64
Summary: Changes to enable building JDK7 with Microsoft Visual Studio 2010
Reviewed-by: ohair, art, ccheung, dcubed

duke@435 1 /*
duke@435 2 * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 // A memory manager is responsible for managing one or more memory pools.
duke@435 26 // The garbage collector is one type of memory managers responsible
duke@435 27 // for reclaiming memory occupied by unreachable objects. A Java virtual
duke@435 28 // machine may have one or more memory managers. It may
duke@435 29 // add or remove memory managers during execution.
duke@435 30 // A memory pool can be managed by more than one memory managers.
duke@435 31
duke@435 32 class MemoryPool;
duke@435 33 class GCMemoryManager;
duke@435 34 class OopClosure;
duke@435 35
duke@435 36 class MemoryManager : public CHeapObj {
duke@435 37 private:
duke@435 38 enum {
duke@435 39 max_num_pools = 10
duke@435 40 };
duke@435 41
duke@435 42 MemoryPool* _pools[max_num_pools];
duke@435 43 int _num_pools;
duke@435 44
duke@435 45 protected:
duke@435 46 volatile instanceOop _memory_mgr_obj;
duke@435 47
duke@435 48 public:
duke@435 49 enum Name {
duke@435 50 Abstract,
duke@435 51 CodeCache,
duke@435 52 Copy,
duke@435 53 MarkSweepCompact,
duke@435 54 ParNew,
duke@435 55 ConcurrentMarkSweep,
duke@435 56 PSScavenge,
tonyp@1524 57 PSMarkSweep,
tonyp@1524 58 G1YoungGen,
tonyp@1524 59 G1OldGen
duke@435 60 };
duke@435 61
duke@435 62 MemoryManager();
duke@435 63
duke@435 64 int num_memory_pools() const { return _num_pools; }
duke@435 65 MemoryPool* get_memory_pool(int index) {
duke@435 66 assert(index >= 0 && index < _num_pools, "Invalid index");
duke@435 67 return _pools[index];
duke@435 68 }
duke@435 69
duke@435 70 void add_pool(MemoryPool* pool);
duke@435 71
duke@435 72 bool is_manager(instanceHandle mh) { return mh() == _memory_mgr_obj; }
duke@435 73
duke@435 74 virtual instanceOop get_memory_manager_instance(TRAPS);
duke@435 75 virtual MemoryManager::Name kind() { return MemoryManager::Abstract; }
duke@435 76 virtual bool is_gc_memory_manager() { return false; }
duke@435 77 virtual const char* name() = 0;
duke@435 78
duke@435 79 // GC support
duke@435 80 void oops_do(OopClosure* f);
duke@435 81
duke@435 82 // Static factory methods to get a memory manager of a specific type
duke@435 83 static MemoryManager* get_code_cache_memory_manager();
duke@435 84 static GCMemoryManager* get_copy_memory_manager();
duke@435 85 static GCMemoryManager* get_msc_memory_manager();
duke@435 86 static GCMemoryManager* get_parnew_memory_manager();
duke@435 87 static GCMemoryManager* get_cms_memory_manager();
duke@435 88 static GCMemoryManager* get_psScavenge_memory_manager();
duke@435 89 static GCMemoryManager* get_psMarkSweep_memory_manager();
tonyp@1524 90 static GCMemoryManager* get_g1YoungGen_memory_manager();
tonyp@1524 91 static GCMemoryManager* get_g1OldGen_memory_manager();
duke@435 92
duke@435 93 };
duke@435 94
duke@435 95 class CodeCacheMemoryManager : public MemoryManager {
duke@435 96 private:
duke@435 97 public:
duke@435 98 CodeCacheMemoryManager() : MemoryManager() {}
duke@435 99
duke@435 100 MemoryManager::Name kind() { return MemoryManager::CodeCache; }
duke@435 101 const char* name() { return "CodeCacheManager"; }
duke@435 102 };
duke@435 103
duke@435 104 class GCStatInfo : public CHeapObj {
duke@435 105 private:
duke@435 106 size_t _index;
duke@435 107 jlong _start_time;
duke@435 108 jlong _end_time;
duke@435 109
duke@435 110 // We keep memory usage of all memory pools
duke@435 111 MemoryUsage* _before_gc_usage_array;
duke@435 112 MemoryUsage* _after_gc_usage_array;
duke@435 113 int _usage_array_size;
duke@435 114
duke@435 115 void set_gc_usage(int pool_index, MemoryUsage, bool before_gc);
duke@435 116
duke@435 117 public:
duke@435 118 GCStatInfo(int num_pools);
duke@435 119 ~GCStatInfo();
duke@435 120
duke@435 121 size_t gc_index() { return _index; }
duke@435 122 jlong start_time() { return _start_time; }
duke@435 123 jlong end_time() { return _end_time; }
duke@435 124 int usage_array_size() { return _usage_array_size; }
duke@435 125 MemoryUsage before_gc_usage_for_pool(int pool_index) {
duke@435 126 assert(pool_index >= 0 && pool_index < _usage_array_size, "Range checking");
duke@435 127 return _before_gc_usage_array[pool_index];
duke@435 128 }
duke@435 129 MemoryUsage after_gc_usage_for_pool(int pool_index) {
duke@435 130 assert(pool_index >= 0 && pool_index < _usage_array_size, "Range checking");
duke@435 131 return _after_gc_usage_array[pool_index];
duke@435 132 }
duke@435 133
duke@435 134 void set_index(size_t index) { _index = index; }
duke@435 135 void set_start_time(jlong time) { _start_time = time; }
duke@435 136 void set_end_time(jlong time) { _end_time = time; }
duke@435 137 void set_before_gc_usage(int pool_index, MemoryUsage usage) {
duke@435 138 assert(pool_index >= 0 && pool_index < _usage_array_size, "Range checking");
duke@435 139 set_gc_usage(pool_index, usage, true /* before gc */);
duke@435 140 }
duke@435 141 void set_after_gc_usage(int pool_index, MemoryUsage usage) {
duke@435 142 assert(pool_index >= 0 && pool_index < _usage_array_size, "Range checking");
duke@435 143 set_gc_usage(pool_index, usage, false /* after gc */);
duke@435 144 }
duke@435 145
duke@435 146 void copy_stat(GCStatInfo* stat);
duke@435 147 };
duke@435 148
duke@435 149 class GCMemoryManager : public MemoryManager {
duke@435 150 private:
duke@435 151 // TODO: We should unify the GCCounter and GCMemoryManager statistic
duke@435 152 size_t _num_collections;
duke@435 153 elapsedTimer _accumulated_timer;
duke@435 154 elapsedTimer _gc_timer; // for measuring every GC duration
duke@435 155 GCStatInfo* _last_gc_stat;
duke@435 156 int _num_gc_threads;
duke@435 157 public:
duke@435 158 GCMemoryManager();
duke@435 159 ~GCMemoryManager();
duke@435 160
duke@435 161 void initialize_gc_stat_info();
duke@435 162
duke@435 163 bool is_gc_memory_manager() { return true; }
duke@435 164 jlong gc_time_ms() { return _accumulated_timer.milliseconds(); }
duke@435 165 size_t gc_count() { return _num_collections; }
duke@435 166 int num_gc_threads() { return _num_gc_threads; }
duke@435 167 void set_num_gc_threads(int count) { _num_gc_threads = count; }
duke@435 168
duke@435 169 void gc_begin();
duke@435 170 void gc_end();
duke@435 171
duke@435 172 void reset_gc_stat() { _num_collections = 0; _accumulated_timer.reset(); }
duke@435 173 GCStatInfo* last_gc_stat() { return _last_gc_stat; }
duke@435 174
duke@435 175 virtual MemoryManager::Name kind() = 0;
duke@435 176 };
duke@435 177
duke@435 178 // These subclasses of GCMemoryManager are defined to include
duke@435 179 // GC-specific information.
duke@435 180 // TODO: Add GC-specific information
duke@435 181 class CopyMemoryManager : public GCMemoryManager {
duke@435 182 private:
duke@435 183 public:
duke@435 184 CopyMemoryManager() : GCMemoryManager() {}
duke@435 185
duke@435 186 MemoryManager::Name kind() { return MemoryManager::Copy; }
duke@435 187 const char* name() { return "Copy"; }
duke@435 188 };
duke@435 189
duke@435 190 class MSCMemoryManager : public GCMemoryManager {
duke@435 191 private:
duke@435 192 public:
duke@435 193 MSCMemoryManager() : GCMemoryManager() {}
duke@435 194
duke@435 195 MemoryManager::Name kind() { return MemoryManager::MarkSweepCompact; }
duke@435 196 const char* name() { return "MarkSweepCompact"; }
duke@435 197
duke@435 198 };
duke@435 199
duke@435 200 class ParNewMemoryManager : public GCMemoryManager {
duke@435 201 private:
duke@435 202 public:
duke@435 203 ParNewMemoryManager() : GCMemoryManager() {}
duke@435 204
duke@435 205 MemoryManager::Name kind() { return MemoryManager::ParNew; }
duke@435 206 const char* name() { return "ParNew"; }
duke@435 207
duke@435 208 };
duke@435 209
duke@435 210 class CMSMemoryManager : public GCMemoryManager {
duke@435 211 private:
duke@435 212 public:
duke@435 213 CMSMemoryManager() : GCMemoryManager() {}
duke@435 214
duke@435 215 MemoryManager::Name kind() { return MemoryManager::ConcurrentMarkSweep; }
duke@435 216 const char* name() { return "ConcurrentMarkSweep";}
duke@435 217
duke@435 218 };
duke@435 219
duke@435 220 class PSScavengeMemoryManager : public GCMemoryManager {
duke@435 221 private:
duke@435 222 public:
duke@435 223 PSScavengeMemoryManager() : GCMemoryManager() {}
duke@435 224
duke@435 225 MemoryManager::Name kind() { return MemoryManager::PSScavenge; }
duke@435 226 const char* name() { return "PS Scavenge"; }
duke@435 227
duke@435 228 };
duke@435 229
duke@435 230 class PSMarkSweepMemoryManager : public GCMemoryManager {
duke@435 231 private:
duke@435 232 public:
duke@435 233 PSMarkSweepMemoryManager() : GCMemoryManager() {}
duke@435 234
duke@435 235 MemoryManager::Name kind() { return MemoryManager::PSMarkSweep; }
duke@435 236 const char* name() { return "PS MarkSweep"; }
duke@435 237 };
tonyp@1524 238
tonyp@1524 239 class G1YoungGenMemoryManager : public GCMemoryManager {
tonyp@1524 240 private:
tonyp@1524 241 public:
tonyp@1524 242 G1YoungGenMemoryManager() : GCMemoryManager() {}
tonyp@1524 243
tonyp@1524 244 MemoryManager::Name kind() { return MemoryManager::G1YoungGen; }
tonyp@1524 245 const char* name() { return "G1 Young Generation"; }
tonyp@1524 246 };
tonyp@1524 247
tonyp@1524 248 class G1OldGenMemoryManager : public GCMemoryManager {
tonyp@1524 249 private:
tonyp@1524 250 public:
tonyp@1524 251 G1OldGenMemoryManager() : GCMemoryManager() {}
tonyp@1524 252
tonyp@1524 253 MemoryManager::Name kind() { return MemoryManager::G1OldGen; }
tonyp@1524 254 const char* name() { return "G1 Old Generation"; }
tonyp@1524 255 };

mercurial