< prev index next >

src/hotspot/share/gc/shared/collectedHeap.cpp

Print this page
rev 49244 : [mq]: event-only


 339 #ifdef ASSERT
 340 void CollectedHeap::check_for_valid_allocation_state() {
 341   Thread *thread = Thread::current();
 342   // How to choose between a pending exception and a potential
 343   // OutOfMemoryError?  Don't allow pending exceptions.
 344   // This is a VM policy failure, so how do we exhaustively test it?
 345   assert(!thread->has_pending_exception(),
 346          "shouldn't be allocating with pending exception");
 347   if (StrictSafepointChecks) {
 348     assert(thread->allow_allocation(),
 349            "Allocation done by thread for which allocation is blocked "
 350            "by No_Allocation_Verifier!");
 351     // Allocation of an oop can always invoke a safepoint,
 352     // hence, the true argument
 353     thread->check_for_valid_safepoint_state(true);
 354   }
 355 }
 356 #endif
 357 
 358 HeapWord* CollectedHeap::allocate_from_tlab_slow(Klass* klass, Thread* thread, size_t size) {











 359 
 360   // Retain tlab and allocate object in shared space if
 361   // the amount free in the tlab is too large to discard.
 362   if (thread->tlab().free() > thread->tlab().refill_waste_limit()) {
 363     thread->tlab().record_slow_allocation(size);
 364     return NULL;
 365   }
 366 
 367   // Discard tlab and allocate a new one.
 368   // To minimize fragmentation, the last TLAB may be smaller than the rest.
 369   size_t new_tlab_size = thread->tlab().compute_size(size);
 370 
 371   thread->tlab().clear_before_allocation();
 372 
 373   if (new_tlab_size == 0) {
 374     return NULL;
 375   }
 376 
 377   // Allocate a new TLAB...
 378   HeapWord* obj = Universe::heap()->allocate_new_tlab(new_tlab_size);
 379   if (obj == NULL) {
 380     return NULL;
 381   }
 382 
 383   AllocTracer::send_allocation_in_new_tlab(klass, obj, new_tlab_size * HeapWordSize, size * HeapWordSize, thread);
 384 
 385   if (ZeroTLAB) {
 386     // ..and clear it.
 387     Copy::zero_to_words(obj, new_tlab_size);
 388   } else {
 389     // ...and zap just allocated object.
 390 #ifdef ASSERT
 391     // Skip mangling the space corresponding to the object header to
 392     // ensure that the returned space is not considered parsable by
 393     // any concurrent GC thread.
 394     size_t hdr_size = oopDesc::header_size();
 395     Copy::fill_to_words(obj + hdr_size, new_tlab_size - hdr_size, badHeapWordVal);
 396 #endif // ASSERT
 397   }








 398   thread->tlab().fill(obj, obj + size, new_tlab_size);
 399   return obj;
 400 }
 401 
 402 size_t CollectedHeap::max_tlab_size() const {
 403   // TLABs can't be bigger than we can fill with a int[Integer.MAX_VALUE].
 404   // This restriction could be removed by enabling filling with multiple arrays.
 405   // If we compute that the reasonable way as
 406   //    header_size + ((sizeof(jint) * max_jint) / HeapWordSize)
 407   // we'll overflow on the multiply, so we do the divide first.
 408   // We actually lose a little by dividing first,
 409   // but that just makes the TLAB  somewhat smaller than the biggest array,
 410   // which is fine, since we'll be able to fill that.
 411   size_t max_int_size = typeArrayOopDesc::header_size(T_INT) +
 412               sizeof(jint) *
 413               ((juint) max_jint / (size_t) HeapWordSize);
 414   return align_down(max_int_size, MinObjAlignment);
 415 }
 416 
 417 size_t CollectedHeap::filler_array_hdr_size() {




 339 #ifdef ASSERT
 340 void CollectedHeap::check_for_valid_allocation_state() {
 341   Thread *thread = Thread::current();
 342   // How to choose between a pending exception and a potential
 343   // OutOfMemoryError?  Don't allow pending exceptions.
 344   // This is a VM policy failure, so how do we exhaustively test it?
 345   assert(!thread->has_pending_exception(),
 346          "shouldn't be allocating with pending exception");
 347   if (StrictSafepointChecks) {
 348     assert(thread->allow_allocation(),
 349            "Allocation done by thread for which allocation is blocked "
 350            "by No_Allocation_Verifier!");
 351     // Allocation of an oop can always invoke a safepoint,
 352     // hence, the true argument
 353     thread->check_for_valid_safepoint_state(true);
 354   }
 355 }
 356 #endif
 357 
 358 HeapWord* CollectedHeap::allocate_from_tlab_slow(Klass* klass, Thread* thread, size_t size) {
 359   HeapWord* obj = NULL;
 360 
 361   if (ThreadHeapSampler::enabled()) {
 362     // Try to allocate the sampled object from TLAB, it is possible a sample
 363     // point was put and the TLAB still has space.
 364     obj = thread->tlab().allocate_sampled_object(size);
 365 
 366     if (obj != NULL) {
 367       return obj;
 368     }
 369   }
 370 
 371   // Retain tlab and allocate object in shared space if
 372   // the amount free in the tlab is too large to discard.
 373   if (thread->tlab().free() > thread->tlab().refill_waste_limit()) {
 374     thread->tlab().record_slow_allocation(size);
 375     return NULL;
 376   }
 377 
 378   // Discard tlab and allocate a new one.
 379   // To minimize fragmentation, the last TLAB may be smaller than the rest.
 380   size_t new_tlab_size = thread->tlab().compute_size(size);
 381 
 382   thread->tlab().clear_before_allocation();
 383 
 384   if (new_tlab_size == 0) {
 385     return NULL;
 386   }
 387 
 388   // Allocate a new TLAB...
 389   obj = Universe::heap()->allocate_new_tlab(new_tlab_size);
 390   if (obj == NULL) {
 391     return NULL;
 392   }
 393 
 394   AllocTracer::send_allocation_in_new_tlab(klass, obj, new_tlab_size * HeapWordSize, size * HeapWordSize, thread);
 395 
 396   if (ZeroTLAB) {
 397     // ..and clear it.
 398     Copy::zero_to_words(obj, new_tlab_size);
 399   } else {
 400     // ...and zap just allocated object.
 401 #ifdef ASSERT
 402     // Skip mangling the space corresponding to the object header to
 403     // ensure that the returned space is not considered parsable by
 404     // any concurrent GC thread.
 405     size_t hdr_size = oopDesc::header_size();
 406     Copy::fill_to_words(obj + hdr_size, new_tlab_size - hdr_size, badHeapWordVal);
 407 #endif // ASSERT
 408   }
 409 
 410   // Send the thread information about this allocation in case a sample is
 411   // requested.
 412   if (ThreadHeapSampler::enabled()) {
 413     size_t tlab_bytes_since_last_sample = thread->tlab().bytes_since_last_sample_point();
 414     thread->heap_sampler().check_for_sampling(obj, size, tlab_bytes_since_last_sample);
 415   }
 416 
 417   thread->tlab().fill(obj, obj + size, new_tlab_size);
 418   return obj;
 419 }
 420 
 421 size_t CollectedHeap::max_tlab_size() const {
 422   // TLABs can't be bigger than we can fill with a int[Integer.MAX_VALUE].
 423   // This restriction could be removed by enabling filling with multiple arrays.
 424   // If we compute that the reasonable way as
 425   //    header_size + ((sizeof(jint) * max_jint) / HeapWordSize)
 426   // we'll overflow on the multiply, so we do the divide first.
 427   // We actually lose a little by dividing first,
 428   // but that just makes the TLAB  somewhat smaller than the biggest array,
 429   // which is fine, since we'll be able to fill that.
 430   size_t max_int_size = typeArrayOopDesc::header_size(T_INT) +
 431               sizeof(jint) *
 432               ((juint) max_jint / (size_t) HeapWordSize);
 433   return align_down(max_int_size, MinObjAlignment);
 434 }
 435 
 436 size_t CollectedHeap::filler_array_hdr_size() {


< prev index next >