src/java.base/share/classes/java/lang/ClassLoader.java

Print this page




  33 import java.security.AccessController;
  34 import java.security.AccessControlContext;
  35 import java.security.CodeSource;
  36 import java.security.PrivilegedAction;
  37 import java.security.PrivilegedActionException;
  38 import java.security.PrivilegedExceptionAction;
  39 import java.security.ProtectionDomain;
  40 import java.security.cert.Certificate;
  41 import java.util.Collections;
  42 import java.util.Enumeration;
  43 import java.util.HashMap;
  44 import java.util.HashSet;
  45 import java.util.Set;
  46 import java.util.Stack;
  47 import java.util.Map;
  48 import java.util.NoSuchElementException;
  49 import java.util.Vector;
  50 import java.util.Hashtable;
  51 import java.util.WeakHashMap;
  52 import java.util.concurrent.ConcurrentHashMap;


  53 import sun.misc.Resource;
  54 import sun.misc.URLClassPath;
  55 import sun.reflect.CallerSensitive;
  56 import sun.reflect.Reflection;
  57 import sun.reflect.misc.ReflectUtil;
  58 import sun.security.util.SecurityConstants;
  59 
  60 /**
  61  * A class loader is an object that is responsible for loading classes. The
  62  * class <tt>ClassLoader</tt> is an abstract class.  Given the <a
  63  * href="#name">binary name</a> of a class, a class loader should attempt to
  64  * locate or generate data that constitutes a definition for the class.  A
  65  * typical strategy is to transform the name into a file name and then read a
  66  * "class file" of that name from a file system.
  67  *
  68  * <p> Every {@link Class <tt>Class</tt>} object contains a {@link
  69  * Class#getClassLoader() reference} to the <tt>ClassLoader</tt> that defined
  70  * it.
  71  *
  72  * <p> <tt>Class</tt> objects for array classes are not created by class


 406             if (c == null) {
 407                 long t0 = System.nanoTime();
 408                 try {
 409                     if (parent != null) {
 410                         c = parent.loadClass(name, false);
 411                     } else {
 412                         c = findBootstrapClassOrNull(name);
 413                     }
 414                 } catch (ClassNotFoundException e) {
 415                     // ClassNotFoundException thrown if class not found
 416                     // from the non-null parent class loader
 417                 }
 418 
 419                 if (c == null) {
 420                     // If still not found, then invoke findClass in order
 421                     // to find the class.
 422                     long t1 = System.nanoTime();
 423                     c = findClass(name);
 424 
 425                     // this is the defining class loader; record the stats
 426                     sun.misc.PerfCounter.getParentDelegationTime().addTime(t1 - t0);
 427                     sun.misc.PerfCounter.getFindClassTime().addElapsedTimeFrom(t1);
 428                     sun.misc.PerfCounter.getFindClasses().increment();
 429                 }
 430             }
 431             if (resolve) {
 432                 resolveClass(c);
 433             }
 434             return c;
 435         }
 436     }
 437 
 438     /**
 439      * Returns the lock object for class loading operations.
 440      * For backward compatibility, the default implementation of this method
 441      * behaves as follows. If this ClassLoader object is registered as
 442      * parallel capable, the method returns a dedicated object associated
 443      * with the specified class name. Otherwise, the method returns this
 444      * ClassLoader object.
 445      *
 446      * @param  className
 447      *         The name of the to-be-loaded class
 448      *




  33 import java.security.AccessController;
  34 import java.security.AccessControlContext;
  35 import java.security.CodeSource;
  36 import java.security.PrivilegedAction;
  37 import java.security.PrivilegedActionException;
  38 import java.security.PrivilegedExceptionAction;
  39 import java.security.ProtectionDomain;
  40 import java.security.cert.Certificate;
  41 import java.util.Collections;
  42 import java.util.Enumeration;
  43 import java.util.HashMap;
  44 import java.util.HashSet;
  45 import java.util.Set;
  46 import java.util.Stack;
  47 import java.util.Map;
  48 import java.util.NoSuchElementException;
  49 import java.util.Vector;
  50 import java.util.Hashtable;
  51 import java.util.WeakHashMap;
  52 import java.util.concurrent.ConcurrentHashMap;
  53 
  54 import jdk.internal.perf.PerfCounter;
  55 import sun.misc.Resource;
  56 import sun.misc.URLClassPath;
  57 import sun.reflect.CallerSensitive;
  58 import sun.reflect.Reflection;
  59 import sun.reflect.misc.ReflectUtil;
  60 import sun.security.util.SecurityConstants;
  61 
  62 /**
  63  * A class loader is an object that is responsible for loading classes. The
  64  * class <tt>ClassLoader</tt> is an abstract class.  Given the <a
  65  * href="#name">binary name</a> of a class, a class loader should attempt to
  66  * locate or generate data that constitutes a definition for the class.  A
  67  * typical strategy is to transform the name into a file name and then read a
  68  * "class file" of that name from a file system.
  69  *
  70  * <p> Every {@link Class <tt>Class</tt>} object contains a {@link
  71  * Class#getClassLoader() reference} to the <tt>ClassLoader</tt> that defined
  72  * it.
  73  *
  74  * <p> <tt>Class</tt> objects for array classes are not created by class


 408             if (c == null) {
 409                 long t0 = System.nanoTime();
 410                 try {
 411                     if (parent != null) {
 412                         c = parent.loadClass(name, false);
 413                     } else {
 414                         c = findBootstrapClassOrNull(name);
 415                     }
 416                 } catch (ClassNotFoundException e) {
 417                     // ClassNotFoundException thrown if class not found
 418                     // from the non-null parent class loader
 419                 }
 420 
 421                 if (c == null) {
 422                     // If still not found, then invoke findClass in order
 423                     // to find the class.
 424                     long t1 = System.nanoTime();
 425                     c = findClass(name);
 426 
 427                     // this is the defining class loader; record the stats
 428                     PerfCounter.getParentDelegationTime().addTime(t1 - t0);
 429                     PerfCounter.getFindClassTime().addElapsedTimeFrom(t1);
 430                     PerfCounter.getFindClasses().increment();
 431                 }
 432             }
 433             if (resolve) {
 434                 resolveClass(c);
 435             }
 436             return c;
 437         }
 438     }
 439 
 440     /**
 441      * Returns the lock object for class loading operations.
 442      * For backward compatibility, the default implementation of this method
 443      * behaves as follows. If this ClassLoader object is registered as
 444      * parallel capable, the method returns a dedicated object associated
 445      * with the specified class name. Otherwise, the method returns this
 446      * ClassLoader object.
 447      *
 448      * @param  className
 449      *         The name of the to-be-loaded class
 450      *