8202605: Standardize on ClassLoaderData::loader_name() throughout the VM to obtain a class loader's name

Introduced ClassLoaderData::name() and ClassLoaderData::name_and_id() for use when obtaining a class loader's name.

Reviewed-by: coleenp, goetz, mchung, stuefe
This commit is contained in:
Lois Foltan 2018-06-19 07:54:11 -04:00
parent 731d9b1499
commit 425e1a8bb8
27 changed files with 243 additions and 171 deletions

View file

@ -59,6 +59,7 @@ 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;
@ -246,6 +247,9 @@ public abstract class ClassLoader {
// 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.
*/
@ -381,6 +385,24 @@ public abstract class ClassLoader {
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;
}
/**