RFR [7192942] Optimizing calculation of power of 2 in HashMap

Ivan Gerasimov ivan.gerasimov at oracle.com
Tue Jul 30 15:35:10 UTC 2013

Hello everybody!

HashTable needs to calculate the power of two that is not less that the 
given number.
This calculation used to be implemented as a relatively inefficient loop 
(that's why the issue 7192942 was created).
The implementation was improved with 

However it can be improved even more. I reused 7192942 number for this 

Would you please help with reviewing?
Here's the webrev: 

I also created a benchmark test to make sure the improvement is observable.
Here's the jmh benchmark I used:

Benchmark                                Mode Thr    Cnt Sec         
Mean   Mean error    Units
o.b.PowerOfTwoBench.benchPowerOfTwoA     avgt   1     20 5       
60.697        0.850  msec/op
o.b.PowerOfTwoBench.benchPowerOfTwoB     avgt   1     20 5       
53.013        0.940  msec/op

The first line is for the current implementation and the second one is 
for the proposed change.
Thus, the time gets reduced by 12%.

Sincerely yours,

More information about the core-libs-dev mailing list