annotate src/share/vm/services/memoryService.cpp @ 342:37f87013dfd8

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