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

Aleksey Shipilev aleksey.shipilev at oracle.com
Tue Jul 30 16:47:29 UTC 2013


On 07/30/2013 07:35 PM, Ivan Gerasimov wrote:
> I also created a benchmark test to make sure the improvement is observable.
> Here's the jmh benchmark I used:
> http://cr.openjdk.java.net/~igerasim/bench/powoftwo/src/main/java/org/benches/PowerOfTwoBench.java
> <http://cr.openjdk.java.net/%7Eigerasim/bench/powoftwo/src/main/java/org/benches/PowerOfTwoBench.java>

The nit: volatile writes are probably offset the results too much, it's
better to use the explicit idiom to feed the values:

    @GenerateMicroBenchmark
    public void benchPowerOfTwoA(BlackHole bh) {
        for (i = 0; i != MAX_I; ++i) {
            bh.consume(roundUpToPowerOf2A(i));
        }
    }

-Aleksey.



More information about the core-libs-dev mailing list