Path: blob/master/src/hotspot/share/services/memoryService.hpp
41144 views
/*1* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_SERVICES_MEMORYSERVICE_HPP25#define SHARE_SERVICES_MEMORYSERVICE_HPP2627#include "gc/shared/gcCause.hpp"28#include "logging/log.hpp"29#include "memory/allocation.hpp"30#include "runtime/handles.hpp"31#include "services/memoryUsage.hpp"32#include "utilities/growableArray.hpp"3334// Forward declaration35class MemoryPool;36class MemoryManager;37class GCMemoryManager;38class CollectedHeap;39class CodeHeap;4041// VM Monitoring and Management Support4243class MemoryService : public AllStatic {44private:45enum {46init_pools_list_size = 10,47init_managers_list_size = 5,48init_code_heap_pools_size = 949};5051static GrowableArray<MemoryPool*>* _pools_list;52static GrowableArray<MemoryManager*>* _managers_list;5354// memory manager and code heap pools for the CodeCache55static MemoryManager* _code_cache_manager;56static GrowableArray<MemoryPool*>* _code_heap_pools;5758static MemoryPool* _metaspace_pool;59static MemoryPool* _compressed_class_pool;6061public:62static void set_universe_heap(CollectedHeap* heap);63static void add_code_heap_memory_pool(CodeHeap* heap, const char* name);64static void add_metaspace_memory_pools();6566static MemoryPool* get_memory_pool(instanceHandle pool);67static MemoryManager* get_memory_manager(instanceHandle mgr);6869static const int num_memory_pools() {70return _pools_list->length();71}72static const int num_memory_managers() {73return _managers_list->length();74}7576static MemoryPool* get_memory_pool(int index) {77return _pools_list->at(index);78}7980static MemoryManager* get_memory_manager(int index) {81return _managers_list->at(index);82}8384static void track_memory_usage();85static void track_code_cache_memory_usage() {86// Track memory pool usage of all CodeCache memory pools87for (int i = 0; i < _code_heap_pools->length(); ++i) {88track_memory_pool_usage(_code_heap_pools->at(i));89}90}91static void track_metaspace_memory_usage() {92track_memory_pool_usage(_metaspace_pool);93}94static void track_compressed_class_memory_usage() {95track_memory_pool_usage(_compressed_class_pool);96}97static void track_memory_pool_usage(MemoryPool* pool);9899static void gc_begin(GCMemoryManager* manager, bool recordGCBeginTime,100bool recordAccumulatedGCTime,101bool recordPreGCUsage, bool recordPeakUsage);102static void gc_end(GCMemoryManager* manager, bool recordPostGCUsage,103bool recordAccumulatedGCTime,104bool recordGCEndTime, bool countCollection,105GCCause::Cause cause,106bool allMemoryPoolsAffected);107108static bool get_verbose() { return log_is_enabled(Info, gc); }109static bool set_verbose(bool verbose);110111// Create an instance of java/lang/management/MemoryUsage112static Handle create_MemoryUsage_obj(MemoryUsage usage, TRAPS);113};114115class TraceMemoryManagerStats : public StackObj {116private:117GCMemoryManager* _gc_memory_manager;118bool _allMemoryPoolsAffected;119bool _recordGCBeginTime;120bool _recordPreGCUsage;121bool _recordPeakUsage;122bool _recordPostGCUsage;123bool _recordAccumulatedGCTime;124bool _recordGCEndTime;125bool _countCollection;126GCCause::Cause _cause;127public:128TraceMemoryManagerStats() {}129TraceMemoryManagerStats(GCMemoryManager* gc_memory_manager,130GCCause::Cause cause,131bool allMemoryPoolsAffected = true,132bool recordGCBeginTime = true,133bool recordPreGCUsage = true,134bool recordPeakUsage = true,135bool recordPostGCUsage = true,136bool recordAccumulatedGCTime = true,137bool recordGCEndTime = true,138bool countCollection = true);139140void initialize(GCMemoryManager* gc_memory_manager,141GCCause::Cause cause,142bool allMemoryPoolsAffected,143bool recordGCBeginTime,144bool recordPreGCUsage,145bool recordPeakUsage,146bool recordPostGCUsage,147bool recordAccumulatedGCTime,148bool recordGCEndTime,149bool countCollection);150151~TraceMemoryManagerStats();152};153154#endif // SHARE_SERVICES_MEMORYSERVICE_HPP155156157