# HG changeset patch # User mullan # Date 1244650335 25200 # Node ID 0418028311a29928d07bcd60537e6062cb064450 # Parent 37d9baeb7518882a5d5db81b2d86115ffc5bebd2 6845161: Bottleneck in Configuration.getConfiguration synchronized call Summary: Reduce scope of synchronized block Reviewed-by: weijun diff -r 37d9baeb7518 -r 0418028311a2 jdk/src/share/classes/javax/security/auth/login/Configuration.java --- 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() { - 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() { - 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() { + 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() { + 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; } /**