Index: core/bootstrap/src/org/netbeans/JarClassLoader.java =================================================================== RCS file: /cvs/core/bootstrap/src/org/netbeans/JarClassLoader.java,v retrieving revision 1.7 diff -u -r1.7 JarClassLoader.java --- core/bootstrap/src/org/netbeans/JarClassLoader.java 6 Jan 2003 21:34:42 -0000 1.7 +++ core/bootstrap/src/org/netbeans/JarClassLoader.java 8 Jan 2003 18:45:14 -0000 @@ -109,7 +109,7 @@ return val; } - protected Class simpleFindClass(String name, String path) { + protected Class simpleFindClass(String name, String path, String pkgnameSlashes) { // look up the Sources and return a class based on their content for( int i=0; i Checks the caches whether another class from the same package * was already loaded and uses the same classloader *
  • Tries to find the class using parent loaders in their order. - *
  • Calls the {@link #simpleFindClass(String,String)} method to find + *
  • Calls the {@link #simpleFindClass} method to find * the class using this class loader. * * @@ -155,9 +155,10 @@ * java/lang/Object.class for java.lang.Object * The ClassLoader implementation may or may not use it, depending * whether it is usefull to it. + * @param pkg the package name, in the format org/netbeans/modules/foo/ * @return the resulting Class object or null */ - protected Class simpleFindClass(String name, String fileName) { + protected Class simpleFindClass(String name, String fileName, String pkg) { return null; } @@ -298,6 +299,7 @@ } + static final boolean FAST_PKGS = Boolean.getBoolean("pcl.fast.pkgs"); // XXX /** * Returns a Package that has been defined by this class loader or any * of its parents. @@ -306,6 +308,9 @@ * @return the Package corresponding to the given name, or null if not found */ protected Package getPackage(String name) { + if (FAST_PKGS) { + return getPackageFast(name, name.replace('.', '/') + '/', true); + } zombieCheck(name); String spkg = name.replace('.', '/') + '/'; @@ -330,17 +335,60 @@ return pkg; } } + + /** + * Faster way to find a package. + * @param name package name in org.netbeans.modules.foo format + * @param sname package name in org/netbeans/modules/foo/ format + * @param recurse whether to also ask parents + */ + protected Package getPackageFast(String name, String sname, boolean recurse) { + synchronized (packages) { + Package pkg = (Package)packages.get(name); + if (pkg != null) { + return pkg; + } + if (!recurse) { + return null; + } + for (int i = 0; i < parents.length; i++) { + ClassLoader par = parents[i]; + if (par instanceof ProxyClassLoader && shouldDelegateResource(sname, par)) { + pkg = ((ProxyClassLoader)par).getPackageFast(name, sname, false); + if (pkg != null) { + break; + } + } + } + if (pkg == null) { + // Cannot access either Package.getSystemPackage nor ClassLoader.getPackage + // from here, so do the best we can though it will cause unnecessary + // duplication of the package cache (PCL.packages vs. CL.packages): + pkg = super.getPackage(name); + } + if (pkg != null) { + packages.put(name, pkg); + } + return pkg; + } + } /** This is here just for locking serialization purposes. * Delegates to super.definePackage with proper locking. + * Also tracks the package in our private cache, since + * getPackageFast(...,...,false) will not call super.getPackage. */ protected Package definePackage(String name, String specTitle, String specVersion, String specVendor, String implTitle, String implVersion, String implVendor, URL sealBase ) throws IllegalArgumentException { synchronized (packages) { - return super.definePackage (name, specTitle, specVersion, specVendor, implTitle, + Package pkg = super.definePackage (name, specTitle, specVersion, specVendor, implTitle, implVersion, implVendor, sealBase); + if (FAST_PKGS) { + packages.put(name, pkg); + } + return pkg; } } @@ -453,12 +501,12 @@ final ClassLoader owner = isSpecialResource(pkg) ? null : (ClassLoader)domainsByPackage.get(pkg); if (owner == this) { - return simpleFindClass(name,fileName); + return simpleFindClass(name, fileName, pkg); } if (owner != null) { // Note that shouldDelegateResource should already be true as we hit this pkg before. if (owner instanceof ProxyClassLoader) { - return ((ProxyClassLoader)owner).fullFindClass(name,fileName); + return ((ProxyClassLoader)owner).fullFindClass(name, fileName, pkg); } else { return owner.loadClass(name); // May throw CNFE, will be propagated } @@ -482,7 +530,7 @@ if (!shouldDelegateResource(pkg, par)) continue; if (par instanceof ProxyClassLoader) { ProxyClassLoader pcl = (ProxyClassLoader)par; - Class c = pcl.fullFindClass(name,fileName); + Class c = pcl.fullFindClass(name, fileName, pkg); // pcl might have have c in its already-loaded classes even though // it was not the defining class loader. In that case, if pcl was // not transitive (should not expose its own parents), reject this. @@ -512,15 +560,15 @@ } } - Class c = simpleFindClass(name,fileName); // Try it ourselves + Class c = simpleFindClass(name, fileName, pkg); // Try it ourselves if (c != null) return c; if (cached != null) throw cached; return null; } - private synchronized Class fullFindClass(String name, String fileName) { + private synchronized Class fullFindClass(String name, String fileName, String pkg) { Class c = findLoadedClass(name); - return (c == null) ? simpleFindClass(name, fileName) : c; + return (c == null) ? simpleFindClass(name, fileName, pkg) : c; } private void addPackages(Map all, Package[] pkgs) {