RFR: 8256387: Unexpected result if patching an entire instruction on AArch64

Andrew Haley aph at openjdk.java.net
Mon Nov 23 10:25:00 UTC 2020


On Tue, 17 Nov 2020 06:14:37 GMT, Eric Liu <github.com+10482586+erik1iu at openjdk.org> wrote:

> This patch fixed some potential risks in assembler_aarch64.hpp.
> 
> According to the C standard, shift operation is undefined if the shift
> count greater than or equals to the length in bits of the promoted left
> operand.
> 
> In assembler_aarch64.hpp, there are some utility functions for easily
> operating the encoded instructions. E.g.
> 
>         Instruction_aarch64::patch(address, int, int, uint64_t)
> 
> All those functions use `(1U << nbits) - 1` to calculate mask which may
> have some potential risks if `nbits` equals 32. That would be an
> unexpected result if someone intends to deal with an entire instruction.
> 
> To fix this issue, this patch simply uses `1ULL` to replace `1U`.

src/hotspot/cpu/aarch64/assembler_aarch64.hpp line 207:

> 205:     int nbits = msb - lsb + 1;
> 206:     assert_cond(msb >= lsb);
> 207:     uint32_t mask = (1ULL << nbits) - 1;

Please use checked_cast<uint32_t>((1ULL << nbits) - 1) here.
If we don't cast to the shorter type at this point, some compilers will give a warning.

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

PR: https://git.openjdk.java.net/jdk/pull/1248


More information about the hotspot-compiler-dev mailing list