Mercurial > hg > truffle
annotate src/share/vm/services/memoryManager.hpp @ 15063:36e1a11a72b3
new StackIntrospection interface to allow access to stack contents
author | Lukas Stadler <lukas.stadler@oracle.com> |
---|---|
date | Fri, 11 Apr 2014 11:52:19 +0200 |
parents | 4ca6dc0799b6 |
children | 89152779163c |
rev | line source |
---|---|
0 | 1 /* |
14909 | 2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1089
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1089
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1089
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 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 | |
0 | 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 | |
6197 | 43 class MemoryManager : public CHeapObj<mtInternal> { |
0 | 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, | |
11039
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
59 Metaspace, |
0 | 60 Copy, |
61 MarkSweepCompact, | |
62 ParNew, | |
63 ConcurrentMarkSweep, | |
64 PSScavenge, | |
1089
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
0
diff
changeset
|
65 PSMarkSweep, |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
0
diff
changeset
|
66 G1YoungGen, |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
0
diff
changeset
|
67 G1OldGen |
0 | 68 }; |
69 | |
70 MemoryManager(); | |
71 | |
72 int num_memory_pools() const { return _num_pools; } | |
73 MemoryPool* get_memory_pool(int index) { | |
74 assert(index >= 0 && index < _num_pools, "Invalid index"); | |
75 return _pools[index]; | |
76 } | |
77 | |
78 void add_pool(MemoryPool* pool); | |
79 | |
80 bool is_manager(instanceHandle mh) { return mh() == _memory_mgr_obj; } | |
81 | |
82 virtual instanceOop get_memory_manager_instance(TRAPS); | |
83 virtual MemoryManager::Name kind() { return MemoryManager::Abstract; } | |
84 virtual bool is_gc_memory_manager() { return false; } | |
85 virtual const char* name() = 0; | |
86 | |
87 // GC support | |
88 void oops_do(OopClosure* f); | |
89 | |
90 // Static factory methods to get a memory manager of a specific type | |
91 static MemoryManager* get_code_cache_memory_manager(); | |
11039
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
92 static MemoryManager* get_metaspace_memory_manager(); |
0 | 93 static GCMemoryManager* get_copy_memory_manager(); |
94 static GCMemoryManager* get_msc_memory_manager(); | |
95 static GCMemoryManager* get_parnew_memory_manager(); | |
96 static GCMemoryManager* get_cms_memory_manager(); | |
97 static GCMemoryManager* get_psScavenge_memory_manager(); | |
98 static GCMemoryManager* get_psMarkSweep_memory_manager(); | |
1089
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
0
diff
changeset
|
99 static GCMemoryManager* get_g1YoungGen_memory_manager(); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
0
diff
changeset
|
100 static GCMemoryManager* get_g1OldGen_memory_manager(); |
0 | 101 |
102 }; | |
103 | |
104 class CodeCacheMemoryManager : public MemoryManager { | |
105 private: | |
106 public: | |
107 CodeCacheMemoryManager() : MemoryManager() {} | |
108 | |
109 MemoryManager::Name kind() { return MemoryManager::CodeCache; } | |
110 const char* name() { return "CodeCacheManager"; } | |
111 }; | |
112 | |
11039
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
113 class MetaspaceMemoryManager : public MemoryManager { |
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
114 public: |
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
115 MetaspaceMemoryManager() : MemoryManager() {} |
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
116 |
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
117 MemoryManager::Name kind() { return MemoryManager::Metaspace; } |
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
118 const char *name() { return "Metaspace Manager"; } |
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
119 }; |
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
120 |
4844
bf864f701a4a
7066129: GarbageCollectorMXBean#getLastGcInfo leaks native memory
dsamersoff
parents:
3356
diff
changeset
|
121 class GCStatInfo : public ResourceObj { |
0 | 122 private: |
123 size_t _index; | |
124 jlong _start_time; | |
125 jlong _end_time; | |
126 | |
127 // We keep memory usage of all memory pools | |
128 MemoryUsage* _before_gc_usage_array; | |
129 MemoryUsage* _after_gc_usage_array; | |
130 int _usage_array_size; | |
131 | |
132 void set_gc_usage(int pool_index, MemoryUsage, bool before_gc); | |
133 | |
134 public: | |
135 GCStatInfo(int num_pools); | |
136 ~GCStatInfo(); | |
137 | |
138 size_t gc_index() { return _index; } | |
139 jlong start_time() { return _start_time; } | |
140 jlong end_time() { return _end_time; } | |
141 int usage_array_size() { return _usage_array_size; } | |
142 MemoryUsage before_gc_usage_for_pool(int pool_index) { | |
143 assert(pool_index >= 0 && pool_index < _usage_array_size, "Range checking"); | |
144 return _before_gc_usage_array[pool_index]; | |
145 } | |
146 MemoryUsage after_gc_usage_for_pool(int pool_index) { | |
147 assert(pool_index >= 0 && pool_index < _usage_array_size, "Range checking"); | |
148 return _after_gc_usage_array[pool_index]; | |
149 } | |
150 | |
1703
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1552
diff
changeset
|
151 MemoryUsage* before_gc_usage_array() { return _before_gc_usage_array; } |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1552
diff
changeset
|
152 MemoryUsage* after_gc_usage_array() { return _after_gc_usage_array; } |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1552
diff
changeset
|
153 |
0 | 154 void set_index(size_t index) { _index = index; } |
155 void set_start_time(jlong time) { _start_time = time; } | |
156 void set_end_time(jlong time) { _end_time = time; } | |
157 void set_before_gc_usage(int pool_index, MemoryUsage usage) { | |
158 assert(pool_index >= 0 && pool_index < _usage_array_size, "Range checking"); | |
159 set_gc_usage(pool_index, usage, true /* before gc */); | |
160 } | |
161 void set_after_gc_usage(int pool_index, MemoryUsage usage) { | |
162 assert(pool_index >= 0 && pool_index < _usage_array_size, "Range checking"); | |
163 set_gc_usage(pool_index, usage, false /* after gc */); | |
164 } | |
165 | |
1703
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1552
diff
changeset
|
166 void clear(); |
0 | 167 }; |
168 | |
169 class GCMemoryManager : public MemoryManager { | |
170 private: | |
171 // TODO: We should unify the GCCounter and GCMemoryManager statistic | |
172 size_t _num_collections; | |
173 elapsedTimer _accumulated_timer; | |
174 elapsedTimer _gc_timer; // for measuring every GC duration | |
175 GCStatInfo* _last_gc_stat; | |
1703
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1552
diff
changeset
|
176 Mutex* _last_gc_lock; |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1552
diff
changeset
|
177 GCStatInfo* _current_gc_stat; |
0 | 178 int _num_gc_threads; |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
1972
diff
changeset
|
179 volatile bool _notification_enabled; |
0 | 180 public: |
181 GCMemoryManager(); | |
182 ~GCMemoryManager(); | |
183 | |
184 void initialize_gc_stat_info(); | |
185 | |
186 bool is_gc_memory_manager() { return true; } | |
187 jlong gc_time_ms() { return _accumulated_timer.milliseconds(); } | |
188 size_t gc_count() { return _num_collections; } | |
189 int num_gc_threads() { return _num_gc_threads; } | |
190 void set_num_gc_threads(int count) { _num_gc_threads = count; } | |
191 | |
1703
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1552
diff
changeset
|
192 void gc_begin(bool recordGCBeginTime, bool recordPreGCUsage, |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1552
diff
changeset
|
193 bool recordAccumulatedGCTime); |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1552
diff
changeset
|
194 void gc_end(bool recordPostGCUsage, bool recordAccumulatedGCTime, |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
1972
diff
changeset
|
195 bool recordGCEndTime, bool countCollection, GCCause::Cause cause); |
0 | 196 |
197 void reset_gc_stat() { _num_collections = 0; _accumulated_timer.reset(); } | |
1703
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1552
diff
changeset
|
198 |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1552
diff
changeset
|
199 // Copy out _last_gc_stat to the given destination, returning |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1552
diff
changeset
|
200 // the collection count. Zero signifies no gc has taken place. |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1552
diff
changeset
|
201 size_t get_last_gc_stat(GCStatInfo* dest); |
0 | 202 |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
1972
diff
changeset
|
203 void set_notification_enabled(bool enabled) { _notification_enabled = enabled; } |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
1972
diff
changeset
|
204 bool is_notification_enabled() { return _notification_enabled; } |
0 | 205 virtual MemoryManager::Name kind() = 0; |
206 }; | |
207 | |
208 // These subclasses of GCMemoryManager are defined to include | |
209 // GC-specific information. | |
210 // TODO: Add GC-specific information | |
211 class CopyMemoryManager : public GCMemoryManager { | |
212 private: | |
213 public: | |
214 CopyMemoryManager() : GCMemoryManager() {} | |
215 | |
216 MemoryManager::Name kind() { return MemoryManager::Copy; } | |
217 const char* name() { return "Copy"; } | |
218 }; | |
219 | |
220 class MSCMemoryManager : public GCMemoryManager { | |
221 private: | |
222 public: | |
223 MSCMemoryManager() : GCMemoryManager() {} | |
224 | |
225 MemoryManager::Name kind() { return MemoryManager::MarkSweepCompact; } | |
226 const char* name() { return "MarkSweepCompact"; } | |
227 | |
228 }; | |
229 | |
230 class ParNewMemoryManager : public GCMemoryManager { | |
231 private: | |
232 public: | |
233 ParNewMemoryManager() : GCMemoryManager() {} | |
234 | |
235 MemoryManager::Name kind() { return MemoryManager::ParNew; } | |
236 const char* name() { return "ParNew"; } | |
237 | |
238 }; | |
239 | |
240 class CMSMemoryManager : public GCMemoryManager { | |
241 private: | |
242 public: | |
243 CMSMemoryManager() : GCMemoryManager() {} | |
244 | |
245 MemoryManager::Name kind() { return MemoryManager::ConcurrentMarkSweep; } | |
246 const char* name() { return "ConcurrentMarkSweep";} | |
247 | |
248 }; | |
249 | |
250 class PSScavengeMemoryManager : public GCMemoryManager { | |
251 private: | |
252 public: | |
253 PSScavengeMemoryManager() : GCMemoryManager() {} | |
254 | |
255 MemoryManager::Name kind() { return MemoryManager::PSScavenge; } | |
256 const char* name() { return "PS Scavenge"; } | |
257 | |
258 }; | |
259 | |
260 class PSMarkSweepMemoryManager : public GCMemoryManager { | |
261 private: | |
262 public: | |
263 PSMarkSweepMemoryManager() : GCMemoryManager() {} | |
264 | |
265 MemoryManager::Name kind() { return MemoryManager::PSMarkSweep; } | |
266 const char* name() { return "PS MarkSweep"; } | |
267 }; | |
1089
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
0
diff
changeset
|
268 |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
0
diff
changeset
|
269 class G1YoungGenMemoryManager : public GCMemoryManager { |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
0
diff
changeset
|
270 private: |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
0
diff
changeset
|
271 public: |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
0
diff
changeset
|
272 G1YoungGenMemoryManager() : GCMemoryManager() {} |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
0
diff
changeset
|
273 |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
0
diff
changeset
|
274 MemoryManager::Name kind() { return MemoryManager::G1YoungGen; } |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
0
diff
changeset
|
275 const char* name() { return "G1 Young Generation"; } |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
0
diff
changeset
|
276 }; |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
0
diff
changeset
|
277 |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
0
diff
changeset
|
278 class G1OldGenMemoryManager : public GCMemoryManager { |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
0
diff
changeset
|
279 private: |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
0
diff
changeset
|
280 public: |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
0
diff
changeset
|
281 G1OldGenMemoryManager() : GCMemoryManager() {} |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
0
diff
changeset
|
282 |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
0
diff
changeset
|
283 MemoryManager::Name kind() { return MemoryManager::G1OldGen; } |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
0
diff
changeset
|
284 const char* name() { return "G1 Old Generation"; } |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
0
diff
changeset
|
285 }; |
1972 | 286 |
287 #endif // SHARE_VM_SERVICES_MEMORYMANAGER_HPP |