changeset 20756:d998355e6a5c

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>
author bpb
date Wed, 09 Oct 2013 17:22:34 -0700
parents e3f8b7f63dc7
children 1e9f01f43f5c
files jdk/src/share/classes/java/math/BigInteger.java
diffstat 1 files changed, 2 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- 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)