Mercurial > hg > truffle
annotate src/share/vm/gc_interface/collectedHeap.inline.hpp @ 3852:fdb992d83a87
7071653: JSR 292: call site change notification should be pushed not pulled
Reviewed-by: kvn, never, bdelsart
author | twisti |
---|---|
date | Tue, 16 Aug 2011 04:14:05 -0700 |
parents | c9ca3f51cf41 |
children | baf763f388e6 |
rev | line source |
---|---|
0 | 1 /* |
2100
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
2 * Copyright (c) 2001, 2011, 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:
579
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
579
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:
579
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #ifndef SHARE_VM_GC_INTERFACE_COLLECTEDHEAP_INLINE_HPP |
26 #define SHARE_VM_GC_INTERFACE_COLLECTEDHEAP_INLINE_HPP | |
27 | |
28 #include "gc_interface/collectedHeap.hpp" | |
29 #include "memory/threadLocalAllocBuffer.inline.hpp" | |
30 #include "memory/universe.hpp" | |
31 #include "oops/arrayOop.hpp" | |
32 #include "prims/jvmtiExport.hpp" | |
33 #include "runtime/sharedRuntime.hpp" | |
34 #include "runtime/thread.hpp" | |
35 #include "services/lowMemoryDetector.hpp" | |
36 #include "utilities/copy.hpp" | |
37 #ifdef TARGET_OS_FAMILY_linux | |
38 # include "thread_linux.inline.hpp" | |
39 #endif | |
40 #ifdef TARGET_OS_FAMILY_solaris | |
41 # include "thread_solaris.inline.hpp" | |
42 #endif | |
43 #ifdef TARGET_OS_FAMILY_windows | |
44 # include "thread_windows.inline.hpp" | |
45 #endif | |
46 | |
0 | 47 // Inline allocation implementations. |
48 | |
49 void CollectedHeap::post_allocation_setup_common(KlassHandle klass, | |
50 HeapWord* obj, | |
51 size_t size) { | |
52 post_allocation_setup_no_klass_install(klass, obj, size); | |
53 post_allocation_install_obj_klass(klass, oop(obj), (int) size); | |
54 } | |
55 | |
56 void CollectedHeap::post_allocation_setup_no_klass_install(KlassHandle klass, | |
57 HeapWord* objPtr, | |
58 size_t size) { | |
59 oop obj = (oop)objPtr; | |
60 | |
61 assert(obj != NULL, "NULL object pointer"); | |
62 if (UseBiasedLocking && (klass() != NULL)) { | |
63 obj->set_mark(klass->prototype_header()); | |
64 } else { | |
65 // May be bootstrapping | |
66 obj->set_mark(markOopDesc::prototype()); | |
67 } | |
68 } | |
69 | |
70 void CollectedHeap::post_allocation_install_obj_klass(KlassHandle klass, | |
71 oop obj, | |
72 int size) { | |
73 // These asserts are kind of complicated because of klassKlass | |
74 // and the beginning of the world. | |
75 assert(klass() != NULL || !Universe::is_fully_initialized(), "NULL klass"); | |
76 assert(klass() == NULL || klass()->is_klass(), "not a klass"); | |
77 assert(klass() == NULL || klass()->klass_part() != NULL, "not a klass"); | |
78 assert(obj != NULL, "NULL object pointer"); | |
79 obj->set_klass(klass()); | |
80 assert(!Universe::is_fully_initialized() || obj->blueprint() != NULL, | |
81 "missing blueprint"); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
82 } |
0 | 83 |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
84 // Support for jvmti and dtrace |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
85 inline void post_allocation_notify(KlassHandle klass, oop obj) { |
481
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
86 // support low memory notifications (no-op if not enabled) |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
87 LowMemoryDetector::detect_low_memory_for_collected_pools(); |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
356
diff
changeset
|
88 |
0 | 89 // support for JVMTI VMObjectAlloc event (no-op if not enabled) |
90 JvmtiExport::vm_object_alloc_event_collector(obj); | |
91 | |
92 if (DTraceAllocProbes) { | |
93 // support for Dtrace object alloc event (no-op most of the time) | |
94 if (klass() != NULL && klass()->klass_part()->name() != NULL) { | |
95 SharedRuntime::dtrace_object_alloc(obj); | |
96 } | |
97 } | |
98 } | |
99 | |
100 void CollectedHeap::post_allocation_setup_obj(KlassHandle klass, | |
101 HeapWord* obj, | |
102 size_t size) { | |
103 post_allocation_setup_common(klass, obj, size); | |
104 assert(Universe::is_bootstrapping() || | |
105 !((oop)obj)->blueprint()->oop_is_array(), "must not be an array"); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
106 // notify jvmti and dtrace |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
107 post_allocation_notify(klass, (oop)obj); |
0 | 108 } |
109 | |
110 void CollectedHeap::post_allocation_setup_array(KlassHandle klass, | |
111 HeapWord* obj, | |
112 size_t size, | |
113 int length) { | |
167
feeb96a45707
6696264: assert("narrow oop can never be zero") for GCBasher & ParNewGC
coleenp
parents:
113
diff
changeset
|
114 // Set array length before setting the _klass field |
feeb96a45707
6696264: assert("narrow oop can never be zero") for GCBasher & ParNewGC
coleenp
parents:
113
diff
changeset
|
115 // in post_allocation_setup_common() because the klass field |
feeb96a45707
6696264: assert("narrow oop can never be zero") for GCBasher & ParNewGC
coleenp
parents:
113
diff
changeset
|
116 // indicates that the object is parsable by concurrent GC. |
0 | 117 assert(length >= 0, "length should be non-negative"); |
167
feeb96a45707
6696264: assert("narrow oop can never be zero") for GCBasher & ParNewGC
coleenp
parents:
113
diff
changeset
|
118 ((arrayOop)obj)->set_length(length); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
119 post_allocation_setup_common(klass, obj, size); |
0 | 120 assert(((oop)obj)->blueprint()->oop_is_array(), "must be an array"); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
121 // notify jvmti and dtrace (must be after length is set for dtrace) |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
122 post_allocation_notify(klass, (oop)obj); |
0 | 123 } |
124 | |
3774
c9ca3f51cf41
6994322: Remove the is_tlab and is_noref / is_large_noref parameters from the CollectedHeap
tonyp
parents:
2100
diff
changeset
|
125 HeapWord* CollectedHeap::common_mem_allocate_noinit(size_t size, TRAPS) { |
0 | 126 |
127 // Clear unhandled oops for memory allocation. Memory allocation might | |
128 // not take out a lock if from tlab, so clear here. | |
129 CHECK_UNHANDLED_OOPS_ONLY(THREAD->clear_unhandled_oops();) | |
130 | |
131 if (HAS_PENDING_EXCEPTION) { | |
132 NOT_PRODUCT(guarantee(false, "Should not allocate with exception pending")); | |
133 return NULL; // caller does a CHECK_0 too | |
134 } | |
135 | |
136 HeapWord* result = NULL; | |
137 if (UseTLAB) { | |
138 result = CollectedHeap::allocate_from_tlab(THREAD, size); | |
139 if (result != NULL) { | |
140 assert(!HAS_PENDING_EXCEPTION, | |
141 "Unexpected exception, will result in uninitialized storage"); | |
142 return result; | |
143 } | |
144 } | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
145 bool gc_overhead_limit_was_exceeded = false; |
0 | 146 result = Universe::heap()->mem_allocate(size, |
147 &gc_overhead_limit_was_exceeded); | |
148 if (result != NULL) { | |
149 NOT_PRODUCT(Universe::heap()-> | |
150 check_for_non_bad_heap_word_value(result, size)); | |
151 assert(!HAS_PENDING_EXCEPTION, | |
152 "Unexpected exception, will result in uninitialized storage"); | |
2100
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
153 THREAD->incr_allocated_bytes(size * HeapWordSize); |
0 | 154 return result; |
155 } | |
156 | |
157 | |
158 if (!gc_overhead_limit_was_exceeded) { | |
159 // -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError support | |
160 report_java_out_of_memory("Java heap space"); | |
161 | |
162 if (JvmtiExport::should_post_resource_exhausted()) { | |
163 JvmtiExport::post_resource_exhausted( | |
164 JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR | JVMTI_RESOURCE_EXHAUSTED_JAVA_HEAP, | |
165 "Java heap space"); | |
166 } | |
167 | |
168 THROW_OOP_0(Universe::out_of_memory_error_java_heap()); | |
169 } else { | |
170 // -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError support | |
171 report_java_out_of_memory("GC overhead limit exceeded"); | |
172 | |
173 if (JvmtiExport::should_post_resource_exhausted()) { | |
174 JvmtiExport::post_resource_exhausted( | |
175 JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR | JVMTI_RESOURCE_EXHAUSTED_JAVA_HEAP, | |
176 "GC overhead limit exceeded"); | |
177 } | |
178 | |
179 THROW_OOP_0(Universe::out_of_memory_error_gc_overhead_limit()); | |
180 } | |
181 } | |
182 | |
3774
c9ca3f51cf41
6994322: Remove the is_tlab and is_noref / is_large_noref parameters from the CollectedHeap
tonyp
parents:
2100
diff
changeset
|
183 HeapWord* CollectedHeap::common_mem_allocate_init(size_t size, TRAPS) { |
c9ca3f51cf41
6994322: Remove the is_tlab and is_noref / is_large_noref parameters from the CollectedHeap
tonyp
parents:
2100
diff
changeset
|
184 HeapWord* obj = common_mem_allocate_noinit(size, CHECK_NULL); |
0 | 185 init_obj(obj, size); |
186 return obj; | |
187 } | |
188 | |
189 // Need to investigate, do we really want to throw OOM exception here? | |
190 HeapWord* CollectedHeap::common_permanent_mem_allocate_noinit(size_t size, TRAPS) { | |
191 if (HAS_PENDING_EXCEPTION) { | |
192 NOT_PRODUCT(guarantee(false, "Should not allocate with exception pending")); | |
193 return NULL; // caller does a CHECK_NULL too | |
194 } | |
195 | |
196 #ifdef ASSERT | |
197 if (CIFireOOMAt > 0 && THREAD->is_Compiler_thread() && | |
198 ++_fire_out_of_memory_count >= CIFireOOMAt) { | |
199 // For testing of OOM handling in the CI throw an OOM and see how | |
200 // it does. Historically improper handling of these has resulted | |
201 // in crashes which we really don't want to have in the CI. | |
202 THROW_OOP_0(Universe::out_of_memory_error_perm_gen()); | |
203 } | |
204 #endif | |
205 | |
206 HeapWord* result = Universe::heap()->permanent_mem_allocate(size); | |
207 if (result != NULL) { | |
208 NOT_PRODUCT(Universe::heap()-> | |
209 check_for_non_bad_heap_word_value(result, size)); | |
210 assert(!HAS_PENDING_EXCEPTION, | |
211 "Unexpected exception, will result in uninitialized storage"); | |
212 return result; | |
213 } | |
214 // -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError support | |
215 report_java_out_of_memory("PermGen space"); | |
216 | |
217 if (JvmtiExport::should_post_resource_exhausted()) { | |
218 JvmtiExport::post_resource_exhausted( | |
219 JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR, | |
220 "PermGen space"); | |
221 } | |
222 | |
223 THROW_OOP_0(Universe::out_of_memory_error_perm_gen()); | |
224 } | |
225 | |
226 HeapWord* CollectedHeap::common_permanent_mem_allocate_init(size_t size, TRAPS) { | |
227 HeapWord* obj = common_permanent_mem_allocate_noinit(size, CHECK_NULL); | |
228 init_obj(obj, size); | |
229 return obj; | |
230 } | |
231 | |
232 HeapWord* CollectedHeap::allocate_from_tlab(Thread* thread, size_t size) { | |
233 assert(UseTLAB, "should use UseTLAB"); | |
234 | |
235 HeapWord* obj = thread->tlab().allocate(size); | |
236 if (obj != NULL) { | |
237 return obj; | |
238 } | |
239 // Otherwise... | |
240 return allocate_from_tlab_slow(thread, size); | |
241 } | |
242 | |
243 void CollectedHeap::init_obj(HeapWord* obj, size_t size) { | |
244 assert(obj != NULL, "cannot initialize NULL object"); | |
245 const size_t hs = oopDesc::header_size(); | |
246 assert(size >= hs, "unexpected object size"); | |
167
feeb96a45707
6696264: assert("narrow oop can never be zero") for GCBasher & ParNewGC
coleenp
parents:
113
diff
changeset
|
247 ((oop)obj)->set_klass_gap(0); |
0 | 248 Copy::fill_to_aligned_words(obj + hs, size - hs); |
249 } | |
250 | |
251 oop CollectedHeap::obj_allocate(KlassHandle klass, int size, TRAPS) { | |
252 debug_only(check_for_valid_allocation_state()); | |
253 assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed"); | |
254 assert(size >= 0, "int won't convert to size_t"); | |
3774
c9ca3f51cf41
6994322: Remove the is_tlab and is_noref / is_large_noref parameters from the CollectedHeap
tonyp
parents:
2100
diff
changeset
|
255 HeapWord* obj = common_mem_allocate_init(size, CHECK_NULL); |
0 | 256 post_allocation_setup_obj(klass, obj, size); |
257 NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value(obj, size)); | |
258 return (oop)obj; | |
259 } | |
260 | |
261 oop CollectedHeap::array_allocate(KlassHandle klass, | |
262 int size, | |
263 int length, | |
264 TRAPS) { | |
265 debug_only(check_for_valid_allocation_state()); | |
266 assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed"); | |
267 assert(size >= 0, "int won't convert to size_t"); | |
3774
c9ca3f51cf41
6994322: Remove the is_tlab and is_noref / is_large_noref parameters from the CollectedHeap
tonyp
parents:
2100
diff
changeset
|
268 HeapWord* obj = common_mem_allocate_init(size, CHECK_NULL); |
0 | 269 post_allocation_setup_array(klass, obj, size, length); |
270 NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value(obj, size)); | |
271 return (oop)obj; | |
272 } | |
273 | |
274 oop CollectedHeap::permanent_obj_allocate(KlassHandle klass, int size, TRAPS) { | |
275 oop obj = permanent_obj_allocate_no_klass_install(klass, size, CHECK_NULL); | |
276 post_allocation_install_obj_klass(klass, obj, size); | |
277 NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value((HeapWord*) obj, | |
278 size)); | |
279 return obj; | |
280 } | |
281 | |
282 oop CollectedHeap::permanent_obj_allocate_no_klass_install(KlassHandle klass, | |
283 int size, | |
284 TRAPS) { | |
285 debug_only(check_for_valid_allocation_state()); | |
286 assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed"); | |
287 assert(size >= 0, "int won't convert to size_t"); | |
288 HeapWord* obj = common_permanent_mem_allocate_init(size, CHECK_NULL); | |
289 post_allocation_setup_no_klass_install(klass, obj, size); | |
290 NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value(obj, size)); | |
291 return (oop)obj; | |
292 } | |
293 | |
294 oop CollectedHeap::permanent_array_allocate(KlassHandle klass, | |
295 int size, | |
296 int length, | |
297 TRAPS) { | |
298 debug_only(check_for_valid_allocation_state()); | |
299 assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed"); | |
300 assert(size >= 0, "int won't convert to size_t"); | |
301 HeapWord* obj = common_permanent_mem_allocate_init(size, CHECK_NULL); | |
302 post_allocation_setup_array(klass, obj, size, length); | |
303 NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value(obj, size)); | |
304 return (oop)obj; | |
305 } | |
306 | |
307 // Returns "TRUE" if "p" is a method oop in the | |
308 // current heap with high probability. NOTE: The main | |
309 // current consumers of this interface are Forte:: | |
310 // and ThreadProfiler::. In these cases, the | |
311 // interpreter frame from which "p" came, may be | |
312 // under construction when sampled asynchronously, so | |
313 // the clients want to check that it represents a | |
314 // valid method before using it. Nonetheless since | |
315 // the clients do not typically lock out GC, the | |
316 // predicate is_valid_method() is not stable, so | |
317 // it is possible that by the time "p" is used, it | |
318 // is no longer valid. | |
319 inline bool CollectedHeap::is_valid_method(oop p) const { | |
320 return | |
321 p != NULL && | |
322 | |
323 // Check whether it is aligned at a HeapWord boundary. | |
324 Space::is_aligned(p) && | |
325 | |
326 // Check whether "method" is in the allocated part of the | |
327 // permanent generation -- this needs to be checked before | |
328 // p->klass() below to avoid a SEGV (but see below | |
329 // for a potential window of vulnerability). | |
330 is_permanent((void*)p) && | |
331 | |
332 // See if GC is active; however, there is still an | |
333 // apparently unavoidable window after this call | |
334 // and before the client of this interface uses "p". | |
335 // If the client chooses not to lock out GC, then | |
336 // it's a risk the client must accept. | |
337 !is_gc_active() && | |
338 | |
339 // Check that p is a methodOop. | |
340 p->klass() == Universe::methodKlassObj(); | |
341 } | |
342 | |
343 | |
344 #ifndef PRODUCT | |
345 | |
346 inline bool | |
347 CollectedHeap::promotion_should_fail(volatile size_t* count) { | |
348 // Access to count is not atomic; the value does not have to be exact. | |
349 if (PromotionFailureALot) { | |
350 const size_t gc_num = total_collections(); | |
351 const size_t elapsed_gcs = gc_num - _promotion_failure_alot_gc_number; | |
352 if (elapsed_gcs >= PromotionFailureALotInterval) { | |
353 // Test for unsigned arithmetic wrap-around. | |
354 if (++*count >= PromotionFailureALotCount) { | |
355 *count = 0; | |
356 return true; | |
357 } | |
358 } | |
359 } | |
360 return false; | |
361 } | |
362 | |
363 inline bool CollectedHeap::promotion_should_fail() { | |
364 return promotion_should_fail(&_promotion_failure_alot_count); | |
365 } | |
366 | |
367 inline void CollectedHeap::reset_promotion_should_fail(volatile size_t* count) { | |
368 if (PromotionFailureALot) { | |
369 _promotion_failure_alot_gc_number = total_collections(); | |
370 *count = 0; | |
371 } | |
372 } | |
373 | |
374 inline void CollectedHeap::reset_promotion_should_fail() { | |
375 reset_promotion_should_fail(&_promotion_failure_alot_count); | |
376 } | |
377 #endif // #ifndef PRODUCT | |
1972 | 378 |
379 #endif // SHARE_VM_GC_INTERFACE_COLLECTEDHEAP_INLINE_HPP |