Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/services/memoryService.hpp
32285 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;48class ShenandoahHeap;4950// VM Monitoring and Management Support5152class MemoryService : public AllStatic {53private:54enum {55init_pools_list_size = 10,56init_managers_list_size = 557};5859// index for minor and major generations60enum {61minor = 0,62major = 1,63n_gens = 264};6566static GrowableArray<MemoryPool*>* _pools_list;67static GrowableArray<MemoryManager*>* _managers_list;6869// memory managers for minor and major GC statistics70static GCMemoryManager* _major_gc_manager;71static GCMemoryManager* _minor_gc_manager;7273// Code heap memory pool74static MemoryPool* _code_heap_pool;7576static MemoryPool* _metaspace_pool;77static MemoryPool* _compressed_class_pool;7879static void add_generation_memory_pool(Generation* gen,80GCMemoryManager* major_mgr,81GCMemoryManager* minor_mgr);82static void add_generation_memory_pool(Generation* gen,83GCMemoryManager* major_mgr) {84add_generation_memory_pool(gen, major_mgr, NULL);85}868788static void add_psYoung_memory_pool(PSYoungGen* gen,89GCMemoryManager* major_mgr,90GCMemoryManager* minor_mgr);91static void add_psOld_memory_pool(PSOldGen* gen,92GCMemoryManager* mgr);9394static void add_g1YoungGen_memory_pool(G1CollectedHeap* g1h,95GCMemoryManager* major_mgr,96GCMemoryManager* minor_mgr);97static void add_g1OldGen_memory_pool(G1CollectedHeap* g1h,98GCMemoryManager* major_mgr,99GCMemoryManager* minor_mgr);100101static MemoryPool* add_space(ContiguousSpace* space,102const char* name,103bool is_heap,104size_t max_size,105bool support_usage_threshold);106static MemoryPool* add_survivor_spaces(DefNewGeneration* gen,107const char* name,108bool is_heap,109size_t max_size,110bool support_usage_threshold);111static MemoryPool* add_gen(Generation* gen,112const char* name,113bool is_heap,114bool support_usage_threshold);115static MemoryPool* add_cms_space(CompactibleFreeListSpace* space,116const char* name,117bool is_heap,118size_t max_size,119bool support_usage_threshold);120121static void add_gen_collected_heap_info(GenCollectedHeap* heap);122static void add_parallel_scavenge_heap_info(ParallelScavengeHeap* heap);123static void add_g1_heap_info(G1CollectedHeap* g1h);124static void add_shenandoah_heap_info(ShenandoahHeap* heap);125126public:127static void set_universe_heap(CollectedHeap* heap);128static void add_code_heap_memory_pool(CodeHeap* heap);129static void add_metaspace_memory_pools();130131static MemoryPool* get_memory_pool(instanceHandle pool);132static MemoryManager* get_memory_manager(instanceHandle mgr);133134static const int num_memory_pools() {135return _pools_list->length();136}137static const int num_memory_managers() {138return _managers_list->length();139}140141static MemoryPool* get_memory_pool(int index) {142return _pools_list->at(index);143}144145static MemoryManager* get_memory_manager(int index) {146return _managers_list->at(index);147}148149static void track_memory_usage();150static void track_code_cache_memory_usage() {151track_memory_pool_usage(_code_heap_pool);152}153static void track_metaspace_memory_usage() {154track_memory_pool_usage(_metaspace_pool);155}156static void track_compressed_class_memory_usage() {157track_memory_pool_usage(_compressed_class_pool);158}159static void track_memory_pool_usage(MemoryPool* pool);160161static void gc_begin(bool fullGC, bool recordGCBeginTime,162bool recordAccumulatedGCTime,163bool recordPreGCUsage, bool recordPeakUsage);164static void gc_end(bool fullGC, bool recordPostGCUsage,165bool recordAccumulatedGCTime,166bool recordGCEndTime, bool countCollection,167GCCause::Cause cause,168bool allMemoryPoolsAffected);169170171static void oops_do(OopClosure* f);172173static bool get_verbose() { return PrintGC; }174static bool set_verbose(bool verbose);175176// Create an instance of java/lang/management/MemoryUsage177static Handle create_MemoryUsage_obj(MemoryUsage usage, TRAPS);178179static const GCMemoryManager* get_minor_gc_manager() {180return _minor_gc_manager;181}182183static const GCMemoryManager* get_major_gc_manager() {184return _major_gc_manager;185}186};187188class TraceMemoryManagerStats : public StackObj {189private:190bool _fullGC;191bool _allMemoryPoolsAffected;192bool _recordGCBeginTime;193bool _recordPreGCUsage;194bool _recordPeakUsage;195bool _recordPostGCUsage;196bool _recordAccumulatedGCTime;197bool _recordGCEndTime;198bool _countCollection;199GCCause::Cause _cause;200public:201TraceMemoryManagerStats() {}202TraceMemoryManagerStats(bool fullGC,203GCCause::Cause cause,204bool allMemoryPoolsAffected = true,205bool recordGCBeginTime = true,206bool recordPreGCUsage = true,207bool recordPeakUsage = true,208bool recordPostGCUsage = true,209bool recordAccumulatedGCTime = true,210bool recordGCEndTime = true,211bool countCollection = true);212213void initialize(bool fullGC,214GCCause::Cause cause,215bool allMemoryPoolsAffected,216bool recordGCBeginTime,217bool recordPreGCUsage,218bool recordPeakUsage,219bool recordPostGCUsage,220bool recordAccumulatedGCTime,221bool recordGCEndTime,222bool countCollection);223224TraceMemoryManagerStats(Generation::Name kind, GCCause::Cause cause);225~TraceMemoryManagerStats();226};227228#endif // SHARE_VM_SERVICES_MEMORYSERVICE_HPP229230231