Path: blob/jdk8u272-b10-aarch32-20201026/hotspot/src/share/vm/services/memoryService.hpp
48773 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_VM_SERVICES_MEMORYSERVICE_HPP25#define SHARE_VM_SERVICES_MEMORYSERVICE_HPP2627#include "memory/allocation.hpp"28#include "memory/generation.hpp"29#include "runtime/handles.hpp"30#include "services/memoryUsage.hpp"31#include "gc_interface/gcCause.hpp"3233// Forward declaration34class MemoryPool;35class MemoryManager;36class GCMemoryManager;37class CollectedHeap;38class Generation;39class DefNewGeneration;40class PSYoungGen;41class PSOldGen;42class CodeHeap;43class ContiguousSpace;44class CompactibleFreeListSpace;45class GenCollectedHeap;46class ParallelScavengeHeap;47class G1CollectedHeap;4849// VM Monitoring and Management Support5051class MemoryService : public AllStatic {52private:53enum {54init_pools_list_size = 10,55init_managers_list_size = 556};5758// index for minor and major generations59enum {60minor = 0,61major = 1,62n_gens = 263};6465static GrowableArray<MemoryPool*>* _pools_list;66static GrowableArray<MemoryManager*>* _managers_list;6768// memory managers for minor and major GC statistics69static GCMemoryManager* _major_gc_manager;70static GCMemoryManager* _minor_gc_manager;7172// Code heap memory pool73static MemoryPool* _code_heap_pool;7475static MemoryPool* _metaspace_pool;76static MemoryPool* _compressed_class_pool;7778static void add_generation_memory_pool(Generation* gen,79GCMemoryManager* major_mgr,80GCMemoryManager* minor_mgr);81static void add_generation_memory_pool(Generation* gen,82GCMemoryManager* major_mgr) {83add_generation_memory_pool(gen, major_mgr, NULL);84}858687static void add_psYoung_memory_pool(PSYoungGen* gen,88GCMemoryManager* major_mgr,89GCMemoryManager* minor_mgr);90static void add_psOld_memory_pool(PSOldGen* gen,91GCMemoryManager* mgr);9293static void add_g1YoungGen_memory_pool(G1CollectedHeap* g1h,94GCMemoryManager* major_mgr,95GCMemoryManager* minor_mgr);96static void add_g1OldGen_memory_pool(G1CollectedHeap* g1h,97GCMemoryManager* major_mgr,98GCMemoryManager* minor_mgr);99100static MemoryPool* add_space(ContiguousSpace* space,101const char* name,102bool is_heap,103size_t max_size,104bool support_usage_threshold);105static MemoryPool* add_survivor_spaces(DefNewGeneration* gen,106const char* name,107bool is_heap,108size_t max_size,109bool support_usage_threshold);110static MemoryPool* add_gen(Generation* gen,111const char* name,112bool is_heap,113bool support_usage_threshold);114static MemoryPool* add_cms_space(CompactibleFreeListSpace* space,115const char* name,116bool is_heap,117size_t max_size,118bool support_usage_threshold);119120static void add_gen_collected_heap_info(GenCollectedHeap* heap);121static void add_parallel_scavenge_heap_info(ParallelScavengeHeap* heap);122static void add_g1_heap_info(G1CollectedHeap* g1h);123124public:125static void set_universe_heap(CollectedHeap* heap);126static void add_code_heap_memory_pool(CodeHeap* heap);127static void add_metaspace_memory_pools();128129static MemoryPool* get_memory_pool(instanceHandle pool);130static MemoryManager* get_memory_manager(instanceHandle mgr);131132static const int num_memory_pools() {133return _pools_list->length();134}135static const int num_memory_managers() {136return _managers_list->length();137}138139static MemoryPool* get_memory_pool(int index) {140return _pools_list->at(index);141}142143static MemoryManager* get_memory_manager(int index) {144return _managers_list->at(index);145}146147static void track_memory_usage();148static void track_code_cache_memory_usage() {149track_memory_pool_usage(_code_heap_pool);150}151static void track_metaspace_memory_usage() {152track_memory_pool_usage(_metaspace_pool);153}154static void track_compressed_class_memory_usage() {155track_memory_pool_usage(_compressed_class_pool);156}157static void track_memory_pool_usage(MemoryPool* pool);158159static void gc_begin(bool fullGC, bool recordGCBeginTime,160bool recordAccumulatedGCTime,161bool recordPreGCUsage, bool recordPeakUsage);162static void gc_end(bool fullGC, bool recordPostGCUsage,163bool recordAccumulatedGCTime,164bool recordGCEndTime, bool countCollection,165GCCause::Cause cause,166bool allMemoryPoolsAffected);167168169static void oops_do(OopClosure* f);170171static bool get_verbose() { return PrintGC; }172static bool set_verbose(bool verbose);173174// Create an instance of java/lang/management/MemoryUsage175static Handle create_MemoryUsage_obj(MemoryUsage usage, TRAPS);176177static const GCMemoryManager* get_minor_gc_manager() {178return _minor_gc_manager;179}180181static const GCMemoryManager* get_major_gc_manager() {182return _major_gc_manager;183}184};185186class TraceMemoryManagerStats : public StackObj {187private:188bool _fullGC;189bool _allMemoryPoolsAffected;190bool _recordGCBeginTime;191bool _recordPreGCUsage;192bool _recordPeakUsage;193bool _recordPostGCUsage;194bool _recordAccumulatedGCTime;195bool _recordGCEndTime;196bool _countCollection;197GCCause::Cause _cause;198public:199TraceMemoryManagerStats() {}200TraceMemoryManagerStats(bool fullGC,201GCCause::Cause cause,202bool allMemoryPoolsAffected = true,203bool recordGCBeginTime = true,204bool recordPreGCUsage = true,205bool recordPeakUsage = true,206bool recordPostGCUsage = true,207bool recordAccumulatedGCTime = true,208bool recordGCEndTime = true,209bool countCollection = true);210211void initialize(bool fullGC,212GCCause::Cause cause,213bool allMemoryPoolsAffected,214bool recordGCBeginTime,215bool recordPreGCUsage,216bool recordPeakUsage,217bool recordPostGCUsage,218bool recordAccumulatedGCTime,219bool recordGCEndTime,220bool countCollection);221222TraceMemoryManagerStats(Generation::Name kind, GCCause::Cause cause);223~TraceMemoryManagerStats();224};225226#endif // SHARE_VM_SERVICES_MEMORYSERVICE_HPP227228229