Skip to content

Commit

Permalink
8293197: Avoid double racy reads from non-volatile fields in SharedSe…
Browse files Browse the repository at this point in the history
…crets

Reviewed-by: alanb
  • Loading branch information
Andrey Turbanov committed Sep 7, 2022
1 parent 205f992 commit 2259e42
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/java.base/share/classes/jdk/internal/access/SharedSecrets.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,27 @@ public static void setJavaUtilConcurrentTLRAccess(JavaUtilConcurrentTLRAccess ac
}

public static JavaUtilConcurrentTLRAccess getJavaUtilConcurrentTLRAccess() {
if (javaUtilConcurrentTLRAccess == null) {
var access = javaUtilConcurrentTLRAccess;
if (access == null) {
try {
Class.forName("java.util.concurrent.ThreadLocalRandom$Access", true, null);
access = javaUtilConcurrentTLRAccess;
} catch (ClassNotFoundException e) {}
}
return javaUtilConcurrentTLRAccess;
return access;
}

public static void setJavaUtilConcurrentFJPAccess(JavaUtilConcurrentFJPAccess access) {
javaUtilConcurrentFJPAccess = access;
}

public static JavaUtilConcurrentFJPAccess getJavaUtilConcurrentFJPAccess() {
if (javaUtilConcurrentFJPAccess == null) {
var access = javaUtilConcurrentFJPAccess;
if (access == null) {
ensureClassInitialized(ForkJoinPool.class);
access = javaUtilConcurrentFJPAccess;
}
return javaUtilConcurrentFJPAccess;
return access;
}

public static JavaUtilJarAccess javaUtilJarAccess() {
Expand Down Expand Up @@ -463,21 +467,25 @@ public static void setJavaSecuritySpecAccess(JavaSecuritySpecAccess jssa) {
}

public static JavaSecuritySpecAccess getJavaSecuritySpecAccess() {
if (javaSecuritySpecAccess == null) {
var access = javaSecuritySpecAccess;
if (access == null) {
ensureClassInitialized(EncodedKeySpec.class);
access = javaSecuritySpecAccess;
}
return javaSecuritySpecAccess;
return access;
}

public static void setJavaxCryptoSpecAccess(JavaxCryptoSpecAccess jcsa) {
javaxCryptoSpecAccess = jcsa;
}

public static JavaxCryptoSpecAccess getJavaxCryptoSpecAccess() {
if (javaxCryptoSpecAccess == null) {
var access = javaxCryptoSpecAccess;
if (access == null) {
ensureClassInitialized(SecretKeySpec.class);
access = javaxCryptoSpecAccess;
}
return javaxCryptoSpecAccess;
return access;
}

public static void setJavaxCryptoSealedObjectAccess(JavaxCryptoSealedObjectAccess jcsoa) {
Expand Down

1 comment on commit 2259e42

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.