RFR: 8240615: is_power_of_2() has Undefined Behaviour and is inconsistent

Doerr, Martin martin.doerr at sap.com
Mon Mar 9 15:56:33 UTC 2020


Hi Andrew,

it doesn't run into the UB case, but log2_jint(x) returns 63 for negative x.
I'd treat this as bug. A jint has 32 bit and log2 should never return 63.

Best regards,
Martin


> -----Original Message-----
> From: Andrew Haley <aph at redhat.com>
> Sent: Montag, 9. März 2020 16:42
> To: Doerr, Martin <martin.doerr at sap.com>; Stefan Karlsson
> <stefan.karlsson at oracle.com>; John Rose <john.r.rose at oracle.com>
> Cc: hotspot-dev at openjdk.java.net; hotspot-runtime-dev at openjdk.java.net
> Subject: Re: RFR: 8240615: is_power_of_2() has Undefined Behaviour and is
> inconsistent
> 
> On 3/9/20 2:46 PM, Doerr, Martin wrote:
> > Sorry, my comment about log2_int + log2_jint was not precise.
> >
> > The comment
> > "If x < 0, the function returns 31 on a 32-bit machine and 63 on a 64-bit
> machine."
> > belongs to log2_intptr,
> 
> Indeed.
> 
> > but it also applies to log2_int + log2_jint which is not desirable IMHO.
> > I guess using zero extend would be better for these 2 functions:
> > "If x < 0, the function returns 31 on all machines."
> 
> As far as I can see, log2_jint() does the right thing: it returns
> 31 for 0x8000_0000-0xffff_ffff, and it does this with no undefined
> behaviour.
> 
> --
> 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-dev mailing list