src/share/classes/sun/misc/Hashing.java
Print this page
@@ -22,11 +22,11 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.misc;
-import java.util.Random;
+import java.util.concurrent.ThreadLocalRandom;
/**
* Hashing utilities.
*
* Little endian implementations of Murmur3 hashing.
@@ -205,32 +205,20 @@
return h1;
}
/**
- * Holds references to things that can't be initialized until after VM
- * is fully booted.
- */
- private static class Holder {
-
- /**
- * Used for generating per-instance hash seeds.
+ * Return a non-zero 32-bit pseudo random value. The {@code instance} object
+ * may be used as part of the value.
*
- * We try to improve upon the default seeding.
+ * @param instance an object to use if desired in choosing value.
+ * @return a non-zero 32-bit pseudo random value.
*/
- static final Random SEED_MAKER = new Random(
- Double.doubleToRawLongBits(Math.random())
- ^ System.identityHashCode(Hashing.class)
- ^ System.currentTimeMillis()
- ^ System.nanoTime()
- ^ Runtime.getRuntime().freeMemory());
- }
-
public static int randomHashSeed(Object instance) {
int seed;
if (sun.misc.VM.isBooted()) {
- seed = Holder.SEED_MAKER.nextInt();
+ seed = ThreadLocalRandom.current().nextInt();
} else {
// lower quality "random" seed value--still better than zero and not
// not practically reversible.
int hashing_seed[] = {
System.identityHashCode(Hashing.class),