Skip to content

Commit a2dd6df

Browse files
committed
[GR-65519] In AArch64FarReturnOp, write lr late in case it initially holds sp.
PullRequest: graal/21007
2 parents 76f0980 + 3ef7de1 commit a2dd6df

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

substratevm/src/com.oracle.svm.core.graal.aarch64/src/com/oracle/svm/core/graal/aarch64/AArch64FarReturnOp.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,11 @@ public AArch64FarReturnOp(AllocatableValue result, AllocatableValue sp, Allocata
6868
public void emitCode(CompilationResultBuilder crb, AArch64MacroAssembler masm) {
6969
assert sp.getPlatformKind().getSizeInBytes() == FrameAccess.wordSize() && FrameAccess.wordSize() == Long.BYTES : Assertions.errorMessage(sp.getPlatformKind().getSizeInBytes(),
7070
FrameAccess.wordSize());
71-
/*
72-
* Set lr to the new instruction pointer like a regular return does.
73-
*
74-
* For dispatching an exception into a frame pending deoptimization, we farReturn into a
75-
* deopt stub which will do a regular enter and thus push lr. This keeps the stack walkable
76-
* and the frame can be recognized as pending deoptimization due to the return address from
77-
* lr matching the deopt stub entry point.
78-
*/
79-
masm.mov(64, lr, asRegister(ip));
8071

8172
if (!SubstrateOptions.PreserveFramePointer.getValue() && !fromMethodWithCalleeSavedRegisters) {
8273
/* No need to restore anything in the frame of the new stack pointer. */
8374
masm.mov(64, AArch64.sp, asRegister(sp));
84-
masm.ret(asRegister(ip));
75+
returnTo(asRegister(ip), masm);
8576
}
8677

8778
/*
@@ -94,7 +85,7 @@ public void emitCode(CompilationResultBuilder crb, AArch64MacroAssembler masm) {
9485
/*
9586
* If within the same frame then no additional action is needed.
9687
*/
97-
masm.ret(asRegister(ip));
88+
returnTo(asRegister(ip), masm);
9889

9990
/*
10091
* Otherwise we first switch the stack pointer to point to the value of the lowest value
@@ -144,7 +135,20 @@ public void emitCode(CompilationResultBuilder crb, AArch64MacroAssembler masm) {
144135
}
145136

146137
masm.ldr(64, fp, AArch64Address.createImmediateAddress(64, AArch64Address.AddressingMode.IMMEDIATE_POST_INDEXED, AArch64.sp, minCalleeFrameSize));
147-
masm.ret(ipRegister);
138+
returnTo(ipRegister, masm);
148139
}
149140
}
141+
142+
private static void returnTo(Register ipRegister, AArch64MacroAssembler masm) {
143+
/*
144+
* Set lr to the new instruction pointer like a regular return does.
145+
*
146+
* For dispatching an exception into a frame pending deoptimization, we farReturn into a
147+
* deopt stub which will do a regular enter and thus push lr. This keeps the stack walkable
148+
* and the frame can be recognized as pending deoptimization due to the return address from
149+
* lr matching the deopt stub entry point.
150+
*/
151+
masm.mov(64, lr, ipRegister);
152+
masm.ret(lr);
153+
}
150154
}

0 commit comments

Comments
 (0)