8265605: Cannot call BootLoader::loadClassOrNull before initPhase2
Reviewed-by: alanb, mchung
This commit is contained in:
parent
4086081306
commit
1e0ecd6d56
src/java.base/share
classes
java/lang
jdk/internal
native/libjava
test/hotspot/jtreg/runtime/cds/appcds/test-classes
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2019, Azul Systems, Inc. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
@ -1134,7 +1134,7 @@ public abstract class ClassLoader {
|
||||
Object classData);
|
||||
|
||||
// true if the name is null or has the potential to be a valid binary name
|
||||
private boolean checkName(String name) {
|
||||
private static boolean checkName(String name) {
|
||||
if ((name == null) || (name.isEmpty()))
|
||||
return true;
|
||||
if ((name.indexOf('/') != -1) || (name.charAt(0) == '['))
|
||||
@ -1254,14 +1254,14 @@ public abstract class ClassLoader {
|
||||
* Returns a class loaded by the bootstrap class loader;
|
||||
* or return null if not found.
|
||||
*/
|
||||
Class<?> findBootstrapClassOrNull(String name) {
|
||||
static Class<?> findBootstrapClassOrNull(String name) {
|
||||
if (!checkName(name)) return null;
|
||||
|
||||
return findBootstrapClass(name);
|
||||
}
|
||||
|
||||
// return null if not found
|
||||
private native Class<?> findBootstrapClass(String name);
|
||||
private static native Class<?> findBootstrapClass(String name);
|
||||
|
||||
/**
|
||||
* Returns the class with the given <a href="#binary-name">binary name</a> if this
|
||||
|
@ -2218,8 +2218,8 @@ public final class System {
|
||||
boolean initialize, int flags, Object classData) {
|
||||
return ClassLoader.defineClass0(loader, lookup, name, b, 0, b.length, pd, initialize, flags, classData);
|
||||
}
|
||||
public Class<?> findBootstrapClassOrNull(ClassLoader cl, String name) {
|
||||
return cl.findBootstrapClassOrNull(name);
|
||||
public Class<?> findBootstrapClassOrNull(String name) {
|
||||
return ClassLoader.findBootstrapClassOrNull(name);
|
||||
}
|
||||
public Package definePackage(ClassLoader cl, String name, Module module) {
|
||||
return cl.definePackage(name, module);
|
||||
|
@ -161,7 +161,7 @@ public interface JavaLangAccess {
|
||||
/**
|
||||
* Returns a class loaded by the bootstrap class loader.
|
||||
*/
|
||||
Class<?> findBootstrapClassOrNull(ClassLoader cl, String name);
|
||||
Class<?> findBootstrapClassOrNull(String name);
|
||||
|
||||
/**
|
||||
* Define a Package of the given name and module by the given class loader.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -47,7 +47,7 @@ class ArchivedClassLoaders {
|
||||
appLoader = ClassLoaders.appClassLoader();
|
||||
|
||||
servicesCatalogs = new ServicesCatalog[3];
|
||||
servicesCatalogs[0] = BootLoader.getServicesCatalog();
|
||||
servicesCatalogs[0] = ServicesCatalog.getServicesCatalog(bootLoader);
|
||||
servicesCatalogs[1] = ServicesCatalog.getServicesCatalog(platformLoader);
|
||||
servicesCatalogs[2] = ServicesCatalog.getServicesCatalog(appLoader);
|
||||
|
||||
@ -67,7 +67,7 @@ class ArchivedClassLoaders {
|
||||
}
|
||||
|
||||
ServicesCatalog servicesCatalog(ClassLoader loader) {
|
||||
if (loader == null) {
|
||||
if (loader == bootLoader) {
|
||||
return servicesCatalogs[0];
|
||||
} else if (loader == platformLoader) {
|
||||
return servicesCatalogs[1];
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -55,6 +55,8 @@ import jdk.internal.util.StaticProperty;
|
||||
public class BootLoader {
|
||||
private BootLoader() { }
|
||||
|
||||
private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
|
||||
|
||||
// The unnamed module for the boot loader
|
||||
private static final Module UNNAMED_MODULE;
|
||||
private static final String JAVA_HOME = StaticProperty.javaHome();
|
||||
@ -64,17 +66,6 @@ public class BootLoader {
|
||||
setBootLoaderUnnamedModule0(UNNAMED_MODULE);
|
||||
}
|
||||
|
||||
// ServiceCatalog for the boot class loader
|
||||
private static final ServicesCatalog SERVICES_CATALOG;
|
||||
static {
|
||||
ArchivedClassLoaders archivedClassLoaders = ArchivedClassLoaders.get();
|
||||
if (archivedClassLoaders != null) {
|
||||
SERVICES_CATALOG = archivedClassLoaders.servicesCatalog(null);
|
||||
} else {
|
||||
SERVICES_CATALOG = ServicesCatalog.create();
|
||||
}
|
||||
}
|
||||
|
||||
// ClassLoaderValue map for the boot class loader
|
||||
private static final ConcurrentHashMap<?, ?> CLASS_LOADER_VALUE_MAP
|
||||
= new ConcurrentHashMap<>();
|
||||
@ -94,7 +85,7 @@ public class BootLoader {
|
||||
* Returns the ServiceCatalog for modules defined to the boot class loader.
|
||||
*/
|
||||
public static ServicesCatalog getServicesCatalog() {
|
||||
return SERVICES_CATALOG;
|
||||
return ServicesCatalog.getServicesCatalog(ClassLoaders.bootLoader());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -131,7 +122,7 @@ public class BootLoader {
|
||||
* Loads the Class object with the given name defined to the boot loader.
|
||||
*/
|
||||
public static Class<?> loadClassOrNull(String name) {
|
||||
return ClassLoaders.bootLoader().loadClassOrNull(name);
|
||||
return JLA.findBootstrapClassOrNull(name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -55,15 +55,21 @@ public class ClassLoaders {
|
||||
private static final PlatformClassLoader PLATFORM_LOADER;
|
||||
private static final AppClassLoader APP_LOADER;
|
||||
|
||||
// Sets the ServicesCatalog for the specified loader using archived objects.
|
||||
private static void setArchivedServicesCatalog(ClassLoader loader) {
|
||||
ServicesCatalog catalog = ArchivedClassLoaders.get().servicesCatalog(loader);
|
||||
ServicesCatalog.putServicesCatalog(loader, catalog);
|
||||
}
|
||||
|
||||
// Creates the built-in class loaders.
|
||||
static {
|
||||
ArchivedClassLoaders archivedClassLoaders = ArchivedClassLoaders.get();
|
||||
if (archivedClassLoaders != null) {
|
||||
// assert VM.getSavedProperty("jdk.boot.class.path.append") == null
|
||||
BOOT_LOADER = (BootClassLoader) archivedClassLoaders.bootLoader();
|
||||
setArchivedServicesCatalog(BOOT_LOADER);
|
||||
PLATFORM_LOADER = (PlatformClassLoader) archivedClassLoaders.platformLoader();
|
||||
ServicesCatalog catalog = archivedClassLoaders.servicesCatalog(PLATFORM_LOADER);
|
||||
ServicesCatalog.putServicesCatalog(PLATFORM_LOADER, catalog);
|
||||
setArchivedServicesCatalog(PLATFORM_LOADER);
|
||||
} else {
|
||||
// -Xbootclasspath/a or -javaagent with Boot-Class-Path attribute
|
||||
String append = VM.getSavedProperty("jdk.boot.class.path.append");
|
||||
@ -86,8 +92,7 @@ public class ClassLoaders {
|
||||
URLClassPath ucp = new URLClassPath(cp, false);
|
||||
if (archivedClassLoaders != null) {
|
||||
APP_LOADER = (AppClassLoader) archivedClassLoaders.appLoader();
|
||||
ServicesCatalog catalog = archivedClassLoaders.servicesCatalog(APP_LOADER);
|
||||
ServicesCatalog.putServicesCatalog(APP_LOADER, catalog);
|
||||
setArchivedServicesCatalog(APP_LOADER);
|
||||
APP_LOADER.setClassPath(ucp);
|
||||
} else {
|
||||
APP_LOADER = new AppClassLoader(PLATFORM_LOADER, ucp);
|
||||
@ -132,7 +137,7 @@ public class ClassLoaders {
|
||||
|
||||
@Override
|
||||
protected Class<?> loadClassOrNull(String cn, boolean resolve) {
|
||||
return JLA.findBootstrapClassOrNull(this, cn);
|
||||
return JLA.findBootstrapClassOrNull(cn);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -274,7 +274,7 @@ Java_java_lang_ClassLoader_defineClass0(JNIEnv *env,
|
||||
* Returns NULL if class not found.
|
||||
*/
|
||||
JNIEXPORT jclass JNICALL
|
||||
Java_java_lang_ClassLoader_findBootstrapClass(JNIEnv *env, jobject loader,
|
||||
Java_java_lang_ClassLoader_findBootstrapClass(JNIEnv *env, jclass dummy,
|
||||
jstring classname)
|
||||
{
|
||||
char *clname;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -46,7 +46,7 @@ class EmptyClassHelper {
|
||||
System.out.println(ex.toString());
|
||||
}
|
||||
} else {
|
||||
cls = jla.findBootstrapClassOrNull(appLoader, className);
|
||||
cls = jla.findBootstrapClassOrNull(className);
|
||||
System.out.println("bootLoader loaded class");
|
||||
System.out.println("cls = " + cls);
|
||||
try {
|
||||
|
Loading…
x
Reference in New Issue
Block a user