-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8360164: AOT cache creation crashes in ~ThreadTotalCPUTimeClosure() #26008
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8360164: AOT cache creation crashes in ~ThreadTotalCPUTimeClosure() #26008
Conversation
|
👋 Welcome back iklam! A progress list of the required criteria for merging this PR into |
|
@iklam This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 53 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
Webrevs
|
vnkozlov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good.
| vm_exit(0); | ||
| } | ||
| ThreadToNativeFromVM ttnfv(THREAD); | ||
| JVM_Halt(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:
jdk/src/hotspot/share/prims/jni.cpp
Lines 3591 to 3635 in da7080f
| JavaThread *thread = JavaThread::current(); | |
| assert(!thread->has_pending_exception(), "should have returned not OK"); | |
| // thread is thread_in_vm here | |
| *vm = (JavaVM *)(&main_vm); | |
| *(JNIEnv**)penv = thread->jni_environment(); | |
| // mark creation complete for other JNI ops | |
| Atomic::release_store(&vm_created, COMPLETE); | |
| #if INCLUDE_JVMCI | |
| if (EnableJVMCI) { | |
| if (UseJVMCICompiler) { | |
| // JVMCI is initialized on a CompilerThread | |
| if (BootstrapJVMCI) { | |
| JavaThread* THREAD = thread; // For exception macros. | |
| JVMCICompiler* compiler = JVMCICompiler::instance(true, CATCH); | |
| compiler->bootstrap(THREAD); | |
| if (HAS_PENDING_EXCEPTION) { | |
| HandleMark hm(THREAD); | |
| vm_exit_during_initialization(Handle(THREAD, PENDING_EXCEPTION)); | |
| } | |
| } | |
| } | |
| } | |
| #endif | |
| // Notify JVMTI | |
| if (JvmtiExport::should_post_thread_life()) { | |
| JvmtiExport::post_thread_start(thread); | |
| } | |
| JFR_ONLY(Jfr::on_thread_start(thread);) | |
| if (ReplayCompiles) ciReplay::replay(thread); | |
| #ifdef ASSERT | |
| // Some platforms (like Win*) need a wrapper around these test | |
| // functions in order to properly handle error conditions. | |
| if (ErrorHandlerTest != 0) { | |
| VMError::controlled_crash(ErrorHandlerTest); | |
| } | |
| #endif | |
| // Since this is not a JVM_ENTRY we have to set the thread state manually before leaving. | |
| ThreadStateTransition::transition_from_vm(thread, _thread_in_native); | |
| MACOS_AARCH64_ONLY(thread->enable_wx(WXExec)); |
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:
jdk/src/hotspot/share/jfr/recorder/jfrRecorder.cpp
Lines 198 to 206 in da7080f
| static bool is_cds_dump_requested() { | |
| // we will not be able to launch recordings on startup if a cds dump is being requested | |
| if (CDSConfig::is_dumping_archive() && JfrOptionSet::start_flight_recording_options() != nullptr) { | |
| warning("JFR will be disabled during CDS dumping"); | |
| teardown_startup_support(); | |
| return true; | |
| } | |
| return false; | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure what happens when some of that Java code calls System.exit(), or whether such a scenario has been (sufficiently) tested.
Initialization Java code should not be calling System.exit - ever. If something goes wrong it should throw an exception which is seen by the main thread doing the VM init and that in turn will lead to vm_exit_during_initialization.
To me the simplest model to use here would be to act as-if AOT creation was done by a small Java class such that you know the VM is fully initialized when you create the cache and then you can do a normal Java-level termination afterwards.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried doing that, but it's not straight-forward. At this point, some internal VM states have been zero-ed out by the AOT cache dumping code. As a result, it's no longer possible to resolve a new class. We get a crash when System.exit() resolves the Logger class:
[....]
V [libjvm.so+0xf27aa2] InterpreterRuntime::resolve_from_cache(JavaThread*, Bytecodes::Code)+0x116 (interpreterRuntime.cpp:1001)
j java.lang.System.getLogger(Ljava/lang/String;)Ljava/lang/System$Logger;+28 java.base@26-internal
j java.lang.Shutdown.logRuntimeExit(I)V+2 java.base@26-internal
j java.lang.Shutdown.exit(I)V+1 java.base@26-internal
j java.lang.Runtime.exit(I)V+1 java.base@26-internal
j java.lang.System.exit(I)V+4 java.base@26-internal
v ~StubRoutines::call_stub 0x00007f392ae6072e
Since we need to backport this fix to JDK 25, I think we should go with the vm_direct_exit() now, and perhaps fix the AOT dumping code to avoid zeroing out VM states in a follow-up RFE.
src/hotspot/share/runtime/java.cpp
Outdated
| // run Java code. | ||
| DynamicArchive::dump_at_exit(thread); | ||
| assert(!thread->has_pending_exception(), "must be"); | ||
| if (CDSConfig::is_dumping_dynamic_archive()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume requesting a dynamic dump is mutually exclusive to the use of -XX:AOTMode=create?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
…eads::create_vm() yet, so we may not have done all the initialization to be able to call before_exit()
dholmes-ora
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay so the proposal now is that instead of trying to do a more "refined" termination process by calling before_exit etc (which is problematic because we are only partly initialized), we instead do a more abrupt termination by using vm_direct_exit.
This seems "safe" with regards to the issues Kim was commenting on.
calvinccheung
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
Thanks @vnkozlov @calvinccheung @dholmes-ora for the review |
|
Going to push as commit 7d7e60c.
Your commit was automatically rebased without conflicts. |
java -XX:AOTMode=createcallsvm_exit(0)to terminate the JVM (see this e-mail thread for the reason for doing so). However, at this point, the JVM has executed quite a lot of Java code and there are many threads in the JVM that would require a proper shutdown. See comments by @kimbarrett for a detailed analysis.This fix calls
JVM_Halt(0)instead ofvm_exit(0)so that the proper shutdown code is executed.Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26008/head:pull/26008$ git checkout pull/26008Update a local copy of the PR:
$ git checkout pull/26008$ git pull https://git.openjdk.org/jdk.git pull/26008/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 26008View PR using the GUI difftool:
$ git pr show -t 26008Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26008.diff
Using Webrev
Link to Webrev Comment