Skip to content

Commit bbf11a1

Browse files
committed
Write return address in deopt stubs, too.
1 parent 848b11b commit bbf11a1

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/SubstrateAMD64Backend.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,11 +1361,10 @@ public void enter(CompilationResultBuilder tasm) {
13611361
asm.maybeEmitIndirectTargetMarker();
13621362

13631363
/*
1364-
* Keep the return address slot. This keeps the stack walkable, which is crucial for the
1365-
* interruptible phase of lazy deoptimization. (The return address points to the deopt
1366-
* stub, while the original return address is stored in the deopt slot.)
1364+
* Keep the return address slot. The correct return address is written in the stub
1365+
* itself (read more there). The original return address is stored in the deopt slot.
13671366
*
1368-
* This also ensures that the stack pointer is aligned properly.
1367+
* Keeping the return address also ensures that the stack pointer is aligned properly.
13691368
*/
13701369
asm.subq(registerConfig.getFrameRegister(), FrameAccess.returnAddressSize());
13711370

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/deopt/Deoptimizer.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,14 @@ private static boolean isNonNullValue(UnsignedWord pointer) {
828828
@DeoptStub(stubType = StubType.EntryStub)
829829
@Uninterruptible(reason = "Rewriting stack; gpReturnValue holds object reference.")
830830
public static UnsignedWord lazyDeoptStubObjectReturn(Pointer originalStackPointer, UnsignedWord gpReturnValue, UnsignedWord fpReturnValue) {
831+
/*
832+
* Establish the correct return address for this stub to make the stack walkable. The return
833+
* address could have been overwritten by an interrupt or signal handler if the ABI doesn't
834+
* guarantee a safe zone below the stack pointer.
835+
*/
836+
CodePointer returnAddress = DeoptimizationSupport.getLazyDeoptStubObjectReturnPointer();
837+
FrameAccess.singleton().writeReturnAddress(CurrentIsolate.getCurrentThread(), originalStackPointer, returnAddress);
838+
831839
try {
832840
assert PointerUtils.isAMultiple(KnownIntrinsics.readStackPointer(), Word.unsigned(ConfigurationValues.getTarget().stackAlignment));
833841
assert Options.LazyDeoptimization.getValue();
@@ -855,6 +863,10 @@ public static UnsignedWord lazyDeoptStubObjectReturn(Pointer originalStackPointe
855863
@DeoptStub(stubType = StubType.EntryStub)
856864
@Uninterruptible(reason = "Rewriting stack.")
857865
public static UnsignedWord lazyDeoptStubPrimitiveReturn(Pointer originalStackPointer, UnsignedWord gpReturnValue, UnsignedWord fpReturnValue) {
866+
/* Establish the correct return address for this stub (see ObjectReturn stub for details) */
867+
CodePointer returnAddress = DeoptimizationSupport.getLazyDeoptStubPrimitiveReturnPointer();
868+
FrameAccess.singleton().writeReturnAddress(CurrentIsolate.getCurrentThread(), originalStackPointer, returnAddress);
869+
858870
/*
859871
* Note: when we dispatch an exception, we enter lazyDeoptStubObjectReturn instead, since
860872
* that involves returning an exception object.
@@ -1005,6 +1017,10 @@ private static DeoptimizedFrame constructLazilyDeoptimizedFrameInterruptibly0(Po
10051017
@DeoptStub(stubType = StubType.EntryStub)
10061018
@Uninterruptible(reason = "Frame holds Objects in unmanaged storage.")
10071019
public static UnsignedWord eagerDeoptStub(Pointer originalStackPointer, UnsignedWord gpReturnValue, UnsignedWord fpReturnValue) {
1020+
/* Establish the correct return address for this stub to make the stack walkable. */
1021+
CodePointer returnAddress = DeoptimizationSupport.getEagerDeoptStubPointer();
1022+
FrameAccess.singleton().writeReturnAddress(CurrentIsolate.getCurrentThread(), originalStackPointer, returnAddress);
1023+
10081024
try {
10091025
assert PointerUtils.isAMultiple(KnownIntrinsics.readStackPointer(), Word.unsigned(ConfigurationValues.getTarget().stackAlignment));
10101026
VMError.guarantee(VMThreads.StatusSupport.isStatusJava(), "Deopt stub execution must not be visible to other threads.");

0 commit comments

Comments
 (0)