RFR: 8305247: On RISC-V generate_fixed_frame() sometimes generate a relativized locals value which is way too large.
Fei Yang
fyang at openjdk.org
Mon Apr 3 00:45:18 UTC 2023
On Thu, 30 Mar 2023 12:57:23 GMT, Fredrik Bredberg <duke at openjdk.org> wrote:
> The relativized locals value is supposed to contain the distance between the frame pointer and the local variables in an interpreter frame, expressed in number of words. It typically contains the value "frame::sender_sp_offset + padding + max_locals - 1"
>
> On most architectures sender_sp_offset is 2. This gives us the value "1 + padding + max_locals", which is always greater or equal to 1.
>
> However on RISC-V the value of frame::sender_sp_offset is 0, which means that if we don't have any padding and no local variables we end up with a relativized_locals value of -1.
>
> When generate_fixed_frame() calculates the relativized_locals value it subtracts the frame pointer from the xlocals and then logically shifts the result right by Interpreter::logStackElementSize (to convert it into a word index).
>
> This works fine on all platforms (except RISC-V), because the subtraction will never become negative. But since the subtraction can end up negative on RISC-V, the shift instruction must be a arithmetic-shift-right (not a logical-shift-right) to preserve the sign and not end up with a very large positive index.
>
> This is currently not a real problem since the relativized_locals value is not used if max_local is zero, which is the only case the value is wrong.
>
> It is however a real problem when implementing JDK-8300197.
>
> The bug was introduced in JDK-8299795 and is fixed by changing a "srli" instruction to a "srai" in generate_fixed_frame().
Looks reasonable. I performed tier1-3 tests on my linux-riscv64 boards, result looks good.
BTW: You might want to change the issue title removing the '.' symbol.
-------------
Marked as reviewed by fyang (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/13245#pullrequestreview-1368173997
More information about the hotspot-dev
mailing list