RFR 8203279 : Faster calculation of power of two

Ivan Gerasimov ivan.gerasimov at oracle.com
Thu May 17 00:32:57 UTC 2018


Hello!

In a few places we have code that rounds an integer up to the nearest 
power of two.

It is done with a series of RSHOTFs and ORs, but it can possibly be done 
faster with the use of Integer.numberOfLeadingZeros (assuming it is 
intrinsified).

Would you please help review this trivial optimization:

BUGURL: https://bugs.openjdk.java.net/browse/JDK-8203279
WEBREV: http://cr.openjdk.java.net/~igerasim/8203279/00/webrev/

For HashMap.tableSizeFor() I created a simple test with a loop from 
Integer.MIN_VALUE to Integer.MAX_VALUE (including), to make sure the 
result is the same.

For TimSort.ensureCapacity() I checked all positive values of minCapacity.

-- 
With kind regards,
Ivan Gerasimov



More information about the core-libs-dev mailing list