author | herrick |
Wed, 09 Feb 2011 09:19:33 -0500 | |
changeset 8197 | e45f21c2a40b |
parent 7668 | d4a77089c587 |
permissions | -rw-r--r-- |
3958 | 1 |
/* |
7668 | 2 |
* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. |
3958 | 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 |
3958 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
3958 | 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. |
|
3958 | 24 |
*/ |
25 |
||
26 |
package sun.misc; |
|
27 |
||
28 |
import java.io.File; |
|
29 |
import java.io.IOException; |
|
6882
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
5506
diff
changeset
|
30 |
import java.net.URLStreamHandlerFactory; |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
5506
diff
changeset
|
31 |
import sun.misc.URLClassPath; |
3958 | 32 |
|
33 |
/** |
|
34 |
* BootClassLoaderHook defines an interface for a hook to inject |
|
35 |
* into the bootstrap class loader. |
|
36 |
* |
|
8197 | 37 |
* With jkernel now removed, no hook is set |
3958 | 38 |
*/ |
39 |
public abstract class BootClassLoaderHook { |
|
40 |
private static BootClassLoaderHook bootLoaderHook = null; |
|
41 |
public static synchronized BootClassLoaderHook getHook() { |
|
42 |
return bootLoaderHook; |
|
43 |
} |
|
44 |
||
45 |
public static synchronized void setHook(BootClassLoaderHook hook) { |
|
46 |
if (!VM.isBooted()) { |
|
47 |
throw new InternalError("hook can only be set after VM is booted"); |
|
48 |
} |
|
49 |
if (bootLoaderHook != null) { |
|
50 |
throw new InternalError("hook should not be reinitialized"); |
|
51 |
} |
|
52 |
bootLoaderHook = hook; |
|
53 |
} |
|
54 |
||
55 |
protected BootClassLoaderHook() { |
|
56 |
} |
|
57 |
||
58 |
/** |
|
59 |
* A method to be invoked before a class loader loads |
|
60 |
* a bootstrap class. |
|
61 |
* |
|
62 |
* @param classname the binary name of the class |
|
63 |
*/ |
|
64 |
public static void preLoadClass(String classname) { |
|
65 |
BootClassLoaderHook hook = getHook(); |
|
66 |
if (hook != null) { |
|
67 |
hook.loadBootstrapClass(classname); |
|
68 |
} |
|
69 |
} |
|
70 |
||
71 |
/** |
|
72 |
* A method to be invoked before a class loader loads |
|
73 |
* a resource. |
|
74 |
* |
|
75 |
* @param resourcename the resource name |
|
76 |
*/ |
|
77 |
public static void preLoadResource(String resourcename) { |
|
78 |
BootClassLoaderHook hook = getHook(); |
|
79 |
if (hook != null) { |
|
80 |
hook.getBootstrapResource(resourcename); |
|
81 |
} |
|
82 |
} |
|
83 |
||
84 |
/** |
|
85 |
* A method to be invoked before a library is loaded. |
|
86 |
* |
|
87 |
* @param libname the name of the library |
|
88 |
*/ |
|
89 |
public static void preLoadLibrary(String libname) { |
|
90 |
BootClassLoaderHook hook = getHook(); |
|
91 |
if (hook != null) { |
|
92 |
hook.loadLibrary(libname); |
|
93 |
} |
|
94 |
} |
|
95 |
||
96 |
/** |
|
97 |
* Returns a pathname of a JAR or class that the hook loads |
|
98 |
* per this loadClass request; or null. |
|
99 |
* |
|
100 |
* @param classname the binary name of the class |
|
101 |
*/ |
|
102 |
public abstract String loadBootstrapClass(String className); |
|
103 |
||
104 |
/** |
|
105 |
* Returns a pathname of a resource file that the hook loads |
|
106 |
* per this getResource request; or null. |
|
107 |
* |
|
108 |
* @param resourceName the resource name |
|
109 |
*/ |
|
110 |
public abstract String getBootstrapResource(String resourceName); |
|
111 |
||
112 |
/** |
|
113 |
* Returns true if the hook successfully performs an operation per |
|
114 |
* this loadLibrary request; or false if it fails. |
|
115 |
* |
|
116 |
* @param libname the name of the library |
|
117 |
*/ |
|
118 |
public abstract boolean loadLibrary(String libname); |
|
119 |
||
120 |
/** |
|
6882
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
5506
diff
changeset
|
121 |
* Returns a bootstrap class path constructed by the hook. |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
5506
diff
changeset
|
122 |
* |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
5506
diff
changeset
|
123 |
* @param bcp VM's bootstrap class path |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
5506
diff
changeset
|
124 |
* @param factory Launcher's URL stream handler |
3958 | 125 |
*/ |
6882
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
5506
diff
changeset
|
126 |
public abstract URLClassPath getBootstrapClassPath(URLClassPath bcp, |
637546039be3
6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents:
5506
diff
changeset
|
127 |
URLStreamHandlerFactory factory); |
3958 | 128 |
|
129 |
/** |
|
130 |
* Returns true if the current thread is in the process of doing |
|
131 |
* a prefetching operation. |
|
132 |
*/ |
|
133 |
public abstract boolean isCurrentThreadPrefetching(); |
|
134 |
||
135 |
/** |
|
136 |
* Returns true if the hook successfully prefetches the specified file. |
|
137 |
* |
|
138 |
* @param name a platform independent pathname |
|
139 |
*/ |
|
140 |
public abstract boolean prefetchFile(String name); |
|
141 |
} |