2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2018-03-14 12:12:00 +01:00
|
|
|
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
|
2007-12-01 00:00:00 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
2010-05-27 19:08:38 -07:00
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
2007-12-01 00:00:00 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "precompiled.hpp"
|
|
|
|
#include "classfile/systemDictionary.hpp"
|
|
|
|
#include "classfile/vmSymbols.hpp"
|
2017-11-30 13:40:07 +01:00
|
|
|
#include "gc/shared/collectedHeap.hpp"
|
2015-12-10 14:57:55 +01:00
|
|
|
#include "logging/logConfiguration.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "memory/heap.hpp"
|
|
|
|
#include "memory/memRegion.hpp"
|
2018-03-15 21:29:36 +01:00
|
|
|
#include "memory/resourceArea.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "oops/oop.inline.hpp"
|
2013-06-26 16:58:37 +02:00
|
|
|
#include "runtime/globals.hpp"
|
2018-03-14 12:12:00 +01:00
|
|
|
#include "runtime/handles.inline.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "runtime/javaCalls.hpp"
|
|
|
|
#include "services/classLoadingService.hpp"
|
|
|
|
#include "services/lowMemoryDetector.hpp"
|
|
|
|
#include "services/management.hpp"
|
|
|
|
#include "services/memoryManager.hpp"
|
|
|
|
#include "services/memoryPool.hpp"
|
|
|
|
#include "services/memoryService.hpp"
|
|
|
|
#include "utilities/growableArray.hpp"
|
2013-01-23 13:02:39 -05:00
|
|
|
#include "utilities/macros.hpp"
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
GrowableArray<MemoryPool*>* MemoryService::_pools_list =
|
2012-06-28 17:03:16 -04:00
|
|
|
new (ResourceObj::C_HEAP, mtInternal) GrowableArray<MemoryPool*>(init_pools_list_size, true);
|
2007-12-01 00:00:00 +00:00
|
|
|
GrowableArray<MemoryManager*>* MemoryService::_managers_list =
|
2012-06-28 17:03:16 -04:00
|
|
|
new (ResourceObj::C_HEAP, mtInternal) GrowableArray<MemoryManager*>(init_managers_list_size, true);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2014-09-17 08:00:07 +02:00
|
|
|
MemoryManager* MemoryService::_code_cache_manager = NULL;
|
|
|
|
GrowableArray<MemoryPool*>* MemoryService::_code_heap_pools =
|
|
|
|
new (ResourceObj::C_HEAP, mtInternal) GrowableArray<MemoryPool*>(init_code_heap_pools_size, true);
|
2013-06-26 16:58:37 +02:00
|
|
|
MemoryPool* MemoryService::_metaspace_pool = NULL;
|
|
|
|
MemoryPool* MemoryService::_compressed_class_pool = NULL;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
class GcThreadCountClosure: public ThreadClosure {
|
|
|
|
private:
|
|
|
|
int _count;
|
|
|
|
public:
|
|
|
|
GcThreadCountClosure() : _count(0) {};
|
|
|
|
void do_thread(Thread* thread);
|
|
|
|
int count() { return _count; }
|
|
|
|
};
|
|
|
|
|
|
|
|
void GcThreadCountClosure::do_thread(Thread* thread) {
|
|
|
|
_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryService::set_universe_heap(CollectedHeap* heap) {
|
2017-11-30 13:40:07 +01:00
|
|
|
ResourceMark rm; // For internal allocations in GrowableArray.
|
|
|
|
|
|
|
|
GrowableArray<MemoryPool*> gc_mem_pools = heap->memory_pools();
|
|
|
|
_pools_list->appendAll(&gc_mem_pools);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// set the GC thread count
|
|
|
|
GcThreadCountClosure gctcc;
|
|
|
|
heap->gc_threads_do(&gctcc);
|
|
|
|
int count = gctcc.count();
|
|
|
|
|
2017-11-30 13:40:07 +01:00
|
|
|
GrowableArray<GCMemoryManager*> gc_memory_managers = heap->memory_managers();
|
|
|
|
for (int i = 0; i < gc_memory_managers.length(); i++) {
|
|
|
|
GCMemoryManager* gc_manager = gc_memory_managers.at(i);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2017-11-30 13:40:07 +01:00
|
|
|
if (count > 0) {
|
|
|
|
gc_manager->set_num_gc_threads(count);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
2017-11-30 13:40:07 +01:00
|
|
|
gc_manager->initialize_gc_stat_info();
|
|
|
|
_managers_list->append(gc_manager);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-17 08:00:07 +02:00
|
|
|
void MemoryService::add_code_heap_memory_pool(CodeHeap* heap, const char* name) {
|
|
|
|
// Create new memory pool for this heap
|
|
|
|
MemoryPool* code_heap_pool = new CodeHeapPool(heap, name, true /* support_usage_threshold */);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2014-09-17 08:00:07 +02:00
|
|
|
// Append to lists
|
|
|
|
_code_heap_pools->append(code_heap_pool);
|
|
|
|
_pools_list->append(code_heap_pool);
|
|
|
|
|
|
|
|
if (_code_cache_manager == NULL) {
|
|
|
|
// Create CodeCache memory manager
|
|
|
|
_code_cache_manager = MemoryManager::get_code_cache_memory_manager();
|
|
|
|
_managers_list->append(_code_cache_manager);
|
|
|
|
}
|
|
|
|
|
|
|
|
_code_cache_manager->add_pool(code_heap_pool);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2013-06-26 16:58:37 +02:00
|
|
|
void MemoryService::add_metaspace_memory_pools() {
|
|
|
|
MemoryManager* mgr = MemoryManager::get_metaspace_memory_manager();
|
|
|
|
|
|
|
|
_metaspace_pool = new MetaspacePool();
|
|
|
|
mgr->add_pool(_metaspace_pool);
|
|
|
|
_pools_list->append(_metaspace_pool);
|
|
|
|
|
2013-08-12 17:37:02 +02:00
|
|
|
if (UseCompressedClassPointers) {
|
2013-06-26 16:58:37 +02:00
|
|
|
_compressed_class_pool = new CompressedKlassSpacePool();
|
|
|
|
mgr->add_pool(_compressed_class_pool);
|
|
|
|
_pools_list->append(_compressed_class_pool);
|
|
|
|
}
|
|
|
|
|
|
|
|
_managers_list->append(mgr);
|
|
|
|
}
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
MemoryManager* MemoryService::get_memory_manager(instanceHandle mh) {
|
|
|
|
for (int i = 0; i < _managers_list->length(); i++) {
|
|
|
|
MemoryManager* mgr = _managers_list->at(i);
|
|
|
|
if (mgr->is_manager(mh)) {
|
|
|
|
return mgr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
MemoryPool* MemoryService::get_memory_pool(instanceHandle ph) {
|
|
|
|
for (int i = 0; i < _pools_list->length(); i++) {
|
|
|
|
MemoryPool* pool = _pools_list->at(i);
|
|
|
|
if (pool->is_pool(ph)) {
|
|
|
|
return pool;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryService::track_memory_usage() {
|
|
|
|
// Track the peak memory usage
|
|
|
|
for (int i = 0; i < _pools_list->length(); i++) {
|
|
|
|
MemoryPool* pool = _pools_list->at(i);
|
|
|
|
pool->record_peak_memory_usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Detect low memory
|
|
|
|
LowMemoryDetector::detect_low_memory();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryService::track_memory_pool_usage(MemoryPool* pool) {
|
|
|
|
// Track the peak memory usage
|
|
|
|
pool->record_peak_memory_usage();
|
|
|
|
|
|
|
|
// Detect low memory
|
|
|
|
if (LowMemoryDetector::is_enabled(pool)) {
|
|
|
|
LowMemoryDetector::detect_low_memory(pool);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-30 13:40:07 +01:00
|
|
|
void MemoryService::gc_begin(GCMemoryManager* manager, bool recordGCBeginTime,
|
2010-07-30 22:43:50 +01:00
|
|
|
bool recordAccumulatedGCTime,
|
|
|
|
bool recordPreGCUsage, bool recordPeakUsage) {
|
|
|
|
|
2017-11-30 13:40:07 +01:00
|
|
|
manager->gc_begin(recordGCBeginTime, recordPreGCUsage, recordAccumulatedGCTime);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Track the peak memory usage when GC begins
|
2010-07-30 22:43:50 +01:00
|
|
|
if (recordPeakUsage) {
|
|
|
|
for (int i = 0; i < _pools_list->length(); i++) {
|
|
|
|
MemoryPool* pool = _pools_list->at(i);
|
|
|
|
pool->record_peak_memory_usage();
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-30 13:40:07 +01:00
|
|
|
void MemoryService::gc_end(GCMemoryManager* manager, bool recordPostGCUsage,
|
2010-07-30 22:43:50 +01:00
|
|
|
bool recordAccumulatedGCTime,
|
2011-05-12 10:30:11 -07:00
|
|
|
bool recordGCEndTime, bool countCollection,
|
2018-06-19 05:18:49 -07:00
|
|
|
GCCause::Cause cause,
|
|
|
|
bool allMemoryPoolsAffected) {
|
2007-12-01 00:00:00 +00:00
|
|
|
// register the GC end statistics and memory usage
|
2017-11-30 13:40:07 +01:00
|
|
|
manager->gc_end(recordPostGCUsage, recordAccumulatedGCTime, recordGCEndTime,
|
2018-06-19 05:18:49 -07:00
|
|
|
countCollection, cause, allMemoryPoolsAffected);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryService::oops_do(OopClosure* f) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < _pools_list->length(); i++) {
|
|
|
|
MemoryPool* pool = _pools_list->at(i);
|
|
|
|
pool->oops_do(f);
|
|
|
|
}
|
|
|
|
for (i = 0; i < _managers_list->length(); i++) {
|
|
|
|
MemoryManager* mgr = _managers_list->at(i);
|
|
|
|
mgr->oops_do(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MemoryService::set_verbose(bool verbose) {
|
|
|
|
MutexLocker m(Management_lock);
|
|
|
|
// verbose will be set to the previous value
|
2015-12-10 14:57:55 +01:00
|
|
|
if (verbose) {
|
2016-01-18 09:14:58 +01:00
|
|
|
LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(gc));
|
2015-12-10 14:57:55 +01:00
|
|
|
} else {
|
2016-01-18 09:14:58 +01:00
|
|
|
LogConfiguration::configure_stdout(LogLevel::Off, true, LOG_TAGS(gc));
|
2015-12-10 14:57:55 +01:00
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
ClassLoadingService::reset_trace_class_unloading();
|
|
|
|
|
|
|
|
return verbose;
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle MemoryService::create_MemoryUsage_obj(MemoryUsage usage, TRAPS) {
|
2017-03-15 10:25:37 -04:00
|
|
|
InstanceKlass* ik = Management::java_lang_management_MemoryUsage_klass(CHECK_NH);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
JavaCallArguments args(10);
|
2018-05-18 09:15:08 -07:00
|
|
|
args.push_long(usage.init_size_as_jlong());
|
|
|
|
args.push_long(usage.used_as_jlong());
|
|
|
|
args.push_long(usage.committed_as_jlong());
|
|
|
|
args.push_long(usage.max_size_as_jlong());
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2018-05-18 09:15:08 -07:00
|
|
|
return JavaCalls::construct_new_instance(
|
2007-12-01 00:00:00 +00:00
|
|
|
ik,
|
2011-01-27 16:11:27 -08:00
|
|
|
vmSymbols::long_long_long_long_void_signature(),
|
2007-12-01 00:00:00 +00:00
|
|
|
&args,
|
|
|
|
CHECK_NH);
|
|
|
|
}
|
2015-10-26 16:21:37 +01:00
|
|
|
|
2017-11-30 13:40:07 +01:00
|
|
|
TraceMemoryManagerStats::TraceMemoryManagerStats(GCMemoryManager* gc_memory_manager,
|
2011-05-12 10:30:11 -07:00
|
|
|
GCCause::Cause cause,
|
2018-06-19 05:18:49 -07:00
|
|
|
bool allMemoryPoolsAffected,
|
2010-07-30 22:43:50 +01:00
|
|
|
bool recordGCBeginTime,
|
|
|
|
bool recordPreGCUsage,
|
|
|
|
bool recordPeakUsage,
|
|
|
|
bool recordPostGCUsage,
|
|
|
|
bool recordAccumulatedGCTime,
|
|
|
|
bool recordGCEndTime,
|
|
|
|
bool countCollection) {
|
2018-06-19 05:18:49 -07:00
|
|
|
initialize(gc_memory_manager, cause, allMemoryPoolsAffected,
|
|
|
|
recordGCBeginTime, recordPreGCUsage, recordPeakUsage,
|
2010-07-30 22:43:50 +01:00
|
|
|
recordPostGCUsage, recordAccumulatedGCTime, recordGCEndTime,
|
|
|
|
countCollection);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
2010-07-30 22:43:50 +01:00
|
|
|
|
|
|
|
// for a subclass to create then initialize an instance before invoking
|
|
|
|
// the MemoryService
|
2017-11-30 13:40:07 +01:00
|
|
|
void TraceMemoryManagerStats::initialize(GCMemoryManager* gc_memory_manager,
|
2011-05-12 10:30:11 -07:00
|
|
|
GCCause::Cause cause,
|
2018-06-19 05:18:49 -07:00
|
|
|
bool allMemoryPoolsAffected,
|
2010-07-30 22:43:50 +01:00
|
|
|
bool recordGCBeginTime,
|
|
|
|
bool recordPreGCUsage,
|
|
|
|
bool recordPeakUsage,
|
|
|
|
bool recordPostGCUsage,
|
|
|
|
bool recordAccumulatedGCTime,
|
|
|
|
bool recordGCEndTime,
|
|
|
|
bool countCollection) {
|
2017-11-30 13:40:07 +01:00
|
|
|
_gc_memory_manager = gc_memory_manager;
|
2018-06-19 05:18:49 -07:00
|
|
|
_allMemoryPoolsAffected = allMemoryPoolsAffected;
|
2010-07-30 22:43:50 +01:00
|
|
|
_recordGCBeginTime = recordGCBeginTime;
|
|
|
|
_recordPreGCUsage = recordPreGCUsage;
|
|
|
|
_recordPeakUsage = recordPeakUsage;
|
|
|
|
_recordPostGCUsage = recordPostGCUsage;
|
|
|
|
_recordAccumulatedGCTime = recordAccumulatedGCTime;
|
|
|
|
_recordGCEndTime = recordGCEndTime;
|
|
|
|
_countCollection = countCollection;
|
2011-05-12 10:30:11 -07:00
|
|
|
_cause = cause;
|
2010-07-30 22:43:50 +01:00
|
|
|
|
2017-11-30 13:40:07 +01:00
|
|
|
MemoryService::gc_begin(_gc_memory_manager, _recordGCBeginTime, _recordAccumulatedGCTime,
|
2010-07-30 22:43:50 +01:00
|
|
|
_recordPreGCUsage, _recordPeakUsage);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TraceMemoryManagerStats::~TraceMemoryManagerStats() {
|
2017-11-30 13:40:07 +01:00
|
|
|
MemoryService::gc_end(_gc_memory_manager, _recordPostGCUsage, _recordAccumulatedGCTime,
|
2018-06-19 05:18:49 -07:00
|
|
|
_recordGCEndTime, _countCollection, _cause, _allMemoryPoolsAffected);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|