Path: blob/master/src/hotspot/share/services/memoryPool.hpp
41144 views
/*1* Copyright (c) 2003, 2020, 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_MEMORYPOOL_HPP25#define SHARE_SERVICES_MEMORYPOOL_HPP2627#include "memory/heap.hpp"28#include "oops/oop.hpp"29#include "services/memoryUsage.hpp"30#include "utilities/macros.hpp"3132// A memory pool represents the memory area that the VM manages.33// The Java virtual machine has at least one memory pool34// and it may create or remove memory pools during execution.35// A memory pool can belong to the heap or the non-heap memory.36// A Java virtual machine may also have memory pools belonging to37// both heap and non-heap memory.3839// Forward declaration40class MemoryManager;41class SensorInfo;42class ThresholdSupport;4344class MemoryPool : public CHeapObj<mtInternal> {45friend class MemoryManager;46public:47enum PoolType {48Heap = 1,49NonHeap = 250};5152private:53enum {54max_num_managers = 555};5657// We could make some of the following as performance counters58// for external monitoring.59const char* _name;60PoolType _type;61size_t _initial_size;62size_t _max_size;63bool _available_for_allocation; // Default is true64MemoryManager* _managers[max_num_managers];65int _num_managers;66MemoryUsage _peak_usage; // Peak memory usage67MemoryUsage _after_gc_usage; // After GC memory usage6869ThresholdSupport* _usage_threshold;70ThresholdSupport* _gc_usage_threshold;7172SensorInfo* _usage_sensor;73SensorInfo* _gc_usage_sensor;7475volatile OopHandle _memory_pool_obj;7677void add_manager(MemoryManager* mgr);7879public:80MemoryPool(const char* name,81PoolType type,82size_t init_size,83size_t max_size,84bool support_usage_threshold,85bool support_gc_threshold);8687virtual ~MemoryPool() { }8889const char* name() { return _name; }90bool is_heap() { return _type == Heap; }91bool is_non_heap() { return _type == NonHeap; }92size_t initial_size() const { return _initial_size; }93int num_memory_managers() const { return _num_managers; }94// max size could be changed95virtual size_t max_size() const { return _max_size; }9697bool is_pool(instanceHandle pool) const;9899bool available_for_allocation() { return _available_for_allocation; }100bool set_available_for_allocation(bool value) {101bool prev = _available_for_allocation;102_available_for_allocation = value;103return prev;104}105106MemoryManager* get_memory_manager(int index) {107assert(index >= 0 && index < _num_managers, "Invalid index");108return _managers[index];109}110111// Records current memory usage if it's a peak usage112void record_peak_memory_usage();113114MemoryUsage get_peak_memory_usage() {115// check current memory usage first and then return peak usage116record_peak_memory_usage();117return _peak_usage;118}119void reset_peak_memory_usage() {120_peak_usage = get_memory_usage();121}122123ThresholdSupport* usage_threshold() { return _usage_threshold; }124ThresholdSupport* gc_usage_threshold() { return _gc_usage_threshold; }125126SensorInfo* usage_sensor() { return _usage_sensor; }127SensorInfo* gc_usage_sensor() { return _gc_usage_sensor; }128129void set_usage_sensor_obj(instanceHandle s);130void set_gc_usage_sensor_obj(instanceHandle s);131void set_last_collection_usage(MemoryUsage u) { _after_gc_usage = u; }132133virtual instanceOop get_memory_pool_instance(TRAPS);134virtual MemoryUsage get_memory_usage() = 0;135virtual size_t used_in_bytes() = 0;136virtual bool is_collected_pool() { return false; }137virtual MemoryUsage get_last_collection_usage() { return _after_gc_usage; }138};139140class CollectedMemoryPool : public MemoryPool {141public:142CollectedMemoryPool(const char* name, size_t init_size, size_t max_size, bool support_usage_threshold) :143MemoryPool(name, MemoryPool::Heap, init_size, max_size, support_usage_threshold, true) {};144bool is_collected_pool() { return true; }145};146147class CodeHeapPool: public MemoryPool {148private:149CodeHeap* _codeHeap;150public:151CodeHeapPool(CodeHeap* codeHeap, const char* name, bool support_usage_threshold);152MemoryUsage get_memory_usage();153size_t used_in_bytes() { return _codeHeap->allocated_capacity(); }154};155156class MetaspacePool : public MemoryPool {157size_t calculate_max_size() const;158public:159MetaspacePool();160MemoryUsage get_memory_usage();161size_t used_in_bytes();162};163164class CompressedKlassSpacePool : public MemoryPool {165public:166CompressedKlassSpacePool();167MemoryUsage get_memory_usage();168size_t used_in_bytes();169};170171#endif // SHARE_SERVICES_MEMORYPOOL_HPP172173174