提交 f2270291 编写于 作者: B bpb

7189139: BigInteger's staticRandom field can be a source of bottlenecks.

Summary: Use ThreadLocalRandom instead of SecureRandom.
Reviewed-by: shade, psandoz
Contributed-by: NBrian Burkhalter <brian.burkhalter@oracle.com>
上级 2fdb14de
...@@ -35,6 +35,7 @@ import java.io.ObjectOutputStream; ...@@ -35,6 +35,7 @@ import java.io.ObjectOutputStream;
import java.io.ObjectStreamField; import java.io.ObjectStreamField;
import java.util.Arrays; import java.util.Arrays;
import java.util.Random; import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import sun.misc.DoubleConsts; import sun.misc.DoubleConsts;
import sun.misc.FloatConsts; import sun.misc.FloatConsts;
...@@ -918,15 +919,6 @@ public class BigInteger extends Number implements Comparable<BigInteger> { ...@@ -918,15 +919,6 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
return u; 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 * Returns true iff this BigInteger passes the specified number of
* Miller-Rabin tests. This test is taken from the DSA spec (NIST FIPS * Miller-Rabin tests. This test is taken from the DSA spec (NIST FIPS
...@@ -945,7 +937,7 @@ public class BigInteger extends Number implements Comparable<BigInteger> { ...@@ -945,7 +937,7 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
// Do the tests // Do the tests
if (rnd == null) { if (rnd == null) {
rnd = getSecureRandom(); rnd = ThreadLocalRandom.current();
} }
for (int i=0; i < iterations; i++) { for (int i=0; i < iterations; i++) {
// Generate a uniform random on (1, this) // Generate a uniform random on (1, this)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册