changeset 10306:97a964e285ac

8066397: Remove network-related seed initialization code in ThreadLocal/SplittableRandom Reviewed-by: alanb, dl, chegar, rriggs, shade
author psandoz
date Tue, 02 Dec 2014 13:41:18 +0100
parents 48e1550d58a6
children bbf9bd35ef5b
files src/share/classes/java/util/SplittableRandom.java src/share/classes/java/util/concurrent/ThreadLocalRandom.java
diffstat 2 files changed, 6 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/SplittableRandom.java	Wed Dec 03 17:21:04 2014 +0300
+++ b/src/share/classes/java/util/SplittableRandom.java	Tue Dec 02 13:41:18 2014 +0100
@@ -25,7 +25,6 @@
 
 package java.util;
 
-import java.net.NetworkInterface;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.function.IntConsumer;
 import java.util.function.LongConsumer;
@@ -140,11 +139,10 @@
      * other cases, this split must be performed in a thread-safe
      * manner, so we use an AtomicLong to represent the seed rather
      * than use an explicit SplittableRandom. To bootstrap the
-     * defaultGen, we start off using a seed based on current time and
-     * network interface address unless the java.util.secureRandomSeed
-     * property is set. This serves as a slimmed-down (and insecure)
-     * variant of SecureRandom that also avoids stalls that may occur
-     * when using /dev/random.
+     * defaultGen, we start off using a seed based on current time
+     * unless the java.util.secureRandomSeed property is set. This
+     * serves as a slimmed-down (and insecure) variant of SecureRandom
+     * that also avoids stalls that may occur when using /dev/random.
      *
      * It is a relatively simple matter to apply the basic design here
      * to use 128 bit seeds. However, emulating 128bit arithmetic and
@@ -237,34 +235,7 @@
                 s = (s << 8) | ((long)(seedBytes[i]) & 0xffL);
             return s;
         }
-        long h = 0L;
-        try {
-            Enumeration<NetworkInterface> ifcs =
-                    NetworkInterface.getNetworkInterfaces();
-            boolean retry = false; // retry once if getHardwareAddress is null
-            while (ifcs.hasMoreElements()) {
-                NetworkInterface ifc = ifcs.nextElement();
-                if (!ifc.isVirtual()) { // skip fake addresses
-                    byte[] bs = ifc.getHardwareAddress();
-                    if (bs != null) {
-                        int n = bs.length;
-                        int m = Math.min(n >>> 1, 4);
-                        for (int i = 0; i < m; ++i)
-                            h = (h << 16) ^ (bs[i] << 8) ^ bs[n-1-i];
-                        if (m < 4)
-                            h = (h << 8) ^ bs[n-1-m];
-                        h = mix64(h);
-                        break;
-                    }
-                    else if (!retry)
-                        retry = true;
-                    else
-                        break;
-                }
-            }
-        } catch (Exception ignore) {
-        }
-        return (h ^ mix64(System.currentTimeMillis()) ^
+        return (mix64(System.currentTimeMillis()) ^
                 mix64(System.nanoTime()));
     }
 
--- a/src/share/classes/java/util/concurrent/ThreadLocalRandom.java	Wed Dec 03 17:21:04 2014 +0300
+++ b/src/share/classes/java/util/concurrent/ThreadLocalRandom.java	Tue Dec 02 13:41:18 2014 +0100
@@ -36,8 +36,6 @@
 package java.util.concurrent;
 
 import java.io.ObjectStreamField;
-import java.net.NetworkInterface;
-import java.util.Enumeration;
 import java.util.Random;
 import java.util.Spliterator;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -147,34 +145,7 @@
                 s = (s << 8) | ((long)(seedBytes[i]) & 0xffL);
             return s;
         }
-        long h = 0L;
-        try {
-            Enumeration<NetworkInterface> ifcs =
-                    NetworkInterface.getNetworkInterfaces();
-            boolean retry = false; // retry once if getHardwareAddress is null
-            while (ifcs.hasMoreElements()) {
-                NetworkInterface ifc = ifcs.nextElement();
-                if (!ifc.isVirtual()) { // skip fake addresses
-                    byte[] bs = ifc.getHardwareAddress();
-                    if (bs != null) {
-                        int n = bs.length;
-                        int m = Math.min(n >>> 1, 4);
-                        for (int i = 0; i < m; ++i)
-                            h = (h << 16) ^ (bs[i] << 8) ^ bs[n-1-i];
-                        if (m < 4)
-                            h = (h << 8) ^ bs[n-1-m];
-                        h = mix64(h);
-                        break;
-                    }
-                    else if (!retry)
-                        retry = true;
-                    else
-                        break;
-                }
-            }
-        } catch (Exception ignore) {
-        }
-        return (h ^ mix64(System.currentTimeMillis()) ^
+        return (mix64(System.currentTimeMillis()) ^
                 mix64(System.nanoTime()));
     }