[jboss-cvs] JBossAS SVN: r87896 - projects/jboss-cl/branches/Branch_2_0/classloader/src/main/java/org/jboss/classloader/spi/base.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Apr 27 15:47:57 EDT 2009


Author: alesj
Date: 2009-04-27 15:47:57 -0400 (Mon, 27 Apr 2009)
New Revision: 87896

Modified:
   projects/jboss-cl/branches/Branch_2_0/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoader.java
Log:
Use trace instead of true.

Modified: projects/jboss-cl/branches/Branch_2_0/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoader.java
===================================================================
--- projects/jboss-cl/branches/Branch_2_0/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoader.java	2009-04-27 19:45:00 UTC (rev 87895)
+++ projects/jboss-cl/branches/Branch_2_0/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoader.java	2009-04-27 19:47:57 UTC (rev 87896)
@@ -56,42 +56,42 @@
 
 /**
  * BaseClassLoader.
- * 
+ *
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
  * @version $Revision: 1.1 $
  */
-public class BaseClassLoader extends SecureClassLoader implements BaseClassLoaderMBean, RealClassLoader 
+public class BaseClassLoader extends SecureClassLoader implements BaseClassLoaderMBean, RealClassLoader
 {
    /** The log */
    private static final Logger log = Logger.getLogger(BaseClassLoader.class);
 
    /** The lock object */
    private ReentrantLock lock = new ReentrantLock(true);
-   
+
    /** The policy for this classloader */
    private ClassLoaderPolicy policy;
-   
+
    /** Our Loader front end */
    private DelegateLoader loader;
-   
+
    /** The loaded classes */
    private Map<String, String> loadedClasses = new ConcurrentHashMap<String, String>();
-   
+
    /** Our resource cache */
    private Map<String, URL> resourceCache;
-   
+
    /** Our black list */
    private Map<String, String> blackList;
 
    /** A cached version of toLongString() */
    private String cachedToString;
-   
+
    /**
     * Create a new ClassLoader with no parent.
-    * 
+    *
     * @param policy the policy
-    * @throws IllegalArgumentException for a null policy 
-    * @throws IllegalStateException if the policy is already associated with a classloader 
+    * @throws IllegalArgumentException for a null policy
+    * @throws IllegalStateException if the policy is already associated with a classloader
     */
    public BaseClassLoader(ClassLoaderPolicy policy)
    {
@@ -110,7 +110,7 @@
 
       if (basePolicy.isBlackListable())
          blackList = new ConcurrentHashMap<String, String>();
-      
+
       log.debug("Created " + this + " with policy " + policy.toLongString());
    }
 
@@ -118,7 +118,7 @@
    {
       return policy.getObjectName();
    }
-   
+
    public ObjectName getClassLoaderDomain()
    {
       BaseClassLoaderPolicy basePolicy = policy;
@@ -130,7 +130,7 @@
    {
       return policy.getName();
    }
-   
+
    public boolean isBlackListable()
    {
       BaseClassLoaderPolicy basePolicy = policy;
@@ -175,7 +175,7 @@
       }
       return result;
    }
-   
+
    public String listPolicyDetails()
    {
       return policy.toLongString();
@@ -186,18 +186,18 @@
       final Class<?> clazz = loadClass(name);
       if (clazz == null)
          return null;
-      
+
       ClassLoader cl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
       {
          public ClassLoader run()
          {
-            return clazz.getClassLoader(); 
+            return clazz.getClassLoader();
          }
       });
-      
+
       if (cl != null && cl instanceof RealClassLoader)
          return ((RealClassLoader) cl).getObjectName();
-      
+
       return null;
    }
 
@@ -222,7 +222,7 @@
 
    /**
     * Get the policy.
-    * 
+    *
     * @return the policy.
     */
    ClassLoaderPolicy getPolicy()
@@ -232,7 +232,7 @@
 
    /**
     * Get the loader.
-    * 
+    *
     * @return the loader.
     */
    DelegateLoader getLoader()
