RFR: 8150617: nth_bit and friends are broken

Vladimir Ivanov vladimir.x.ivanov at oracle.com
Thu Feb 25 13:53:31 UTC 2016


Looks good.

Best regards,
Vladimir Ivanov

On 2/25/16 3:22 PM, Stefan Karlsson wrote:
> Hi all,
>
> Please review this patch to fix the nth_bit, right_n_bits, and
> left_n_bits macros.
>   http://cr.openjdk.java.net/~stefank/8150617/webrev.00
>
> The macros were broken when expressions with low-precedence operators
> were used. For example (in 64 bit JVMs):
>    nth_bit(true ? 32 : 64) returns 0x20 instead of 0x100000000
> nth_bit(1|2) returns 0x0 instead of 0x8
>
> The fix is to add parentheses around all usages of the macro input
> parameter. I also added some extra parentheses to further disambiguate
> the expression for readers of the code.
>
> I added STATIC_ASSERTS to show the problem, but I can remove them if
> someone thinks they are unnecessary. Tested with JPRT.
>
> Thanks,
> StefanK


More information about the hotspot-dev mailing list