Mercurial > hg > truffle
annotate src/share/vm/services/memoryPool.cpp @ 14702:d4dd5204c0aa
Merge
author | ehelin |
---|---|
date | Fri, 14 Mar 2014 13:27:18 +0100 |
parents | 190899198332 |
children | 270d7cb38f40 |
rev | line source |
---|---|
0 | 1 /* |
12316
190899198332
7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents:
12248
diff
changeset
|
2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "classfile/systemDictionary.hpp" | |
27 #include "classfile/vmSymbols.hpp" | |
11039
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
28 #include "memory/metaspace.hpp" |
1972 | 29 #include "oops/oop.inline.hpp" |
30 #include "runtime/handles.inline.hpp" | |
31 #include "runtime/javaCalls.hpp" | |
32 #include "services/lowMemoryDetector.hpp" | |
33 #include "services/management.hpp" | |
34 #include "services/memoryManager.hpp" | |
35 #include "services/memoryPool.hpp" | |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
6725
diff
changeset
|
36 #include "utilities/macros.hpp" |
11039
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
37 #include "utilities/globalDefinitions.hpp" |
0 | 38 |
39 MemoryPool::MemoryPool(const char* name, | |
40 PoolType type, | |
41 size_t init_size, | |
42 size_t max_size, | |
43 bool support_usage_threshold, | |
44 bool support_gc_threshold) { | |
45 _name = name; | |
46 _initial_size = init_size; | |
47 _max_size = max_size; | |
12316
190899198332
7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents:
12248
diff
changeset
|
48 (void)const_cast<instanceOop&>(_memory_pool_obj = NULL); |
0 | 49 _available_for_allocation = true; |
50 _num_managers = 0; | |
51 _type = type; | |
52 | |
53 // initialize the max and init size of collection usage | |
54 _after_gc_usage = MemoryUsage(_initial_size, 0, 0, _max_size); | |
55 | |
56 _usage_sensor = NULL; | |
57 _gc_usage_sensor = NULL; | |
58 // usage threshold supports both high and low threshold | |
59 _usage_threshold = new ThresholdSupport(support_usage_threshold, support_usage_threshold); | |
60 // gc usage threshold supports only high threshold | |
61 _gc_usage_threshold = new ThresholdSupport(support_gc_threshold, support_gc_threshold); | |
62 } | |
63 | |
64 void MemoryPool::add_manager(MemoryManager* mgr) { | |
65 assert(_num_managers < MemoryPool::max_num_managers, "_num_managers exceeds the max"); | |
66 if (_num_managers < MemoryPool::max_num_managers) { | |
67 _managers[_num_managers] = mgr; | |
68 _num_managers++; | |
69 } | |
70 } | |
71 | |
72 | |
73 // Returns an instanceHandle of a MemoryPool object. | |
74 // It creates a MemoryPool instance when the first time | |
75 // this function is called. | |
76 instanceOop MemoryPool::get_memory_pool_instance(TRAPS) { | |
77 // Must do an acquire so as to force ordering of subsequent | |
78 // loads from anything _memory_pool_obj points to or implies. | |
79 instanceOop pool_obj = (instanceOop)OrderAccess::load_ptr_acquire(&_memory_pool_obj); | |
80 if (pool_obj == NULL) { | |
81 // It's ok for more than one thread to execute the code up to the locked region. | |
82 // Extra pool instances will just be gc'ed. | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
83 Klass* k = Management::sun_management_ManagementFactory_klass(CHECK_NULL); |
0 | 84 instanceKlassHandle ik(THREAD, k); |
85 | |
86 Handle pool_name = java_lang_String::create_from_str(_name, CHECK_NULL); | |
87 jlong usage_threshold_value = (_usage_threshold->is_high_threshold_supported() ? 0 : -1L); | |
88 jlong gc_usage_threshold_value = (_gc_usage_threshold->is_high_threshold_supported() ? 0 : -1L); | |
89 | |
90 JavaValue result(T_OBJECT); | |
91 JavaCallArguments args; | |
92 args.push_oop(pool_name); // Argument 1 | |
93 args.push_int((int) is_heap()); // Argument 2 | |
94 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
95 Symbol* method_name = vmSymbols::createMemoryPool_name(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
96 Symbol* signature = vmSymbols::createMemoryPool_signature(); |
0 | 97 |
98 args.push_long(usage_threshold_value); // Argument 3 | |
99 args.push_long(gc_usage_threshold_value); // Argument 4 | |
100 | |
101 JavaCalls::call_static(&result, | |
102 ik, | |
103 method_name, | |
104 signature, | |
105 &args, | |
106 CHECK_NULL); | |
107 | |
108 instanceOop p = (instanceOop) result.get_jobject(); | |
109 instanceHandle pool(THREAD, p); | |
110 | |
111 { | |
112 // Get lock since another thread may have create the instance | |
113 MutexLocker ml(Management_lock); | |
114 | |
115 // Check if another thread has created the pool. We reload | |
116 // _memory_pool_obj here because some other thread may have | |
117 // initialized it while we were executing the code before the lock. | |
118 // | |
119 // The lock has done an acquire, so the load can't float above it, | |
120 // but we need to do a load_acquire as above. | |
121 pool_obj = (instanceOop)OrderAccess::load_ptr_acquire(&_memory_pool_obj); | |
122 if (pool_obj != NULL) { | |
123 return pool_obj; | |
124 } | |
125 | |
126 // Get the address of the object we created via call_special. | |
127 pool_obj = pool(); | |
128 | |
129 // Use store barrier to make sure the memory accesses associated | |
130 // with creating the pool are visible before publishing its address. | |
131 // The unlock will publish the store to _memory_pool_obj because | |
132 // it does a release first. | |
133 OrderAccess::release_store_ptr(&_memory_pool_obj, pool_obj); | |
134 } | |
135 } | |
136 | |
137 return pool_obj; | |
138 } | |
139 | |
140 inline static size_t get_max_value(size_t val1, size_t val2) { | |
141 return (val1 > val2 ? val1 : val2); | |
142 } | |
143 | |
144 void MemoryPool::record_peak_memory_usage() { | |
145 // Caller in JDK is responsible for synchronization - | |
146 // acquire the lock for this memory pool before calling VM | |
147 MemoryUsage usage = get_memory_usage(); | |
148 size_t peak_used = get_max_value(usage.used(), _peak_usage.used()); | |
149 size_t peak_committed = get_max_value(usage.committed(), _peak_usage.committed()); | |
150 size_t peak_max_size = get_max_value(usage.max_size(), _peak_usage.max_size()); | |
151 | |
152 _peak_usage = MemoryUsage(initial_size(), peak_used, peak_committed, peak_max_size); | |
153 } | |
154 | |
155 static void set_sensor_obj_at(SensorInfo** sensor_ptr, instanceHandle sh) { | |
156 assert(*sensor_ptr == NULL, "Should be called only once"); | |
157 SensorInfo* sensor = new SensorInfo(); | |
158 sensor->set_sensor(sh()); | |
159 *sensor_ptr = sensor; | |
160 } | |
161 | |
162 void MemoryPool::set_usage_sensor_obj(instanceHandle sh) { | |
163 set_sensor_obj_at(&_usage_sensor, sh); | |
164 } | |
165 | |
166 void MemoryPool::set_gc_usage_sensor_obj(instanceHandle sh) { | |
167 set_sensor_obj_at(&_gc_usage_sensor, sh); | |
168 } | |
169 | |
170 void MemoryPool::oops_do(OopClosure* f) { | |
171 f->do_oop((oop*) &_memory_pool_obj); | |
172 if (_usage_sensor != NULL) { | |
173 _usage_sensor->oops_do(f); | |
174 } | |
175 if (_gc_usage_sensor != NULL) { | |
176 _gc_usage_sensor->oops_do(f); | |
177 } | |
178 } | |
179 | |
180 ContiguousSpacePool::ContiguousSpacePool(ContiguousSpace* space, | |
181 const char* name, | |
182 PoolType type, | |
183 size_t max_size, | |
184 bool support_usage_threshold) : | |
185 CollectedMemoryPool(name, type, space->capacity(), max_size, | |
186 support_usage_threshold), _space(space) { | |
187 } | |
188 | |
189 MemoryUsage ContiguousSpacePool::get_memory_usage() { | |
190 size_t maxSize = (available_for_allocation() ? max_size() : 0); | |
191 size_t used = used_in_bytes(); | |
192 size_t committed = _space->capacity(); | |
193 | |
194 return MemoryUsage(initial_size(), used, committed, maxSize); | |
195 } | |
196 | |
197 SurvivorContiguousSpacePool::SurvivorContiguousSpacePool(DefNewGeneration* gen, | |
198 const char* name, | |
199 PoolType type, | |
200 size_t max_size, | |
201 bool support_usage_threshold) : | |
202 CollectedMemoryPool(name, type, gen->from()->capacity(), max_size, | |
203 support_usage_threshold), _gen(gen) { | |
204 } | |
205 | |
206 MemoryUsage SurvivorContiguousSpacePool::get_memory_usage() { | |
207 size_t maxSize = (available_for_allocation() ? max_size() : 0); | |
208 size_t used = used_in_bytes(); | |
209 size_t committed = committed_in_bytes(); | |
210 | |
211 return MemoryUsage(initial_size(), used, committed, maxSize); | |
212 } | |
213 | |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
6725
diff
changeset
|
214 #if INCLUDE_ALL_GCS |
0 | 215 CompactibleFreeListSpacePool::CompactibleFreeListSpacePool(CompactibleFreeListSpace* space, |
216 const char* name, | |
217 PoolType type, | |
218 size_t max_size, | |
219 bool support_usage_threshold) : | |
220 CollectedMemoryPool(name, type, space->capacity(), max_size, | |
221 support_usage_threshold), _space(space) { | |
222 } | |
223 | |
224 MemoryUsage CompactibleFreeListSpacePool::get_memory_usage() { | |
225 size_t maxSize = (available_for_allocation() ? max_size() : 0); | |
226 size_t used = used_in_bytes(); | |
227 size_t committed = _space->capacity(); | |
228 | |
229 return MemoryUsage(initial_size(), used, committed, maxSize); | |
230 } | |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
6725
diff
changeset
|
231 #endif // INCLUDE_ALL_GCS |
0 | 232 |
233 GenerationPool::GenerationPool(Generation* gen, | |
234 const char* name, | |
235 PoolType type, | |
236 bool support_usage_threshold) : | |
237 CollectedMemoryPool(name, type, gen->capacity(), gen->max_capacity(), | |
238 support_usage_threshold), _gen(gen) { | |
239 } | |
240 | |
241 MemoryUsage GenerationPool::get_memory_usage() { | |
242 size_t used = used_in_bytes(); | |
243 size_t committed = _gen->capacity(); | |
244 size_t maxSize = (available_for_allocation() ? max_size() : 0); | |
245 | |
246 return MemoryUsage(initial_size(), used, committed, maxSize); | |
247 } | |
248 | |
249 CodeHeapPool::CodeHeapPool(CodeHeap* codeHeap, const char* name, bool support_usage_threshold) : | |
250 MemoryPool(name, NonHeap, codeHeap->capacity(), codeHeap->max_capacity(), | |
251 support_usage_threshold, false), _codeHeap(codeHeap) { | |
252 } | |
253 | |
254 MemoryUsage CodeHeapPool::get_memory_usage() { | |
255 size_t used = used_in_bytes(); | |
256 size_t committed = _codeHeap->capacity(); | |
257 size_t maxSize = (available_for_allocation() ? max_size() : 0); | |
258 | |
259 return MemoryUsage(initial_size(), used, committed, maxSize); | |
260 } | |
11039
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
261 |
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
262 MetaspacePool::MetaspacePool() : |
12248
73d0d0218068
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
12226
diff
changeset
|
263 MemoryPool("Metaspace", NonHeap, 0, calculate_max_size(), true, false) { } |
11039
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
264 |
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
265 MemoryUsage MetaspacePool::get_memory_usage() { |
12248
73d0d0218068
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
12226
diff
changeset
|
266 size_t committed = MetaspaceAux::committed_bytes(); |
11039
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
267 return MemoryUsage(initial_size(), used_in_bytes(), committed, max_size()); |
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
268 } |
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
269 |
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
270 size_t MetaspacePool::used_in_bytes() { |
12084
422920730903
8023219: NPG: MetaspaceMemoryPool should report statistics for all of metaspace
ehelin
parents:
11039
diff
changeset
|
271 return MetaspaceAux::allocated_used_bytes(); |
11039
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
272 } |
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
273 |
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
274 size_t MetaspacePool::calculate_max_size() const { |
12248
73d0d0218068
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
12226
diff
changeset
|
275 return FLAG_IS_CMDLINE(MaxMetaspaceSize) ? MaxMetaspaceSize : |
73d0d0218068
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
12226
diff
changeset
|
276 MemoryUsage::undefined_size(); |
11039
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
277 } |
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
278 |
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
279 CompressedKlassSpacePool::CompressedKlassSpacePool() : |
12248
73d0d0218068
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
12226
diff
changeset
|
280 MemoryPool("Compressed Class Space", NonHeap, 0, CompressedClassSpaceSize, true, false) { } |
11039
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
281 |
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
282 size_t CompressedKlassSpacePool::used_in_bytes() { |
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
283 return MetaspaceAux::allocated_used_bytes(Metaspace::ClassType); |
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
284 } |
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
285 |
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
286 MemoryUsage CompressedKlassSpacePool::get_memory_usage() { |
12248
73d0d0218068
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
12226
diff
changeset
|
287 size_t committed = MetaspaceAux::committed_bytes(Metaspace::ClassType); |
11039
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
288 return MemoryUsage(initial_size(), used_in_bytes(), committed, max_size()); |
71963b3f802a
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
8827
diff
changeset
|
289 } |