RFR: 8366865: G1: Allocation GC Pauses Triggered after JVM has started shutdown [v2]

Ivan Walulya iwalulya at openjdk.org
Mon Sep 15 10:32:14 UTC 2025


On Thu, 11 Sep 2025 08:19:45 GMT, Ivan Walulya <iwalulya at openjdk.org> wrote:

>> src/hotspot/share/gc/shared/collectedHeap.cpp line 616:
>> 
>>> 614:   // If the VM is shutting down, we may have skipped VM_CollectForAllocation.
>>> 615:   // To avoid returning nullptr (which could cause premature OOME), we stall
>>> 616:   // allocation requests here until the VM shutdown is complete.
>> 
>> If I understand the shutdown sequence correctly, I don't think you can do this without risking a hang. The thread doing the shutdown can potentially execute code that requires allocation after `is_shutting_down()` returns true. This is due to the JVMTI events posted from `before_exit`:
>> 
>> if (JvmtiExport::should_post_thread_life()) {
>>     JvmtiExport::post_thread_end(thread);
>>   }
>> 
>>   // Always call even when there are not JVMTI environments yet, since environments
>>   // may be attached late and JVMTI must track phases of VM execution
>>   JvmtiExport::post_vm_death();
>> 
>> I think if you can't GC during shutdown then you have to simply let the allocation fail.
>
> Thanks, I completely overlooked the JVMTI callbacks. It’s probably better to stall with a timeout and then return an allocation failure.

I moved the `Universe::before_exit()` call and also added a timed `wait`. 
@dholmes-ora do you have any concerns with this approach?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/27190#discussion_r2348552023


More information about the hotspot-gc-dev mailing list