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), |