8308764: Reporting errors from create_vm may crash

Reviewed-by: stuefe, coleenp, kbarrett
(cherry picked from commit 6646272a05)
This commit is contained in:
David Holmes
2023-06-08 03:30:11 +00:00
committed by Vitaly Provodin
parent 9a5f0e005d
commit fb3766b94c
2 changed files with 10 additions and 3 deletions

View File

@@ -3646,8 +3646,10 @@ static jint JNI_CreateJavaVM_inner(JavaVM **vm, void **penv, void *args) {
// to continue.
if (Universe::is_fully_initialized()) {
// otherwise no pending exception possible - VM will already have aborted
JavaThread* THREAD = JavaThread::current(); // For exception macros.
if (HAS_PENDING_EXCEPTION) {
Thread* current = Thread::current_or_null();
if (current != nullptr) {
JavaThread* THREAD = JavaThread::cast(current); // For exception macros.
assert(HAS_PENDING_EXCEPTION, "must be - else no current thread exists");
HandleMark hm(THREAD);
vm_exit_during_initialization(Handle(THREAD, PENDING_EXCEPTION));
}

View File

@@ -564,7 +564,12 @@ jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) {
status = init_globals2();
if (status != JNI_OK) {
Threads::remove(main_thread, false);
main_thread->smr_delete();
// It is possible that we managed to fully initialize Universe but have then
// failed by throwing an exception. In that case our caller JNI_CreateJavaVM
// will want to report it, so we can't delete the main thread.
if (!main_thread->has_pending_exception()) {
main_thread->smr_delete();
}
*canTryAgain = false; // don't let caller call JNI_CreateJavaVM again
return status;
}