5050import org .graalvm .word .impl .Word ;
5151
5252import com .oracle .svm .core .jfr .events .ShutdownEvent ;
53- import com .oracle .svm .guest .staging .jdk .RuntimeSupport ;
5453import com .oracle .svm .core .jni .JNIJavaVMList ;
5554import com .oracle .svm .core .jni .functions .JNIFunctionTables ;
5655import com .oracle .svm .core .log .Log ;
7271import com .oracle .svm .guest .staging .core .UnmanagedMemoryUtil ;
7372import com .oracle .svm .guest .staging .core .thread .OSThreadHandle ;
7473import com .oracle .svm .guest .staging .jdk .InternalVMMethod ;
74+ import com .oracle .svm .guest .staging .jdk .RuntimeSupport ;
7575import com .oracle .svm .sdk .staging .layeredimage .LayeredCompilationBehavior ;
7676import com .oracle .svm .sdk .staging .layeredimage .LayeredCompilationBehavior .Behavior ;
7777import com .oracle .svm .shared .Uninterruptible ;
@@ -277,14 +277,13 @@ private static int doRun(int argc, CCharPointerPointer argv) {
277277 private static int doRunInNewThread (int argc , CCharPointerPointer argv ) {
278278 try {
279279 Isolate isolate = createMainIsolate (argc , argv );
280- long javaStackSize = PlatformThreads .singleton ().getMainThreadRunnerJavaStackSize ();
281- PlatformThreads .singleton ().releaseMainThreadFromCurrent ();
280+ long javaStackSize = getJavaStackSize ();
282281 WordPointer threadExitStatus = StackValue .get (WordPointer .class );
283282 /*
284283 * The launcher blocks in a no-transition OS join, so detach it before the runner can
285284 * request VM operations.
286285 */
287- VMThreads . singleton (). detachCurrentThread ();
286+ detachCurrentThread ();
288287 int exitCode = startAndJoinMainRunner (isolate , javaStackSize , threadExitStatus );
289288
290289 runShutdownOnInitialThread (isolate );
@@ -294,6 +293,20 @@ private static int doRunInNewThread(int argc, CCharPointerPointer argv) {
294293 }
295294 }
296295
296+ @ Uninterruptible (reason = "Thread state not setup yet." )
297+ @ LayeredCompilationBehavior (Behavior .PINNED_TO_INITIAL_LAYER )
298+ private static long getJavaStackSize () {
299+ long javaStackSize = PlatformThreads .singleton ().getMainThreadRunnerJavaStackSize ();
300+ PlatformThreads .singleton ().releaseMainThreadFromCurrent ();
301+ return javaStackSize ;
302+ }
303+
304+ @ Uninterruptible (reason = "Thread state not setup yet." )
305+ @ LayeredCompilationBehavior (Behavior .PINNED_TO_INITIAL_LAYER )
306+ private static void detachCurrentThread () {
307+ VMThreads .singleton ().detachCurrentThread ();
308+ }
309+
297310 /**
298311 * Starts and joins the runner while the current launcher thread is detached from the isolate.
299312 */
0 commit comments