1 /*
2 * Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2019, Azul Systems, Inc. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation. Oracle designates this
9 * particular file as subject to the "Classpath" exception as provided
10 * by Oracle in the LICENSE file that accompanied this code.
11 *
12 * This code is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * version 2 for more details (a copy is included in the LICENSE file that
16 * accompanied this code).
17 *
18 * You should have received a copy of the GNU General Public License version
19 * 2 along with this work; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
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.
2700 /**
2701 * Attempts to atomically set a volatile field in this object. Returns
2702 * {@code true} if not beaten by another thread. Avoids the use of
2703 * AtomicReferenceFieldUpdater in this class.
2704 */
2705 private boolean trySetObjectField(String name, Object obj) {
2706 Unsafe unsafe = Unsafe.getUnsafe();
2707 Class<?> k = ClassLoader.class;
2708 long offset;
2709 offset = unsafe.objectFieldOffset(k, name);
2710 return unsafe.compareAndSetReference(this, offset, null, obj);
2711 }
2712
2713 /**
2714 * Called by the VM, during -Xshare:dump
2715 */
2716 private void resetArchivedStates() {
2717 if (parallelLockMap != null) {
2718 parallelLockMap.clear();
2719 }
2720 packages.clear();
2721 package2certs.clear();
2722 classes.clear();
2723 classLoaderValueMap = null;
2724 }
2725 }
2726
2727 /*
2728 * A utility class that will enumerate over an array of enumerations.
2729 */
2730 final class CompoundEnumeration<E> implements Enumeration<E> {
2731 private final Enumeration<E>[] enums;
2732 private int index;
2733
2734 public CompoundEnumeration(Enumeration<E>[] enums) {
2735 this.enums = enums;
2736 }
2737
2738 private boolean next() {
2739 while (index < enums.length) {
2740 if (enums[index] != null && enums[index].hasMoreElements()) {
2741 return true;
|
1 /*
2 * Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2019, Azul Systems, Inc. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation. Oracle designates this
9 * particular file as subject to the "Classpath" exception as provided
10 * by Oracle in the LICENSE file that accompanied this code.
11 *
12 * This code is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * version 2 for more details (a copy is included in the LICENSE file that
16 * accompanied this code).
17 *
18 * You should have received a copy of the GNU General Public License version
19 * 2 along with this work; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
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.
2701 /**
2702 * Attempts to atomically set a volatile field in this object. Returns
2703 * {@code true} if not beaten by another thread. Avoids the use of
2704 * AtomicReferenceFieldUpdater in this class.
2705 */
2706 private boolean trySetObjectField(String name, Object obj) {
2707 Unsafe unsafe = Unsafe.getUnsafe();
2708 Class<?> k = ClassLoader.class;
2709 long offset;
2710 offset = unsafe.objectFieldOffset(k, name);
2711 return unsafe.compareAndSetReference(this, offset, null, obj);
2712 }
2713
2714 /**
2715 * Called by the VM, during -Xshare:dump
2716 */
2717 private void resetArchivedStates() {
2718 if (parallelLockMap != null) {
2719 parallelLockMap.clear();
2720 }
2721
2722 if (CDS.isDumpingPackages()) {
2723 if (System.getProperty("cds.debug.archived.packages") != null) {
2724 for (Map.Entry<String, NamedPackage> entry : packages.entrySet()) {
2725 String key = entry.getKey();
2726 NamedPackage value = entry.getValue();
2727 System.out.println("Archiving " +
2728 (value instanceof Package ? "Package" : "NamedPackage") +
2729 " \"" + key + "\" for " + this);
2730 }
2731 }
2732 } else {
2733 packages.clear();
2734 package2certs.clear();
2735 }
2736 classes.clear();
2737 classLoaderValueMap = null;
2738 }
2739 }
2740
2741 /*
2742 * A utility class that will enumerate over an array of enumerations.
2743 */
2744 final class CompoundEnumeration<E> implements Enumeration<E> {
2745 private final Enumeration<E>[] enums;
2746 private int index;
2747
2748 public CompoundEnumeration(Enumeration<E>[] enums) {
2749 this.enums = enums;
2750 }
2751
2752 private boolean next() {
2753 while (index < enums.length) {
2754 if (enums[index] != null && enums[index].hasMoreElements()) {
2755 return true;
|