Tue, 09 Oct 2012 10:09:34 -0700
7197424: update copyright year to match last edit in jdk8 hotspot repository
Summary: Update copyright year to 2012 for relevant files
Reviewed-by: dholmes, coleenp
1 /*
2 * Copyright (c) 2003, 2012, 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 */
25 #ifndef SHARE_VM_SERVICES_MEMORYPOOL_HPP
26 #define SHARE_VM_SERVICES_MEMORYPOOL_HPP
28 #include "gc_implementation/shared/mutableSpace.hpp"
29 #include "memory/defNewGeneration.hpp"
30 #include "memory/heap.hpp"
31 #include "memory/space.hpp"
32 #include "services/memoryUsage.hpp"
33 #ifndef SERIALGC
34 #include "gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp"
35 #endif
37 // A memory pool represents the memory area that the VM manages.
38 // The Java virtual machine has at least one memory pool
39 // 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 to
42 // both heap and non-heap memory.
44 // Forward declaration
45 class MemoryManager;
46 class SensorInfo;
47 class Generation;
48 class DefNewGeneration;
49 class ThresholdSupport;
51 class MemoryPool : public CHeapObj<mtInternal> {
52 friend class MemoryManager;
53 public:
54 enum PoolType {
55 Heap = 1,
56 NonHeap = 2
57 };
59 private:
60 enum {
61 max_num_managers = 5
62 };
64 // We could make some of the following as performance counters
65 // for external monitoring.
66 const char* _name;
67 PoolType _type;
68 size_t _initial_size;
69 size_t _max_size;
70 bool _available_for_allocation; // Default is true
71 MemoryManager* _managers[max_num_managers];
72 int _num_managers;
73 MemoryUsage _peak_usage; // Peak memory usage
74 MemoryUsage _after_gc_usage; // After GC memory usage
76 ThresholdSupport* _usage_threshold;
77 ThresholdSupport* _gc_usage_threshold;
79 SensorInfo* _usage_sensor;
80 SensorInfo* _gc_usage_sensor;
82 volatile instanceOop _memory_pool_obj;
84 void add_manager(MemoryManager* mgr);
86 public:
87 MemoryPool(const char* name,
88 PoolType type,
89 size_t init_size,
90 size_t max_size,
91 bool support_usage_threshold,
92 bool support_gc_threshold);
94 const char* name() { return _name; }
95 bool is_heap() { return _type == Heap; }
96 bool is_non_heap() { return _type == NonHeap; }
97 size_t initial_size() const { return _initial_size; }
98 int num_memory_managers() const { return _num_managers; }
99 // max size could be changed
100 virtual size_t max_size() const { return _max_size; }
102 bool is_pool(instanceHandle pool) { return (pool() == _memory_pool_obj); }
104 bool available_for_allocation() { return _available_for_allocation; }
105 bool set_available_for_allocation(bool value) {
106 bool prev = _available_for_allocation;
107 _available_for_allocation = value;
108 return prev;
109 }
111 MemoryManager* get_memory_manager(int index) {
112 assert(index >= 0 && index < _num_managers, "Invalid index");
113 return _managers[index];
114 }
116 // Records current memory usage if it's a peak usage
117 void record_peak_memory_usage();
119 MemoryUsage get_peak_memory_usage() {
120 // check current memory usage first and then return peak usage
121 record_peak_memory_usage();
122 return _peak_usage;
123 }
124 void reset_peak_memory_usage() {
125 _peak_usage = get_memory_usage();
126 }
128 ThresholdSupport* usage_threshold() { return _usage_threshold; }
129 ThresholdSupport* gc_usage_threshold() { return _gc_usage_threshold; }
131 SensorInfo* usage_sensor() { return _usage_sensor; }
132 SensorInfo* gc_usage_sensor() { return _gc_usage_sensor; }
134 void set_usage_sensor_obj(instanceHandle s);
135 void set_gc_usage_sensor_obj(instanceHandle s);
136 void set_last_collection_usage(MemoryUsage u) { _after_gc_usage = u; }
138 virtual instanceOop get_memory_pool_instance(TRAPS);
139 virtual MemoryUsage get_memory_usage() = 0;
140 virtual size_t used_in_bytes() = 0;
141 virtual bool is_collected_pool() { return false; }
142 virtual MemoryUsage get_last_collection_usage() { return _after_gc_usage; }
144 // GC support
145 void oops_do(OopClosure* f);
146 };
148 class CollectedMemoryPool : public MemoryPool {
149 public:
150 CollectedMemoryPool(const char* name, PoolType type, size_t init_size, size_t max_size, bool support_usage_threshold) :
151 MemoryPool(name, type, init_size, max_size, support_usage_threshold, true) {};
152 bool is_collected_pool() { return true; }
153 };
155 class ContiguousSpacePool : public CollectedMemoryPool {
156 private:
157 ContiguousSpace* _space;
159 public:
160 ContiguousSpacePool(ContiguousSpace* space, const char* name, PoolType type, size_t max_size, bool support_usage_threshold);
162 ContiguousSpace* space() { return _space; }
163 MemoryUsage get_memory_usage();
164 size_t used_in_bytes() { return space()->used(); }
165 };
167 class SurvivorContiguousSpacePool : public CollectedMemoryPool {
168 private:
169 DefNewGeneration* _gen;
171 public:
172 SurvivorContiguousSpacePool(DefNewGeneration* gen,
173 const char* name,
174 PoolType type,
175 size_t max_size,
176 bool support_usage_threshold);
178 MemoryUsage get_memory_usage();
180 size_t used_in_bytes() {
181 return _gen->from()->used();
182 }
183 size_t committed_in_bytes() {
184 return _gen->from()->capacity();
185 }
186 };
188 #ifndef SERIALGC
189 class CompactibleFreeListSpacePool : public CollectedMemoryPool {
190 private:
191 CompactibleFreeListSpace* _space;
192 public:
193 CompactibleFreeListSpacePool(CompactibleFreeListSpace* space,
194 const char* name,
195 PoolType type,
196 size_t max_size,
197 bool support_usage_threshold);
199 MemoryUsage get_memory_usage();
200 size_t used_in_bytes() { return _space->used(); }
201 };
202 #endif // SERIALGC
205 class GenerationPool : public CollectedMemoryPool {
206 private:
207 Generation* _gen;
208 public:
209 GenerationPool(Generation* gen, const char* name, PoolType type, bool support_usage_threshold);
211 MemoryUsage get_memory_usage();
212 size_t used_in_bytes() { return _gen->used(); }
213 };
215 class CodeHeapPool: public MemoryPool {
216 private:
217 CodeHeap* _codeHeap;
218 public:
219 CodeHeapPool(CodeHeap* codeHeap, const char* name, bool support_usage_threshold);
220 MemoryUsage get_memory_usage();
221 size_t used_in_bytes() { return _codeHeap->allocated_capacity(); }
222 };
224 #endif // SHARE_VM_SERVICES_MEMORYPOOL_HPP