[aarch64] assert(is_power_of_2(x)) failed: x must be a power of 2: 0xffffffff80000000
Schmidt, Lutz
lutz.schmidt at sap.com
Mon Feb 24 16:27:44 UTC 2020
On 24.02.20, 17:09, "Andrew Haley" <aph at redhat.com> wrote:
On 2/24/20 3:51 PM, Schmidt, Lutz wrote:
> I would locate the real bug in is_power_of_2(jint). Why?
>
> The function is passed in a jint (= signed int) of value 0x8000_0000. This clearly is a negative number. There does not exist a negative number which is a power of 2.
I'm pretty sure you're wrong. jint multiplication is defined as being
the low-order 32 bits of the true result; i.e. it is modulo 2**32. It
is different from C++ arithmetic in this regard, in which integer
arithmetic may overflow. In Java, if you start with 1 and multiply it
by 2, 31 times, you get exactly 0x8000_0000. The inverse operation of
those multiplication is exact_log2, and given that the result of the
multiplications is well defined so is its inverse, exact_log2().
OK. That's a different way to look at it.
> Separate from that, exact_log2(jint) sign-extends the passed-in
> value to long, creating a bit pattern which obviously is not a power
> of two.
And in my opinion that sign extension should not be done in the case
of a jint argument. We should try to do the most useful thing.
I agree. Just didn't say it explicitly.
> A possible fix would include:
> - make is_power_of_2() and exact_log_2() sign-aware.
> - call is_power_of_2() and exact_log_2() with arguments of proper
> type (juint in this case).
Or fix exact_log2(jint) by specializing it appropriately.
Yes, by treating the jint argument as unsigned.
--
Andrew Haley (he/him)
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
https://keybase.io/andrewhaley
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671
More information about the hotspot-compiler-dev
mailing list