< prev index next >
src/java.base/share/classes/java/lang/ClassLoader.java
Print this page
@@ -57,10 +57,11 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
+import jdk.internal.loader.BuiltinClassLoader;
import jdk.internal.perf.PerfCounter;
import jdk.internal.loader.BootLoader;
import jdk.internal.loader.ClassLoaders;
import jdk.internal.misc.Unsafe;
import jdk.internal.misc.VM;
@@ -244,10 +245,13 @@
private final String name;
// the unnamed module for this ClassLoader
private final Module unnamedModule;
+ // a string for exception message printing
+ private final String nameAndId;
+
/**
* Encapsulates the set of parallel capable loader types.
*/
private static class ParallelLoaders {
private ParallelLoaders() {}
@@ -379,10 +383,28 @@
// no finer-grained lock; lock on the classloader instance
parallelLockMap = null;
package2certs = new Hashtable<>();
assertionLock = this;
}
+ this.nameAndId = nameAndId(this);
+ }
+
+ /**
+ * If the defining loader has a name explicitly set then
+ * '<loader-name>' @<id>
+ * If the defining loader has no name then
+ * <qualified-class-name> @<id>
+ * If it's built-in loader then omit `@<id>` as there is only one instance.
+ */
+ private static String nameAndId(ClassLoader ld) {
+ String nid = ld.getName() != null ? "\'" + ld.getName() + "\'"
+ : ld.getClass().getName();
+ if (!(ld instanceof BuiltinClassLoader)) {
+ String id = Integer.toHexString(System.identityHashCode(ld));
+ nid = nid + " @" + id;
+ }
+ return nid;
}
/**
* Creates a new class loader of the specified name and using the
* specified parent class loader for delegation.
< prev index next >