376 |
376 |
377 return allocate_outside_tlab(klass, size, gc_overhead_limit_was_exceeded, THREAD); |
377 return allocate_outside_tlab(klass, size, gc_overhead_limit_was_exceeded, THREAD); |
378 } |
378 } |
379 |
379 |
380 HeapWord* CollectedHeap::allocate_from_tlab_slow(Klass* klass, size_t size, TRAPS) { |
380 HeapWord* CollectedHeap::allocate_from_tlab_slow(Klass* klass, size_t size, TRAPS) { |
|
381 HeapWord* obj = NULL; |
|
382 |
|
383 // In assertion mode, check that there was a sampling collector present |
|
384 // in the stack. This enforces checking that no path is without a sampling |
|
385 // collector. |
|
386 // Only check if the sampler could actually sample something in this call path. |
|
387 assert(!JvmtiExport::should_post_sampled_object_alloc() |
|
388 || !JvmtiSampledObjectAllocEventCollector::object_alloc_is_safe_to_sample() |
|
389 || THREAD->heap_sampler().sampling_collector_present(), |
|
390 "Sampling collector not present."); |
|
391 |
|
392 if (ThreadHeapSampler::enabled()) { |
|
393 // Try to allocate the sampled object from TLAB, it is possible a sample |
|
394 // point was put and the TLAB still has space. |
|
395 obj = THREAD->tlab().allocate_sampled_object(size); |
|
396 |
|
397 if (obj != NULL) { |
|
398 return obj; |
|
399 } |
|
400 } |
|
401 |
381 ThreadLocalAllocBuffer& tlab = THREAD->tlab(); |
402 ThreadLocalAllocBuffer& tlab = THREAD->tlab(); |
382 |
403 |
383 // Retain tlab and allocate object in shared space if |
404 // Retain tlab and allocate object in shared space if |
384 // the amount free in the tlab is too large to discard. |
405 // the amount free in the tlab is too large to discard. |
385 if (tlab.free() > tlab.refill_waste_limit()) { |
406 if (tlab.free() > tlab.refill_waste_limit()) { |
399 |
420 |
400 // Allocate a new TLAB requesting new_tlab_size. Any size |
421 // Allocate a new TLAB requesting new_tlab_size. Any size |
401 // between minimal and new_tlab_size is accepted. |
422 // between minimal and new_tlab_size is accepted. |
402 size_t actual_tlab_size = 0; |
423 size_t actual_tlab_size = 0; |
403 size_t min_tlab_size = ThreadLocalAllocBuffer::compute_min_size(size); |
424 size_t min_tlab_size = ThreadLocalAllocBuffer::compute_min_size(size); |
404 HeapWord* obj = Universe::heap()->allocate_new_tlab(min_tlab_size, new_tlab_size, &actual_tlab_size); |
425 obj = Universe::heap()->allocate_new_tlab(min_tlab_size, new_tlab_size, &actual_tlab_size); |
405 if (obj == NULL) { |
426 if (obj == NULL) { |
406 assert(actual_tlab_size == 0, "Allocation failed, but actual size was updated. min: " SIZE_FORMAT ", desired: " SIZE_FORMAT ", actual: " SIZE_FORMAT, |
427 assert(actual_tlab_size == 0, "Allocation failed, but actual size was updated. min: " SIZE_FORMAT ", desired: " SIZE_FORMAT ", actual: " SIZE_FORMAT, |
407 min_tlab_size, new_tlab_size, actual_tlab_size); |
428 min_tlab_size, new_tlab_size, actual_tlab_size); |
408 return NULL; |
429 return NULL; |
409 } |
430 } |
423 // any concurrent GC thread. |
444 // any concurrent GC thread. |
424 size_t hdr_size = oopDesc::header_size(); |
445 size_t hdr_size = oopDesc::header_size(); |
425 Copy::fill_to_words(obj + hdr_size, actual_tlab_size - hdr_size, badHeapWordVal); |
446 Copy::fill_to_words(obj + hdr_size, actual_tlab_size - hdr_size, badHeapWordVal); |
426 #endif // ASSERT |
447 #endif // ASSERT |
427 } |
448 } |
|
449 |
|
450 // Send the thread information about this allocation in case a sample is |
|
451 // requested. |
|
452 if (ThreadHeapSampler::enabled()) { |
|
453 size_t tlab_bytes_since_last_sample = THREAD->tlab().bytes_since_last_sample_point(); |
|
454 THREAD->heap_sampler().check_for_sampling(obj, size, tlab_bytes_since_last_sample); |
|
455 } |
|
456 |
428 tlab.fill(obj, obj + size, actual_tlab_size); |
457 tlab.fill(obj, obj + size, actual_tlab_size); |
429 return obj; |
458 return obj; |
430 } |
459 } |
431 |
460 |
432 size_t CollectedHeap::max_tlab_size() const { |
461 size_t CollectedHeap::max_tlab_size() const { |