Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/services/memoryManager.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_MEMORYMANAGER_HPP25#define SHARE_VM_SERVICES_MEMORYMANAGER_HPP2627#include "memory/allocation.hpp"28#include "runtime/timer.hpp"29#include "services/memoryUsage.hpp"3031// A memory manager is responsible for managing one or more memory pools.32// The garbage collector is one type of memory managers responsible33// for reclaiming memory occupied by unreachable objects. A Java virtual34// machine may have one or more memory managers. It may35// add or remove memory managers during execution.36// A memory pool can be managed by more than one memory managers.3738class MemoryPool;39class GCMemoryManager;40class OopClosure;4142class MemoryManager : public CHeapObj<mtInternal> {43protected:44enum {45max_num_pools = 1046};4748private:49MemoryPool* _pools[max_num_pools];50int _num_pools;5152protected:53volatile instanceOop _memory_mgr_obj;5455public:56enum Name {57Abstract,58CodeCache,59Metaspace,60Copy,61MarkSweepCompact,62ParNew,63ConcurrentMarkSweep,64PSScavenge,65PSMarkSweep,66G1YoungGen,67G1OldGen,68ShenandoahCycles,69ShenandoahPauses70};7172MemoryManager();7374int num_memory_pools() const { return _num_pools; }75MemoryPool* get_memory_pool(int index) {76assert(index >= 0 && index < _num_pools, "Invalid index");77return _pools[index];78}7980int add_pool(MemoryPool* pool);8182bool is_manager(instanceHandle mh) { return mh() == _memory_mgr_obj; }8384virtual instanceOop get_memory_manager_instance(TRAPS);85virtual MemoryManager::Name kind() { return MemoryManager::Abstract; }86virtual bool is_gc_memory_manager() { return false; }87virtual const char* name() = 0;8889// GC support90void oops_do(OopClosure* f);9192// Static factory methods to get a memory manager of a specific type93static MemoryManager* get_code_cache_memory_manager();94static MemoryManager* get_metaspace_memory_manager();95static GCMemoryManager* get_copy_memory_manager();96static GCMemoryManager* get_msc_memory_manager();97static GCMemoryManager* get_parnew_memory_manager();98static GCMemoryManager* get_cms_memory_manager();99static GCMemoryManager* get_psScavenge_memory_manager();100static GCMemoryManager* get_psMarkSweep_memory_manager();101static GCMemoryManager* get_g1YoungGen_memory_manager();102static GCMemoryManager* get_g1OldGen_memory_manager();103static GCMemoryManager* get_shenandoah_cycles_memory_manager();104static GCMemoryManager* get_shenandoah_pauses_memory_manager();105};106107class CodeCacheMemoryManager : public MemoryManager {108private:109public:110CodeCacheMemoryManager() : MemoryManager() {}111112MemoryManager::Name kind() { return MemoryManager::CodeCache; }113const char* name() { return "CodeCacheManager"; }114};115116class MetaspaceMemoryManager : public MemoryManager {117public:118MetaspaceMemoryManager() : MemoryManager() {}119120MemoryManager::Name kind() { return MemoryManager::Metaspace; }121const char *name() { return "Metaspace Manager"; }122};123124class GCStatInfo : public ResourceObj {125private:126size_t _index;127jlong _start_time;128jlong _end_time;129130// We keep memory usage of all memory pools131MemoryUsage* _before_gc_usage_array;132MemoryUsage* _after_gc_usage_array;133int _usage_array_size;134135void set_gc_usage(int pool_index, MemoryUsage, bool before_gc);136137public:138GCStatInfo(int num_pools);139~GCStatInfo();140141size_t gc_index() { return _index; }142jlong start_time() { return _start_time; }143jlong end_time() { return _end_time; }144int usage_array_size() { return _usage_array_size; }145MemoryUsage before_gc_usage_for_pool(int pool_index) {146assert(pool_index >= 0 && pool_index < _usage_array_size, "Range checking");147return _before_gc_usage_array[pool_index];148}149MemoryUsage after_gc_usage_for_pool(int pool_index) {150assert(pool_index >= 0 && pool_index < _usage_array_size, "Range checking");151return _after_gc_usage_array[pool_index];152}153154MemoryUsage* before_gc_usage_array() { return _before_gc_usage_array; }155MemoryUsage* after_gc_usage_array() { return _after_gc_usage_array; }156157void set_index(size_t index) { _index = index; }158void set_start_time(jlong time) { _start_time = time; }159void set_end_time(jlong time) { _end_time = time; }160void set_before_gc_usage(int pool_index, MemoryUsage usage) {161assert(pool_index >= 0 && pool_index < _usage_array_size, "Range checking");162set_gc_usage(pool_index, usage, true /* before gc */);163}164void set_after_gc_usage(int pool_index, MemoryUsage usage) {165assert(pool_index >= 0 && pool_index < _usage_array_size, "Range checking");166set_gc_usage(pool_index, usage, false /* after gc */);167}168169void clear();170};171172class GCMemoryManager : public MemoryManager {173private:174// TODO: We should unify the GCCounter and GCMemoryManager statistic175size_t _num_collections;176elapsedTimer _accumulated_timer;177elapsedTimer _gc_timer; // for measuring every GC duration178GCStatInfo* _last_gc_stat;179Mutex* _last_gc_lock;180GCStatInfo* _current_gc_stat;181int _num_gc_threads;182volatile bool _notification_enabled;183bool _pool_always_affected_by_gc[MemoryManager::max_num_pools];184185public:186GCMemoryManager();187~GCMemoryManager();188189void add_pool(MemoryPool* pool);190void add_pool(MemoryPool* pool, bool always_affected_by_gc);191192bool pool_always_affected_by_gc(int index) {193assert(index >= 0 && index < num_memory_pools(), "Invalid index");194return _pool_always_affected_by_gc[index];195}196197void initialize_gc_stat_info();198199bool is_gc_memory_manager() { return true; }200jlong gc_time_ms() { return _accumulated_timer.milliseconds(); }201size_t gc_count() { return _num_collections; }202int num_gc_threads() { return _num_gc_threads; }203void set_num_gc_threads(int count) { _num_gc_threads = count; }204205void gc_begin(bool recordGCBeginTime, bool recordPreGCUsage,206bool recordAccumulatedGCTime);207void gc_end(bool recordPostGCUsage, bool recordAccumulatedGCTime,208bool recordGCEndTime, bool countCollection, GCCause::Cause cause,209bool allMemoryPoolsAffected);210211void reset_gc_stat() { _num_collections = 0; _accumulated_timer.reset(); }212213// Copy out _last_gc_stat to the given destination, returning214// the collection count. Zero signifies no gc has taken place.215size_t get_last_gc_stat(GCStatInfo* dest);216217void set_notification_enabled(bool enabled) { _notification_enabled = enabled; }218bool is_notification_enabled() { return _notification_enabled; }219virtual MemoryManager::Name kind() = 0;220};221222// These subclasses of GCMemoryManager are defined to include223// GC-specific information.224// TODO: Add GC-specific information225class CopyMemoryManager : public GCMemoryManager {226private:227public:228CopyMemoryManager() : GCMemoryManager() {}229230MemoryManager::Name kind() { return MemoryManager::Copy; }231const char* name() { return "Copy"; }232};233234class MSCMemoryManager : public GCMemoryManager {235private:236public:237MSCMemoryManager() : GCMemoryManager() {}238239MemoryManager::Name kind() { return MemoryManager::MarkSweepCompact; }240const char* name() { return "MarkSweepCompact"; }241242};243244class ParNewMemoryManager : public GCMemoryManager {245private:246public:247ParNewMemoryManager() : GCMemoryManager() {}248249MemoryManager::Name kind() { return MemoryManager::ParNew; }250const char* name() { return "ParNew"; }251252};253254class CMSMemoryManager : public GCMemoryManager {255private:256public:257CMSMemoryManager() : GCMemoryManager() {}258259MemoryManager::Name kind() { return MemoryManager::ConcurrentMarkSweep; }260const char* name() { return "ConcurrentMarkSweep";}261262};263264class PSScavengeMemoryManager : public GCMemoryManager {265private:266public:267PSScavengeMemoryManager() : GCMemoryManager() {}268269MemoryManager::Name kind() { return MemoryManager::PSScavenge; }270const char* name() { return "PS Scavenge"; }271272};273274class PSMarkSweepMemoryManager : public GCMemoryManager {275private:276public:277PSMarkSweepMemoryManager() : GCMemoryManager() {}278279MemoryManager::Name kind() { return MemoryManager::PSMarkSweep; }280const char* name() { return "PS MarkSweep"; }281};282283class G1YoungGenMemoryManager : public GCMemoryManager {284private:285public:286G1YoungGenMemoryManager() : GCMemoryManager() {}287288MemoryManager::Name kind() { return MemoryManager::G1YoungGen; }289const char* name() { return "G1 Young Generation"; }290};291292class G1OldGenMemoryManager : public GCMemoryManager {293private:294public:295G1OldGenMemoryManager() : GCMemoryManager() {}296297MemoryManager::Name kind() { return MemoryManager::G1OldGen; }298const char* name() { return "G1 Old Generation"; }299};300301class ShenandoahCyclesMemoryManager : public GCMemoryManager {302public:303ShenandoahCyclesMemoryManager() : GCMemoryManager() {}304305MemoryManager::Name kind() { return MemoryManager::ShenandoahCycles; }306const char* name() { return "Shenandoah Cycles"; }307};308309class ShenandoahPausesMemoryManager : public GCMemoryManager {310public:311ShenandoahPausesMemoryManager() : GCMemoryManager() {}312313MemoryManager::Name kind() { return MemoryManager::ShenandoahPauses; }314const char* name() { return "Shenandoah Pauses"; }315};316#endif // SHARE_VM_SERVICES_MEMORYMANAGER_HPP317318319