JDK-8191850 : Performance issue with synchronized blocks in java.security.Permissions
  • Type: Enhancement
  • Component: security-libs
  • Sub-Component: java.security
  • Affected Version: 8,9,10
  • Priority: P4
  • Status: Closed
  • Resolution: Incomplete
  • Submitted: 2017-11-23
  • Updated: 2017-11-27
  • Resolved: 2017-11-27
Related Reports
Relates :  
Description
A DESCRIPTION OF THE REQUEST :
We are facing performance issue because of blocking code in java.security.Permissions.

The code that is being accessed in java.security.Permissions.implies :
public boolean implies(Permission permission) {
        // No sync; staleness -> skip optimization, which is OK
        if (allPermission != null) {
            return true; // AllPermission has already been added
        } else {
            synchronized (this) {
                PermissionCollection pc = getPermissionCollection(permission,
                    false);
                if (pc != null) {
                    return pc.implies(permission);
                } else {
                    // none found
                    return false;
                }
            }
        }
    }

You will notice that the call here is within synchronized block which requires lock on instance monitor to proceed.

In my view, we should use a read write lock here such that multiple read operations can run in parallel without blocking each other as is the case now.

JUSTIFICATION :
Since Java is used in such large number of production deployments, it is mostly assumed that it is optimized for performance. As far as I know there is continuous endeavour to improve code quality and performance of JDK. I will appreciate if this issue is accepted and concerns specified here are addressed.



Comments
The synchronized blocks were removed as part of the work for JEP 232 (Improve Secure Application Performance) in JDK 9 in JDK-8056179. Please ask the submitter to check if performance is still an issue on JDK 9.
27-11-2017