RFR: 8360164: AOT cache creation crashes in ~ThreadTotalCPUTimeClosure() [v3]

Ioi Lam iklam at openjdk.org
Fri Jun 27 16:55:33 UTC 2025


On Fri, 27 Jun 2025 04:40:51 GMT, David Holmes <dholmes at openjdk.org> wrote:

>> Ioi Lam has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Use vm_direct_exit instead, as at this point we have not finished Threads::create_vm() yet, so we may not have done all the initialization to be able to call before_exit()
>
> src/hotspot/share/cds/metaspaceShared.cpp line 846:
> 
>> 844:       }
>> 845:       ThreadToNativeFromVM ttnfv(THREAD);
>> 846:       JVM_Halt(0);
> 
> `JVM_Halt` is the native backend for the JDK's `System.halt()` method. Whilst it might do what you need under-the-covers, I think it would be clearer to not actually call it, but just call `before_exit` and `vm_exit` directly. Even then you need to be careful as to how the `halt` parameter will be interpreted - in particular the affect on `Jfr::on_vm_shutdown`. In fact `before_exit` needs detailed examination to see if everything it does truly makes sense in this context.

I changed the code to call `vm_direct_exit()` instead. At this point, we are still in the middle of `JNI_CreateJavaVM_inner`


0 vm_direct_exit 
1 MetaspaceShared::preload_and_dump 
2 Threads::create_vm 
3 JNI_CreateJavaVM_inner 
4 JNI_CreateJavaVM 
5 start_thread 
6 clone3 


so we may not have finished all the initialization that `before_exit()` may rely on.

Here's the code that's not yet executed:

https://github.com/openjdk/jdk/blob/da7080fffb2389465dc9afca6d02e9085fe15302/src/hotspot/share/prims/jni.cpp#L3591-L3635


To be honest, I am not sure where is the starting point where it's safe to call `before_exit()` or `System.exit()`. At this point a lot of Java code has been executed (for setting up the module graph, etc), but I am not sure what happens when some of that Java code calls `System.exit()`, or whether such a scenario has been (sufficiently) tested.

BTW, JFR is disabled when we are dumping CDS:

https://github.com/openjdk/jdk/blob/da7080fffb2389465dc9afca6d02e9085fe15302/src/hotspot/share/jfr/recorder/jfrRecorder.cpp#L198-L206

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

PR Review Comment: https://git.openjdk.org/jdk/pull/26008#discussion_r2172422372


More information about the hotspot-runtime-dev mailing list