|
62 | 62 |
|
63 | 63 | class ClassLoaderData; |
64 | 64 |
|
| 65 | +bool CollectedHeap::_is_shutting_down = false; |
| 66 | + |
65 | 67 | size_t CollectedHeap::_lab_alignment_reserve = SIZE_MAX; |
66 | 68 | Klass* CollectedHeap::_filler_object_klass = nullptr; |
67 | 69 | size_t CollectedHeap::_filler_array_max_size = 0; |
@@ -386,11 +388,6 @@ MetaWord* CollectedHeap::satisfy_failed_metadata_allocation(ClassLoaderData* loa |
386 | 388 | return op.result(); |
387 | 389 | } |
388 | 390 |
|
389 | | - if (is_shutting_down()) { |
390 | | - stall_for_vm_shutdown(); |
391 | | - return nullptr; |
392 | | - } |
393 | | - |
394 | 391 | loop_count++; |
395 | 392 | if ((QueuedAllocationWarningCount > 0) && |
396 | 393 | (loop_count % QueuedAllocationWarningCount == 0)) { |
@@ -605,30 +602,20 @@ void CollectedHeap::post_initialize() { |
605 | 602 | initialize_serviceability(); |
606 | 603 | } |
607 | 604 |
|
608 | | -bool CollectedHeap::is_shutting_down() const { |
609 | | - return Universe::is_shutting_down(); |
| 605 | +bool CollectedHeap::is_shutting_down() { |
| 606 | + assert(Heap_lock->owned_by_self(), "Protected by this lock"); |
| 607 | + return _is_shutting_down; |
610 | 608 | } |
611 | 609 |
|
612 | | -void CollectedHeap::stall_for_vm_shutdown() { |
613 | | - assert(is_shutting_down(), "Precondition"); |
614 | | - // Stall the thread (2 seconds) instead of an indefinite wait to avoid deadlock |
615 | | - // if the VM shutdown triggers a GC. |
616 | | - // The 2-seconds sleep is: |
617 | | - // - long enough to keep daemon threads stalled, while the shutdown |
618 | | - // sequence completes in the common case. |
619 | | - // - short enough to avoid excessive stall time if the shutdown itself |
620 | | - // triggers a GC. |
621 | | - JavaThread::current()->sleep(2 * MILLIUNITS); |
622 | | - |
623 | | - ResourceMark rm; |
624 | | - log_warning(gc, alloc)("%s: Stall for VM-Shutdown timed out; allocation may fail with OOME", Thread::current()->name()); |
625 | | -} |
| 610 | +void CollectedHeap::initiate_shutdown() { |
| 611 | + { |
| 612 | + // Acquire the Heap_lock to synchronize with VM_Heap_Sync_Operations, |
| 613 | + // which may depend on the value of _is_shutting_down flag. |
| 614 | + MutexLocker hl(Heap_lock); |
| 615 | + _is_shutting_down = true; |
| 616 | + } |
626 | 617 |
|
627 | | -void CollectedHeap::before_exit() { |
628 | 618 | print_tracing_info(); |
629 | | - |
630 | | - // Stop any on-going concurrent work and prepare for exit. |
631 | | - stop(); |
632 | 619 | } |
633 | 620 |
|
634 | 621 | size_t CollectedHeap::bootstrap_max_memory() const { |
|
0 commit comments