@@ -256,12 +256,13 @@ public static void initBaseRegisters(PointerBase heapBase, PointerBase codeBase)
256
256
@ Snippet (allowMissingProbabilities = true )
257
257
public static int createIsolateSnippet (CEntryPointCreateIsolateParameters parameters ) {
258
258
writeCurrentVMThread (Word .nullPointer ());
259
+
259
260
int result = runtimeCall (CREATE_ISOLATE , parameters );
260
261
if (result != CEntryPointErrors .NO_ERROR ) {
261
262
return result ;
262
263
}
263
- ThreadStatusTransition .fromNativeToJava (false );
264
264
265
+ ThreadStatusTransition .fromNativeToJava (false );
265
266
return runtimeCallInitializeIsolate (INITIALIZE_ISOLATE , parameters );
266
267
}
267
268
@@ -310,14 +311,15 @@ private static int createIsolate(CEntryPointCreateIsolateParameters providedPara
310
311
IsolateArgumentParser .singleton ().tearDown (arguments );
311
312
return error ;
312
313
}
314
+
313
315
Isolate isolate = isolatePtr .read ();
314
316
initBaseRegisters (Isolates .getHeapBase (isolate ));
315
317
316
318
return createIsolate0 (isolate , arguments );
317
319
}
318
320
319
321
@ Uninterruptible (reason = "Thread state not yet set up." )
320
- @ NeverInline (value = "Ensure this code cannot rise above where heap base is set ." )
322
+ @ NeverInline ("Base registers are set in caller, prevent reads from floating before that ." )
321
323
private static int createIsolate0 (Isolate isolate , IsolateArguments arguments ) {
322
324
assert Heap .getHeap ().verifyImageHeapMapping ();
323
325
IsolateArgumentParser .singleton ().persistOptions (arguments );
@@ -327,10 +329,12 @@ private static int createIsolate0(Isolate isolate, IsolateArguments arguments) {
327
329
if (!VMThreads .ensureInitialized ()) {
328
330
return CEntryPointErrors .THREADING_INITIALIZATION_FAILED ;
329
331
}
332
+
330
333
int error = enterAttachThread0 (isolate , false , true );
331
334
if (error != CEntryPointErrors .NO_ERROR ) {
332
335
return error ;
333
336
}
337
+
334
338
PlatformThreads .singleton ().assignMainThread ();
335
339
return CEntryPointErrors .NO_ERROR ;
336
340
}
@@ -504,13 +508,13 @@ private static int initializeIsolateInterruptibly1(CEntryPointCreateIsolateParam
504
508
@ Snippet (allowMissingProbabilities = true )
505
509
public static int attachThreadSnippet (Isolate isolate , boolean startedByIsolate , boolean ensureJavaThread ) {
506
510
writeCurrentVMThread (Word .nullPointer ());
511
+
507
512
int error = runtimeCall (ATTACH_THREAD , isolate , startedByIsolate , ensureJavaThread );
508
513
if (error != CEntryPointErrors .NO_ERROR ) {
509
514
return error ;
510
515
}
511
516
512
517
ThreadStatusTransition .fromNativeToJava (false );
513
-
514
518
if (ensureJavaThread ) {
515
519
return runtimeCallEnsureJavaThread (ENSURE_JAVA_THREAD );
516
520
}
@@ -534,7 +538,14 @@ private static int enterAttachThread0(Isolate isolate, boolean startedByIsolate,
534
538
if (error != CEntryPointErrors .NO_ERROR ) {
535
539
return error ;
536
540
}
541
+
537
542
initBaseRegisters (Isolates .getHeapBase (isolate ));
543
+ return enterAttachThread1 (isolate , startedByIsolate , ensureJavaThread , allowAttach , inCrashHandler );
544
+ }
545
+
546
+ @ Uninterruptible (reason = "Thread state not set up yet." )
547
+ @ NeverInline ("Base registers are set in caller, prevent reads from floating before that." )
548
+ private static int enterAttachThread1 (Isolate isolate , boolean startedByIsolate , boolean ensureJavaThread , boolean allowAttach , boolean inCrashHandler ) {
538
549
if (!VMThreads .isInitialized ()) {
539
550
return CEntryPointErrors .UNINITIALIZED_ISOLATE ;
540
551
}
@@ -567,6 +578,7 @@ private static int attachUnattachedThread(Isolate isolate, boolean startedByIsol
567
578
if (thread .isNull ()) {
568
579
return CEntryPointErrors .ALLOCATION_FAILED ;
569
580
}
581
+
570
582
writeCurrentVMThread (thread );
571
583
if (!StackOverflowCheck .singleton ().initialize ()) {
572
584
return CEntryPointErrors .UNKNOWN_STACK_BOUNDARIES ;
@@ -601,8 +613,13 @@ public static int enterFromCrashHandler(Isolate isolate) {
601
613
@ Uninterruptible (reason = "Thread state not yet set up." )
602
614
public static void initializeIsolateThreadForCrashHandler (Isolate isolate , IsolateThread thread ) {
603
615
initBaseRegisters (Isolates .getHeapBase (isolate ));
604
-
605
616
writeCurrentVMThread (thread );
617
+ initializeIsolateThreadForCrashHandler0 (isolate , thread );
618
+ }
619
+
620
+ @ Uninterruptible (reason = CALLED_FROM_UNINTERRUPTIBLE_CODE )
621
+ @ NeverInline ("Base registers are set in caller, prevent reads from floating before that." )
622
+ private static void initializeIsolateThreadForCrashHandler0 (Isolate isolate , IsolateThread thread ) {
606
623
VMThreads .StatusSupport .setStatusNative ();
607
624
VMThreads .IsolateTL .set (thread , isolate );
608
625
SubstrateDiagnostics .setOnlyAttachedForCrashHandler (thread );
@@ -713,13 +730,11 @@ private static boolean initiateTearDownIsolateInterruptibly() {
713
730
714
731
@ Snippet (allowMissingProbabilities = true )
715
732
public static int enterByIsolateSnippet (Isolate isolate ) {
716
- int result ;
717
733
writeCurrentVMThread (Word .nullPointer ());
718
- result = runtimeCall (ENTER_BY_ISOLATE , isolate );
719
- if (result == CEntryPointErrors .NO_ERROR ) {
720
- if (VMThreads .StatusSupport .isStatusNativeOrSafepoint ()) {
721
- ThreadStatusTransition .fromNativeToJava (false );
722
- }
734
+
735
+ int result = runtimeCall (ENTER_BY_ISOLATE , isolate );
736
+ if (result == CEntryPointErrors .NO_ERROR && VMThreads .StatusSupport .isStatusNativeOrSafepoint ()) {
737
+ ThreadStatusTransition .fromNativeToJava (false );
723
738
}
724
739
return result ;
725
740
}
@@ -731,14 +746,23 @@ private static int enterByIsolate(Isolate isolate) {
731
746
if (error != CEntryPointErrors .NO_ERROR ) {
732
747
return error ;
733
748
}
749
+
734
750
initBaseRegisters (Isolates .getHeapBase (isolate ));
751
+ return enterByIsolate0 ();
752
+ }
753
+
754
+ @ Uninterruptible (reason = "Thread state not set up yet." )
755
+ @ NeverInline ("Base registers are set in caller, prevent reads from floating before that." )
756
+ private static int enterByIsolate0 () {
735
757
if (!VMThreads .isInitialized ()) {
736
758
return CEntryPointErrors .UNINITIALIZED_ISOLATE ;
737
759
}
760
+
738
761
IsolateThread thread = VMThreads .singleton ().findIsolateThreadForCurrentOSThread (false );
739
762
if (thread .isNull ()) {
740
763
return CEntryPointErrors .UNATTACHED_THREAD ;
741
764
}
765
+
742
766
writeCurrentVMThread (thread );
743
767
return CEntryPointErrors .NO_ERROR ;
744
768
}
@@ -748,9 +772,11 @@ public static int enterSnippet(IsolateThread thread) {
748
772
if (thread .isNull ()) {
749
773
return CEntryPointErrors .NULL_ARGUMENT ;
750
774
}
775
+
751
776
writeCurrentVMThread (thread );
752
777
Isolate isolate = VMThreads .IsolateTL .get (thread );
753
778
initBaseRegisters (Isolates .getHeapBase (isolate ));
779
+
754
780
if (runtimeAssertionsEnabled () || SubstrateOptions .CheckIsolateThreadAtEntry .getValue ()) {
755
781
/*
756
782
* Verification must happen before the thread state transition. It locks the raw
@@ -759,9 +785,7 @@ public static int enterSnippet(IsolateThread thread) {
759
785
runtimeCall (VERIFY_ISOLATE_THREAD , thread );
760
786
}
761
787
ThreadStatusTransition .fromNativeToJava (false );
762
-
763
788
return CEntryPointErrors .NO_ERROR ;
764
-
765
789
}
766
790
767
791
@ Fold
@@ -804,7 +828,7 @@ private static int reportException(Throwable exception) {
804
828
805
829
private static void reportExceptionInterruptibly (Throwable exception ) {
806
830
logException (exception );
807
- VMError .shouldNotReachHere ("Unhandled exception" );
831
+ throw VMError .shouldNotReachHere ("Unhandled exception" );
808
832
}
809
833
810
834
@ RestrictHeapAccess (access = NO_ALLOCATION , reason = "Must not allocate in fatal error handling." )
@@ -825,13 +849,23 @@ public static int returnFromJavaToCSnippet() {
825
849
826
850
@ Snippet (allowMissingProbabilities = true )
827
851
public static boolean isAttachedSnippet (Isolate isolate ) {
828
- return Isolates . checkIsolate ( isolate ) == CEntryPointErrors . NO_ERROR && runtimeCallIsAttached (IS_ATTACHED , isolate );
852
+ return runtimeCallIsAttached (IS_ATTACHED , isolate );
829
853
}
830
854
831
855
@ Uninterruptible (reason = "Thread state not yet set up." )
832
856
@ SubstrateForeignCallTarget (stubCallingConvention = false )
833
857
private static boolean isAttached (Isolate isolate ) {
858
+ if (Isolates .checkIsolate (isolate ) != CEntryPointErrors .NO_ERROR ) {
859
+ return false ;
860
+ }
861
+
834
862
initBaseRegisters (Isolates .getHeapBase (isolate ));
863
+ return isAttached0 ();
864
+ }
865
+
866
+ @ Uninterruptible (reason = "Thread state not yet set up." )
867
+ @ NeverInline ("Base registers are set in caller, prevent reads from floating before that." )
868
+ private static boolean isAttached0 () {
835
869
return VMThreads .isInitialized () && VMThreads .singleton ().findIsolateThreadForCurrentOSThread (false ).isNonNull ();
836
870
}
837
871
0 commit comments