7189139: BigInteger's staticRandom field can be a source of bottlenecks.
authorbpb
Wed, 09 Oct 2013 17:22:34 -0700
changeset 20756 d998355e6a5c
parent 20755 e3f8b7f63dc7
child 20757 1e9f01f43f5c
7189139: BigInteger's staticRandom field can be a source of bottlenecks. Summary: Use ThreadLocalRandom instead of SecureRandom. Reviewed-by: shade, psandoz Contributed-by: Brian Burkhalter <brian.burkhalter@oracle.com>
jdk/src/share/classes/java/math/BigInteger.java
--- a/jdk/src/share/classes/java/math/BigInteger.java	Wed Oct 09 13:07:58 2013 -0700
+++ b/jdk/src/share/classes/java/math/BigInteger.java	Wed Oct 09 17:22:34 2013 -0700
@@ -35,6 +35,7 @@
 import java.io.ObjectStreamField;
 import java.util.Arrays;
 import java.util.Random;
+import java.util.concurrent.ThreadLocalRandom;
 import sun.misc.DoubleConsts;
 import sun.misc.FloatConsts;
 
@@ -918,15 +919,6 @@
         return u;
     }
 
-    private static volatile Random staticRandom;
-
-    private static Random getSecureRandom() {
-        if (staticRandom == null) {
-            staticRandom = new java.security.SecureRandom();
-        }
-        return staticRandom;
-    }
-
     /**
      * Returns true iff this BigInteger passes the specified number of
      * Miller-Rabin tests. This test is taken from the DSA spec (NIST FIPS
@@ -945,7 +937,7 @@
 
         // Do the tests
         if (rnd == null) {
-            rnd = getSecureRandom();
+            rnd = ThreadLocalRandom.current();
         }
         for (int i=0; i < iterations; i++) {
             // Generate a uniform random on (1, this)