262
263 #ifdef ASSERT
264 void CollectedHeap::check_for_valid_allocation_state() {
265 Thread *thread = Thread::current();
266 // How to choose between a pending exception and a potential
267 // OutOfMemoryError? Don't allow pending exceptions.
268 // This is a VM policy failure, so how do we exhaustively test it?
269 assert(!thread->has_pending_exception(),
270 "shouldn't be allocating with pending exception");
271 if (StrictSafepointChecks) {
272 assert(thread->allow_allocation(),
273 "Allocation done by thread for which allocation is blocked "
274 "by No_Allocation_Verifier!");
275 // Allocation of an oop can always invoke a safepoint,
276 // hence, the true argument
277 thread->check_for_valid_safepoint_state(true);
278 }
279 }
280 #endif
281
282 HeapWord* CollectedHeap::allocate_from_tlab_slow(KlassHandle klass, Thread* thread, size_t size) {
283
284 // Retain tlab and allocate object in shared space if
285 // the amount free in the tlab is too large to discard.
286 if (thread->tlab().free() > thread->tlab().refill_waste_limit()) {
287 thread->tlab().record_slow_allocation(size);
288 return NULL;
289 }
290
291 // Discard tlab and allocate a new one.
292 // To minimize fragmentation, the last TLAB may be smaller than the rest.
293 size_t new_tlab_size = thread->tlab().compute_size(size);
294
295 thread->tlab().clear_before_allocation();
296
297 if (new_tlab_size == 0) {
298 return NULL;
299 }
300
301 // Allocate a new TLAB...
302 HeapWord* obj = Universe::heap()->allocate_new_tlab(new_tlab_size);
|
262
263 #ifdef ASSERT
264 void CollectedHeap::check_for_valid_allocation_state() {
265 Thread *thread = Thread::current();
266 // How to choose between a pending exception and a potential
267 // OutOfMemoryError? Don't allow pending exceptions.
268 // This is a VM policy failure, so how do we exhaustively test it?
269 assert(!thread->has_pending_exception(),
270 "shouldn't be allocating with pending exception");
271 if (StrictSafepointChecks) {
272 assert(thread->allow_allocation(),
273 "Allocation done by thread for which allocation is blocked "
274 "by No_Allocation_Verifier!");
275 // Allocation of an oop can always invoke a safepoint,
276 // hence, the true argument
277 thread->check_for_valid_safepoint_state(true);
278 }
279 }
280 #endif
281
282 HeapWord* CollectedHeap::allocate_from_tlab_slow(Klass* klass, Thread* thread, size_t size) {
283
284 // Retain tlab and allocate object in shared space if
285 // the amount free in the tlab is too large to discard.
286 if (thread->tlab().free() > thread->tlab().refill_waste_limit()) {
287 thread->tlab().record_slow_allocation(size);
288 return NULL;
289 }
290
291 // Discard tlab and allocate a new one.
292 // To minimize fragmentation, the last TLAB may be smaller than the rest.
293 size_t new_tlab_size = thread->tlab().compute_size(size);
294
295 thread->tlab().clear_before_allocation();
296
297 if (new_tlab_size == 0) {
298 return NULL;
299 }
300
301 // Allocate a new TLAB...
302 HeapWord* obj = Universe::heap()->allocate_new_tlab(new_tlab_size);
|