Skip to content

Commit

Permalink
Backport GR-27649
Browse files Browse the repository at this point in the history
  • Loading branch information
vjovanov committed Dec 24, 2020
1 parent e97ad62 commit 19298b7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 48 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static AtomicLong getSeeder() {
return SINGLETON.getOrInitializeSeeder();
}

/** The setter is necessary if ThreadLocalRandom is initilized at run time. */
/** The setter is necessary if ThreadLocalRandom is initialized at run time. */
public static void setSeeder(AtomicLong value) {
SINGLETON.seeder = value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,14 @@ public void afterRegistration(AfterRegistrationAccess access) {
RuntimeClassInitialization.initializeAtBuildTime("sun.security.x509", "Core JDK classes are initialized at build time");
RuntimeClassInitialization.initializeAtBuildTime("sun.security.smartcardio", "Core JDK classes are initialized at build time");

// contains a SecureRandom reference, therefore it can't be included in the image heap
// contain Random references, therefore can't be included in the image heap
RuntimeClassInitialization.initializeAtRunTime(com.sun.jndi.dns.DnsClient.class);
RuntimeClassInitialization.initializeAtRunTime("sun.net.www.protocol.http.DigestAuthentication$Parameters");
RuntimeClassInitialization.initializeAtRunTime("sun.security.krb5.KrbServiceLocator");

// The random number provider classes should be reinitialized at runtime to reset their
// values properly. Otherwise the numbers generated will be fixed for each generated image.
RuntimeClassInitialization.initializeAtRunTime("java.lang.Math$RandomNumberGeneratorHolder");
RuntimeClassInitialization.initializeAtRunTime("java.lang.StrictMath$RandomNumberGeneratorHolder");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1756,7 +1756,7 @@ private void checkFileOperationPreconditions() throws IOException {
}

private static TruffleFile createUniquePath(TruffleFile targetDirectory, String prefix, String suffix) {
long n = TempFileRandomHolder.RANDOM.nextLong();
long n = TempFileRandomHolder.getRandom().nextLong();
n = n == Long.MIN_VALUE ? Long.MAX_VALUE : Math.abs(n);
String name = prefix + Long.toString(n) + suffix;
TruffleFile result = targetDirectory.resolve(name);
Expand Down Expand Up @@ -1784,7 +1784,16 @@ private static boolean isEmptyPath(Path path) {
}

private static final class TempFileRandomHolder {
static final Random RANDOM = new Random();
private static Random RANDOM;

static Random getRandom() {
if (RANDOM == null) {
/* We don't want RANDOM seeds in the image heap. */
RANDOM = new Random();
}
return RANDOM;
}

}

private static final class AttributeGroup {
Expand Down

0 comments on commit 19298b7

Please sign in to comment.