author | mikael |
Tue, 09 Oct 2012 10:09:34 -0700 | |
changeset 13963 | e5b53c306fb5 |
parent 13195 | be27e1b6a4b9 |
child 16451 | 2f68393e1bef |
permissions | -rw-r--r-- |
1 | 1 |
/* |
13963
e5b53c306fb5
7197424: update copyright year to match last edit in jdk8 hotspot repository
mikael
parents:
13195
diff
changeset
|
2 |
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4459
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4459
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4459
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#ifndef SHARE_VM_SERVICES_MEMORYMANAGER_HPP |
26 |
#define SHARE_VM_SERVICES_MEMORYMANAGER_HPP |
|
27 |
||
28 |
#include "memory/allocation.hpp" |
|
29 |
#include "runtime/timer.hpp" |
|
30 |
#include "services/memoryUsage.hpp" |
|
31 |
||
1 | 32 |
// A memory manager is responsible for managing one or more memory pools. |
33 |
// The garbage collector is one type of memory managers responsible |
|
34 |
// for reclaiming memory occupied by unreachable objects. A Java virtual |
|
35 |
// machine may have one or more memory managers. It may |
|
36 |
// add or remove memory managers during execution. |
|
37 |
// A memory pool can be managed by more than one memory managers. |
|
38 |
||
39 |
class MemoryPool; |
|
40 |
class GCMemoryManager; |
|
41 |
class OopClosure; |
|
42 |
||
13195 | 43 |
class MemoryManager : public CHeapObj<mtInternal> { |
1 | 44 |
private: |
45 |
enum { |
|
46 |
max_num_pools = 10 |
|
47 |
}; |
|
48 |
||
49 |
MemoryPool* _pools[max_num_pools]; |
|
50 |
int _num_pools; |
|
51 |
||
52 |
protected: |
|
53 |
volatile instanceOop _memory_mgr_obj; |
|
54 |
||
55 |
public: |
|
56 |
enum Name { |
|
57 |
Abstract, |
|
58 |
CodeCache, |
|
59 |
Copy, |
|
60 |
MarkSweepCompact, |
|
61 |
ParNew, |
|
62 |
ConcurrentMarkSweep, |
|
63 |
PSScavenge, |
|
4459
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
64 |
PSMarkSweep, |
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
65 |
G1YoungGen, |
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
66 |
G1OldGen |
1 | 67 |
}; |
68 |
||
69 |
MemoryManager(); |
|
70 |
||
71 |
int num_memory_pools() const { return _num_pools; } |
|
72 |
MemoryPool* get_memory_pool(int index) { |
|
73 |
assert(index >= 0 && index < _num_pools, "Invalid index"); |
|
74 |
return _pools[index]; |
|
75 |
} |
|
76 |
||
77 |
void add_pool(MemoryPool* pool); |
|
78 |
||
79 |
bool is_manager(instanceHandle mh) { return mh() == _memory_mgr_obj; } |
|
80 |
||
81 |
virtual instanceOop get_memory_manager_instance(TRAPS); |
|
82 |
virtual MemoryManager::Name kind() { return MemoryManager::Abstract; } |
|
83 |
virtual bool is_gc_memory_manager() { return false; } |
|
84 |
virtual const char* name() = 0; |
|
85 |
||
86 |
// GC support |
|
87 |
void oops_do(OopClosure* f); |
|
88 |
||
89 |
// Static factory methods to get a memory manager of a specific type |
|
90 |
static MemoryManager* get_code_cache_memory_manager(); |
|
91 |
static GCMemoryManager* get_copy_memory_manager(); |
|
92 |
static GCMemoryManager* get_msc_memory_manager(); |
|
93 |
static GCMemoryManager* get_parnew_memory_manager(); |
|
94 |
static GCMemoryManager* get_cms_memory_manager(); |
|
95 |
static GCMemoryManager* get_psScavenge_memory_manager(); |
|
96 |
static GCMemoryManager* get_psMarkSweep_memory_manager(); |
|
4459
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
97 |
static GCMemoryManager* get_g1YoungGen_memory_manager(); |
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
98 |
static GCMemoryManager* get_g1OldGen_memory_manager(); |
1 | 99 |
|
100 |
}; |
|
101 |
||
102 |
class CodeCacheMemoryManager : public MemoryManager { |
|
103 |
private: |
|
104 |
public: |
|
105 |
CodeCacheMemoryManager() : MemoryManager() {} |
|
106 |
||
107 |
MemoryManager::Name kind() { return MemoryManager::CodeCache; } |
|
108 |
const char* name() { return "CodeCacheManager"; } |
|
109 |
}; |
|
110 |
||
11591
854c0dff3844
7066129: GarbageCollectorMXBean#getLastGcInfo leaks native memory
dsamersoff
parents:
9623
diff
changeset
|
111 |
class GCStatInfo : public ResourceObj { |
1 | 112 |
private: |
113 |
size_t _index; |
|
114 |
jlong _start_time; |
|
115 |
jlong _end_time; |
|
116 |
||
117 |
// We keep memory usage of all memory pools |
|
118 |
MemoryUsage* _before_gc_usage_array; |
|
119 |
MemoryUsage* _after_gc_usage_array; |
|
120 |
int _usage_array_size; |
|
121 |
||
122 |
void set_gc_usage(int pool_index, MemoryUsage, bool before_gc); |
|
123 |
||
124 |
public: |
|
125 |
GCStatInfo(int num_pools); |
|
126 |
~GCStatInfo(); |
|
127 |
||
128 |
size_t gc_index() { return _index; } |
|
129 |
jlong start_time() { return _start_time; } |
|
130 |
jlong end_time() { return _end_time; } |
|
131 |
int usage_array_size() { return _usage_array_size; } |
|
132 |
MemoryUsage before_gc_usage_for_pool(int pool_index) { |
|
133 |
assert(pool_index >= 0 && pool_index < _usage_array_size, "Range checking"); |
|
134 |
return _before_gc_usage_array[pool_index]; |
|
135 |
} |
|
136 |
MemoryUsage after_gc_usage_for_pool(int pool_index) { |
|
137 |
assert(pool_index >= 0 && pool_index < _usage_array_size, "Range checking"); |
|
138 |
return _after_gc_usage_array[pool_index]; |
|
139 |
} |
|
140 |
||
6245
c37d2cf6de1a
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
5547
diff
changeset
|
141 |
MemoryUsage* before_gc_usage_array() { return _before_gc_usage_array; } |
c37d2cf6de1a
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
5547
diff
changeset
|
142 |
MemoryUsage* after_gc_usage_array() { return _after_gc_usage_array; } |
c37d2cf6de1a
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
5547
diff
changeset
|
143 |
|
1 | 144 |
void set_index(size_t index) { _index = index; } |
145 |
void set_start_time(jlong time) { _start_time = time; } |
|
146 |
void set_end_time(jlong time) { _end_time = time; } |
|
147 |
void set_before_gc_usage(int pool_index, MemoryUsage usage) { |
|
148 |
assert(pool_index >= 0 && pool_index < _usage_array_size, "Range checking"); |
|
149 |
set_gc_usage(pool_index, usage, true /* before gc */); |
|
150 |
} |
|
151 |
void set_after_gc_usage(int pool_index, MemoryUsage usage) { |
|
152 |
assert(pool_index >= 0 && pool_index < _usage_array_size, "Range checking"); |
|
153 |
set_gc_usage(pool_index, usage, false /* after gc */); |
|
154 |
} |
|
155 |
||
6245
c37d2cf6de1a
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
5547
diff
changeset
|
156 |
void clear(); |
1 | 157 |
}; |
158 |
||
159 |
class GCMemoryManager : public MemoryManager { |
|
160 |
private: |
|
161 |
// TODO: We should unify the GCCounter and GCMemoryManager statistic |
|
162 |
size_t _num_collections; |
|
163 |
elapsedTimer _accumulated_timer; |
|
164 |
elapsedTimer _gc_timer; // for measuring every GC duration |
|
165 |
GCStatInfo* _last_gc_stat; |
|
6245
c37d2cf6de1a
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
5547
diff
changeset
|
166 |
Mutex* _last_gc_lock; |
c37d2cf6de1a
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
5547
diff
changeset
|
167 |
GCStatInfo* _current_gc_stat; |
1 | 168 |
int _num_gc_threads; |
9623
151c0b638488
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
7397
diff
changeset
|
169 |
volatile bool _notification_enabled; |
1 | 170 |
public: |
171 |
GCMemoryManager(); |
|
172 |
~GCMemoryManager(); |
|
173 |
||
174 |
void initialize_gc_stat_info(); |
|
175 |
||
176 |
bool is_gc_memory_manager() { return true; } |
|
177 |
jlong gc_time_ms() { return _accumulated_timer.milliseconds(); } |
|
178 |
size_t gc_count() { return _num_collections; } |
|
179 |
int num_gc_threads() { return _num_gc_threads; } |
|
180 |
void set_num_gc_threads(int count) { _num_gc_threads = count; } |
|
181 |
||
6245
c37d2cf6de1a
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
5547
diff
changeset
|
182 |
void gc_begin(bool recordGCBeginTime, bool recordPreGCUsage, |
c37d2cf6de1a
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
5547
diff
changeset
|
183 |
bool recordAccumulatedGCTime); |
c37d2cf6de1a
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
5547
diff
changeset
|
184 |
void gc_end(bool recordPostGCUsage, bool recordAccumulatedGCTime, |
9623
151c0b638488
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
7397
diff
changeset
|
185 |
bool recordGCEndTime, bool countCollection, GCCause::Cause cause); |
1 | 186 |
|
187 |
void reset_gc_stat() { _num_collections = 0; _accumulated_timer.reset(); } |
|
6245
c37d2cf6de1a
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
5547
diff
changeset
|
188 |
|
c37d2cf6de1a
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
5547
diff
changeset
|
189 |
// Copy out _last_gc_stat to the given destination, returning |
c37d2cf6de1a
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
5547
diff
changeset
|
190 |
// the collection count. Zero signifies no gc has taken place. |
c37d2cf6de1a
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
5547
diff
changeset
|
191 |
size_t get_last_gc_stat(GCStatInfo* dest); |
1 | 192 |
|
9623
151c0b638488
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
7397
diff
changeset
|
193 |
void set_notification_enabled(bool enabled) { _notification_enabled = enabled; } |
151c0b638488
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
7397
diff
changeset
|
194 |
bool is_notification_enabled() { return _notification_enabled; } |
1 | 195 |
virtual MemoryManager::Name kind() = 0; |
196 |
}; |
|
197 |
||
198 |
// These subclasses of GCMemoryManager are defined to include |
|
199 |
// GC-specific information. |
|
200 |
// TODO: Add GC-specific information |
|
201 |
class CopyMemoryManager : public GCMemoryManager { |
|
202 |
private: |
|
203 |
public: |
|
204 |
CopyMemoryManager() : GCMemoryManager() {} |
|
205 |
||
206 |
MemoryManager::Name kind() { return MemoryManager::Copy; } |
|
207 |
const char* name() { return "Copy"; } |
|
208 |
}; |
|
209 |
||
210 |
class MSCMemoryManager : public GCMemoryManager { |
|
211 |
private: |
|
212 |
public: |
|
213 |
MSCMemoryManager() : GCMemoryManager() {} |
|
214 |
||
215 |
MemoryManager::Name kind() { return MemoryManager::MarkSweepCompact; } |
|
216 |
const char* name() { return "MarkSweepCompact"; } |
|
217 |
||
218 |
}; |
|
219 |
||
220 |
class ParNewMemoryManager : public GCMemoryManager { |
|
221 |
private: |
|
222 |
public: |
|
223 |
ParNewMemoryManager() : GCMemoryManager() {} |
|
224 |
||
225 |
MemoryManager::Name kind() { return MemoryManager::ParNew; } |
|
226 |
const char* name() { return "ParNew"; } |
|
227 |
||
228 |
}; |
|
229 |
||
230 |
class CMSMemoryManager : public GCMemoryManager { |
|
231 |
private: |
|
232 |
public: |
|
233 |
CMSMemoryManager() : GCMemoryManager() {} |
|
234 |
||
235 |
MemoryManager::Name kind() { return MemoryManager::ConcurrentMarkSweep; } |
|
236 |
const char* name() { return "ConcurrentMarkSweep";} |
|
237 |
||
238 |
}; |
|
239 |
||
240 |
class PSScavengeMemoryManager : public GCMemoryManager { |
|
241 |
private: |
|
242 |
public: |
|
243 |
PSScavengeMemoryManager() : GCMemoryManager() {} |
|
244 |
||
245 |
MemoryManager::Name kind() { return MemoryManager::PSScavenge; } |
|
246 |
const char* name() { return "PS Scavenge"; } |
|
247 |
||
248 |
}; |
|
249 |
||
250 |
class PSMarkSweepMemoryManager : public GCMemoryManager { |
|
251 |
private: |
|
252 |
public: |
|
253 |
PSMarkSweepMemoryManager() : GCMemoryManager() {} |
|
254 |
||
255 |
MemoryManager::Name kind() { return MemoryManager::PSMarkSweep; } |
|
256 |
const char* name() { return "PS MarkSweep"; } |
|
257 |
}; |
|
4459
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
258 |
|
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
259 |
class G1YoungGenMemoryManager : public GCMemoryManager { |
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
260 |
private: |
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
261 |
public: |
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
262 |
G1YoungGenMemoryManager() : GCMemoryManager() {} |
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
263 |
|
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
264 |
MemoryManager::Name kind() { return MemoryManager::G1YoungGen; } |
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
265 |
const char* name() { return "G1 Young Generation"; } |
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
266 |
}; |
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
267 |
|
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
268 |
class G1OldGenMemoryManager : public GCMemoryManager { |
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
269 |
private: |
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
270 |
public: |
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
271 |
G1OldGenMemoryManager() : GCMemoryManager() {} |
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
272 |
|
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
273 |
MemoryManager::Name kind() { return MemoryManager::G1OldGen; } |
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
274 |
const char* name() { return "G1 Old Generation"; } |
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
275 |
}; |
7397 | 276 |
|
277 |
#endif // SHARE_VM_SERVICES_MEMORYMANAGER_HPP |