RFR: 8257985: count_trailing_zeros doesn't handle 64-bit values on 32-bit JVM [v7]

Kim Barrett kim.barrett at oracle.com
Fri Dec 11 15:04:45 UTC 2020


> On Dec 11, 2020, at 9:53 AM, Kim Barrett <kbarrett at openjdk.java.net> wrote:
> src/hotspot/share/utilities/count_trailing_zeros.hpp line 82:
> 
>> 80:     // no bit found? If so, try the upper dword. Otherwise index already contains the result
>> 81:     _BitScanForward(&index, x >> 32);
>> 82:     assert(index > 0, "invariant since x != 0");
> 
> I'm not sure this assert really does anything useful.  If both of the BSFs failed because the value is zero (which shouldn't happen because we checked for that), then the value of index is undefined.

Actually, it’s worse than that.  The assert is just wrong.  index will be zero if bit zero of the
high half is set.  But it looks like you’ve already removed the assert.




More information about the hotspot-dev mailing list