Mercurial > hg > graal-compiler
annotate src/share/vm/services/memoryService.cpp @ 1397:b4776199210f
6943485: JVMTI always on capabilities change code generation too much
Reviewed-by: twisti, dcubed
author | never |
---|---|
date | Mon, 26 Apr 2010 23:59:45 -0700 |
parents | db0d5eba9d20 |
children | c18cbe5936b8 |
rev | line source |
---|---|
0 | 1 /* |
2 * Copyright 2003-2006 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 # include "incls/_precompiled.incl" | |
26 # include "incls/_memoryService.cpp.incl" | |
27 | |
28 GrowableArray<MemoryPool*>* MemoryService::_pools_list = | |
29 new (ResourceObj::C_HEAP) GrowableArray<MemoryPool*>(init_pools_list_size, true); | |
30 GrowableArray<MemoryManager*>* MemoryService::_managers_list = | |
31 new (ResourceObj::C_HEAP) GrowableArray<MemoryManager*>(init_managers_list_size, true); | |
32 | |
33 GCMemoryManager* MemoryService::_minor_gc_manager = NULL; | |
34 GCMemoryManager* MemoryService::_major_gc_manager = NULL; | |
35 MemoryPool* MemoryService::_code_heap_pool = NULL; | |
36 | |
37 class GcThreadCountClosure: public ThreadClosure { | |
38 private: | |
39 int _count; | |
40 public: | |
41 GcThreadCountClosure() : _count(0) {}; | |
42 void do_thread(Thread* thread); | |
43 int count() { return _count; } | |
44 }; | |
45 | |
46 void GcThreadCountClosure::do_thread(Thread* thread) { | |
47 _count++; | |
48 } | |
49 | |
50 void MemoryService::set_universe_heap(CollectedHeap* heap) { | |
51 CollectedHeap::Name kind = heap->kind(); | |
52 switch (kind) { | |
53 case CollectedHeap::GenCollectedHeap : { | |
54 add_gen_collected_heap_info(GenCollectedHeap::heap()); | |
55 break; | |
56 } | |
57 #ifndef SERIALGC | |
58 case CollectedHeap::ParallelScavengeHeap : { | |
59 add_parallel_scavenge_heap_info(ParallelScavengeHeap::heap()); | |
60 break; | |
61 } | |
342 | 62 case CollectedHeap::G1CollectedHeap : { |
1089
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
63 add_g1_heap_info(G1CollectedHeap::heap()); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
64 break; |
342 | 65 } |
0 | 66 #endif // SERIALGC |
67 default: { | |
342 | 68 guarantee(false, "Unrecognized kind of heap"); |
0 | 69 } |
70 } | |
71 | |
72 // set the GC thread count | |
73 GcThreadCountClosure gctcc; | |
74 heap->gc_threads_do(&gctcc); | |
75 int count = gctcc.count(); | |
76 if (count > 0) { | |
77 _minor_gc_manager->set_num_gc_threads(count); | |
78 _major_gc_manager->set_num_gc_threads(count); | |
79 } | |
80 | |
81 // All memory pools and memory managers are initialized. | |
82 // | |
83 _minor_gc_manager->initialize_gc_stat_info(); | |
84 _major_gc_manager->initialize_gc_stat_info(); | |
85 } | |
86 | |
87 // Add memory pools for GenCollectedHeap | |
88 // This function currently only supports two generations collected heap. | |
89 // The collector for GenCollectedHeap will have two memory managers. | |
90 void MemoryService::add_gen_collected_heap_info(GenCollectedHeap* heap) { | |
91 CollectorPolicy* policy = heap->collector_policy(); | |
92 | |
93 assert(policy->is_two_generation_policy(), "Only support two generations"); | |
94 guarantee(heap->n_gens() == 2, "Only support two-generation heap"); | |
95 | |
96 TwoGenerationCollectorPolicy* two_gen_policy = policy->as_two_generation_policy(); | |
97 if (two_gen_policy != NULL) { | |
98 GenerationSpec** specs = two_gen_policy->generations(); | |
99 Generation::Name kind = specs[0]->name(); | |
100 switch (kind) { | |
101 case Generation::DefNew: | |
102 _minor_gc_manager = MemoryManager::get_copy_memory_manager(); | |
103 break; | |
104 #ifndef SERIALGC | |
105 case Generation::ParNew: | |
106 case Generation::ASParNew: | |
107 _minor_gc_manager = MemoryManager::get_parnew_memory_manager(); | |
108 break; | |
109 #endif // SERIALGC | |
110 default: | |
111 guarantee(false, "Unrecognized generation spec"); | |
112 break; | |
113 } | |
114 if (policy->is_mark_sweep_policy()) { | |
115 _major_gc_manager = MemoryManager::get_msc_memory_manager(); | |
116 #ifndef SERIALGC | |
117 } else if (policy->is_concurrent_mark_sweep_policy()) { | |
118 _major_gc_manager = MemoryManager::get_cms_memory_manager(); | |
119 #endif // SERIALGC | |
120 } else { | |
121 guarantee(false, "Unknown two-gen policy"); | |
122 } | |
123 } else { | |
124 guarantee(false, "Non two-gen policy"); | |
125 } | |
126 _managers_list->append(_minor_gc_manager); | |
127 _managers_list->append(_major_gc_manager); | |
128 | |
129 add_generation_memory_pool(heap->get_gen(minor), _major_gc_manager, _minor_gc_manager); | |
130 add_generation_memory_pool(heap->get_gen(major), _major_gc_manager); | |
131 | |
132 PermGen::Name name = policy->permanent_generation()->name(); | |
133 switch (name) { | |
134 case PermGen::MarkSweepCompact: { | |
135 CompactingPermGenGen* perm_gen = (CompactingPermGenGen*) heap->perm_gen(); | |
136 add_compact_perm_gen_memory_pool(perm_gen, _major_gc_manager); | |
137 break; | |
138 } | |
139 #ifndef SERIALGC | |
140 case PermGen::ConcurrentMarkSweep: { | |
141 CMSPermGenGen* cms_gen = (CMSPermGenGen*) heap->perm_gen(); | |
142 add_cms_perm_gen_memory_pool(cms_gen, _major_gc_manager); | |
143 break; | |
144 } | |
145 #endif // SERIALGC | |
146 default: | |
147 guarantee(false, "Unrecognized perm generation"); | |
148 break; | |
149 } | |
150 } | |
151 | |
152 #ifndef SERIALGC | |
153 // Add memory pools for ParallelScavengeHeap | |
154 // This function currently only supports two generations collected heap. | |
155 // The collector for ParallelScavengeHeap will have two memory managers. | |
156 void MemoryService::add_parallel_scavenge_heap_info(ParallelScavengeHeap* heap) { | |
157 // Two managers to keep statistics about _minor_gc_manager and _major_gc_manager GC. | |
158 _minor_gc_manager = MemoryManager::get_psScavenge_memory_manager(); | |
159 _major_gc_manager = MemoryManager::get_psMarkSweep_memory_manager(); | |
160 _managers_list->append(_minor_gc_manager); | |
161 _managers_list->append(_major_gc_manager); | |
162 | |
163 add_psYoung_memory_pool(heap->young_gen(), _major_gc_manager, _minor_gc_manager); | |
164 add_psOld_memory_pool(heap->old_gen(), _major_gc_manager); | |
165 add_psPerm_memory_pool(heap->perm_gen(), _major_gc_manager); | |
166 } | |
1089
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
167 |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
168 void MemoryService::add_g1_heap_info(G1CollectedHeap* g1h) { |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
169 assert(UseG1GC, "sanity"); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
170 |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
171 _minor_gc_manager = MemoryManager::get_g1YoungGen_memory_manager(); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
172 _major_gc_manager = MemoryManager::get_g1OldGen_memory_manager(); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
173 _managers_list->append(_minor_gc_manager); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
174 _managers_list->append(_major_gc_manager); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
175 |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
176 add_g1YoungGen_memory_pool(g1h, _major_gc_manager, _minor_gc_manager); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
177 add_g1OldGen_memory_pool(g1h, _major_gc_manager); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
178 add_g1PermGen_memory_pool(g1h, _major_gc_manager); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
179 } |
0 | 180 #endif // SERIALGC |
181 | |
182 MemoryPool* MemoryService::add_gen(Generation* gen, | |
183 const char* name, | |
184 bool is_heap, | |
185 bool support_usage_threshold) { | |
186 | |
187 MemoryPool::PoolType type = (is_heap ? MemoryPool::Heap : MemoryPool::NonHeap); | |
188 GenerationPool* pool = new GenerationPool(gen, name, type, support_usage_threshold); | |
189 _pools_list->append(pool); | |
190 return (MemoryPool*) pool; | |
191 } | |
192 | |
193 MemoryPool* MemoryService::add_space(ContiguousSpace* space, | |
194 const char* name, | |
195 bool is_heap, | |
196 size_t max_size, | |
197 bool support_usage_threshold) { | |
198 MemoryPool::PoolType type = (is_heap ? MemoryPool::Heap : MemoryPool::NonHeap); | |
199 ContiguousSpacePool* pool = new ContiguousSpacePool(space, name, type, max_size, support_usage_threshold); | |
200 | |
201 _pools_list->append(pool); | |
202 return (MemoryPool*) pool; | |
203 } | |
204 | |
205 MemoryPool* MemoryService::add_survivor_spaces(DefNewGeneration* gen, | |
206 const char* name, | |
207 bool is_heap, | |
208 size_t max_size, | |
209 bool support_usage_threshold) { | |
210 MemoryPool::PoolType type = (is_heap ? MemoryPool::Heap : MemoryPool::NonHeap); | |
211 SurvivorContiguousSpacePool* pool = new SurvivorContiguousSpacePool(gen, name, type, max_size, support_usage_threshold); | |
212 | |
213 _pools_list->append(pool); | |
214 return (MemoryPool*) pool; | |
215 } | |
216 | |
217 #ifndef SERIALGC | |
218 MemoryPool* MemoryService::add_cms_space(CompactibleFreeListSpace* space, | |
219 const char* name, | |
220 bool is_heap, | |
221 size_t max_size, | |
222 bool support_usage_threshold) { | |
223 MemoryPool::PoolType type = (is_heap ? MemoryPool::Heap : MemoryPool::NonHeap); | |
224 CompactibleFreeListSpacePool* pool = new CompactibleFreeListSpacePool(space, name, type, max_size, support_usage_threshold); | |
225 _pools_list->append(pool); | |
226 return (MemoryPool*) pool; | |
227 } | |
228 #endif // SERIALGC | |
229 | |
230 // Add memory pool(s) for one generation | |
231 void MemoryService::add_generation_memory_pool(Generation* gen, | |
232 MemoryManager* major_mgr, | |
233 MemoryManager* minor_mgr) { | |
234 Generation::Name kind = gen->kind(); | |
235 int index = _pools_list->length(); | |
236 | |
237 switch (kind) { | |
238 case Generation::DefNew: { | |
239 assert(major_mgr != NULL && minor_mgr != NULL, "Should have two managers"); | |
240 DefNewGeneration* young_gen = (DefNewGeneration*) gen; | |
241 // Add a memory pool for each space and young gen doesn't | |
242 // support low memory detection as it is expected to get filled up. | |
243 MemoryPool* eden = add_space(young_gen->eden(), | |
244 "Eden Space", | |
245 true, /* is_heap */ | |
246 young_gen->max_eden_size(), | |
247 false /* support_usage_threshold */); | |
248 MemoryPool* survivor = add_survivor_spaces(young_gen, | |
249 "Survivor Space", | |
250 true, /* is_heap */ | |
251 young_gen->max_survivor_size(), | |
252 false /* support_usage_threshold */); | |
253 break; | |
254 } | |
255 | |
256 #ifndef SERIALGC | |
257 case Generation::ParNew: | |
258 case Generation::ASParNew: | |
259 { | |
260 assert(major_mgr != NULL && minor_mgr != NULL, "Should have two managers"); | |
261 // Add a memory pool for each space and young gen doesn't | |
262 // support low memory detection as it is expected to get filled up. | |
263 ParNewGeneration* parnew_gen = (ParNewGeneration*) gen; | |
264 MemoryPool* eden = add_space(parnew_gen->eden(), | |
265 "Par Eden Space", | |
266 true /* is_heap */, | |
267 parnew_gen->max_eden_size(), | |
268 false /* support_usage_threshold */); | |
269 MemoryPool* survivor = add_survivor_spaces(parnew_gen, | |
270 "Par Survivor Space", | |
271 true, /* is_heap */ | |
272 parnew_gen->max_survivor_size(), | |
273 false /* support_usage_threshold */); | |
274 | |
275 break; | |
276 } | |
277 #endif // SERIALGC | |
278 | |
279 case Generation::MarkSweepCompact: { | |
280 assert(major_mgr != NULL && minor_mgr == NULL, "Should have only one manager"); | |
281 add_gen(gen, | |
282 "Tenured Gen", | |
283 true, /* is_heap */ | |
284 true /* support_usage_threshold */); | |
285 break; | |
286 } | |
287 | |
288 #ifndef SERIALGC | |
289 case Generation::ConcurrentMarkSweep: | |
290 case Generation::ASConcurrentMarkSweep: | |
291 { | |
292 assert(major_mgr != NULL && minor_mgr == NULL, "Should have only one manager"); | |
293 ConcurrentMarkSweepGeneration* cms = (ConcurrentMarkSweepGeneration*) gen; | |
294 MemoryPool* pool = add_cms_space(cms->cmsSpace(), | |
295 "CMS Old Gen", | |
296 true, /* is_heap */ | |
297 cms->reserved().byte_size(), | |
298 true /* support_usage_threshold */); | |
299 break; | |
300 } | |
301 #endif // SERIALGC | |
302 | |
303 default: | |
304 assert(false, "should not reach here"); | |
305 // no memory pool added for others | |
306 break; | |
307 } | |
308 | |
309 assert(major_mgr != NULL, "Should have at least one manager"); | |
310 // Link managers and the memory pools together | |
311 for (int i = index; i < _pools_list->length(); i++) { | |
312 MemoryPool* pool = _pools_list->at(i); | |
313 major_mgr->add_pool(pool); | |
314 if (minor_mgr != NULL) { | |
315 minor_mgr->add_pool(pool); | |
316 } | |
317 } | |
318 } | |
319 | |
320 void MemoryService::add_compact_perm_gen_memory_pool(CompactingPermGenGen* perm_gen, | |
321 MemoryManager* mgr) { | |
322 PermanentGenerationSpec* spec = perm_gen->spec(); | |
323 size_t max_size = spec->max_size() - spec->read_only_size() - spec->read_write_size(); | |
324 MemoryPool* pool = add_space(perm_gen->unshared_space(), | |
325 "Perm Gen", | |
326 false, /* is_heap */ | |
327 max_size, | |
328 true /* support_usage_threshold */); | |
329 mgr->add_pool(pool); | |
330 if (UseSharedSpaces) { | |
331 pool = add_space(perm_gen->ro_space(), | |
332 "Perm Gen [shared-ro]", | |
333 false, /* is_heap */ | |
334 spec->read_only_size(), | |
335 true /* support_usage_threshold */); | |
336 mgr->add_pool(pool); | |
337 | |
338 pool = add_space(perm_gen->rw_space(), | |
339 "Perm Gen [shared-rw]", | |
340 false, /* is_heap */ | |
341 spec->read_write_size(), | |
342 true /* support_usage_threshold */); | |
343 mgr->add_pool(pool); | |
344 } | |
345 } | |
346 | |
347 #ifndef SERIALGC | |
348 void MemoryService::add_cms_perm_gen_memory_pool(CMSPermGenGen* cms_gen, | |
349 MemoryManager* mgr) { | |
350 | |
351 MemoryPool* pool = add_cms_space(cms_gen->cmsSpace(), | |
352 "CMS Perm Gen", | |
353 false, /* is_heap */ | |
354 cms_gen->reserved().byte_size(), | |
355 true /* support_usage_threshold */); | |
356 mgr->add_pool(pool); | |
357 } | |
358 | |
359 void MemoryService::add_psYoung_memory_pool(PSYoungGen* gen, MemoryManager* major_mgr, MemoryManager* minor_mgr) { | |
360 assert(major_mgr != NULL && minor_mgr != NULL, "Should have two managers"); | |
361 | |
362 // Add a memory pool for each space and young gen doesn't | |
363 // support low memory detection as it is expected to get filled up. | |
364 EdenMutableSpacePool* eden = new EdenMutableSpacePool(gen, | |
365 gen->eden_space(), | |
366 "PS Eden Space", | |
367 MemoryPool::Heap, | |
368 false /* support_usage_threshold */); | |
369 | |
370 SurvivorMutableSpacePool* survivor = new SurvivorMutableSpacePool(gen, | |
371 "PS Survivor Space", | |
372 MemoryPool::Heap, | |
373 false /* support_usage_threshold */); | |
374 | |
375 major_mgr->add_pool(eden); | |
376 major_mgr->add_pool(survivor); | |
377 minor_mgr->add_pool(eden); | |
378 minor_mgr->add_pool(survivor); | |
379 _pools_list->append(eden); | |
380 _pools_list->append(survivor); | |
381 } | |
382 | |
383 void MemoryService::add_psOld_memory_pool(PSOldGen* gen, MemoryManager* mgr) { | |
384 PSGenerationPool* old_gen = new PSGenerationPool(gen, | |
385 "PS Old Gen", | |
386 MemoryPool::Heap, | |
387 true /* support_usage_threshold */); | |
388 mgr->add_pool(old_gen); | |
389 _pools_list->append(old_gen); | |
390 } | |
391 | |
392 void MemoryService::add_psPerm_memory_pool(PSPermGen* gen, MemoryManager* mgr) { | |
393 PSGenerationPool* perm_gen = new PSGenerationPool(gen, | |
394 "PS Perm Gen", | |
395 MemoryPool::NonHeap, | |
396 true /* support_usage_threshold */); | |
397 mgr->add_pool(perm_gen); | |
398 _pools_list->append(perm_gen); | |
399 } | |
1089
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
400 |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
401 void MemoryService::add_g1YoungGen_memory_pool(G1CollectedHeap* g1h, |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
402 MemoryManager* major_mgr, |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
403 MemoryManager* minor_mgr) { |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
404 assert(major_mgr != NULL && minor_mgr != NULL, "should have two managers"); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
405 |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
406 G1EdenPool* eden = new G1EdenPool(g1h); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
407 G1SurvivorPool* survivor = new G1SurvivorPool(g1h); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
408 |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
409 major_mgr->add_pool(eden); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
410 major_mgr->add_pool(survivor); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
411 minor_mgr->add_pool(eden); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
412 minor_mgr->add_pool(survivor); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
413 _pools_list->append(eden); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
414 _pools_list->append(survivor); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
415 } |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
416 |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
417 void MemoryService::add_g1OldGen_memory_pool(G1CollectedHeap* g1h, |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
418 MemoryManager* mgr) { |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
419 assert(mgr != NULL, "should have one manager"); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
420 |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
421 G1OldGenPool* old_gen = new G1OldGenPool(g1h); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
422 mgr->add_pool(old_gen); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
423 _pools_list->append(old_gen); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
424 } |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
425 |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
426 void MemoryService::add_g1PermGen_memory_pool(G1CollectedHeap* g1h, |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
427 MemoryManager* mgr) { |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
428 assert(mgr != NULL, "should have one manager"); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
429 |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
430 CompactingPermGenGen* perm_gen = (CompactingPermGenGen*) g1h->perm_gen(); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
431 PermanentGenerationSpec* spec = perm_gen->spec(); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
432 size_t max_size = spec->max_size() - spec->read_only_size() |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
433 - spec->read_write_size(); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
434 MemoryPool* pool = add_space(perm_gen->unshared_space(), |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
435 "G1 Perm Gen", |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
436 false, /* is_heap */ |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
437 max_size, |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
438 true /* support_usage_threshold */); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
439 mgr->add_pool(pool); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
440 |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
441 // in case we support CDS in G1 |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
442 if (UseSharedSpaces) { |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
443 pool = add_space(perm_gen->ro_space(), |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
444 "G1 Perm Gen [shared-ro]", |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
445 false, /* is_heap */ |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
446 spec->read_only_size(), |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
447 true /* support_usage_threshold */); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
448 mgr->add_pool(pool); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
449 |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
450 pool = add_space(perm_gen->rw_space(), |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
451 "G1 Perm Gen [shared-rw]", |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
452 false, /* is_heap */ |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
453 spec->read_write_size(), |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
454 true /* support_usage_threshold */); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
455 mgr->add_pool(pool); |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
456 } |
db0d5eba9d20
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
342
diff
changeset
|
457 } |
0 | 458 #endif // SERIALGC |
459 | |
460 void MemoryService::add_code_heap_memory_pool(CodeHeap* heap) { | |
461 _code_heap_pool = new CodeHeapPool(heap, | |
462 "Code Cache", | |
463 true /* support_usage_threshold */); | |
464 MemoryManager* mgr = MemoryManager::get_code_cache_memory_manager(); | |
465 mgr->add_pool(_code_heap_pool); | |
466 | |
467 _pools_list->append(_code_heap_pool); | |
468 _managers_list->append(mgr); | |
469 } | |
470 | |
471 MemoryManager* MemoryService::get_memory_manager(instanceHandle mh) { | |
472 for (int i = 0; i < _managers_list->length(); i++) { | |
473 MemoryManager* mgr = _managers_list->at(i); | |
474 if (mgr->is_manager(mh)) { | |
475 return mgr; | |
476 } | |
477 } | |
478 return NULL; | |
479 } | |
480 | |
481 MemoryPool* MemoryService::get_memory_pool(instanceHandle ph) { | |
482 for (int i = 0; i < _pools_list->length(); i++) { | |
483 MemoryPool* pool = _pools_list->at(i); | |
484 if (pool->is_pool(ph)) { | |
485 return pool; | |
486 } | |
487 } | |
488 return NULL; | |
489 } | |
490 | |
491 void MemoryService::track_memory_usage() { | |
492 // Track the peak memory usage | |
493 for (int i = 0; i < _pools_list->length(); i++) { | |
494 MemoryPool* pool = _pools_list->at(i); | |
495 pool->record_peak_memory_usage(); | |
496 } | |
497 | |
498 // Detect low memory | |
499 LowMemoryDetector::detect_low_memory(); | |
500 } | |
501 | |
502 void MemoryService::track_memory_pool_usage(MemoryPool* pool) { | |
503 // Track the peak memory usage | |
504 pool->record_peak_memory_usage(); | |
505 | |
506 // Detect low memory | |
507 if (LowMemoryDetector::is_enabled(pool)) { | |
508 LowMemoryDetector::detect_low_memory(pool); | |
509 } | |
510 } | |
511 | |
512 void MemoryService::gc_begin(bool fullGC) { | |
513 GCMemoryManager* mgr; | |
514 if (fullGC) { | |
515 mgr = _major_gc_manager; | |
516 } else { | |
517 mgr = _minor_gc_manager; | |
518 } | |
519 assert(mgr->is_gc_memory_manager(), "Sanity check"); | |
520 mgr->gc_begin(); | |
521 | |
522 // Track the peak memory usage when GC begins | |
523 for (int i = 0; i < _pools_list->length(); i++) { | |
524 MemoryPool* pool = _pools_list->at(i); | |
525 pool->record_peak_memory_usage(); | |
526 } | |
527 } | |
528 | |
529 void MemoryService::gc_end(bool fullGC) { | |
530 GCMemoryManager* mgr; | |
531 if (fullGC) { | |
532 mgr = (GCMemoryManager*) _major_gc_manager; | |
533 } else { | |
534 mgr = (GCMemoryManager*) _minor_gc_manager; | |
535 } | |
536 assert(mgr->is_gc_memory_manager(), "Sanity check"); | |
537 | |
538 // register the GC end statistics and memory usage | |
539 mgr->gc_end(); | |
540 } | |
541 | |
542 void MemoryService::oops_do(OopClosure* f) { | |
543 int i; | |
544 | |
545 for (i = 0; i < _pools_list->length(); i++) { | |
546 MemoryPool* pool = _pools_list->at(i); | |
547 pool->oops_do(f); | |
548 } | |
549 for (i = 0; i < _managers_list->length(); i++) { | |
550 MemoryManager* mgr = _managers_list->at(i); | |
551 mgr->oops_do(f); | |
552 } | |
553 } | |
554 | |
555 bool MemoryService::set_verbose(bool verbose) { | |
556 MutexLocker m(Management_lock); | |
557 // verbose will be set to the previous value | |
558 bool succeed = CommandLineFlags::boolAtPut((char*)"PrintGC", &verbose, MANAGEMENT); | |
559 assert(succeed, "Setting PrintGC flag fails"); | |
560 ClassLoadingService::reset_trace_class_unloading(); | |
561 | |
562 return verbose; | |
563 } | |
564 | |
565 Handle MemoryService::create_MemoryUsage_obj(MemoryUsage usage, TRAPS) { | |
566 klassOop k = Management::java_lang_management_MemoryUsage_klass(CHECK_NH); | |
567 instanceKlassHandle ik(THREAD, k); | |
568 | |
569 instanceHandle obj = ik->allocate_instance_handle(CHECK_NH); | |
570 | |
571 JavaValue result(T_VOID); | |
572 JavaCallArguments args(10); | |
573 args.push_oop(obj); // receiver | |
574 args.push_long(usage.init_size_as_jlong()); // Argument 1 | |
575 args.push_long(usage.used_as_jlong()); // Argument 2 | |
576 args.push_long(usage.committed_as_jlong()); // Argument 3 | |
577 args.push_long(usage.max_size_as_jlong()); // Argument 4 | |
578 | |
579 JavaCalls::call_special(&result, | |
580 ik, | |
581 vmSymbolHandles::object_initializer_name(), | |
582 vmSymbolHandles::long_long_long_long_void_signature(), | |
583 &args, | |
584 CHECK_NH); | |
585 return obj; | |
586 } | |
587 // | |
588 // GC manager type depends on the type of Generation. Depending the space | |
589 // availablity and vm option the gc uses major gc manager or minor gc | |
590 // manager or both. The type of gc manager depends on the generation kind. | |
591 // For DefNew, ParNew and ASParNew generation doing scavange gc uses minor | |
592 // gc manager (so _fullGC is set to false ) and for other generation kind | |
593 // DOing mark-sweep-compact uses major gc manager (so _fullGC is set | |
594 // to true). | |
595 TraceMemoryManagerStats::TraceMemoryManagerStats(Generation::Name kind) { | |
596 switch (kind) { | |
597 case Generation::DefNew: | |
598 #ifndef SERIALGC | |
599 case Generation::ParNew: | |
600 case Generation::ASParNew: | |
601 #endif // SERIALGC | |
602 _fullGC=false; | |
603 break; | |
604 case Generation::MarkSweepCompact: | |
605 #ifndef SERIALGC | |
606 case Generation::ConcurrentMarkSweep: | |
607 case Generation::ASConcurrentMarkSweep: | |
608 #endif // SERIALGC | |
609 _fullGC=true; | |
610 break; | |
611 default: | |
612 assert(false, "Unrecognized gc generation kind."); | |
613 } | |
614 MemoryService::gc_begin(_fullGC); | |
615 } | |
616 TraceMemoryManagerStats::TraceMemoryManagerStats(bool fullGC) { | |
617 _fullGC = fullGC; | |
618 MemoryService::gc_begin(_fullGC); | |
619 } | |
620 | |
621 TraceMemoryManagerStats::~TraceMemoryManagerStats() { | |
622 MemoryService::gc_end(_fullGC); | |
623 } |