changeset 2943:0418028311a2

6845161: Bottleneck in Configuration.getConfiguration synchronized call Summary: Reduce scope of synchronized block Reviewed-by: weijun
author mullan
date Wed, 10 Jun 2009 09:12:15 -0700
parents 37d9baeb7518
children 276b6d106714
files jdk/src/share/classes/javax/security/auth/login/Configuration.java
diffstat 1 files changed, 43 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/src/share/classes/javax/security/auth/login/Configuration.java	Tue Jun 09 14:17:05 2009 +0800
+++ b/jdk/src/share/classes/javax/security/auth/login/Configuration.java	Wed Jun 10 09:12:15 2009 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright 1998-2006 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 1998-2009 Sun Microsystems, Inc.  All Rights Reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -234,56 +234,58 @@
      *
      * @see #setConfiguration
      */
-    public static synchronized Configuration getConfiguration() {
+    public static Configuration getConfiguration() {
 
         SecurityManager sm = System.getSecurityManager();
         if (sm != null)
             sm.checkPermission(new AuthPermission("getLoginConfiguration"));
 
-        if (configuration == null) {
-            String config_class = null;
-            config_class = AccessController.doPrivileged
-                (new PrivilegedAction<String>() {
-                public String run() {
-                    return java.security.Security.getProperty
-                                ("login.configuration.provider");
-                }
-            });
-            if (config_class == null) {
-                config_class = "com.sun.security.auth.login.ConfigFile";
-            }
-
-            try {
-                final String finalClass = config_class;
-                configuration = AccessController.doPrivileged
-                    (new PrivilegedExceptionAction<Configuration>() {
-                    public Configuration run() throws ClassNotFoundException,
-                                        InstantiationException,
-                                        IllegalAccessException {
-                        return (Configuration)Class.forName
-                                (finalClass,
-                                true,
-                                contextClassLoader).newInstance();
+        synchronized (Configuration.class) {
+            if (configuration == null) {
+                String config_class = null;
+                config_class = AccessController.doPrivileged
+                    (new PrivilegedAction<String>() {
+                    public String run() {
+                        return java.security.Security.getProperty
+                                    ("login.configuration.provider");
                     }
                 });
-            } catch (PrivilegedActionException e) {
-                Exception ee = e.getException();
-                if (ee instanceof InstantiationException) {
-                    throw (SecurityException) new
-                        SecurityException
-                                ("Configuration error:" +
-                                 ee.getCause().getMessage() +
-                                 "\n").initCause(ee.getCause());
-                } else {
-                    throw (SecurityException) new
-                        SecurityException
-                                ("Configuration error: " +
-                                 ee.toString() +
-                                 "\n").initCause(ee);
+                if (config_class == null) {
+                    config_class = "com.sun.security.auth.login.ConfigFile";
+                }
+
+                try {
+                    final String finalClass = config_class;
+                    configuration = AccessController.doPrivileged
+                        (new PrivilegedExceptionAction<Configuration>() {
+                        public Configuration run() throws ClassNotFoundException,
+                                            InstantiationException,
+                                            IllegalAccessException {
+                            return (Configuration)Class.forName
+                                    (finalClass,
+                                    true,
+                                    contextClassLoader).newInstance();
+                        }
+                    });
+                } catch (PrivilegedActionException e) {
+                    Exception ee = e.getException();
+                    if (ee instanceof InstantiationException) {
+                        throw (SecurityException) new
+                            SecurityException
+                                    ("Configuration error:" +
+                                     ee.getCause().getMessage() +
+                                     "\n").initCause(ee.getCause());
+                    } else {
+                        throw (SecurityException) new
+                            SecurityException
+                                    ("Configuration error: " +
+                                     ee.toString() +
+                                     "\n").initCause(ee);
+                    }
                 }
             }
+            return configuration;
         }
-        return configuration;
     }
 
     /**