src/share/classes/java/util/concurrent/ThreadLocalRandom.java
Print this page
*** 33,44 ****
--- 33,50 ----
* http://creativecommons.org/publicdomain/zero/1.0/
*/
package java.util.concurrent;
+ import sun.misc.JavaNetAccess;
+ import sun.misc.SharedSecrets;
+
import java.io.ObjectStreamField;
import java.net.NetworkInterface;
+ import java.security.NoSuchAlgorithmException;
+ import java.security.NoSuchProviderException;
+ import java.security.SecureRandom;
import java.util.Enumeration;
import java.util.Random;
import java.util.Spliterator;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
*** 138,163 ****
private static long initialSeed() {
String pp = java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction(
"java.util.secureRandomSeed"));
! if (pp != null && pp.equalsIgnoreCase("true")) {
! byte[] seedBytes = java.security.SecureRandom.getSeed(8);
long s = (long)(seedBytes[0]) & 0xffL;
for (int i = 1; i < 8; ++i)
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];
--- 144,184 ----
private static long initialSeed() {
String pp = java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction(
"java.util.secureRandomSeed"));
! if (pp != null) {
! SecureRandom sr;
! if (pp.equalsIgnoreCase("true")) {
! sr = new SecureRandom();
! } else {
! String[] args = pp.split(",", 2);
! try {
! sr = args.length > 1
! ? SecureRandom.getInstance(args[0], args[1])
! : SecureRandom.getInstance(args[0]);
! } catch (NoSuchAlgorithmException | NoSuchProviderException e) {
! throw new IllegalArgumentException(
! "Invalid java.util.secureRandomSeed property: " + pp, e);
! }
! }
! byte[] seedBytes = sr.generateSeed(8);
long s = (long)(seedBytes[0]) & 0xffL;
for (int i = 1; i < 8; ++i)
s = (s << 8) | ((long)(seedBytes[i]) & 0xffL);
return s;
}
long h = 0L;
try {
Enumeration<NetworkInterface> ifcs =
NetworkInterface.getNetworkInterfaces();
+ JavaNetAccess jna = SharedSecrets.getJavaNetAccess();
boolean retry = false; // retry once if getHardwareAddress is null
while (ifcs.hasMoreElements()) {
NetworkInterface ifc = ifcs.nextElement();
if (!ifc.isVirtual()) { // skip fake addresses
! byte[] bs = jna.getHardwareAddress0(ifc);
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];