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