src/share/vm/services/memoryPool.hpp

Wed, 03 Jul 2019 20:42:37 +0800

author
aoqi
date
Wed, 03 Jul 2019 20:42:37 +0800
changeset 9637
eef07cd490d4
parent 6876
710a3c8b516e
child 9806
758c07667682
permissions
-rw-r--r--

Merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_SERVICES_MEMORYPOOL_HPP
aoqi@0 26 #define SHARE_VM_SERVICES_MEMORYPOOL_HPP
aoqi@0 27
aoqi@0 28 #include "gc_implementation/shared/mutableSpace.hpp"
aoqi@0 29 #include "memory/defNewGeneration.hpp"
aoqi@0 30 #include "memory/heap.hpp"
aoqi@0 31 #include "memory/space.hpp"
aoqi@0 32 #include "services/memoryUsage.hpp"
aoqi@0 33 #include "utilities/macros.hpp"
aoqi@0 34 #if INCLUDE_ALL_GCS
aoqi@0 35 #include "gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp"
aoqi@0 36 #endif // INCLUDE_ALL_GCS
aoqi@0 37
aoqi@0 38 // A memory pool represents the memory area that the VM manages.
aoqi@0 39 // The Java virtual machine has at least one memory pool
aoqi@0 40 // and it may create or remove memory pools during execution.
aoqi@0 41 // A memory pool can belong to the heap or the non-heap memory.
aoqi@0 42 // A Java virtual machine may also have memory pools belonging to
aoqi@0 43 // both heap and non-heap memory.
aoqi@0 44
aoqi@0 45 // Forward declaration
aoqi@0 46 class MemoryManager;
aoqi@0 47 class SensorInfo;
aoqi@0 48 class Generation;
aoqi@0 49 class DefNewGeneration;
aoqi@0 50 class ThresholdSupport;
aoqi@0 51
aoqi@0 52 class MemoryPool : public CHeapObj<mtInternal> {
aoqi@0 53 friend class MemoryManager;
aoqi@0 54 public:
aoqi@0 55 enum PoolType {
aoqi@0 56 Heap = 1,
aoqi@0 57 NonHeap = 2
aoqi@0 58 };
aoqi@0 59
aoqi@0 60 private:
aoqi@0 61 enum {
aoqi@0 62 max_num_managers = 5
aoqi@0 63 };
aoqi@0 64
aoqi@0 65 // We could make some of the following as performance counters
aoqi@0 66 // for external monitoring.
aoqi@0 67 const char* _name;
aoqi@0 68 PoolType _type;
aoqi@0 69 size_t _initial_size;
aoqi@0 70 size_t _max_size;
aoqi@0 71 bool _available_for_allocation; // Default is true
aoqi@0 72 MemoryManager* _managers[max_num_managers];
aoqi@0 73 int _num_managers;
aoqi@0 74 MemoryUsage _peak_usage; // Peak memory usage
aoqi@0 75 MemoryUsage _after_gc_usage; // After GC memory usage
aoqi@0 76
aoqi@0 77 ThresholdSupport* _usage_threshold;
aoqi@0 78 ThresholdSupport* _gc_usage_threshold;
aoqi@0 79
aoqi@0 80 SensorInfo* _usage_sensor;
aoqi@0 81 SensorInfo* _gc_usage_sensor;
aoqi@0 82
aoqi@0 83 volatile instanceOop _memory_pool_obj;
aoqi@0 84
aoqi@0 85 void add_manager(MemoryManager* mgr);
aoqi@0 86
aoqi@0 87 public:
aoqi@0 88 MemoryPool(const char* name,
aoqi@0 89 PoolType type,
aoqi@0 90 size_t init_size,
aoqi@0 91 size_t max_size,
aoqi@0 92 bool support_usage_threshold,
aoqi@0 93 bool support_gc_threshold);
aoqi@0 94
aoqi@0 95 const char* name() { return _name; }
aoqi@0 96 bool is_heap() { return _type == Heap; }
aoqi@0 97 bool is_non_heap() { return _type == NonHeap; }
aoqi@0 98 size_t initial_size() const { return _initial_size; }
aoqi@0 99 int num_memory_managers() const { return _num_managers; }
aoqi@0 100 // max size could be changed
aoqi@0 101 virtual size_t max_size() const { return _max_size; }
aoqi@0 102
aoqi@0 103 bool is_pool(instanceHandle pool) { return (pool() == _memory_pool_obj); }
aoqi@0 104
aoqi@0 105 bool available_for_allocation() { return _available_for_allocation; }
aoqi@0 106 bool set_available_for_allocation(bool value) {
aoqi@0 107 bool prev = _available_for_allocation;
aoqi@0 108 _available_for_allocation = value;
aoqi@0 109 return prev;
aoqi@0 110 }
aoqi@0 111
aoqi@0 112 MemoryManager* get_memory_manager(int index) {
aoqi@0 113 assert(index >= 0 && index < _num_managers, "Invalid index");
aoqi@0 114 return _managers[index];
aoqi@0 115 }
aoqi@0 116
aoqi@0 117 // Records current memory usage if it's a peak usage
aoqi@0 118 void record_peak_memory_usage();
aoqi@0 119
aoqi@0 120 MemoryUsage get_peak_memory_usage() {
aoqi@0 121 // check current memory usage first and then return peak usage
aoqi@0 122 record_peak_memory_usage();
aoqi@0 123 return _peak_usage;
aoqi@0 124 }
aoqi@0 125 void reset_peak_memory_usage() {
aoqi@0 126 _peak_usage = get_memory_usage();
aoqi@0 127 }
aoqi@0 128
aoqi@0 129 ThresholdSupport* usage_threshold() { return _usage_threshold; }
aoqi@0 130 ThresholdSupport* gc_usage_threshold() { return _gc_usage_threshold; }
aoqi@0 131
aoqi@0 132 SensorInfo* usage_sensor() { return _usage_sensor; }
aoqi@0 133 SensorInfo* gc_usage_sensor() { return _gc_usage_sensor; }
aoqi@0 134
aoqi@0 135 void set_usage_sensor_obj(instanceHandle s);
aoqi@0 136 void set_gc_usage_sensor_obj(instanceHandle s);
aoqi@0 137 void set_last_collection_usage(MemoryUsage u) { _after_gc_usage = u; }
aoqi@0 138
aoqi@0 139 virtual instanceOop get_memory_pool_instance(TRAPS);
aoqi@0 140 virtual MemoryUsage get_memory_usage() = 0;
aoqi@0 141 virtual size_t used_in_bytes() = 0;
aoqi@0 142 virtual bool is_collected_pool() { return false; }
aoqi@0 143 virtual MemoryUsage get_last_collection_usage() { return _after_gc_usage; }
aoqi@0 144
aoqi@0 145 // GC support
aoqi@0 146 void oops_do(OopClosure* f);
aoqi@0 147 };
aoqi@0 148
aoqi@0 149 class CollectedMemoryPool : public MemoryPool {
aoqi@0 150 public:
aoqi@0 151 CollectedMemoryPool(const char* name, PoolType type, size_t init_size, size_t max_size, bool support_usage_threshold) :
aoqi@0 152 MemoryPool(name, type, init_size, max_size, support_usage_threshold, true) {};
aoqi@0 153 bool is_collected_pool() { return true; }
aoqi@0 154 };
aoqi@0 155
aoqi@0 156 class ContiguousSpacePool : public CollectedMemoryPool {
aoqi@0 157 private:
aoqi@0 158 ContiguousSpace* _space;
aoqi@0 159
aoqi@0 160 public:
aoqi@0 161 ContiguousSpacePool(ContiguousSpace* space, const char* name, PoolType type, size_t max_size, bool support_usage_threshold);
aoqi@0 162
aoqi@0 163 ContiguousSpace* space() { return _space; }
aoqi@0 164 MemoryUsage get_memory_usage();
aoqi@0 165 size_t used_in_bytes() { return space()->used(); }
aoqi@0 166 };
aoqi@0 167
aoqi@0 168 class SurvivorContiguousSpacePool : public CollectedMemoryPool {
aoqi@0 169 private:
aoqi@0 170 DefNewGeneration* _gen;
aoqi@0 171
aoqi@0 172 public:
aoqi@0 173 SurvivorContiguousSpacePool(DefNewGeneration* gen,
aoqi@0 174 const char* name,
aoqi@0 175 PoolType type,
aoqi@0 176 size_t max_size,
aoqi@0 177 bool support_usage_threshold);
aoqi@0 178
aoqi@0 179 MemoryUsage get_memory_usage();
aoqi@0 180
aoqi@0 181 size_t used_in_bytes() {
aoqi@0 182 return _gen->from()->used();
aoqi@0 183 }
aoqi@0 184 size_t committed_in_bytes() {
aoqi@0 185 return _gen->from()->capacity();
aoqi@0 186 }
aoqi@0 187 };
aoqi@0 188
aoqi@0 189 #if INCLUDE_ALL_GCS
aoqi@0 190 class CompactibleFreeListSpacePool : public CollectedMemoryPool {
aoqi@0 191 private:
aoqi@0 192 CompactibleFreeListSpace* _space;
aoqi@0 193 public:
aoqi@0 194 CompactibleFreeListSpacePool(CompactibleFreeListSpace* space,
aoqi@0 195 const char* name,
aoqi@0 196 PoolType type,
aoqi@0 197 size_t max_size,
aoqi@0 198 bool support_usage_threshold);
aoqi@0 199
aoqi@0 200 MemoryUsage get_memory_usage();
aoqi@0 201 size_t used_in_bytes() { return _space->used(); }
aoqi@0 202 };
aoqi@0 203 #endif // INCLUDE_ALL_GCS
aoqi@0 204
aoqi@0 205
aoqi@0 206 class GenerationPool : public CollectedMemoryPool {
aoqi@0 207 private:
aoqi@0 208 Generation* _gen;
aoqi@0 209 public:
aoqi@0 210 GenerationPool(Generation* gen, const char* name, PoolType type, bool support_usage_threshold);
aoqi@0 211
aoqi@0 212 MemoryUsage get_memory_usage();
aoqi@0 213 size_t used_in_bytes() { return _gen->used(); }
aoqi@0 214 };
aoqi@0 215
aoqi@0 216 class CodeHeapPool: public MemoryPool {
aoqi@0 217 private:
aoqi@0 218 CodeHeap* _codeHeap;
aoqi@0 219 public:
aoqi@0 220 CodeHeapPool(CodeHeap* codeHeap, const char* name, bool support_usage_threshold);
aoqi@0 221 MemoryUsage get_memory_usage();
aoqi@0 222 size_t used_in_bytes() { return _codeHeap->allocated_capacity(); }
aoqi@0 223 };
aoqi@0 224
aoqi@0 225 class MetaspacePool : public MemoryPool {
aoqi@0 226 size_t calculate_max_size() const;
aoqi@0 227 public:
aoqi@0 228 MetaspacePool();
aoqi@0 229 MemoryUsage get_memory_usage();
aoqi@0 230 size_t used_in_bytes();
aoqi@0 231 };
aoqi@0 232
aoqi@0 233 class CompressedKlassSpacePool : public MemoryPool {
aoqi@0 234 public:
aoqi@0 235 CompressedKlassSpacePool();
aoqi@0 236 MemoryUsage get_memory_usage();
aoqi@0 237 size_t used_in_bytes();
aoqi@0 238 };
aoqi@0 239
aoqi@0 240 #endif // SHARE_VM_SERVICES_MEMORYPOOL_HPP

mercurial