1 /*
2 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_SERVICES_MEMORYPOOL_HPP
26 #define SHARE_VM_SERVICES_MEMORYPOOL_HPP
27
28 #include "memory/heap.hpp"
29 #include "services/memoryUsage.hpp"
30 #include "utilities/macros.hpp"
31
32 // A memory pool represents the memory area that the VM manages.
33 // The Java virtual machine has at least one memory pool
34 // 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 to
37 // both heap and non-heap memory.
38
39 // Forward declaration
40 class CompactibleFreeListSpace;
41 class ContiguousSpace;
42 class MemoryManager;
43 class SensorInfo;
44 class Generation;
45 class DefNewGeneration;
46 class ThresholdSupport;
47
48 class MemoryPool : public CHeapObj<mtInternal> {
49 friend class MemoryManager;
50 public:
51 enum PoolType {
52 Heap = 1,
53 NonHeap = 2
54 };
55
56 private:
57 enum {
58 max_num_managers = 5
59 };
60
61 // We could make some of the following as performance counters
62 // for external monitoring.
63 const char* _name;
64 PoolType _type;
65 size_t _initial_size;
127
128 SensorInfo* usage_sensor() { return _usage_sensor; }
129 SensorInfo* gc_usage_sensor() { return _gc_usage_sensor; }
130
131 void set_usage_sensor_obj(instanceHandle s);
132 void set_gc_usage_sensor_obj(instanceHandle s);
133 void set_last_collection_usage(MemoryUsage u) { _after_gc_usage = u; }
134
135 virtual instanceOop get_memory_pool_instance(TRAPS);
136 virtual MemoryUsage get_memory_usage() = 0;
137 virtual size_t used_in_bytes() = 0;
138 virtual bool is_collected_pool() { return false; }
139 virtual MemoryUsage get_last_collection_usage() { return _after_gc_usage; }
140
141 // GC support
142 void oops_do(OopClosure* f);
143 };
144
145 class CollectedMemoryPool : public MemoryPool {
146 public:
147 CollectedMemoryPool(const char* name, PoolType type, size_t init_size, size_t max_size, bool support_usage_threshold) :
148 MemoryPool(name, type, init_size, max_size, support_usage_threshold, true) {};
149 bool is_collected_pool() { return true; }
150 };
151
152 class ContiguousSpacePool : public CollectedMemoryPool {
153 private:
154 ContiguousSpace* _space;
155
156 public:
157 ContiguousSpacePool(ContiguousSpace* space, const char* name, PoolType type, size_t max_size, bool support_usage_threshold);
158
159 ContiguousSpace* space() { return _space; }
160 MemoryUsage get_memory_usage();
161 size_t used_in_bytes();
162 };
163
164 class SurvivorContiguousSpacePool : public CollectedMemoryPool {
165 private:
166 DefNewGeneration* _young_gen;
167
168 public:
169 SurvivorContiguousSpacePool(DefNewGeneration* young_gen,
170 const char* name,
171 PoolType type,
172 size_t max_size,
173 bool support_usage_threshold);
174
175 MemoryUsage get_memory_usage();
176
177 size_t used_in_bytes();
178 size_t committed_in_bytes();
179 };
180
181 #if INCLUDE_ALL_GCS
182 class CompactibleFreeListSpacePool : public CollectedMemoryPool {
183 private:
184 CompactibleFreeListSpace* _space;
185 public:
186 CompactibleFreeListSpacePool(CompactibleFreeListSpace* space,
187 const char* name,
188 PoolType type,
189 size_t max_size,
190 bool support_usage_threshold);
191
192 MemoryUsage get_memory_usage();
193 size_t used_in_bytes();
194 };
195 #endif // INCLUDE_ALL_GCS
196
197
198 class GenerationPool : public CollectedMemoryPool {
199 private:
200 Generation* _gen;
201 public:
202 GenerationPool(Generation* gen, const char* name, PoolType type, bool support_usage_threshold);
203
204 MemoryUsage get_memory_usage();
205 size_t used_in_bytes();
206 };
207
208 class CodeHeapPool: public MemoryPool {
209 private:
210 CodeHeap* _codeHeap;
211 public:
212 CodeHeapPool(CodeHeap* codeHeap, const char* name, bool support_usage_threshold);
213 MemoryUsage get_memory_usage();
214 size_t used_in_bytes() { return _codeHeap->allocated_capacity(); }
215 };
216
217 class MetaspacePool : public MemoryPool {
218 size_t calculate_max_size() const;
219 public:
220 MetaspacePool();
221 MemoryUsage get_memory_usage();
222 size_t used_in_bytes();
223 };
224
225 class CompressedKlassSpacePool : public MemoryPool {
|
1 /*
2 * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_SERVICES_MEMORYPOOL_HPP
26 #define SHARE_VM_SERVICES_MEMORYPOOL_HPP
27
28 #include "memory/heap.hpp"
29 #include "services/memoryUsage.hpp"
30 #include "utilities/macros.hpp"
31
32 // A memory pool represents the memory area that the VM manages.
33 // The Java virtual machine has at least one memory pool
34 // 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 to
37 // both heap and non-heap memory.
38
39 // Forward declaration
40 class MemoryManager;
41 class SensorInfo;
42 class ThresholdSupport;
43
44 class MemoryPool : public CHeapObj<mtInternal> {
45 friend class MemoryManager;
46 public:
47 enum PoolType {
48 Heap = 1,
49 NonHeap = 2
50 };
51
52 private:
53 enum {
54 max_num_managers = 5
55 };
56
57 // We could make some of the following as performance counters
58 // for external monitoring.
59 const char* _name;
60 PoolType _type;
61 size_t _initial_size;
123
124 SensorInfo* usage_sensor() { return _usage_sensor; }
125 SensorInfo* gc_usage_sensor() { return _gc_usage_sensor; }
126
127 void set_usage_sensor_obj(instanceHandle s);
128 void set_gc_usage_sensor_obj(instanceHandle s);
129 void set_last_collection_usage(MemoryUsage u) { _after_gc_usage = u; }
130
131 virtual instanceOop get_memory_pool_instance(TRAPS);
132 virtual MemoryUsage get_memory_usage() = 0;
133 virtual size_t used_in_bytes() = 0;
134 virtual bool is_collected_pool() { return false; }
135 virtual MemoryUsage get_last_collection_usage() { return _after_gc_usage; }
136
137 // GC support
138 void oops_do(OopClosure* f);
139 };
140
141 class CollectedMemoryPool : public MemoryPool {
142 public:
143 CollectedMemoryPool(const char* name, size_t init_size, size_t max_size, bool support_usage_threshold) :
144 MemoryPool(name, MemoryPool::Heap, init_size, max_size, support_usage_threshold, true) {};
145 bool is_collected_pool() { return true; }
146 };
147
148 class CodeHeapPool: public MemoryPool {
149 private:
150 CodeHeap* _codeHeap;
151 public:
152 CodeHeapPool(CodeHeap* codeHeap, const char* name, bool support_usage_threshold);
153 MemoryUsage get_memory_usage();
154 size_t used_in_bytes() { return _codeHeap->allocated_capacity(); }
155 };
156
157 class MetaspacePool : public MemoryPool {
158 size_t calculate_max_size() const;
159 public:
160 MetaspacePool();
161 MemoryUsage get_memory_usage();
162 size_t used_in_bytes();
163 };
164
165 class CompressedKlassSpacePool : public MemoryPool {
|