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