author | mchung |
Thu, 12 Mar 2009 10:27:22 -0700 | |
changeset 2277 | 445a331b4a8b |
parent 1247 | b4c26443dee5 |
child 5183 | 7825d97c4cf2 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
1247 | 2 |
* Copyright 2002-2008 Sun Microsystems, Inc. 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 |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
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 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
26 |
package sun.misc; |
|
27 |
||
28 |
import java.util.jar.JarFile; |
|
29 |
import java.io.Console; |
|
30 |
import java.io.File; |
|
31 |
import java.io.FileDescriptor; |
|
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; |
50 |
||
51 |
public static JavaUtilJarAccess javaUtilJarAccess() { |
|
52 |
if (javaUtilJarAccess == null) { |
|
53 |
// Ensure JarFile is initialized; we know that that class |
|
54 |
// provides the shared secret |
|
55 |
unsafe.ensureClassInitialized(JarFile.class); |
|
56 |
} |
|
57 |
return javaUtilJarAccess; |
|
58 |
} |
|
59 |
||
60 |
public static void setJavaUtilJarAccess(JavaUtilJarAccess access) { |
|
61 |
javaUtilJarAccess = access; |
|
62 |
} |
|
63 |
||
64 |
public static void setJavaLangAccess(JavaLangAccess jla) { |
|
65 |
javaLangAccess = jla; |
|
66 |
} |
|
67 |
||
68 |
public static JavaLangAccess getJavaLangAccess() { |
|
69 |
return javaLangAccess; |
|
70 |
} |
|
71 |
||
72 |
public static void setJavaNetAccess(JavaNetAccess jna) { |
|
73 |
javaNetAccess = jna; |
|
74 |
} |
|
75 |
||
76 |
public static JavaNetAccess getJavaNetAccess() { |
|
77 |
return javaNetAccess; |
|
78 |
} |
|
79 |
||
1143
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
80 |
public static void setJavaNioAccess(JavaNioAccess jna) { |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
81 |
javaNioAccess = jna; |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
82 |
} |
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 |
public static JavaNioAccess getJavaNioAccess() { |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
85 |
if (javaNioAccess == null) { |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
86 |
// 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
|
87 |
// 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
|
88 |
// shared secret. |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
89 |
unsafe.ensureClassInitialized(java.nio.ByteOrder.class); |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
90 |
} |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
91 |
return javaNioAccess; |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
92 |
} |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
93 |
|
2 | 94 |
public static void setJavaIOAccess(JavaIOAccess jia) { |
95 |
javaIOAccess = jia; |
|
96 |
} |
|
97 |
||
98 |
public static JavaIOAccess getJavaIOAccess() { |
|
99 |
if (javaIOAccess == null) { |
|
100 |
unsafe.ensureClassInitialized(Console.class); |
|
101 |
} |
|
102 |
return javaIOAccess; |
|
103 |
} |
|
104 |
||
105 |
public static void setJavaIOFileDescriptorAccess(JavaIOFileDescriptorAccess jiofda) { |
|
106 |
javaIOFileDescriptorAccess = jiofda; |
|
107 |
} |
|
108 |
||
109 |
public static JavaIOFileDescriptorAccess getJavaIOFileDescriptorAccess() { |
|
110 |
if (javaIOFileDescriptorAccess == null) |
|
111 |
unsafe.ensureClassInitialized(FileDescriptor.class); |
|
112 |
||
113 |
return javaIOFileDescriptorAccess; |
|
114 |
} |
|
115 |
||
116 |
} |