RFR: 8150617: nth_bit and friends are broken

Stefan Karlsson stefan.karlsson at oracle.com
Thu Feb 25 15:00:05 UTC 2016


Thanks, Thomas.

StefanK

On 2016-02-25 14:39, Thomas Schatzl wrote:
> Hi,
>
> On Thu, 2016-02-25 at 13:22 +0100, 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.
>    looks good.
>
> Thomas



More information about the hotspot-dev mailing list