Lines 123-129
Link Here
|
123 |
* <li> Checks the caches whether another class from the same package |
123 |
* <li> Checks the caches whether another class from the same package |
124 |
* was already loaded and uses the same classloader |
124 |
* was already loaded and uses the same classloader |
125 |
* <li> Tries to find the class using parent loaders in their order. |
125 |
* <li> Tries to find the class using parent loaders in their order. |
126 |
* <li> Calls the {@link #simpleFindClass(String,String)} method to find |
126 |
* <li> Calls the {@link #simpleFindClass} method to find |
127 |
* the class using this class loader. |
127 |
* the class using this class loader. |
128 |
* </ol> |
128 |
* </ol> |
129 |
* |
129 |
* |
Lines 155-163
Link Here
|
155 |
* <CODE>java/lang/Object.class</CODE> for <CODE>java.lang.Object</CODE> |
155 |
* <CODE>java/lang/Object.class</CODE> for <CODE>java.lang.Object</CODE> |
156 |
* The ClassLoader implementation may or may not use it, depending |
156 |
* The ClassLoader implementation may or may not use it, depending |
157 |
* whether it is usefull to it. |
157 |
* whether it is usefull to it. |
|
|
158 |
* @param pkg the package name, in the format org/netbeans/modules/foo/ |
158 |
* @return the resulting <code>Class</code> object or <code>null</code> |
159 |
* @return the resulting <code>Class</code> object or <code>null</code> |
159 |
*/ |
160 |
*/ |
160 |
protected Class simpleFindClass(String name, String fileName) { |
161 |
protected Class simpleFindClass(String name, String fileName, String pkg) { |
161 |
return null; |
162 |
return null; |
162 |
} |
163 |
} |
163 |
|
164 |
|
Lines 298-303
Link Here
|
298 |
} |
299 |
} |
299 |
|
300 |
|
300 |
|
301 |
|
|
|
302 |
static final boolean FAST_PKGS = Boolean.getBoolean("pcl.fast.pkgs"); // XXX |
301 |
/** |
303 |
/** |
302 |
* Returns a Package that has been defined by this class loader or any |
304 |
* Returns a Package that has been defined by this class loader or any |
303 |
* of its parents. |
305 |
* of its parents. |
Lines 306-311
Link Here
|
306 |
* @return the Package corresponding to the given name, or null if not found |
308 |
* @return the Package corresponding to the given name, or null if not found |
307 |
*/ |
309 |
*/ |
308 |
protected Package getPackage(String name) { |
310 |
protected Package getPackage(String name) { |
|
|
311 |
if (FAST_PKGS) { |
312 |
return getPackageFast(name, name.replace('.', '/') + '/', true); |
313 |
} |
309 |
zombieCheck(name); |
314 |
zombieCheck(name); |
310 |
|
315 |
|
311 |
String spkg = name.replace('.', '/') + '/'; |
316 |
String spkg = name.replace('.', '/') + '/'; |
Lines 330-346
Link Here
|
330 |
return pkg; |
335 |
return pkg; |
331 |
} |
336 |
} |
332 |
} |
337 |
} |
|
|
338 |
|
339 |
/** |
340 |
* Faster way to find a package. |
341 |
* @param name package name in org.netbeans.modules.foo format |
342 |
* @param sname package name in org/netbeans/modules/foo/ format |
343 |
* @param recurse whether to also ask parents |
344 |
*/ |
345 |
protected Package getPackageFast(String name, String sname, boolean recurse) { |
346 |
synchronized (packages) { |
347 |
Package pkg = (Package)packages.get(name); |
348 |
if (pkg != null) { |
349 |
return pkg; |
350 |
} |
351 |
if (!recurse) { |
352 |
return null; |
353 |
} |
354 |
for (int i = 0; i < parents.length; i++) { |
355 |
ClassLoader par = parents[i]; |
356 |
if (par instanceof ProxyClassLoader && shouldDelegateResource(sname, par)) { |
357 |
pkg = ((ProxyClassLoader)par).getPackageFast(name, sname, false); |
358 |
if (pkg != null) { |
359 |
break; |
360 |
} |
361 |
} |
362 |
} |
363 |
if (pkg == null) { |
364 |
// Cannot access either Package.getSystemPackage nor ClassLoader.getPackage |
365 |
// from here, so do the best we can though it will cause unnecessary |
366 |
// duplication of the package cache (PCL.packages vs. CL.packages): |
367 |
pkg = super.getPackage(name); |
368 |
} |
369 |
if (pkg != null) { |
370 |
packages.put(name, pkg); |
371 |
} |
372 |
return pkg; |
373 |
} |
374 |
} |
333 |
|
375 |
|
334 |
/** This is here just for locking serialization purposes. |
376 |
/** This is here just for locking serialization purposes. |
335 |
* Delegates to super.definePackage with proper locking. |
377 |
* Delegates to super.definePackage with proper locking. |
|
|
378 |
* Also tracks the package in our private cache, since |
379 |
* getPackageFast(...,...,false) will not call super.getPackage. |
336 |
*/ |
380 |
*/ |
337 |
protected Package definePackage(String name, String specTitle, |
381 |
protected Package definePackage(String name, String specTitle, |
338 |
String specVersion, String specVendor, String implTitle, |
382 |
String specVersion, String specVendor, String implTitle, |
339 |
String implVersion, String implVendor, URL sealBase ) |
383 |
String implVersion, String implVendor, URL sealBase ) |
340 |
throws IllegalArgumentException { |
384 |
throws IllegalArgumentException { |
341 |
synchronized (packages) { |
385 |
synchronized (packages) { |
342 |
return super.definePackage (name, specTitle, specVersion, specVendor, implTitle, |
386 |
Package pkg = super.definePackage (name, specTitle, specVersion, specVendor, implTitle, |
343 |
implVersion, implVendor, sealBase); |
387 |
implVersion, implVendor, sealBase); |
|
|
388 |
if (FAST_PKGS) { |
389 |
packages.put(name, pkg); |
390 |
} |
391 |
return pkg; |
344 |
} |
392 |
} |
345 |
} |
393 |
} |
346 |
|
394 |
|
Lines 453-464
Link Here
|
453 |
|
501 |
|
454 |
final ClassLoader owner = isSpecialResource(pkg) ? null : (ClassLoader)domainsByPackage.get(pkg); |
502 |
final ClassLoader owner = isSpecialResource(pkg) ? null : (ClassLoader)domainsByPackage.get(pkg); |
455 |
if (owner == this) { |
503 |
if (owner == this) { |
456 |
return simpleFindClass(name,fileName); |
504 |
return simpleFindClass(name, fileName, pkg); |
457 |
} |
505 |
} |
458 |
if (owner != null) { |
506 |
if (owner != null) { |
459 |
// Note that shouldDelegateResource should already be true as we hit this pkg before. |
507 |
// Note that shouldDelegateResource should already be true as we hit this pkg before. |
460 |
if (owner instanceof ProxyClassLoader) { |
508 |
if (owner instanceof ProxyClassLoader) { |
461 |
return ((ProxyClassLoader)owner).fullFindClass(name,fileName); |
509 |
return ((ProxyClassLoader)owner).fullFindClass(name, fileName, pkg); |
462 |
} else { |
510 |
} else { |
463 |
return owner.loadClass(name); // May throw CNFE, will be propagated |
511 |
return owner.loadClass(name); // May throw CNFE, will be propagated |
464 |
} |
512 |
} |
Lines 482-488
Link Here
|
482 |
if (!shouldDelegateResource(pkg, par)) continue; |
530 |
if (!shouldDelegateResource(pkg, par)) continue; |
483 |
if (par instanceof ProxyClassLoader) { |
531 |
if (par instanceof ProxyClassLoader) { |
484 |
ProxyClassLoader pcl = (ProxyClassLoader)par; |
532 |
ProxyClassLoader pcl = (ProxyClassLoader)par; |
485 |
Class c = pcl.fullFindClass(name,fileName); |
533 |
Class c = pcl.fullFindClass(name, fileName, pkg); |
486 |
// pcl might have have c in its already-loaded classes even though |
534 |
// pcl might have have c in its already-loaded classes even though |
487 |
// it was not the defining class loader. In that case, if pcl was |
535 |
// it was not the defining class loader. In that case, if pcl was |
488 |
// not transitive (should not expose its own parents), reject this. |
536 |
// not transitive (should not expose its own parents), reject this. |
Lines 512-526
Link Here
|
512 |
} |
560 |
} |
513 |
} |
561 |
} |
514 |
|
562 |
|
515 |
Class c = simpleFindClass(name,fileName); // Try it ourselves |
563 |
Class c = simpleFindClass(name, fileName, pkg); // Try it ourselves |
516 |
if (c != null) return c; |
564 |
if (c != null) return c; |
517 |
if (cached != null) throw cached; |
565 |
if (cached != null) throw cached; |
518 |
return null; |
566 |
return null; |
519 |
} |
567 |
} |
520 |
|
568 |
|
521 |
private synchronized Class fullFindClass(String name, String fileName) { |
569 |
private synchronized Class fullFindClass(String name, String fileName, String pkg) { |
522 |
Class c = findLoadedClass(name); |
570 |
Class c = findLoadedClass(name); |
523 |
return (c == null) ? simpleFindClass(name, fileName) : c; |
571 |
return (c == null) ? simpleFindClass(name, fileName, pkg) : c; |
524 |
} |
572 |
} |
525 |
|
573 |
|
526 |
private void addPackages(Map all, Package[] pkgs) { |
574 |
private void addPackages(Map all, Package[] pkgs) { |