@@ -249,12 +249,12 @@
 
       if (name == null)
          return null;
-      
+
       // Did we already load this package?
       Package result = super.getPackage(name);
       if (result != null && trace)
          log.trace(this + " already loaded package " + name + " " + result.getName());
-      
+
       // Not already loaded use the domain
       if (result == null)
       {
@@ -266,14 +266,14 @@
             log.trace(this + " getPackage " + name + " domain=" + domain);
          result = domain.getPackage(this, name);
       }
-      
+
       // Still not found
       if (result == null)
       {
          if (trace)
             log.trace(this + " package not found " + name);
       }
-      
+
       return result;
    }
 
@@ -295,7 +295,7 @@
 
    /**
     * Get a package locally
-    * 
+    *
     * @param name the package name
     * @return the package
     */
@@ -306,7 +306,7 @@
 
    /**
     * Get the packages locally
-    * 
+    *
     * @param packages the packages
     */
    void getPackagesLocally(Set<Package> packages)
@@ -315,10 +315,10 @@
       for (Package pkg : pkgs)
          packages.add(pkg);
    }
-   
+
    /**
     * Check to see if the class is already loaded
-    * 
+    *
     * @param name the name of the class
     * @param trace whether trace is enabled
     * @return the class is if it is already loaded, null otherwise
@@ -346,10 +346,10 @@
          log.trace(this + " already loaded class " + ClassLoaderUtils.classToString(result));
       return result;
    }
-   
+
    /**
     * Check the cache and blacklist
-    * 
+    *
     * @param name the name of the class
     * @param trace whether trace is enabled
     * @return the class is if it is already loaded, null otherwise
@@ -367,7 +367,7 @@
 
    /**
     * Find the classloader for a class but don't load the class
-    * 
+    *
     * @param className the class name
     * @return the classloader
     * @throws ClassNotFoundException if the class is not found
@@ -387,11 +387,11 @@
 
       ClassLoaderUtils.checkClassName(className);
       String path = ClassLoaderUtils.classNameToPath(className);
-      
+
       Loader loader = domain.findLoader(this, path, basePolicy.isImportAll(), true);
       if (loader == null)
          throw new ClassNotFoundException("Class " + className + " not found from " + this);
-      
+
       // This is a bit ugly but we can't abstract this behind an interface because
       // that would make the methods public
       if (loader instanceof BaseClassLoaderSource)
@@ -407,10 +407,10 @@
       boolean trace = log.isTraceEnabled();
       if (trace)
          log.trace(this + " loadClass " + name + " resolve=" + resolve);
-      
+
       // Validate the class name makes sense
       ClassLoaderUtils.checkClassName(name);
-      
+
       // Did we already load this class?
       Class<?> result = isLoadedClass(name, trace);
 
@@ -425,17 +425,17 @@
       }
       if (result != null)
          return result;
-      
-      result = checkCacheAndBlackList(name, true);
+
+      result = checkCacheAndBlackList(name, trace);
       if (result != null)
          return result;
-      
+
       synchronized (this)
       {
          // Not already loaded use the domain
          if (result == null)
             result = loadClassFromDomain(name, trace);
-         
+
          // Still not found
          if (result == null)
          {
@@ -443,7 +443,7 @@
                log.trace(this + " class not found " + name);
             throw new ClassNotFoundException(name + " from " + toLongString());
          }
-         
+
          // Link the class if requested
          if (resolve)
          {
@@ -451,7 +451,7 @@
                log.trace(this + " resolveClass " + ClassLoaderUtils.classToString(result));
             resolveClass(result);
          }
-         
+
          return result;
       }
    }
@@ -491,10 +491,10 @@
          domain.getResources(this, name, resourceURLs);
       return resourceURLs;
    }
-   
+
    /**
     * Try to load the class locally
-    * 
+    *
     * @param name the class name
     * @return the class
     */
