RFR: 8283488: AArch64: Improve stack trace accuracy in hs log
Denghui Dong
ddong at openjdk.java.net
Tue Mar 22 07:29:54 UTC 2022
Hi team,
Could I have a review of this patch?
The native stack trace in hs log is not accurate sometime since we cannot get the accurate `sender sp`, and `sp` is the key to walk stack for compiled frames.
frame os::get_sender_for_C_frame(frame* fr) {
return frame(fr->link(), fr->link(), fr->sender_pc());
}
JDK-8277948[1] solved the problem but the premise is that PreserveFramePointer needs to be enabled.
For x86 platform, we can get the `sender sp` by `fp + 2`, but it does not hold in Aarch64.
According to "Procedure Call Standard for the Arm® 64-bit Architecture (AArch64)[2]", section "6.2.3 The Frame Pointer" describes that the location of the frame record within a stack frame is not specified. Hence, I cannot get the `sender sp` by adding a constant to `fp`.
By the way, I found that in the executable I compiled on mac m1, like x86, the frame record is always at the bottom of the stack, but I didn't find a standard specification to prove it. If we can guarantee that this is the case, we can simplify the solution on the mac
This patch deduces the `sender sp` by decoding the native instructions, this solution is applicable to both Mac and Linux I think.
At present, I found that there are mainly three patterns as follows:
a)
stp x29, x30, [sp, #-N]!
mov x29, sp
=> sender sp = fp + N
b)
sub sp, sp, #N1
stp x29, x30, [sp, #N2]
add x29, sp, #N2
=> sender sp = fp + (N1 - N2)
c)
stp Xt1, Xt2, [sp, #-N1]! ; Xt1 is not x29, Xt2 is not x30
stp x29, x30, [sp, #N2]
add x29, sp, #N2
=> sender sp = fp + (N1 - N2)
In addition, special treatment is required for two cases, you can refer to the comments in the code.
To reduce the impact, deducing the `sender sp` is occurred only when a VM error is reported.
I'm not sure if this solution is acceptable as it is a bit tricky, any input is appreciated.
Worth mentioning, the stack trace may still not be accurate sometimes even if this patch is applied. One of the reasons is that `os::is_first_C_frame` will check the `sender fp`. Since `fp` is used as a general register in JIT(When PreserveFramePointer is diabled), it is usually not a reasonable `fp` value in the case of `jit code -> c code`, we may consider modifying the implementation of `os::is_first_C_frame` to apply this case.
[1] https://bugs.openjdk.java.net/browse/JDK-8277948
[2] https://github.com/ARM-software/abi-aa/blob/320a56971fdcba282b7001cf4b84abb4fd993131/aapcs64/aapcs64.rst#the-frame-pointer
Thanks,
Denghui
-------------
Commit messages:
- 8283488: AArch64: Improve stack trace accuracy in hs log
Changes: https://git.openjdk.java.net/jdk/pull/7900/files
Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=7900&range=00
Issue: https://bugs.openjdk.java.net/browse/JDK-8283488
Stats: 136 lines in 4 files changed: 134 ins; 0 del; 2 mod
Patch: https://git.openjdk.java.net/jdk/pull/7900.diff
Fetch: git fetch https://git.openjdk.java.net/jdk pull/7900/head:pull/7900
PR: https://git.openjdk.java.net/jdk/pull/7900
More information about the hotspot-dev
mailing list