@@ -575,7 +575,7 @@ private static boolean checkDeoptimizedThenRegisterSpeculationFailure(boolean de
575
575
* or we are in the thread to which the frame belongs, and with lazy deoptimization
576
576
* enabled, only that thread may deoptimize it eagerly.
577
577
*/
578
- CodePointer originalReturnAddress = sp . readWord ( 0 );
578
+ CodePointer originalReturnAddress = readLazyDeoptOriginalReturnAddress ( targetThread , sp );
579
579
SubstrateInstalledCode installedCode = CodeInfoTable .lookupInstalledCode (originalReturnAddress );
580
580
registerSpeculationFailure (installedCode , speculation );
581
581
return true ;
@@ -675,7 +675,7 @@ public static void invalidateMethodOfFrame(IsolateThread thread, Pointer sp, Spe
675
675
* only the thread to which the frame belongs to may deoptimize it eagerly, which is the
676
676
* current thread.
677
677
*/
678
- ip = sp . readWord ( 0 );
678
+ ip = readLazyDeoptOriginalReturnAddress ( thread , sp );
679
679
}
680
680
SubstrateInstalledCode installedCode = CodeInfoTable .lookupInstalledCode (ip );
681
681
/*
@@ -812,37 +812,49 @@ private static boolean isNonNullValue(UnsignedWord pointer) {
812
812
}
813
813
814
814
@ DeoptStub (stubType = StubType .LazyEntryStub )
815
- @ Uninterruptible (reason = "gpReturnValue may hold unmanaged reference" )
815
+ @ Uninterruptible (reason = "Rewriting stack; gpReturnValue holds object reference. " )
816
816
public static UnsignedWord lazyDeoptStubObjectReturn (Pointer framePointer , UnsignedWord gpReturnValue , UnsignedWord fpReturnValue ) {
817
- assert PointerUtils .isAMultiple (KnownIntrinsics .readStackPointer (), Word .unsigned (ConfigurationValues .getTarget ().stackAlignment ));
818
- assert Options .LazyDeoptimization .getValue ();
819
- assert VMThreads .StatusSupport .isStatusJava () : "Deopt stub execution must not be visible to other threads." ;
817
+ try {
818
+ assert PointerUtils .isAMultiple (KnownIntrinsics .readStackPointer (), Word .unsigned (ConfigurationValues .getTarget ().stackAlignment ));
819
+ assert Options .LazyDeoptimization .getValue ();
820
+ assert VMThreads .StatusSupport .isStatusJava () : "Deopt stub execution must not be visible to other threads." ;
820
821
821
- boolean hasException = ExceptionUnwind .getLazyDeoptStubShouldReturnToExceptionHandler ();
822
- if (hasException ) {
823
- ExceptionUnwind .setLazyDeoptStubShouldReturnToExceptionHandler (false );
824
- }
825
- Object gpReturnValueObject = null ;
826
- if (isNonNullValue (gpReturnValue )) {
827
- gpReturnValueObject = ((Pointer ) gpReturnValue ).toObject ();
828
- }
822
+ boolean hasException = ExceptionUnwind .getLazyDeoptStubShouldReturnToExceptionHandler ();
823
+ if (hasException ) {
824
+ ExceptionUnwind .setLazyDeoptStubShouldReturnToExceptionHandler (false );
825
+ }
826
+ Object gpReturnValueObject = null ;
827
+ if (isNonNullValue (gpReturnValue )) {
828
+ gpReturnValueObject = ((Pointer ) gpReturnValue ).toObject ();
829
+ }
830
+
831
+ lazyDeoptStubCore (framePointer , gpReturnValue , fpReturnValue , hasException , gpReturnValueObject );
832
+ throw UnreachableNode .unreachable ();
829
833
830
- return lazyDeoptStubCore (framePointer , gpReturnValue , fpReturnValue , hasException , gpReturnValueObject );
834
+ } catch (Throwable t ) {
835
+ throw VMError .shouldNotReachHere ("Exception in lazy deopt stub" , t );
836
+ }
831
837
}
832
838
833
839
@ DeoptStub (stubType = StubType .LazyEntryStub )
834
- @ Uninterruptible (reason = "gpReturnValue may hold unmanaged reference " )
840
+ @ Uninterruptible (reason = "Rewriting stack. " )
835
841
public static UnsignedWord lazyDeoptStubPrimitiveReturn (Pointer framePointer , UnsignedWord gpReturnValue , UnsignedWord fpReturnValue ) {
836
842
/*
837
843
* Note: when we dispatch an exception, we enter lazyDeoptStubObjectReturn instead, since
838
844
* that involves returning an exception object.
839
845
*/
840
- assert PointerUtils .isAMultiple (KnownIntrinsics .readStackPointer (), Word .unsigned (ConfigurationValues .getTarget ().stackAlignment ));
841
- assert Options .LazyDeoptimization .getValue ();
842
- assert VMThreads .StatusSupport .isStatusJava () : "Deopt stub execution must not be visible to other threads." ;
843
- assert !ExceptionUnwind .getLazyDeoptStubShouldReturnToExceptionHandler ();
846
+ try {
847
+ assert PointerUtils .isAMultiple (KnownIntrinsics .readStackPointer (), Word .unsigned (ConfigurationValues .getTarget ().stackAlignment ));
848
+ assert Options .LazyDeoptimization .getValue ();
849
+ assert VMThreads .StatusSupport .isStatusJava () : "Deopt stub execution must not be visible to other threads." ;
850
+ assert !ExceptionUnwind .getLazyDeoptStubShouldReturnToExceptionHandler ();
844
851
845
- return lazyDeoptStubCore (framePointer , gpReturnValue , fpReturnValue , false , null );
852
+ lazyDeoptStubCore (framePointer , gpReturnValue , fpReturnValue , false , null );
853
+ throw UnreachableNode .unreachable ();
854
+
855
+ } catch (Throwable t ) {
856
+ throw VMError .shouldNotReachHere ("Exception in lazy deopt stub" , t );
857
+ }
846
858
}
847
859
848
860
/**
@@ -851,7 +863,7 @@ public static UnsignedWord lazyDeoptStubPrimitiveReturn(Pointer framePointer, Un
851
863
* Despite being marked Uninterruptible, this contains interruptible sections when we look up
852
864
* the code info, and construct the {@link DeoptimizedFrame}.
853
865
*/
854
- @ Uninterruptible (reason = "frame will hold objects in unmanaged storage " )
866
+ @ Uninterruptible (reason = "Rewriting stack. " )
855
867
private static UnsignedWord lazyDeoptStubCore (Pointer framePointer , UnsignedWord gpReturnValue , UnsignedWord fpReturnValue , boolean hasException , Object gpReturnValueObject ) {
856
868
CodePointer deoptStubAddress = FrameAccess .singleton ().readReturnAddress (CurrentIsolate .getCurrentThread (), framePointer );
857
869
assert isLazyDeoptStub (deoptStubAddress );
@@ -978,30 +990,36 @@ private static DeoptimizedFrame constructLazilyDeoptimizedFrameInterruptibly0(Po
978
990
@ DeoptStub (stubType = StubType .EagerEntryStub )
979
991
@ Uninterruptible (reason = "Frame holds Objects in unmanaged storage." )
980
992
public static UnsignedWord eagerDeoptStub (Pointer framePointer , UnsignedWord gpReturnValue , UnsignedWord fpReturnValue ) {
981
- assert PointerUtils .isAMultiple (KnownIntrinsics .readStackPointer (), Word .unsigned (ConfigurationValues .getTarget ().stackAlignment ));
982
- VMError .guarantee (VMThreads .StatusSupport .isStatusJava (), "Deopt stub execution must not be visible to other threads." );
983
- DeoptimizedFrame frame = (DeoptimizedFrame ) ReferenceAccess .singleton ().readObjectAt (framePointer , true );
993
+ try {
994
+ assert PointerUtils .isAMultiple (KnownIntrinsics .readStackPointer (), Word .unsigned (ConfigurationValues .getTarget ().stackAlignment ));
995
+ VMError .guarantee (VMThreads .StatusSupport .isStatusJava (), "Deopt stub execution must not be visible to other threads." );
996
+ DeoptimizedFrame frame = (DeoptimizedFrame ) ReferenceAccess .singleton ().readObjectAt (framePointer , true );
984
997
985
- DeoptimizationCounters .counters ().deoptCount .inc ();
986
- if (DeoptimizationCounters .Options .ProfileDeoptimization .getValue ()) {
987
- DeoptimizationCounters .startTime .set (System .nanoTime ());
988
- }
998
+ DeoptimizationCounters .counters ().deoptCount .inc ();
999
+ if (DeoptimizationCounters .Options .ProfileDeoptimization .getValue ()) {
1000
+ DeoptimizationCounters .startTime .set (System .nanoTime ());
1001
+ }
989
1002
990
- final Pointer newSp = computeNewFramePointer (framePointer , frame );
1003
+ final Pointer newSp = computeNewFramePointer (framePointer , frame );
991
1004
992
- /* Build the content of the deopt target stack frames. */
993
- frame .buildContent (newSp );
1005
+ /* Build the content of the deopt target stack frames. */
1006
+ frame .buildContent (newSp );
994
1007
995
- /*
996
- * The frame was pinned to keep it from moving during construction. I can unpin it now that
997
- * I am uninterruptible. (And I have to unpin it.)
998
- */
999
- frame .unpin ();
1008
+ /*
1009
+ * The frame was pinned to keep it from moving during construction. I can unpin it now
1010
+ * that I am uninterruptible. (And I have to unpin it.)
1011
+ */
1012
+ frame .unpin ();
1000
1013
1001
- recentDeoptimizationEvents .append (frame .getCompletedMessage ());
1014
+ recentDeoptimizationEvents .append (frame .getCompletedMessage ());
1002
1015
1003
- /* Do the stack rewriting. Return directly to the deopt target. */
1004
- return rewriteStackStub (newSp , gpReturnValue , fpReturnValue , frame );
1016
+ /* Do the stack rewriting. Return directly to the deopt target. */
1017
+ rewriteStackStub (newSp , gpReturnValue , fpReturnValue , frame );
1018
+ throw UnreachableNode .unreachable ();
1019
+
1020
+ } catch (Throwable t ) {
1021
+ throw VMError .shouldNotReachHere ("Exception in eager deopt stub" , t );
1022
+ }
1005
1023
}
1006
1024
1007
1025
@ Uninterruptible (reason = CALLED_FROM_UNINTERRUPTIBLE_CODE , mayBeInlined = true )
@@ -1111,7 +1129,7 @@ public DeoptimizedFrame deoptimizeEagerly() {
1111
1129
private static void installLazyDeoptStubReturnAddress (boolean returnValueIsObject , Pointer sourceSp , IsolateThread targetThread ) {
1112
1130
assert Options .LazyDeoptimization .getValue ();
1113
1131
assert VMOperation .isInProgressAtSafepoint ();
1114
- CodePointer oldReturnAddress = FrameAccess .singleton ().readReturnAddress (targetThread , sourceSp );
1132
+ CodePointer originalReturnAddress = FrameAccess .singleton ().readReturnAddress (targetThread , sourceSp );
1115
1133
1116
1134
/*
1117
1135
* Replace the return address to the deoptimized method with the entry point of the lazy
@@ -1126,7 +1144,13 @@ private static void installLazyDeoptStubReturnAddress(boolean returnValueIsObjec
1126
1144
* Write the original return address into the slot where the DeoptimizedFrame would go in
1127
1145
* the case of eager deoptimization.
1128
1146
*/
1129
- sourceSp .writeWord (0 , oldReturnAddress );
1147
+ sourceSp .writeWord (0 , originalReturnAddress );
1148
+ }
1149
+
1150
+ @ Uninterruptible (reason = CALLED_FROM_UNINTERRUPTIBLE_CODE , mayBeInlined = true )
1151
+ static CodePointer readLazyDeoptOriginalReturnAddress (IsolateThread thread , Pointer sp ) {
1152
+ assert checkLazyDeoptimized (thread , sp );
1153
+ return sp .readWord (0 );
1130
1154
}
1131
1155
1132
1156
@ Uninterruptible (reason = "Prevent stack walks from seeing an inconsistent stack." )
0 commit comments