@@ -505,7 +505,7 @@
 
    /**
     * Try to load the class locally
-    * 
+    *
     * @param name the class name
     * @param trace whether trace is enabled
     * @return the class if found
@@ -522,7 +522,7 @@
 
       // Look for the resource
       final String resourcePath = ClassLoaderUtils.classNameToPath(name);
-      
+
       result = AccessController.doPrivileged(new PrivilegedAction<Class<?>>()
       {
          public Class<?> run()
@@ -537,7 +537,7 @@
 
             // Load the bytecode
             byte[] byteCode = ClassLoaderUtils.loadByteCode(name, is);
-            
+
             // Let the policy do things before we define the class
             BaseClassLoaderPolicy basePolicy = policy;
             ProtectionDomain protectionDomain = basePolicy.getProtectionDomain(name, resourcePath);
@@ -551,7 +551,7 @@
             {
                throw new RuntimeException("Unexpected error transforming class " + name, t);
             }
-            
+
             // Create the package if necessary
             URL codeSourceURL = null;
             if (protectionDomain != null)
@@ -561,7 +561,7 @@
                   codeSourceURL = codeSource.getLocation();
             }
             definePackage(name, codeSourceURL);
-            
+
             // Finally we can define the class
             Class<?> result;
             if (protectionDomain != null)
@@ -573,15 +573,15 @@
             return result;
          }
       }, policy.getAccessControlContext());
-      
+
       loadedClasses.put(name, name);
-      
+
       return result;
    }
 
    /**
     * Try to find the resource locally
-    * 
+    *
     * @param name the resource name
     * @return the url if found
     */
@@ -592,7 +592,7 @@
 
    /**
     * Try to find the resource locally
-    * 
+    *
     * @param name the resource name
     * @param trace whether trace is enabled
     * @return the URL if found
@@ -613,7 +613,7 @@
             return url;
          }
       }
-      
+
       // Is this resource blacklisted?
       if (blackList != null && blackList.containsKey(name))
       {
@@ -621,7 +621,7 @@
             log.trace(this + " resource is blacklisted " + name);
          return null;
       }
-      
+
       // Ask the policy for the resource
       URL result = AccessController.doPrivileged(new PrivilegedAction<URL>()
       {
@@ -644,17 +644,17 @@
       // Cache what we found
       if (resourceCache != null && result != null)
          resourceCache.put(name, result);
-      
+
       // Blacklist when not found
       if (blackList != null && result == null)
          blackList.put(name, name);
-      
+
       return result;
    }
 
    /**
     * Try to find the resource locally
-    * 
+    *
     * @param name the resource name
     * @param urls the urls to add to
     * @throws IOException for any error
@@ -666,7 +666,7 @@
 
    /**
     * Try to find the resources locally
-    * 
+    *
     * @param name the resource name
     * @param urls the urls to add to
     * @param trace whether trace is enabled
@@ -701,7 +701,7 @@
          throw e2;
       }
    }
-   
+
    /**
     * Define the package for the class if not already done
     *
@@ -713,10 +713,10 @@
       String packageName = ClassLoaderUtils.getClassPackageName(className);
       if (packageName.length() == 0)
          return;
-      
+
       // Ask the policy for the information
       PackageInformation pi = policy.getClassPackageInformation(className, packageName);
-      
+
       // Already defined?
       Package pkge = getPackage(packageName);
       if (pkge != null)
@@ -753,7 +753,7 @@
 
    /**
     * Try to load the class from the domain
-    * 
+    *
     * @param name the class name
     * @param trace whether trace is enabled
     * @return the class if found in the parent
@@ -763,17 +763,17 @@
    {
       // Because of the broken classloading in the Sun JDK we need to
       // serialize access to the classloader.
-      
+
       // Additionally, acquiring the lock on the policy for this classloader
       // ensures that we don't race with somebody undeploying the classloader
       // which could cause leaks
       acquireLockFairly(trace);
       try
       {
-         // Here we have synchronized with the policy 
+         // Here we have synchronized with the policy
          BaseClassLoaderPolicy basePolicy = policy;
          BaseClassLoaderDomain domain = basePolicy.getClassLoaderDomain();
-         
+
          if (trace)
             log.trace(this + " load from domain " + name + " domain=" + domain);
 
@@ -783,7 +783,7 @@
          if (domain == null)
          {
             Class<?> result = loadClassLocally(name, trace);
-            
+
             // So this is almost certainly a classloader leak
             if (result == null)
                throw new IllegalStateException(this + " classLoader is not connected to a domain (probably undeployed?) for class " + name);
@@ -807,7 +807,7 @@
       BaseClassLoaderPolicy basePolicy = policy;
       return basePolicy.getClassLoaderUnchecked() != null;
    }
-   
+
    public Class<?> getCachedClass(String name)
    {
       // TODO look in global and/or local cache
@@ -872,17 +872,17 @@
          policy.clearBlackList(name);
       }
    }
-   
+
    /**
     * A long version of the classloader
-    * 
+    *
     * @return the long string
     */
    public String toLongString()
    {
       if (cachedToString != null)
          return cachedToString;
-      
+
       StringBuilder builder = new StringBuilder();
       builder.append(getClass().getSimpleName());
       builder.append('@').append(Integer.toHexString(System.identityHashCode(this)));
@@ -892,7 +892,7 @@
       cachedToString = builder.toString();
       return cachedToString;
    }
