1 /* |
1 /* |
2 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
47 MemoryManager::MemoryManager() { |
47 MemoryManager::MemoryManager() { |
48 _num_pools = 0; |
48 _num_pools = 0; |
49 (void)const_cast<instanceOop&>(_memory_mgr_obj = instanceOop(NULL)); |
49 (void)const_cast<instanceOop&>(_memory_mgr_obj = instanceOop(NULL)); |
50 } |
50 } |
51 |
51 |
52 void MemoryManager::add_pool(MemoryPool* pool) { |
52 int MemoryManager::add_pool(MemoryPool* pool) { |
53 assert(_num_pools < MemoryManager::max_num_pools, "_num_pools exceeds the max"); |
53 int index = _num_pools; |
54 if (_num_pools < MemoryManager::max_num_pools) { |
54 assert(index < MemoryManager::max_num_pools, "_num_pools exceeds the max"); |
55 _pools[_num_pools] = pool; |
55 if (index < MemoryManager::max_num_pools) { |
|
56 _pools[index] = pool; |
56 _num_pools++; |
57 _num_pools++; |
57 } |
58 } |
58 pool->add_manager(this); |
59 pool->add_manager(this); |
|
60 return index; |
59 } |
61 } |
60 |
62 |
61 MemoryManager* MemoryManager::get_code_cache_memory_manager() { |
63 MemoryManager* MemoryManager::get_code_cache_memory_manager() { |
62 return (MemoryManager*) new CodeCacheMemoryManager(); |
64 return (MemoryManager*) new CodeCacheMemoryManager(); |
63 } |
65 } |
213 |
215 |
214 GCMemoryManager::~GCMemoryManager() { |
216 GCMemoryManager::~GCMemoryManager() { |
215 delete _last_gc_stat; |
217 delete _last_gc_stat; |
216 delete _last_gc_lock; |
218 delete _last_gc_lock; |
217 delete _current_gc_stat; |
219 delete _current_gc_stat; |
|
220 } |
|
221 |
|
222 void GCMemoryManager::add_pool(MemoryPool* pool) { |
|
223 add_pool(pool, true); |
|
224 } |
|
225 |
|
226 void GCMemoryManager::add_pool(MemoryPool* pool, bool always_affected_by_gc) { |
|
227 int index = MemoryManager::add_pool(pool); |
|
228 _pool_always_affected_by_gc[index] = always_affected_by_gc; |
218 } |
229 } |
219 |
230 |
220 void GCMemoryManager::initialize_gc_stat_info() { |
231 void GCMemoryManager::initialize_gc_stat_info() { |
221 assert(MemoryService::num_memory_pools() > 0, "should have one or more memory pools"); |
232 assert(MemoryService::num_memory_pools() > 0, "should have one or more memory pools"); |
222 _last_gc_stat = new(ResourceObj::C_HEAP, mtGC) GCStatInfo(MemoryService::num_memory_pools()); |
233 _last_gc_stat = new(ResourceObj::C_HEAP, mtGC) GCStatInfo(MemoryService::num_memory_pools()); |
264 // make a TraceMemoryManagerStats object where countCollection is true, |
275 // make a TraceMemoryManagerStats object where countCollection is true, |
265 // to ensure the current gc stat is placed in _last_gc_stat. |
276 // to ensure the current gc stat is placed in _last_gc_stat. |
266 void GCMemoryManager::gc_end(bool recordPostGCUsage, |
277 void GCMemoryManager::gc_end(bool recordPostGCUsage, |
267 bool recordAccumulatedGCTime, |
278 bool recordAccumulatedGCTime, |
268 bool recordGCEndTime, bool countCollection, |
279 bool recordGCEndTime, bool countCollection, |
269 GCCause::Cause cause) { |
280 GCCause::Cause cause, |
|
281 bool allMemoryPoolsAffected) { |
270 if (recordAccumulatedGCTime) { |
282 if (recordAccumulatedGCTime) { |
271 _accumulated_timer.stop(); |
283 _accumulated_timer.stop(); |
272 } |
284 } |
273 if (recordGCEndTime) { |
285 if (recordGCEndTime) { |
274 _current_gc_stat->set_end_time(Management::timestamp()); |
286 _current_gc_stat->set_end_time(Management::timestamp()); |
302 for (i = 0; i < num_memory_pools(); i++) { |
314 for (i = 0; i < num_memory_pools(); i++) { |
303 MemoryPool* pool = get_memory_pool(i); |
315 MemoryPool* pool = get_memory_pool(i); |
304 MemoryUsage usage = pool->get_memory_usage(); |
316 MemoryUsage usage = pool->get_memory_usage(); |
305 |
317 |
306 // Compare with GC usage threshold |
318 // Compare with GC usage threshold |
307 pool->set_last_collection_usage(usage); |
319 if (allMemoryPoolsAffected || pool_always_affected_by_gc(i)) { |
308 LowMemoryDetector::detect_after_gc_memory(pool); |
320 // Compare with GC usage threshold |
|
321 pool->set_last_collection_usage(usage); |
|
322 LowMemoryDetector::detect_after_gc_memory(pool); |
|
323 } |
309 } |
324 } |
310 } |
325 } |
311 |
326 |
312 if (countCollection) { |
327 if (countCollection) { |
313 _num_collections++; |
328 _num_collections++; |