Skip to content

Commit

Permalink
Use a static synchronized method for allPermissionsPD
Browse files Browse the repository at this point in the history
Since allPermissionsPD is a static field, a static synchronized
method locks on Class.class, which is the correct approach for
ensuring thread safety.

Fixes: eclipse-openj9#20351

Signed-off-by: Babneet Singh <[email protected]>
  • Loading branch information
babsingh committed Feb 6, 2025
1 parent 516d0f5 commit bc98382
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions jcl/src/java.base/share/classes/java/lang/Class.java
Original file line number Diff line number Diff line change
Expand Up @@ -2491,17 +2491,15 @@ ProtectionDomain getProtectionDomainInternal() {
return allPermissionsPD;
}

private void allocateAllPermissionsPD() {
/* Synchronization to ensure safe initialization and safe publication of
* allPermissionsPD. This addresses the locking contention on allPermissionsPD
* in getProtectionDomain().
*/
synchronized(this) {
if (allPermissionsPD == null) {
Permissions collection = new Permissions();
collection.add(SecurityConstants.ALL_PERMISSION);
allPermissionsPD = new ProtectionDomain(null, collection);
}
/* Synchronization is added to ensure safe initialization and safe
* publication of allPermissionsPD. This addresses the locking contention
* on allPermissionsPD in getProtectionDomain().
*/
private static synchronized void allocateAllPermissionsPD() {
if (allPermissionsPD == null) {
Permissions collection = new Permissions();
collection.add(SecurityConstants.ALL_PERMISSION);
allPermissionsPD = new ProtectionDomain(null, collection);
}
}

Expand Down

0 comments on commit bc98382

Please sign in to comment.