6969import com .oracle .svm .core .jdk .RuntimeSupport ;
7070import com .oracle .svm .core .jni .JNIJavaVMList ;
7171import com .oracle .svm .core .jni .functions .JNIFunctionTables ;
72+ import com .oracle .svm .core .log .Log ;
7273import com .oracle .svm .core .thread .JavaThreads ;
7374import com .oracle .svm .core .thread .PlatformThreads ;
75+ import com .oracle .svm .core .thread .ThreadingSupportImpl ;
7476import com .oracle .svm .core .thread .VMThreads ;
7577import com .oracle .svm .core .thread .VMThreads .OSThreadHandle ;
7678import com .oracle .svm .core .util .UserError ;
@@ -244,22 +246,32 @@ private static int runCore0() {
244246
245247 @ Uninterruptible (reason = "The caller initialized the thread state, so the callees do not need to be uninterruptible." , calleeMustBe = false )
246248 private static void runShutdown () {
249+ ThreadingSupportImpl .pauseRecurringCallback ("Recurring callbacks can't be executed during shutdown." );
247250 runShutdown0 ();
248251 }
249252
250253 private static void runShutdown0 () {
251- PlatformThreads .ensureCurrentAssigned ("DestroyJavaVM" , null , false );
254+ try {
255+ PlatformThreads .ensureCurrentAssigned ("DestroyJavaVM" , null , false );
256+ } catch (Throwable e ) {
257+ Log .log ().string ("PlatformThreads.ensureCurrentAssigned() failed during shutdown: " ).exception (e ).newline ();
258+ return ;
259+ }
252260
253- // Shutdown sequence: First wait for all non-daemon threads to exit.
261+ /* Wait for all non-daemon threads to exit. */
254262 PlatformThreads .singleton ().joinAllNonDaemons ();
255263
256- /*
257- * Run shutdown hooks (both our own hooks and application-registered hooks) and teardown
258- * hooks. Note that this can start new non-daemon threads. We are not responsible to wait
259- * until they have exited.
260- */
261- RuntimeSupport .getRuntimeSupport ().shutdown ();
262- RuntimeSupport .executeTearDownHooks ();
264+ try {
265+ /*
266+ * Run shutdown hooks (both our own hooks and application-registered hooks) and teardown
267+ * hooks. Note that this can start new non-daemon threads. We are not responsible to
268+ * wait until they have exited.
269+ */
270+ RuntimeSupport .getRuntimeSupport ().shutdown ();
271+ RuntimeSupport .executeTearDownHooks ();
272+ } catch (Throwable e ) {
273+ Log .log ().string ("Exception occurred while executing shutdown hooks: " ).exception (e ).newline ();
274+ }
263275 }
264276
265277 @ Uninterruptible (reason = "Thread state not set up yet." )
@@ -278,6 +290,7 @@ private static int doRun(int argc, CCharPointerPointer argv) {
278290 try {
279291 CPUFeatureAccess cpuFeatureAccess = ImageSingletons .lookup (CPUFeatureAccess .class );
280292 cpuFeatureAccess .verifyHostSupportsArchitectureEarlyOrExit ();
293+
281294 // Create the isolate and attach the current C thread as the main Java thread.
282295 EnterCreateIsolateWithCArgumentsPrologue .enter (argc , argv );
283296 assert !VMThreads .wasStartedByCurrentIsolate (CurrentIsolate .getCurrentThread ()) : "re-attach would cause issues otherwise" ;
0 commit comments