author | weijun |
Mon, 28 Feb 2011 23:02:37 +0800 | |
changeset 8556 | d3d6e4643560 |
parent 5506 | 202f599c92aa |
child 8816 | 29f983feda95 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
8556 | 2 |
* Copyright (c) 2002, 2011, 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 |
|
33 |
/** A repository of "shared secrets", which are a mechanism for |
|
34 |
calling implementation-private methods in another package without |
|
35 |
using reflection. A package-private class implements a public |
|
36 |
interface and provides the ability to call package-private methods |
|
37 |
within that package; the object implementing that interface is |
|
38 |
provided through a third package to which access is restricted. |
|
39 |
This framework avoids the primary disadvantage of using reflection |
|
40 |
for this purpose, namely the loss of compile-time checking. */ |
|
41 |
||
42 |
public class SharedSecrets { |
|
43 |
private static final Unsafe unsafe = Unsafe.getUnsafe(); |
|
44 |
private static JavaUtilJarAccess javaUtilJarAccess; |
|
45 |
private static JavaLangAccess javaLangAccess; |
|
46 |
private static JavaIOAccess javaIOAccess; |
|
47 |
private static JavaNetAccess javaNetAccess; |
|
1143
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
48 |
private static JavaNioAccess javaNioAccess; |
2 | 49 |
private static JavaIOFileDescriptorAccess javaIOFileDescriptorAccess; |
5183
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2277
diff
changeset
|
50 |
private static JavaSecurityProtectionDomainAccess javaSecurityProtectionDomainAccess; |
2 | 51 |
|
52 |
public static JavaUtilJarAccess javaUtilJarAccess() { |
|
53 |
if (javaUtilJarAccess == null) { |
|
54 |
// Ensure JarFile is initialized; we know that that class |
|
55 |
// provides the shared secret |
|
56 |
unsafe.ensureClassInitialized(JarFile.class); |
|
57 |
} |
|
58 |
return javaUtilJarAccess; |
|
59 |
} |
|
60 |
||
61 |
public static void setJavaUtilJarAccess(JavaUtilJarAccess access) { |
|
62 |
javaUtilJarAccess = access; |
|
63 |
} |
|
64 |
||
65 |
public static void setJavaLangAccess(JavaLangAccess jla) { |
|
66 |
javaLangAccess = jla; |
|
67 |
} |
|
68 |
||
69 |
public static JavaLangAccess getJavaLangAccess() { |
|
70 |
return javaLangAccess; |
|
71 |
} |
|
72 |
||
73 |
public static void setJavaNetAccess(JavaNetAccess jna) { |
|
74 |
javaNetAccess = jna; |
|
75 |
} |
|
76 |
||
77 |
public static JavaNetAccess getJavaNetAccess() { |
|
78 |
return javaNetAccess; |
|
79 |
} |
|
80 |
||
1143
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
81 |
public static void setJavaNioAccess(JavaNioAccess jna) { |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
82 |
javaNioAccess = jna; |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
83 |
} |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
84 |
|
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
85 |
public static JavaNioAccess getJavaNioAccess() { |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
86 |
if (javaNioAccess == null) { |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
87 |
// 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
|
88 |
// 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
|
89 |
// shared secret. |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
90 |
unsafe.ensureClassInitialized(java.nio.ByteOrder.class); |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
91 |
} |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
92 |
return javaNioAccess; |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
93 |
} |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
94 |
|
2 | 95 |
public static void setJavaIOAccess(JavaIOAccess jia) { |
96 |
javaIOAccess = jia; |
|
97 |
} |
|
98 |
||
99 |
public static JavaIOAccess getJavaIOAccess() { |
|
100 |
if (javaIOAccess == null) { |
|
101 |
unsafe.ensureClassInitialized(Console.class); |
|
102 |
} |
|
103 |
return javaIOAccess; |
|
104 |
} |
|
105 |
||
106 |
public static void setJavaIOFileDescriptorAccess(JavaIOFileDescriptorAccess jiofda) { |
|
107 |
javaIOFileDescriptorAccess = jiofda; |
|
108 |
} |
|
109 |
||
110 |
public static JavaIOFileDescriptorAccess getJavaIOFileDescriptorAccess() { |
|
111 |
if (javaIOFileDescriptorAccess == null) |
|
112 |
unsafe.ensureClassInitialized(FileDescriptor.class); |
|
113 |
||
114 |
return javaIOFileDescriptorAccess; |
|
115 |
} |
|
116 |
||
5183
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2277
diff
changeset
|
117 |
public static void setJavaSecurityProtectionDomainAccess |
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2277
diff
changeset
|
118 |
(JavaSecurityProtectionDomainAccess jspda) { |
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2277
diff
changeset
|
119 |
javaSecurityProtectionDomainAccess = jspda; |
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2277
diff
changeset
|
120 |
} |
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2277
diff
changeset
|
121 |
|
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2277
diff
changeset
|
122 |
public static JavaSecurityProtectionDomainAccess |
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2277
diff
changeset
|
123 |
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
|
124 |
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
|
125 |
unsafe.ensureClassInitialized(ProtectionDomain.class); |
5183
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2277
diff
changeset
|
126 |
return javaSecurityProtectionDomainAccess; |
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2277
diff
changeset
|
127 |
} |
2 | 128 |
} |