annotate src/share/vm/services/memoryManager.hpp @ 196:d1605aabd0a1 jdk7-b30

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