-   
+
    /**
     * Shutdown the classloader
     */
@@ -905,16 +905,16 @@
          blackList.clear();
       cachedToString = null;
    }
-   
+
    /**
     * For subclasses to add things to the long string
-    * 
+    *
     * @param builder the builder
     */
    protected void toLongString(StringBuilder builder)
    {
    }
-   
+
    @Override
    public String toString()
    {
@@ -927,7 +927,7 @@
 
    /**
     * Attempt to lock, but don't wait
-    * 
+    *
     * @return true when the lock was obtained
     */
    boolean attemptLock()
@@ -937,7 +937,7 @@
 
    /**
     * Lock
-    * 
+    *
     * This method must be invoked with the monitor held
     */
    void lock()
@@ -947,7 +947,7 @@
 
    /**
     * Unlock
-    * 
+    *
     * @param rescheduleTasks whether to reschedule tasks
     */
    void unlock(boolean rescheduleTasks)
@@ -957,7 +957,7 @@
 
    /**
     * Attempt to get the lock but don't wait
-    * 
+    *
     * @param trace whether trace is enabled
     * @return true when obtained the lock
     */
@@ -997,12 +997,12 @@
 
       return result;
    }
-   
+
    /**
     * Acquire the lock on the classloader fairly<p>
     *
     * This must be invoked with the monitor held
-    * 
+    *
     * @param trace whether trace is enabled
     */
    private void acquireLockFairly(boolean trace)
@@ -1014,7 +1014,7 @@
       boolean interrupted = Thread.interrupted();
 
       int waits = 0;
-      
+
       try
       {
          while (true)
@@ -1049,14 +1049,14 @@
          if (interrupted)
             thread.interrupt();
       }
-      
+
       if (lock.getHoldCount() == 1)
          ClassLoaderManager.registerLoaderThread(this, thread);
    }
 
    /**
     * Unlock
-    * 
+    *
     * @param trace whether trace is enabled
     * @param rescheduleTasks whether to reschedule tasks
     */
@@ -1068,8 +1068,8 @@
 
       synchronized (this)
       {
-         lock.unlock();      
-      
+         lock.unlock();
+
          if (lock.getHoldCount() == 0)
          {
             ClassLoaderManager.unregisterLoaderThread(this, thread, rescheduleTasks);
@@ -1077,10 +1077,10 @@
          }
       }
    }
-   
+
    /**
     * Get the classloader for a class
-    * 
+    *
     * @param clazz the class
     * @return the classloader or null if it doesn't have one
     */
@@ -1089,7 +1089,7 @@
       SecurityManager sm = System.getSecurityManager();
       if (sm == null)
          return clazz.getClassLoader();
-      
+
       return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
       {
          public ClassLoader run()




More information about the jboss-cvs-commits mailing list