59 GcThreadCountClosure() : _count(0) {};
60 void do_thread(Thread* thread);
61 int count() { return _count; }
62 };
63
64 void GcThreadCountClosure::do_thread(Thread* thread) {
65 _count++;
66 }
67
68 void MemoryService::set_universe_heap(CollectedHeap* heap) {
69 ResourceMark rm; // For internal allocations in GrowableArray.
70
71 GrowableArray<MemoryPool*> gc_mem_pools = heap->memory_pools();
72 _pools_list->appendAll(&gc_mem_pools);
73
74 // set the GC thread count
75 GcThreadCountClosure gctcc;
76 heap->gc_threads_do(&gctcc);
77 int count = gctcc.count();
78
79 GrowableArray<GCMemoryManager*> gc_mem_mgrs = heap->memory_managers();
80 for (int i = 0; i < gc_mem_mgrs.length(); i++) {
81 GCMemoryManager* gc_mgr = gc_mem_mgrs.at(i);
82
83 if (count > 0) {
84 gc_mgr->set_num_gc_threads(count);
85 }
86 gc_mgr->initialize_gc_stat_info();
87 _managers_list->append(gc_mgr);
88 }
89 }
90
91 void MemoryService::add_code_heap_memory_pool(CodeHeap* heap, const char* name) {
92 // Create new memory pool for this heap
93 MemoryPool* code_heap_pool = new CodeHeapPool(heap, name, true /* support_usage_threshold */);
94
95 // Append to lists
96 _code_heap_pools->append(code_heap_pool);
97 _pools_list->append(code_heap_pool);
98
99 if (_code_cache_manager == NULL) {
100 // Create CodeCache memory manager
101 _code_cache_manager = MemoryManager::get_code_cache_memory_manager();
102 _managers_list->append(_code_cache_manager);
103 }
104
105 _code_cache_manager->add_pool(code_heap_pool);
106 }
107
145 // Track the peak memory usage
146 for (int i = 0; i < _pools_list->length(); i++) {
147 MemoryPool* pool = _pools_list->at(i);
148 pool->record_peak_memory_usage();
149 }
150
151 // Detect low memory
152 LowMemoryDetector::detect_low_memory();
153 }
154
155 void MemoryService::track_memory_pool_usage(MemoryPool* pool) {
156 // Track the peak memory usage
157 pool->record_peak_memory_usage();
158
159 // Detect low memory
160 if (LowMemoryDetector::is_enabled(pool)) {
161 LowMemoryDetector::detect_low_memory(pool);
162 }
163 }
164
165 void MemoryService::gc_begin(GCMemoryManager* mgr, bool recordGCBeginTime,
166 bool recordAccumulatedGCTime,
167 bool recordPreGCUsage, bool recordPeakUsage) {
168
169 mgr->gc_begin(recordGCBeginTime, recordPreGCUsage, recordAccumulatedGCTime);
170
171 // Track the peak memory usage when GC begins
172 if (recordPeakUsage) {
173 for (int i = 0; i < _pools_list->length(); i++) {
174 MemoryPool* pool = _pools_list->at(i);
175 pool->record_peak_memory_usage();
176 }
177 }
178 }
179
180 void MemoryService::gc_end(GCMemoryManager* mgr, bool recordPostGCUsage,
181 bool recordAccumulatedGCTime,
182 bool recordGCEndTime, bool countCollection,
183 GCCause::Cause cause) {
184 // register the GC end statistics and memory usage
185 mgr->gc_end(recordPostGCUsage, recordAccumulatedGCTime, recordGCEndTime,
186 countCollection, cause);
187 }
188
189 void MemoryService::oops_do(OopClosure* f) {
190 int i;
191
192 for (i = 0; i < _pools_list->length(); i++) {
193 MemoryPool* pool = _pools_list->at(i);
194 pool->oops_do(f);
195 }
196 for (i = 0; i < _managers_list->length(); i++) {
197 MemoryManager* mgr = _managers_list->at(i);
198 mgr->oops_do(f);
199 }
200 }
201
202 bool MemoryService::set_verbose(bool verbose) {
203 MutexLocker m(Management_lock);
204 // verbose will be set to the previous value
205 if (verbose) {
217
218 instanceHandle obj = ik->allocate_instance_handle(CHECK_NH);
219
220 JavaValue result(T_VOID);
221 JavaCallArguments args(10);
222 args.push_oop(obj); // receiver
223 args.push_long(usage.init_size_as_jlong()); // Argument 1
224 args.push_long(usage.used_as_jlong()); // Argument 2
225 args.push_long(usage.committed_as_jlong()); // Argument 3
226 args.push_long(usage.max_size_as_jlong()); // Argument 4
227
228 JavaCalls::call_special(&result,
229 ik,
230 vmSymbols::object_initializer_name(),
231 vmSymbols::long_long_long_long_void_signature(),
232 &args,
233 CHECK_NH);
234 return obj;
235 }
236
237 TraceMemoryManagerStats::TraceMemoryManagerStats(GCMemoryManager* gc_mem_mgr,
238 GCCause::Cause cause,
239 bool recordGCBeginTime,
240 bool recordPreGCUsage,
241 bool recordPeakUsage,
242 bool recordPostGCUsage,
243 bool recordAccumulatedGCTime,
244 bool recordGCEndTime,
245 bool countCollection) {
246 initialize(gc_mem_mgr, cause, recordGCBeginTime, recordPreGCUsage, recordPeakUsage,
247 recordPostGCUsage, recordAccumulatedGCTime, recordGCEndTime,
248 countCollection);
249 }
250
251 // for a subclass to create then initialize an instance before invoking
252 // the MemoryService
253 void TraceMemoryManagerStats::initialize(GCMemoryManager* gc_mem_mgr,
254 GCCause::Cause cause,
255 bool recordGCBeginTime,
256 bool recordPreGCUsage,
257 bool recordPeakUsage,
258 bool recordPostGCUsage,
259 bool recordAccumulatedGCTime,
260 bool recordGCEndTime,
261 bool countCollection) {
262 _gc_mem_mgr = gc_mem_mgr;
263 _recordGCBeginTime = recordGCBeginTime;
264 _recordPreGCUsage = recordPreGCUsage;
265 _recordPeakUsage = recordPeakUsage;
266 _recordPostGCUsage = recordPostGCUsage;
267 _recordAccumulatedGCTime = recordAccumulatedGCTime;
268 _recordGCEndTime = recordGCEndTime;
269 _countCollection = countCollection;
270 _cause = cause;
271
272 MemoryService::gc_begin(_gc_mem_mgr, _recordGCBeginTime, _recordAccumulatedGCTime,
273 _recordPreGCUsage, _recordPeakUsage);
274 }
275
276 TraceMemoryManagerStats::~TraceMemoryManagerStats() {
277 MemoryService::gc_end(_gc_mem_mgr, _recordPostGCUsage, _recordAccumulatedGCTime,
278 _recordGCEndTime, _countCollection, _cause);
279 }
|
59 GcThreadCountClosure() : _count(0) {};
60 void do_thread(Thread* thread);
61 int count() { return _count; }
62 };
63
64 void GcThreadCountClosure::do_thread(Thread* thread) {
65 _count++;
66 }
67
68 void MemoryService::set_universe_heap(CollectedHeap* heap) {
69 ResourceMark rm; // For internal allocations in GrowableArray.
70
71 GrowableArray<MemoryPool*> gc_mem_pools = heap->memory_pools();
72 _pools_list->appendAll(&gc_mem_pools);
73
74 // set the GC thread count
75 GcThreadCountClosure gctcc;
76 heap->gc_threads_do(&gctcc);
77 int count = gctcc.count();
78
79 GrowableArray<GCMemoryManager*> gc_memory_managers = heap->memory_managers();
80 for (int i = 0; i < gc_memory_managers.length(); i++) {
81 GCMemoryManager* gc_manager = gc_memory_managers.at(i);
82
83 if (count > 0) {
84 gc_manager->set_num_gc_threads(count);
85 }
86 gc_manager->initialize_gc_stat_info();
87 _managers_list->append(gc_manager);
88 }
89 }
90
91 void MemoryService::add_code_heap_memory_pool(CodeHeap* heap, const char* name) {
92 // Create new memory pool for this heap
93 MemoryPool* code_heap_pool = new CodeHeapPool(heap, name, true /* support_usage_threshold */);
94
95 // Append to lists
96 _code_heap_pools->append(code_heap_pool);
97 _pools_list->append(code_heap_pool);
98
99 if (_code_cache_manager == NULL) {
100 // Create CodeCache memory manager
101 _code_cache_manager = MemoryManager::get_code_cache_memory_manager();
102 _managers_list->append(_code_cache_manager);
103 }
104
105 _code_cache_manager->add_pool(code_heap_pool);
106 }
107
145 // Track the peak memory usage
146 for (int i = 0; i < _pools_list->length(); i++) {
147 MemoryPool* pool = _pools_list->at(i);
148 pool->record_peak_memory_usage();
149 }
150
151 // Detect low memory
152 LowMemoryDetector::detect_low_memory();
153 }
154
155 void MemoryService::track_memory_pool_usage(MemoryPool* pool) {
156 // Track the peak memory usage
157 pool->record_peak_memory_usage();
158
159 // Detect low memory
160 if (LowMemoryDetector::is_enabled(pool)) {
161 LowMemoryDetector::detect_low_memory(pool);
162 }
163 }
164
165 void MemoryService::gc_begin(GCMemoryManager* manager, bool recordGCBeginTime,
166 bool recordAccumulatedGCTime,
167 bool recordPreGCUsage, bool recordPeakUsage) {
168
169 manager->gc_begin(recordGCBeginTime, recordPreGCUsage, recordAccumulatedGCTime);
170
171 // Track the peak memory usage when GC begins
172 if (recordPeakUsage) {
173 for (int i = 0; i < _pools_list->length(); i++) {
174 MemoryPool* pool = _pools_list->at(i);
175 pool->record_peak_memory_usage();
176 }
177 }
178 }
179
180 void MemoryService::gc_end(GCMemoryManager* manager, bool recordPostGCUsage,
181 bool recordAccumulatedGCTime,
182 bool recordGCEndTime, bool countCollection,
183 GCCause::Cause cause) {
184 // register the GC end statistics and memory usage
185 manager->gc_end(recordPostGCUsage, recordAccumulatedGCTime, recordGCEndTime,
186 countCollection, cause);
187 }
188
189 void MemoryService::oops_do(OopClosure* f) {
190 int i;
191
192 for (i = 0; i < _pools_list->length(); i++) {
193 MemoryPool* pool = _pools_list->at(i);
194 pool->oops_do(f);
195 }
196 for (i = 0; i < _managers_list->length(); i++) {
197 MemoryManager* mgr = _managers_list->at(i);
198 mgr->oops_do(f);
199 }
200 }
201
202 bool MemoryService::set_verbose(bool verbose) {
203 MutexLocker m(Management_lock);
204 // verbose will be set to the previous value
205 if (verbose) {
217
218 instanceHandle obj = ik->allocate_instance_handle(CHECK_NH);
219
220 JavaValue result(T_VOID);
221 JavaCallArguments args(10);
222 args.push_oop(obj); // receiver
223 args.push_long(usage.init_size_as_jlong()); // Argument 1
224 args.push_long(usage.used_as_jlong()); // Argument 2
225 args.push_long(usage.committed_as_jlong()); // Argument 3
226 args.push_long(usage.max_size_as_jlong()); // Argument 4
227
228 JavaCalls::call_special(&result,
229 ik,
230 vmSymbols::object_initializer_name(),
231 vmSymbols::long_long_long_long_void_signature(),
232 &args,
233 CHECK_NH);
234 return obj;
235 }
236
237 TraceMemoryManagerStats::TraceMemoryManagerStats(GCMemoryManager* gc_memory_manager,
238 GCCause::Cause cause,
239 bool recordGCBeginTime,
240 bool recordPreGCUsage,
241 bool recordPeakUsage,
242 bool recordPostGCUsage,
243 bool recordAccumulatedGCTime,
244 bool recordGCEndTime,
245 bool countCollection) {
246 initialize(gc_memory_manager, cause, recordGCBeginTime, recordPreGCUsage, recordPeakUsage,
247 recordPostGCUsage, recordAccumulatedGCTime, recordGCEndTime,
248 countCollection);
249 }
250
251 // for a subclass to create then initialize an instance before invoking
252 // the MemoryService
253 void TraceMemoryManagerStats::initialize(GCMemoryManager* gc_memory_manager,
254 GCCause::Cause cause,
255 bool recordGCBeginTime,
256 bool recordPreGCUsage,
257 bool recordPeakUsage,
258 bool recordPostGCUsage,
259 bool recordAccumulatedGCTime,
260 bool recordGCEndTime,
261 bool countCollection) {
262 _gc_memory_manager = gc_memory_manager;
263 _recordGCBeginTime = recordGCBeginTime;
264 _recordPreGCUsage = recordPreGCUsage;
265 _recordPeakUsage = recordPeakUsage;
266 _recordPostGCUsage = recordPostGCUsage;
267 _recordAccumulatedGCTime = recordAccumulatedGCTime;
268 _recordGCEndTime = recordGCEndTime;
269 _countCollection = countCollection;
270 _cause = cause;
271
272 MemoryService::gc_begin(_gc_memory_manager, _recordGCBeginTime, _recordAccumulatedGCTime,
273 _recordPreGCUsage, _recordPeakUsage);
274 }
275
276 TraceMemoryManagerStats::~TraceMemoryManagerStats() {
277 MemoryService::gc_end(_gc_memory_manager, _recordPostGCUsage, _recordAccumulatedGCTime,
278 _recordGCEndTime, _countCollection, _cause);
279 }
|