Integrated: 8305247: On RISC-V generate_fixed_frame() sometimes generate a relativized locals value which is way too large

Fredrik Bredberg duke at openjdk.org
Mon Apr 3 12:41:10 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().

This pull request has now been integrated.

Changeset: 33d09e58
Author:    Fredrik Bredberg <fredrik.bredberg at oracle.com>
Committer: Robbin Ehn <rehn at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/33d09e587a87e545bb3f6d21c79bf497cd056815
Stats:     1 line in 1 file changed: 0 ins; 0 del; 1 mod

8305247: On RISC-V generate_fixed_frame() sometimes generate a relativized locals value which is way too large

Reviewed-by: fyang, rehn

-------------

PR: https://git.openjdk.org/jdk/pull/13245


More information about the hotspot-dev mailing list