author | alanb |
Wed, 26 Mar 2014 12:25:09 +0000 | |
changeset 23581 | 0ca496340112 |
parent 23009 | e2c92ddeb57f |
child 25385 | 2c53e38b77aa |
permissions | -rw-r--r-- |
2 | 1 |
/* |
18265
7d1bf89ba22c
8013196: TimeZone.getDefault() throws NPE due to sun.awt.AppContext.getAppContext()
coffeys
parents:
18223
diff
changeset
|
2 |
* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.misc; |
|
27 |
||
28 |
import java.util.jar.JarFile; |
|
29 |
import java.io.Console; |
|
30 |
import java.io.FileDescriptor; |
|
5288
e91651d24b2a
6909281: 6u19 b99(pit):Error loading first applet in browser session( both FF && IE, windows ): NPE is thrown
mullan
parents:
5183
diff
changeset
|
31 |
import java.security.ProtectionDomain; |
2 | 32 |
|
8816
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
8556
diff
changeset
|
33 |
import java.security.AccessController; |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
8556
diff
changeset
|
34 |
|
2 | 35 |
/** A repository of "shared secrets", which are a mechanism for |
36 |
calling implementation-private methods in another package without |
|
37 |
using reflection. A package-private class implements a public |
|
38 |
interface and provides the ability to call package-private methods |
|
39 |
within that package; the object implementing that interface is |
|
40 |
provided through a third package to which access is restricted. |
|
41 |
This framework avoids the primary disadvantage of using reflection |
|
42 |
for this purpose, namely the loss of compile-time checking. */ |
|
43 |
||
44 |
public class SharedSecrets { |
|
45 |
private static final Unsafe unsafe = Unsafe.getUnsafe(); |
|
46 |
private static JavaUtilJarAccess javaUtilJarAccess; |
|
47 |
private static JavaLangAccess javaLangAccess; |
|
23009
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
19809
diff
changeset
|
48 |
private static JavaLangRefAccess javaLangRefAccess; |
2 | 49 |
private static JavaIOAccess javaIOAccess; |
50 |
private static JavaNetAccess javaNetAccess; |
|
11284
2750cfd2352c
7095980: Ensure HttpURLConnection (and supporting APIs) don't expose HttpOnly cookies
chegar
parents:
10044
diff
changeset
|
51 |
private static JavaNetHttpCookieAccess javaNetHttpCookieAccess; |
1143
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
52 |
private static JavaNioAccess javaNioAccess; |
2 | 53 |
private static JavaIOFileDescriptorAccess javaIOFileDescriptorAccess; |
5183
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2277
diff
changeset
|
54 |
private static JavaSecurityProtectionDomainAccess javaSecurityProtectionDomainAccess; |
8816
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
8556
diff
changeset
|
55 |
private static JavaSecurityAccess javaSecurityAccess; |
18223
35a5c2462991
8008593: Better URLClassLoader resource management
chegar
parents:
11902
diff
changeset
|
56 |
private static JavaUtilZipFileAccess javaUtilZipFileAccess; |
11896 | 57 |
private static JavaAWTAccess javaAWTAccess; |
23581
0ca496340112
8038343: Eliminate use of reflection to access JavaBeans Introspector
alanb
parents:
23009
diff
changeset
|
58 |
private static JavaBeansIntrospectorAccess javaBeansIntrospectorAccess; |
2 | 59 |
|
60 |
public static JavaUtilJarAccess javaUtilJarAccess() { |
|
61 |
if (javaUtilJarAccess == null) { |
|
62 |
// Ensure JarFile is initialized; we know that that class |
|
63 |
// provides the shared secret |
|
64 |
unsafe.ensureClassInitialized(JarFile.class); |
|
65 |
} |
|
66 |
return javaUtilJarAccess; |
|
67 |
} |
|
68 |
||
69 |
public static void setJavaUtilJarAccess(JavaUtilJarAccess access) { |
|
70 |
javaUtilJarAccess = access; |
|
71 |
} |
|
72 |
||
73 |
public static void setJavaLangAccess(JavaLangAccess jla) { |
|
74 |
javaLangAccess = jla; |
|
75 |
} |
|
76 |
||
77 |
public static JavaLangAccess getJavaLangAccess() { |
|
78 |
return javaLangAccess; |
|
79 |
} |
|
80 |
||
23009
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
19809
diff
changeset
|
81 |
public static void setJavaLangRefAccess(JavaLangRefAccess jlra) { |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
19809
diff
changeset
|
82 |
javaLangRefAccess = jlra; |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
19809
diff
changeset
|
83 |
} |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
19809
diff
changeset
|
84 |
|
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
19809
diff
changeset
|
85 |
public static JavaLangRefAccess getJavaLangRefAccess() { |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
19809
diff
changeset
|
86 |
return javaLangRefAccess; |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
19809
diff
changeset
|
87 |
} |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
19809
diff
changeset
|
88 |
|
2 | 89 |
public static void setJavaNetAccess(JavaNetAccess jna) { |
90 |
javaNetAccess = jna; |
|
91 |
} |
|
92 |
||
93 |
public static JavaNetAccess getJavaNetAccess() { |
|
94 |
return javaNetAccess; |
|
95 |
} |
|
96 |
||
11284
2750cfd2352c
7095980: Ensure HttpURLConnection (and supporting APIs) don't expose HttpOnly cookies
chegar
parents:
10044
diff
changeset
|
97 |
public static void setJavaNetHttpCookieAccess(JavaNetHttpCookieAccess a) { |
2750cfd2352c
7095980: Ensure HttpURLConnection (and supporting APIs) don't expose HttpOnly cookies
chegar
parents:
10044
diff
changeset
|
98 |
javaNetHttpCookieAccess = a; |
2750cfd2352c
7095980: Ensure HttpURLConnection (and supporting APIs) don't expose HttpOnly cookies
chegar
parents:
10044
diff
changeset
|
99 |
} |
2750cfd2352c
7095980: Ensure HttpURLConnection (and supporting APIs) don't expose HttpOnly cookies
chegar
parents:
10044
diff
changeset
|
100 |
|
2750cfd2352c
7095980: Ensure HttpURLConnection (and supporting APIs) don't expose HttpOnly cookies
chegar
parents:
10044
diff
changeset
|
101 |
public static JavaNetHttpCookieAccess getJavaNetHttpCookieAccess() { |
2750cfd2352c
7095980: Ensure HttpURLConnection (and supporting APIs) don't expose HttpOnly cookies
chegar
parents:
10044
diff
changeset
|
102 |
if (javaNetHttpCookieAccess == null) |
2750cfd2352c
7095980: Ensure HttpURLConnection (and supporting APIs) don't expose HttpOnly cookies
chegar
parents:
10044
diff
changeset
|
103 |
unsafe.ensureClassInitialized(java.net.HttpCookie.class); |
2750cfd2352c
7095980: Ensure HttpURLConnection (and supporting APIs) don't expose HttpOnly cookies
chegar
parents:
10044
diff
changeset
|
104 |
return javaNetHttpCookieAccess; |
2750cfd2352c
7095980: Ensure HttpURLConnection (and supporting APIs) don't expose HttpOnly cookies
chegar
parents:
10044
diff
changeset
|
105 |
} |
2750cfd2352c
7095980: Ensure HttpURLConnection (and supporting APIs) don't expose HttpOnly cookies
chegar
parents:
10044
diff
changeset
|
106 |
|
1143
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
107 |
public static void setJavaNioAccess(JavaNioAccess jna) { |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
108 |
javaNioAccess = jna; |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
109 |
} |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
110 |
|
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
111 |
public static JavaNioAccess getJavaNioAccess() { |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
112 |
if (javaNioAccess == null) { |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
113 |
// Ensure java.nio.ByteOrder is initialized; we know that |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
114 |
// this class initializes java.nio.Bits that provides the |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
115 |
// shared secret. |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
116 |
unsafe.ensureClassInitialized(java.nio.ByteOrder.class); |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
117 |
} |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
118 |
return javaNioAccess; |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
119 |
} |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
120 |
|
2 | 121 |
public static void setJavaIOAccess(JavaIOAccess jia) { |
122 |
javaIOAccess = jia; |
|
123 |
} |
|
124 |
||
125 |
public static JavaIOAccess getJavaIOAccess() { |
|
126 |
if (javaIOAccess == null) { |
|
127 |
unsafe.ensureClassInitialized(Console.class); |
|
128 |
} |
|
129 |
return javaIOAccess; |
|
130 |
} |
|
131 |
||
132 |
public static void setJavaIOFileDescriptorAccess(JavaIOFileDescriptorAccess jiofda) { |
|
133 |
javaIOFileDescriptorAccess = jiofda; |
|
134 |
} |
|
135 |
||
136 |
public static JavaIOFileDescriptorAccess getJavaIOFileDescriptorAccess() { |
|
137 |
if (javaIOFileDescriptorAccess == null) |
|
138 |
unsafe.ensureClassInitialized(FileDescriptor.class); |
|
139 |
||
140 |
return javaIOFileDescriptorAccess; |
|
141 |
} |
|
142 |
||
5183
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2277
diff
changeset
|
143 |
public static void setJavaSecurityProtectionDomainAccess |
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2277
diff
changeset
|
144 |
(JavaSecurityProtectionDomainAccess jspda) { |
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2277
diff
changeset
|
145 |
javaSecurityProtectionDomainAccess = jspda; |
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2277
diff
changeset
|
146 |
} |
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2277
diff
changeset
|
147 |
|
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2277
diff
changeset
|
148 |
public static JavaSecurityProtectionDomainAccess |
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2277
diff
changeset
|
149 |
getJavaSecurityProtectionDomainAccess() { |
5288
e91651d24b2a
6909281: 6u19 b99(pit):Error loading first applet in browser session( both FF && IE, windows ): NPE is thrown
mullan
parents:
5183
diff
changeset
|
150 |
if (javaSecurityProtectionDomainAccess == null) |
e91651d24b2a
6909281: 6u19 b99(pit):Error loading first applet in browser session( both FF && IE, windows ): NPE is thrown
mullan
parents:
5183
diff
changeset
|
151 |
unsafe.ensureClassInitialized(ProtectionDomain.class); |
5183
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2277
diff
changeset
|
152 |
return javaSecurityProtectionDomainAccess; |
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2277
diff
changeset
|
153 |
} |
8816
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
8556
diff
changeset
|
154 |
|
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
8556
diff
changeset
|
155 |
public static void setJavaSecurityAccess(JavaSecurityAccess jsa) { |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
8556
diff
changeset
|
156 |
javaSecurityAccess = jsa; |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
8556
diff
changeset
|
157 |
} |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
8556
diff
changeset
|
158 |
|
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
8556
diff
changeset
|
159 |
public static JavaSecurityAccess getJavaSecurityAccess() { |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
8556
diff
changeset
|
160 |
if (javaSecurityAccess == null) { |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
8556
diff
changeset
|
161 |
unsafe.ensureClassInitialized(AccessController.class); |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
8556
diff
changeset
|
162 |
} |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
8556
diff
changeset
|
163 |
return javaSecurityAccess; |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
8556
diff
changeset
|
164 |
} |
11896 | 165 |
|
18223
35a5c2462991
8008593: Better URLClassLoader resource management
chegar
parents:
11902
diff
changeset
|
166 |
public static JavaUtilZipFileAccess getJavaUtilZipFileAccess() { |
35a5c2462991
8008593: Better URLClassLoader resource management
chegar
parents:
11902
diff
changeset
|
167 |
if (javaUtilZipFileAccess == null) |
35a5c2462991
8008593: Better URLClassLoader resource management
chegar
parents:
11902
diff
changeset
|
168 |
unsafe.ensureClassInitialized(java.util.zip.ZipFile.class); |
35a5c2462991
8008593: Better URLClassLoader resource management
chegar
parents:
11902
diff
changeset
|
169 |
return javaUtilZipFileAccess; |
35a5c2462991
8008593: Better URLClassLoader resource management
chegar
parents:
11902
diff
changeset
|
170 |
} |
35a5c2462991
8008593: Better URLClassLoader resource management
chegar
parents:
11902
diff
changeset
|
171 |
|
35a5c2462991
8008593: Better URLClassLoader resource management
chegar
parents:
11902
diff
changeset
|
172 |
public static void setJavaUtilZipFileAccess(JavaUtilZipFileAccess access) { |
35a5c2462991
8008593: Better URLClassLoader resource management
chegar
parents:
11902
diff
changeset
|
173 |
javaUtilZipFileAccess = access; |
35a5c2462991
8008593: Better URLClassLoader resource management
chegar
parents:
11902
diff
changeset
|
174 |
} |
35a5c2462991
8008593: Better URLClassLoader resource management
chegar
parents:
11902
diff
changeset
|
175 |
|
11896 | 176 |
public static void setJavaAWTAccess(JavaAWTAccess jaa) { |
177 |
javaAWTAccess = jaa; |
|
178 |
} |
|
179 |
||
180 |
public static JavaAWTAccess getJavaAWTAccess() { |
|
181 |
// this may return null in which case calling code needs to |
|
182 |
// provision for. |
|
19809
dc0480c1b36c
8019853: Break logging and AWT circular dependency
dfuchs
parents:
18265
diff
changeset
|
183 |
if (javaAWTAccess == null) { |
18265
7d1bf89ba22c
8013196: TimeZone.getDefault() throws NPE due to sun.awt.AppContext.getAppContext()
coffeys
parents:
18223
diff
changeset
|
184 |
return null; |
7d1bf89ba22c
8013196: TimeZone.getDefault() throws NPE due to sun.awt.AppContext.getAppContext()
coffeys
parents:
18223
diff
changeset
|
185 |
} |
11896 | 186 |
return javaAWTAccess; |
187 |
} |
|
23581
0ca496340112
8038343: Eliminate use of reflection to access JavaBeans Introspector
alanb
parents:
23009
diff
changeset
|
188 |
|
0ca496340112
8038343: Eliminate use of reflection to access JavaBeans Introspector
alanb
parents:
23009
diff
changeset
|
189 |
public static JavaBeansIntrospectorAccess getJavaBeansIntrospectorAccess() { |
0ca496340112
8038343: Eliminate use of reflection to access JavaBeans Introspector
alanb
parents:
23009
diff
changeset
|
190 |
return javaBeansIntrospectorAccess; |
0ca496340112
8038343: Eliminate use of reflection to access JavaBeans Introspector
alanb
parents:
23009
diff
changeset
|
191 |
} |
0ca496340112
8038343: Eliminate use of reflection to access JavaBeans Introspector
alanb
parents:
23009
diff
changeset
|
192 |
|
0ca496340112
8038343: Eliminate use of reflection to access JavaBeans Introspector
alanb
parents:
23009
diff
changeset
|
193 |
public static void setJavaBeansIntrospectorAccess(JavaBeansIntrospectorAccess access) { |
0ca496340112
8038343: Eliminate use of reflection to access JavaBeans Introspector
alanb
parents:
23009
diff
changeset
|
194 |
javaBeansIntrospectorAccess = access; |
0ca496340112
8038343: Eliminate use of reflection to access JavaBeans Introspector
alanb
parents:
23009
diff
changeset
|
195 |
} |
2 | 196 |
} |