# HG changeset patch # User coffeys # Date 1381845864 -3600 # Tue Oct 15 15:04:24 2013 +0100 # Node ID 5d81a5f8a3791316367990b35b1ad5faef42d773 # Parent 77af6e10b333347cd882027ab1bb9a3366278096 7196533: TimeZone.getDefault() slow due to synchronization bottleneck Reviewed-by: okutsu, omajid diff -r 77af6e10b333 -r 5d81a5f8a379 src/share/classes/java/util/TimeZone.java --- jdk/src/share/classes/java/util/TimeZone.java Fri Oct 04 12:22:34 2013 -0400 +++ jdk/src/share/classes/java/util/TimeZone.java Tue Oct 15 15:04:24 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2013, Oracle and/or its affiliates. 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 @@ -646,9 +646,15 @@ * Returns the default TimeZone in an AppContext if any AppContext * has ever used. null is returned if any AppContext hasn't been * used or if the AppContext doesn't have the default TimeZone. + * + * Note that javaAWTAccess may be null if sun.awt.AppContext class hasn't + * been loaded. If so, it implies that AWTSecurityManager is not our + * SecurityManager and we can use a local static variable. + * This works around a build time issue. */ - private synchronized static TimeZone getDefaultInAppContext() { - javaAWTAccess = SharedSecrets.getJavaAWTAccess(); + private static TimeZone getDefaultInAppContext() { + // JavaAWTAccess provides access implementation-private methods without using reflection. + JavaAWTAccess javaAWTAccess = SharedSecrets.getJavaAWTAccess(); if (javaAWTAccess == null) { return mainAppContextDefault; } else { @@ -670,9 +676,15 @@ * tz. null is handled special: do nothing if any AppContext * hasn't been used, remove the default TimeZone in the * AppContext otherwise. + * + * Note that javaAWTAccess may be null if sun.awt.AppContext class hasn't + * been loaded. If so, it implies that AWTSecurityManager is not our + * SecurityManager and we can use a local static variable. + * This works around a build time issue. */ - private synchronized static void setDefaultInAppContext(TimeZone tz) { - javaAWTAccess = SharedSecrets.getJavaAWTAccess(); + private static void setDefaultInAppContext(TimeZone tz) { + // JavaAWTAccess provides access implementation-private methods without using reflection. + JavaAWTAccess javaAWTAccess = SharedSecrets.getJavaAWTAccess(); if (javaAWTAccess == null) { mainAppContextDefault = tz; } else { @@ -736,18 +748,8 @@ static final String GMT_ID = "GMT"; private static final int GMT_ID_LENGTH = 3; - /* - * Provides access implementation-private methods without using reflection - * - * Note that javaAWTAccess may be null if sun.awt.AppContext class hasn't - * been loaded. If so, it implies that AWTSecurityManager is not our - * SecurityManager and we can use a local static variable. - * This works around a build time issue. - */ - private static JavaAWTAccess javaAWTAccess; - // a static TimeZone we can reference if no AppContext is in place - private static TimeZone mainAppContextDefault; + private static volatile TimeZone mainAppContextDefault; /**