< prev index next >

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

Print this page

  47 import java.util.NoSuchElementException;
  48 import java.util.Objects;
  49 import java.util.Set;
  50 import java.util.Spliterator;
  51 import java.util.Spliterators;
  52 import java.util.WeakHashMap;
  53 import java.util.concurrent.ConcurrentHashMap;
  54 import java.util.function.Supplier;
  55 import java.util.stream.Stream;
  56 import java.util.stream.StreamSupport;
  57 
  58 import jdk.internal.loader.BootLoader;
  59 import jdk.internal.loader.BuiltinClassLoader;
  60 import jdk.internal.loader.ClassLoaders;
  61 import jdk.internal.loader.NativeLibrary;
  62 import jdk.internal.loader.NativeLibraries;
  63 import jdk.internal.perf.PerfCounter;
  64 import jdk.internal.misc.Unsafe;
  65 import jdk.internal.misc.VM;
  66 import jdk.internal.reflect.CallerSensitive;

  67 import jdk.internal.reflect.Reflection;
  68 import jdk.internal.util.StaticProperty;
  69 import sun.reflect.misc.ReflectUtil;
  70 import sun.security.util.SecurityConstants;
  71 
  72 /**
  73  * A class loader is an object that is responsible for loading classes. The
  74  * class {@code ClassLoader} is an abstract class.  Given the <a
  75  * href="#binary-name">binary name</a> of a class, a class loader should attempt to
  76  * locate or generate data that constitutes a definition for the class.  A
  77  * typical strategy is to transform the name into a file name and then read a
  78  * "class file" of that name from a file system.
  79  *
  80  * <p> Every {@link java.lang.Class Class} object contains a {@link
  81  * Class#getClassLoader() reference} to the {@code ClassLoader} that defined
  82  * it.
  83  *
  84  * <p> {@code Class} objects for array classes are not created by class
  85  * loaders, but are created automatically as required by the Java runtime.
  86  * The class loader for an array class, as returned by {@link

1598      * {@linkplain #isRegisteredAsParallelCapable() parallel capable}.
1599      * The registration succeeds if and only if all of the following
1600      * conditions are met:
1601      * <ol>
1602      * <li> no instance of the caller has been created</li>
1603      * <li> all of the super classes (except class Object) of the caller are
1604      * registered as parallel capable</li>
1605      * </ol>
1606      * <p>Note that once a class loader is registered as parallel capable, there
1607      * is no way to change it back.</p>
1608      *
1609      * @return  {@code true} if the caller is successfully registered as
1610      *          parallel capable and {@code false} if otherwise.
1611      *
1612      * @see #isRegisteredAsParallelCapable()
1613      *
1614      * @since   1.7
1615      */
1616     @CallerSensitive
1617     protected static boolean registerAsParallelCapable() {
1618         Class<? extends ClassLoader> callerClass =
1619             Reflection.getCallerClass().asSubclass(ClassLoader.class);
1620         return ParallelLoaders.register(callerClass);




1621     }
1622 
1623     /**
1624      * Returns {@code true} if this class loader is registered as
1625      * {@linkplain #registerAsParallelCapable parallel capable}, otherwise
1626      * {@code false}.
1627      *
1628      * @return  {@code true} if this class loader is parallel capable,
1629      *          otherwise {@code false}.
1630      *
1631      * @see #registerAsParallelCapable()
1632      *
1633      * @since   9
1634      */
1635     public final boolean isRegisteredAsParallelCapable() {
1636         return ParallelLoaders.isRegistered(this.getClass());
1637     }
1638 
1639     /**
1640      * Find a resource of the specified name from the search path used to load

  47 import java.util.NoSuchElementException;
  48 import java.util.Objects;
  49 import java.util.Set;
  50 import java.util.Spliterator;
  51 import java.util.Spliterators;
  52 import java.util.WeakHashMap;
  53 import java.util.concurrent.ConcurrentHashMap;
  54 import java.util.function.Supplier;
  55 import java.util.stream.Stream;
  56 import java.util.stream.StreamSupport;
  57 
  58 import jdk.internal.loader.BootLoader;
  59 import jdk.internal.loader.BuiltinClassLoader;
  60 import jdk.internal.loader.ClassLoaders;
  61 import jdk.internal.loader.NativeLibrary;
  62 import jdk.internal.loader.NativeLibraries;
  63 import jdk.internal.perf.PerfCounter;
  64 import jdk.internal.misc.Unsafe;
  65 import jdk.internal.misc.VM;
  66 import jdk.internal.reflect.CallerSensitive;
  67 import jdk.internal.reflect.CallerSensitiveAdapter;
  68 import jdk.internal.reflect.Reflection;
  69 import jdk.internal.util.StaticProperty;
  70 import sun.reflect.misc.ReflectUtil;
  71 import sun.security.util.SecurityConstants;
  72 
  73 /**
  74  * A class loader is an object that is responsible for loading classes. The
  75  * class {@code ClassLoader} is an abstract class.  Given the <a
  76  * href="#binary-name">binary name</a> of a class, a class loader should attempt to
  77  * locate or generate data that constitutes a definition for the class.  A
  78  * typical strategy is to transform the name into a file name and then read a
  79  * "class file" of that name from a file system.
  80  *
  81  * <p> Every {@link java.lang.Class Class} object contains a {@link
  82  * Class#getClassLoader() reference} to the {@code ClassLoader} that defined
  83  * it.
  84  *
  85  * <p> {@code Class} objects for array classes are not created by class
  86  * loaders, but are created automatically as required by the Java runtime.
  87  * The class loader for an array class, as returned by {@link

1599      * {@linkplain #isRegisteredAsParallelCapable() parallel capable}.
1600      * The registration succeeds if and only if all of the following
1601      * conditions are met:
1602      * <ol>
1603      * <li> no instance of the caller has been created</li>
1604      * <li> all of the super classes (except class Object) of the caller are
1605      * registered as parallel capable</li>
1606      * </ol>
1607      * <p>Note that once a class loader is registered as parallel capable, there
1608      * is no way to change it back.</p>
1609      *
1610      * @return  {@code true} if the caller is successfully registered as
1611      *          parallel capable and {@code false} if otherwise.
1612      *
1613      * @see #isRegisteredAsParallelCapable()
1614      *
1615      * @since   1.7
1616      */
1617     @CallerSensitive
1618     protected static boolean registerAsParallelCapable() {
1619         return registerAsParallelCapable(Reflection.getCallerClass());
1620     }
1621 
1622     // Caller-sensitive adapter method for reflective invocation
1623     @CallerSensitiveAdapter
1624     private static boolean registerAsParallelCapable(Class<?> caller) {
1625         return ParallelLoaders.register(caller.asSubclass(ClassLoader.class));
1626     }
1627 
1628     /**
1629      * Returns {@code true} if this class loader is registered as
1630      * {@linkplain #registerAsParallelCapable parallel capable}, otherwise
1631      * {@code false}.
1632      *
1633      * @return  {@code true} if this class loader is parallel capable,
1634      *          otherwise {@code false}.
1635      *
1636      * @see #registerAsParallelCapable()
1637      *
1638      * @since   9
1639      */
1640     public final boolean isRegisteredAsParallelCapable() {
1641         return ParallelLoaders.isRegistered(this.getClass());
1642     }
1643 
1644     /**
1645      * Find a resource of the specified name from the search path used to load
< prev index next >