1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# 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;
/**
|