changeset 6564:5a9b87abdbee

8023563: Bottleneck in java.util.TimeZone.getDefaultInAppContext Reviewed-by: alanb, chegar
author coffeys
date Tue, 03 Sep 2013 23:47:23 +0100
parents 991aa6010ae9
children ffd0a74b30d6
files src/share/classes/java/util/TimeZone.java
diffstat 1 files changed, 13 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/TimeZone.java	Mon Sep 02 08:43:32 2013 +0200
+++ b/src/share/classes/java/util/TimeZone.java	Tue Sep 03 23:47:23 2013 +0100
@@ -728,20 +728,18 @@
     private static TimeZone getDefaultInAppContext() {
         // JavaAWTAccess provides access implementation-private methods without using reflection.
         JavaAWTAccess javaAWTAccess = SharedSecrets.getJavaAWTAccess();
-        if (javaAWTAccess == null) {
+        if (System.getSecurityManager() == null || javaAWTAccess == null) {
             return mainAppContextDefault;
+        } else if (javaAWTAccess.isDisposed()) {
+            return null;
         } else {
-            if (!javaAWTAccess.isDisposed()) {
-                TimeZone tz = (TimeZone)
-                    javaAWTAccess.get(TimeZone.class);
-                if (tz == null && javaAWTAccess.isMainAppContext()) {
-                    return mainAppContextDefault;
-                } else {
-                    return tz;
-                }
+            TimeZone tz = (TimeZone) javaAWTAccess.get(TimeZone.class);
+            if (tz == null && javaAWTAccess.isMainAppContext()) {
+                return mainAppContextDefault;
+            } else {
+                return tz;
             }
         }
-        return null;
     }
 
     /**
@@ -758,14 +756,12 @@
     private static void setDefaultInAppContext(TimeZone tz) {
         // JavaAWTAccess provides access implementation-private methods without using reflection.
         JavaAWTAccess javaAWTAccess = SharedSecrets.getJavaAWTAccess();
-        if (javaAWTAccess == null) {
+        if (System.getSecurityManager() == null || javaAWTAccess == null) {
             mainAppContextDefault = tz;
-        } else {
-            if (!javaAWTAccess.isDisposed()) {
-                javaAWTAccess.put(TimeZone.class, tz);
-                if (javaAWTAccess.isMainAppContext()) {
-                    mainAppContextDefault = null;
-                }
+        } else if (!javaAWTAccess.isDisposed()) {
+            javaAWTAccess.put(TimeZone.class, tz);
+            if (javaAWTAccess.isMainAppContext()) {
+                mainAppContextDefault = null;
             }
         }
     }