jdk/src/share/classes/sun/misc/Hashing.java
changeset 17939 bd750ec19d82
parent 12859 c44b88bb9b5e
equal deleted inserted replaced
17938:af1b01dfea42 17939:bd750ec19d82
    22  * or visit www.oracle.com if you need additional information or have any
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 package sun.misc;
    25 package sun.misc;
    26 
    26 
    27 import java.util.Random;
    27 import java.util.concurrent.ThreadLocalRandom;
    28 
    28 
    29 /**
    29 /**
    30  * Hashing utilities.
    30  * Hashing utilities.
    31  *
    31  *
    32  * Little endian implementations of Murmur3 hashing.
    32  * Little endian implementations of Murmur3 hashing.
   205 
   205 
   206         return h1;
   206         return h1;
   207     }
   207     }
   208 
   208 
   209     /**
   209     /**
   210      * Holds references to things that can't be initialized until after VM
   210      * Return a non-zero 32-bit pseudo random value. The {@code instance} object
   211      * is fully booted.
   211      * may be used as part of the value.
       
   212      *
       
   213      * @param instance an object to use if desired in choosing value.
       
   214      * @return a non-zero 32-bit pseudo random value.
   212      */
   215      */
   213     private static class Holder {
       
   214 
       
   215         /**
       
   216          * Used for generating per-instance hash seeds.
       
   217          *
       
   218          * We try to improve upon the default seeding.
       
   219          */
       
   220         static final Random SEED_MAKER = new Random(
       
   221                 Double.doubleToRawLongBits(Math.random())
       
   222                 ^ System.identityHashCode(Hashing.class)
       
   223                 ^ System.currentTimeMillis()
       
   224                 ^ System.nanoTime()
       
   225                 ^ Runtime.getRuntime().freeMemory());
       
   226     }
       
   227 
       
   228     public static int randomHashSeed(Object instance) {
   216     public static int randomHashSeed(Object instance) {
   229         int seed;
   217         int seed;
   230         if (sun.misc.VM.isBooted()) {
   218         if (sun.misc.VM.isBooted()) {
   231             seed = Holder.SEED_MAKER.nextInt();
   219             seed = ThreadLocalRandom.current().nextInt();
   232         } else {
   220         } else {
   233             // lower quality "random" seed value--still better than zero and not
   221             // lower quality "random" seed value--still better than zero and not
   234             // not practically reversible.
   222             // not practically reversible.
   235             int hashing_seed[] = {
   223             int hashing_seed[] = {
   236                 System.identityHashCode(Hashing.class),
   224                 System.identityHashCode(Hashing.class),