Lines 52-58
Link Here
|
52 |
|
52 |
|
53 |
private final ModuleInstaller installer; |
53 |
private final ModuleInstaller installer; |
54 |
|
54 |
|
55 |
private SystemClassLoader classLoader = null; |
55 |
private SystemClassLoader classLoader = new SystemClassLoader(new ClassLoader[0]); |
|
|
56 |
private final Object classLoaderLock = "ModuleManager.classLoaderLock"; // NOI18N |
56 |
|
57 |
|
57 |
private final Events ev; |
58 |
private final Events ev; |
58 |
|
59 |
|
Lines 198-238
Link Here
|
198 |
/** Get a classloader capable of loading from any |
199 |
/** Get a classloader capable of loading from any |
199 |
* of the enabled modules or their declared extensions. |
200 |
* of the enabled modules or their declared extensions. |
200 |
* Should be used as the result of TopManager.systemClassLoader. |
201 |
* Should be used as the result of TopManager.systemClassLoader. |
201 |
* <strong>Note:</strong> must be called from within write, not |
202 |
* Thread-safe. |
202 |
* just read, access. |
|
|
203 |
* @see #PROP_CLASS_LOADER |
203 |
* @see #PROP_CLASS_LOADER |
204 |
*/ |
204 |
*/ |
205 |
public ClassLoader getClassLoader() { |
205 |
public ClassLoader getClassLoader() { |
206 |
if (classLoader == null) { |
206 |
// #16265: should not require mutex to get at. Many pieces of the IDE |
207 |
// Set, not List, because if we have >1 bootstrap module (using Plain), |
207 |
// require the correct result immediately. |
208 |
// it is likely that some of these classloaders will overlap. |
208 |
synchronized (classLoaderLock) { |
209 |
Set parents = new HashSet(modules.size() * 4 / 3 + 1); // Set<ClassLoader> |
209 |
return classLoader; |
210 |
Iterator it = modules.iterator(); |
|
|
211 |
while (it.hasNext()) { |
212 |
Module m = ((Module)it.next()); |
213 |
if (! m.isEnabled()) { |
214 |
continue; |
215 |
} |
216 |
parents.add(m.getClassLoader()); |
217 |
} |
218 |
ClassLoader[] parentCLs = (ClassLoader[])parents.toArray(new ClassLoader[parents.size()]); |
219 |
try { |
220 |
classLoader = new SystemClassLoader(parentCLs); |
221 |
} catch (IllegalArgumentException iae) { |
222 |
Util.err.notify(iae); |
223 |
classLoader = new SystemClassLoader(new ClassLoader[0]); |
224 |
} |
225 |
} |
210 |
} |
226 |
return classLoader; |
|
|
227 |
} |
211 |
} |
228 |
|
212 |
|
229 |
/** Mark the current class loader as invalid. */ |
213 |
/** Mark the current class loader as invalid and make a new one. */ |
230 |
private void invalidateClassLoader() { |
214 |
private void invalidateClassLoader() { |
231 |
if (classLoader != null) { |
215 |
synchronized (classLoaderLock) { |
232 |
classLoader.destroy(); // probably has no effect, but just in case... |
216 |
classLoader.destroy(); // probably has no effect, but just in case... |
233 |
classLoader = null; |
|
|
234 |
firer.change(new ChangeFirer.Change(this, PROP_CLASS_LOADER, null, null)); |
235 |
} |
217 |
} |
|
|
218 |
// Set, not List, because if we have >1 bootstrap module (using Plain), |
219 |
// it is likely that some of these classloaders will overlap. |
220 |
Set parents = new HashSet(modules.size() * 4 / 3 + 1); // Set<ClassLoader> |
221 |
Iterator it = modules.iterator(); |
222 |
while (it.hasNext()) { |
223 |
Module m = ((Module)it.next()); |
224 |
if (! m.isEnabled()) { |
225 |
continue; |
226 |
} |
227 |
parents.add(m.getClassLoader()); |
228 |
} |
229 |
ClassLoader[] parentCLs = (ClassLoader[])parents.toArray(new ClassLoader[parents.size()]); |
230 |
SystemClassLoader nue; |
231 |
try { |
232 |
nue = new SystemClassLoader(parentCLs); |
233 |
} catch (IllegalArgumentException iae) { |
234 |
Util.err.notify(iae); |
235 |
nue = new SystemClassLoader(new ClassLoader[0]); |
236 |
} |
237 |
synchronized (classLoaderLock) { |
238 |
classLoader = nue; |
239 |
} |
240 |
firer.change(new ChangeFirer.Change(this, PROP_CLASS_LOADER, null, null)); |
236 |
} |
241 |
} |
237 |
|
242 |
|
238 |
/** A classloader giving access to all the module classloaders at once. */ |
243 |
/** A classloader giving access to all the module classloaders at once. */ |