Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/services/memoryPool.hpp
32285 views
/*1* Copyright (c) 2003, 2013, 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_MEMORYPOOL_HPP25#define SHARE_VM_SERVICES_MEMORYPOOL_HPP2627#include "gc_implementation/shared/mutableSpace.hpp"28#include "memory/defNewGeneration.hpp"29#include "memory/heap.hpp"30#include "memory/space.hpp"31#include "services/memoryUsage.hpp"32#include "utilities/macros.hpp"33#if INCLUDE_ALL_GCS34#include "gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp"35#endif // INCLUDE_ALL_GCS3637// A memory pool represents the memory area that the VM manages.38// The Java virtual machine has at least one memory pool39// and it may create or remove memory pools during execution.40// A memory pool can belong to the heap or the non-heap memory.41// A Java virtual machine may also have memory pools belonging to42// both heap and non-heap memory.4344// Forward declaration45class MemoryManager;46class SensorInfo;47class Generation;48class DefNewGeneration;49class ThresholdSupport;5051class MemoryPool : public CHeapObj<mtInternal> {52friend class MemoryManager;53public:54enum PoolType {55Heap = 1,56NonHeap = 257};5859private:60enum {61max_num_managers = 562};6364// We could make some of the following as performance counters65// for external monitoring.66const char* _name;67PoolType _type;68size_t _initial_size;69size_t _max_size;70bool _available_for_allocation; // Default is true71MemoryManager* _managers[max_num_managers];72int _num_managers;73MemoryUsage _peak_usage; // Peak memory usage74MemoryUsage _after_gc_usage; // After GC memory usage7576ThresholdSupport* _usage_threshold;77ThresholdSupport* _gc_usage_threshold;7879SensorInfo* _usage_sensor;80SensorInfo* _gc_usage_sensor;8182volatile instanceOop _memory_pool_obj;8384void add_manager(MemoryManager* mgr);8586public:87MemoryPool(const char* name,88PoolType type,89size_t init_size,90size_t max_size,91bool support_usage_threshold,92bool support_gc_threshold);9394const char* name() { return _name; }95bool is_heap() { return _type == Heap; }96bool is_non_heap() { return _type == NonHeap; }97size_t initial_size() const { return _initial_size; }98int num_memory_managers() const { return _num_managers; }99// max size could be changed100virtual size_t max_size() const { return _max_size; }101102bool is_pool(instanceHandle pool) { return (pool() == _memory_pool_obj); }103104bool available_for_allocation() { return _available_for_allocation; }105bool set_available_for_allocation(bool value) {106bool prev = _available_for_allocation;107_available_for_allocation = value;108return prev;109}110111MemoryManager* get_memory_manager(int index) {112assert(index >= 0 && index < _num_managers, "Invalid index");113return _managers[index];114}115116// Records current memory usage if it's a peak usage117void record_peak_memory_usage();118119MemoryUsage get_peak_memory_usage() {120// check current memory usage first and then return peak usage121record_peak_memory_usage();122return _peak_usage;123}124void reset_peak_memory_usage() {125_peak_usage = get_memory_usage();126}127128ThresholdSupport* usage_threshold() { return _usage_threshold; }129ThresholdSupport* gc_usage_threshold() { return _gc_usage_threshold; }130131SensorInfo* usage_sensor() { return _usage_sensor; }132SensorInfo* gc_usage_sensor() { return _gc_usage_sensor; }133134void set_usage_sensor_obj(instanceHandle s);135void set_gc_usage_sensor_obj(instanceHandle s);136void set_last_collection_usage(MemoryUsage u) { _after_gc_usage = u; }137138virtual instanceOop get_memory_pool_instance(TRAPS);139virtual MemoryUsage get_memory_usage() = 0;140virtual size_t used_in_bytes() = 0;141virtual bool is_collected_pool() { return false; }142virtual MemoryUsage get_last_collection_usage() { return _after_gc_usage; }143144// GC support145void oops_do(OopClosure* f);146};147148class CollectedMemoryPool : public MemoryPool {149public:150CollectedMemoryPool(const char* name, PoolType type, size_t init_size, size_t max_size, bool support_usage_threshold) :151MemoryPool(name, type, init_size, max_size, support_usage_threshold, true) {};152bool is_collected_pool() { return true; }153};154155class ContiguousSpacePool : public CollectedMemoryPool {156private:157ContiguousSpace* _space;158159public:160ContiguousSpacePool(ContiguousSpace* space, const char* name, PoolType type, size_t max_size, bool support_usage_threshold);161162ContiguousSpace* space() { return _space; }163MemoryUsage get_memory_usage();164size_t used_in_bytes() { return space()->used(); }165};166167class SurvivorContiguousSpacePool : public CollectedMemoryPool {168private:169DefNewGeneration* _gen;170171public:172SurvivorContiguousSpacePool(DefNewGeneration* gen,173const char* name,174PoolType type,175size_t max_size,176bool support_usage_threshold);177178MemoryUsage get_memory_usage();179180size_t used_in_bytes() {181return _gen->from()->used();182}183size_t committed_in_bytes() {184return _gen->from()->capacity();185}186};187188#if INCLUDE_ALL_GCS189class CompactibleFreeListSpacePool : public CollectedMemoryPool {190private:191CompactibleFreeListSpace* _space;192public:193CompactibleFreeListSpacePool(CompactibleFreeListSpace* space,194const char* name,195PoolType type,196size_t max_size,197bool support_usage_threshold);198199MemoryUsage get_memory_usage();200size_t used_in_bytes() { return _space->used_stable(); }201};202#endif // INCLUDE_ALL_GCS203204205class GenerationPool : public CollectedMemoryPool {206private:207Generation* _gen;208public:209GenerationPool(Generation* gen, const char* name, PoolType type, bool support_usage_threshold);210211MemoryUsage get_memory_usage();212size_t used_in_bytes() { return _gen->used(); }213};214215class CodeHeapPool: public MemoryPool {216private:217CodeHeap* _codeHeap;218public:219CodeHeapPool(CodeHeap* codeHeap, const char* name, bool support_usage_threshold);220MemoryUsage get_memory_usage();221size_t used_in_bytes() { return _codeHeap->allocated_capacity(); }222};223224class MetaspacePool : public MemoryPool {225size_t calculate_max_size() const;226public:227MetaspacePool();228MemoryUsage get_memory_usage();229size_t used_in_bytes();230};231232class CompressedKlassSpacePool : public MemoryPool {233public:234CompressedKlassSpacePool();235MemoryUsage get_memory_usage();236size_t used_in_bytes();237};238239#endif // SHARE_VM_SERVICES_MEMORYPOOL_HPP240241242