41 import java.util.Enumeration;
42 import java.util.HashMap;
43 import java.util.Map;
44 import java.util.NoSuchElementException;
45 import java.util.Objects;
46 import java.util.Set;
47 import java.util.Spliterator;
48 import java.util.Spliterators;
49 import java.util.WeakHashMap;
50 import java.util.concurrent.ConcurrentHashMap;
51 import java.util.function.Supplier;
52 import java.util.stream.Stream;
53 import java.util.stream.StreamSupport;
54
55 import jdk.internal.loader.BootLoader;
56 import jdk.internal.loader.BuiltinClassLoader;
57 import jdk.internal.loader.ClassLoaders;
58 import jdk.internal.loader.NativeLibrary;
59 import jdk.internal.loader.NativeLibraries;
60 import jdk.internal.perf.PerfCounter;
61 import jdk.internal.misc.Unsafe;
62 import jdk.internal.misc.VM;
63 import jdk.internal.reflect.CallerSensitive;
64 import jdk.internal.reflect.CallerSensitiveAdapter;
65 import jdk.internal.reflect.Reflection;
66 import jdk.internal.util.StaticProperty;
67
68 /**
69 * A class loader is an object that is responsible for loading classes. The
70 * class {@code ClassLoader} is an abstract class. Given the <a
71 * href="#binary-name">binary name</a> of a class, a class loader should attempt to
72 * locate or generate data that constitutes a definition for the class. A
73 * typical strategy is to transform the name into a file name and then read a
74 * "class file" of that name from a file system.
75 *
76 * <p> Every {@link java.lang.Class Class} object contains a {@link
77 * Class#getClassLoader() reference} to the {@code ClassLoader} that defined
78 * it.
79 *
80 * <p> {@code Class} objects for array classes are not created by class
2552 /**
2553 * Attempts to atomically set a volatile field in this object. Returns
2554 * {@code true} if not beaten by another thread. Avoids the use of
2555 * AtomicReferenceFieldUpdater in this class.
2556 */
2557 private boolean trySetObjectField(String name, Object obj) {
2558 Unsafe unsafe = Unsafe.getUnsafe();
2559 Class<?> k = ClassLoader.class;
2560 long offset;
2561 offset = unsafe.objectFieldOffset(k, name);
2562 return unsafe.compareAndSetReference(this, offset, null, obj);
2563 }
2564
2565 /**
2566 * Called by the VM, during -Xshare:dump
2567 */
2568 private void resetArchivedStates() {
2569 if (parallelLockMap != null) {
2570 parallelLockMap.clear();
2571 }
2572 packages.clear();
2573 package2certs.clear();
2574 classes.clear();
2575 classLoaderValueMap = null;
2576 }
2577 }
2578
2579 /*
2580 * A utility class that will enumerate over an array of enumerations.
2581 */
2582 final class CompoundEnumeration<E> implements Enumeration<E> {
2583 private final Enumeration<E>[] enums;
2584 private int index;
2585
2586 public CompoundEnumeration(Enumeration<E>[] enums) {
2587 this.enums = enums;
2588 }
2589
2590 private boolean next() {
2591 while (index < enums.length) {
2592 if (enums[index] != null && enums[index].hasMoreElements()) {
2593 return true;
|
41 import java.util.Enumeration;
42 import java.util.HashMap;
43 import java.util.Map;
44 import java.util.NoSuchElementException;
45 import java.util.Objects;
46 import java.util.Set;
47 import java.util.Spliterator;
48 import java.util.Spliterators;
49 import java.util.WeakHashMap;
50 import java.util.concurrent.ConcurrentHashMap;
51 import java.util.function.Supplier;
52 import java.util.stream.Stream;
53 import java.util.stream.StreamSupport;
54
55 import jdk.internal.loader.BootLoader;
56 import jdk.internal.loader.BuiltinClassLoader;
57 import jdk.internal.loader.ClassLoaders;
58 import jdk.internal.loader.NativeLibrary;
59 import jdk.internal.loader.NativeLibraries;
60 import jdk.internal.perf.PerfCounter;
61 import jdk.internal.misc.CDS;
62 import jdk.internal.misc.Unsafe;
63 import jdk.internal.misc.VM;
64 import jdk.internal.reflect.CallerSensitive;
65 import jdk.internal.reflect.CallerSensitiveAdapter;
66 import jdk.internal.reflect.Reflection;
67 import jdk.internal.util.StaticProperty;
68
69 /**
70 * A class loader is an object that is responsible for loading classes. The
71 * class {@code ClassLoader} is an abstract class. Given the <a
72 * href="#binary-name">binary name</a> of a class, a class loader should attempt to
73 * locate or generate data that constitutes a definition for the class. A
74 * typical strategy is to transform the name into a file name and then read a
75 * "class file" of that name from a file system.
76 *
77 * <p> Every {@link java.lang.Class Class} object contains a {@link
78 * Class#getClassLoader() reference} to the {@code ClassLoader} that defined
79 * it.
80 *
81 * <p> {@code Class} objects for array classes are not created by class
2553 /**
2554 * Attempts to atomically set a volatile field in this object. Returns
2555 * {@code true} if not beaten by another thread. Avoids the use of
2556 * AtomicReferenceFieldUpdater in this class.
2557 */
2558 private boolean trySetObjectField(String name, Object obj) {
2559 Unsafe unsafe = Unsafe.getUnsafe();
2560 Class<?> k = ClassLoader.class;
2561 long offset;
2562 offset = unsafe.objectFieldOffset(k, name);
2563 return unsafe.compareAndSetReference(this, offset, null, obj);
2564 }
2565
2566 /**
2567 * Called by the VM, during -Xshare:dump
2568 */
2569 private void resetArchivedStates() {
2570 if (parallelLockMap != null) {
2571 parallelLockMap.clear();
2572 }
2573
2574 if (CDS.isDumpingPackages()) {
2575 if (System.getProperty("cds.debug.archived.packages") != null) {
2576 for (Map.Entry<String, NamedPackage> entry : packages.entrySet()) {
2577 String key = entry.getKey();
2578 NamedPackage value = entry.getValue();
2579 System.out.println("Archiving " +
2580 (value instanceof Package ? "Package" : "NamedPackage") +
2581 " \"" + key + "\" for " + this);
2582 }
2583 }
2584 } else {
2585 packages.clear();
2586 package2certs.clear();
2587 }
2588 classes.clear();
2589 classLoaderValueMap = null;
2590 }
2591 }
2592
2593 /*
2594 * A utility class that will enumerate over an array of enumerations.
2595 */
2596 final class CompoundEnumeration<E> implements Enumeration<E> {
2597 private final Enumeration<E>[] enums;
2598 private int index;
2599
2600 public CompoundEnumeration(Enumeration<E>[] enums) {
2601 this.enums = enums;
2602 }
2603
2604 private boolean next() {
2605 while (index < enums.length) {
2606 if (enums[index] != null && enums[index].hasMoreElements()) {
2607 return true;
|