466 ClassAllocator allocator(klass, size, THREAD); |
466 ClassAllocator allocator(klass, size, THREAD); |
467 return allocator.allocate(); |
467 return allocator.allocate(); |
468 } |
468 } |
469 |
469 |
470 void CollectedHeap::ensure_parsability(bool retire_tlabs) { |
470 void CollectedHeap::ensure_parsability(bool retire_tlabs) { |
471 // The second disjunct in the assertion below makes a concession |
|
472 // for the start-up verification done while the VM is being |
|
473 // created. Callers be careful that you know that mutators |
|
474 // aren't going to interfere -- for instance, this is permissible |
|
475 // if we are still single-threaded and have either not yet |
|
476 // started allocating (nothing much to verify) or we have |
|
477 // started allocating but are now a full-fledged JavaThread |
|
478 // (and have thus made our TLAB's) available for filling. |
|
479 assert(SafepointSynchronize::is_at_safepoint() || !is_init_completed(), |
471 assert(SafepointSynchronize::is_at_safepoint() || !is_init_completed(), |
480 "Should only be called at a safepoint or at start-up" |
472 "Should only be called at a safepoint or at start-up"); |
481 " otherwise concurrent mutator activity may make heap " |
473 |
482 " unparsable again"); |
474 ThreadLocalAllocStats stats; |
483 |
475 |
484 if (UseTLAB && retire_tlabs) { |
476 for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thread = jtiwh.next();) { |
485 // Accumulate statistics before retiring |
477 BarrierSet::barrier_set()->make_parsable(thread); |
486 ThreadLocalAllocBuffer::accumulate_statistics_before_gc(); |
478 if (UseTLAB) { |
487 } |
479 if (retire_tlabs) { |
488 |
480 thread->tlab().retire(&stats); |
489 // The main thread starts allocating via a TLAB even before it |
481 } else { |
490 // has added itself to the threads list at vm boot-up. |
482 thread->tlab().make_parsable(); |
491 JavaThreadIteratorWithHandle jtiwh; |
483 } |
492 assert(jtiwh.length() > 0, |
484 } |
493 "Attempt to fill tlabs before main thread has been added" |
485 } |
494 " to threads list is doomed to failure!"); |
486 |
495 BarrierSet *bs = BarrierSet::barrier_set(); |
487 stats.publish(); |
496 for (; JavaThread *thread = jtiwh.next(); ) { |
|
497 if (UseTLAB) { |
|
498 thread->tlab().make_parsable(retire_tlabs); |
|
499 } |
|
500 bs->make_parsable(thread); |
|
501 } |
|
502 } |
488 } |
503 |
489 |
504 void CollectedHeap::resize_all_tlabs() { |
490 void CollectedHeap::resize_all_tlabs() { |
505 assert(SafepointSynchronize::is_at_safepoint() || !is_init_completed(), |
491 assert(SafepointSynchronize::is_at_safepoint() || !is_init_completed(), |
506 "Should only resize tlabs at safepoint"); |
492 "Should only resize tlabs at safepoint"); |