< prev index next >

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

Print this page

  44 import java.util.Enumeration;
  45 import java.util.HashMap;
  46 import java.util.Map;
  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.

2718     /**
2719      * Attempts to atomically set a volatile field in this object. Returns
2720      * {@code true} if not beaten by another thread. Avoids the use of
2721      * AtomicReferenceFieldUpdater in this class.
2722      */
2723     private boolean trySetObjectField(String name, Object obj) {
2724         Unsafe unsafe = Unsafe.getUnsafe();
2725         Class<?> k = ClassLoader.class;
2726         long offset;
2727         offset = unsafe.objectFieldOffset(k, name);
2728         return unsafe.compareAndSetReference(this, offset, null, obj);
2729     }
2730 
2731     /**
2732      * Called by the VM, during -Xshare:dump
2733      */
2734     private void resetArchivedStates() {
2735         if (parallelLockMap != null) {
2736             parallelLockMap.clear();
2737         }
2738         packages.clear();
2739         package2certs.clear();













2740         classes.clear();
2741         classLoaderValueMap = null;
2742     }
2743 }
2744 
2745 /*
2746  * A utility class that will enumerate over an array of enumerations.
2747  */
2748 final class CompoundEnumeration<E> implements Enumeration<E> {
2749     private final Enumeration<E>[] enums;
2750     private int index;
2751 
2752     public CompoundEnumeration(Enumeration<E>[] enums) {
2753         this.enums = enums;
2754     }
2755 
2756     private boolean next() {
2757         while (index < enums.length) {
2758             if (enums[index] != null && enums[index].hasMoreElements()) {
2759                 return true;

  44 import java.util.Enumeration;
  45 import java.util.HashMap;
  46 import java.util.Map;
  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.CDS;
  65 import jdk.internal.misc.Unsafe;
  66 import jdk.internal.misc.VM;
  67 import jdk.internal.reflect.CallerSensitive;
  68 import jdk.internal.reflect.CallerSensitiveAdapter;
  69 import jdk.internal.reflect.Reflection;
  70 import jdk.internal.util.StaticProperty;
  71 import sun.reflect.misc.ReflectUtil;
  72 import sun.security.util.SecurityConstants;
  73 
  74 /**
  75  * A class loader is an object that is responsible for loading classes. The
  76  * class {@code ClassLoader} is an abstract class.  Given the <a
  77  * href="#binary-name">binary name</a> of a class, a class loader should attempt to
  78  * locate or generate data that constitutes a definition for the class.  A
  79  * typical strategy is to transform the name into a file name and then read a
  80  * "class file" of that name from a file system.
  81  *
  82  * <p> Every {@link java.lang.Class Class} object contains a {@link
  83  * Class#getClassLoader() reference} to the {@code ClassLoader} that defined
  84  * it.

2719     /**
2720      * Attempts to atomically set a volatile field in this object. Returns
2721      * {@code true} if not beaten by another thread. Avoids the use of
2722      * AtomicReferenceFieldUpdater in this class.
2723      */
2724     private boolean trySetObjectField(String name, Object obj) {
2725         Unsafe unsafe = Unsafe.getUnsafe();
2726         Class<?> k = ClassLoader.class;
2727         long offset;
2728         offset = unsafe.objectFieldOffset(k, name);
2729         return unsafe.compareAndSetReference(this, offset, null, obj);
2730     }
2731 
2732     /**
2733      * Called by the VM, during -Xshare:dump
2734      */
2735     private void resetArchivedStates() {
2736         if (parallelLockMap != null) {
2737             parallelLockMap.clear();
2738         }
2739 
2740         if (CDS.isDumpingPackages()) {
2741             if (System.getProperty("cds.debug.archived.packages") != null) {
2742                 for (Map.Entry<String, NamedPackage> entry : packages.entrySet()) {
2743                     String key = entry.getKey();
2744                     NamedPackage value = entry.getValue();
2745                     System.out.println("Archiving " + 
2746                                        (value instanceof Package ? "Package" : "NamedPackage") +
2747                                        " \"" + key + "\" for " + this);
2748                 }
2749             }
2750         } else {
2751             packages.clear();
2752             package2certs.clear();
2753         }
2754         classes.clear();
2755         classLoaderValueMap = null;
2756     }
2757 }
2758 
2759 /*
2760  * A utility class that will enumerate over an array of enumerations.
2761  */
2762 final class CompoundEnumeration<E> implements Enumeration<E> {
2763     private final Enumeration<E>[] enums;
2764     private int index;
2765 
2766     public CompoundEnumeration(Enumeration<E>[] enums) {
2767         this.enums = enums;
2768     }
2769 
2770     private boolean next() {
2771         while (index < enums.length) {
2772             if (enums[index] != null && enums[index].hasMoreElements()) {
2773                 return true;
< prev index next >