RFR: 8323832: Load JVMCI with the platform class loader [v2]
xxDark
duke at openjdk.org
Wed Jan 24 12:19:27 UTC 2024
On Wed, 24 Jan 2024 08:56:10 GMT, Doug Simon <dnsimon at openjdk.org> wrote:
> > I'm still puzzled by the need to do this as any non-delegating classloader would have allowed this even if JVMCI were loaded by the bootloader.
>
> As far as I understand, even a non-delegating classloader cannot redefine a class loaded by the boot loader. I modified the test to show this and get:
>
> ```
> java.lang.LinkageError: loader LoadAlternativeJVMCI$1 @4a1f4d08 attempted duplicate class definition for jdk.vm.ci.meta.ResolvedJavaType. (jdk.vm.ci.meta.ResolvedJavaType is in unnamed module of loader LoadAlternativeJVMCI$1 @4a1f4d08, parent loader 'bootstrap')
> at java.base/java.lang.ClassLoader.defineClass1(Native Method)
> at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1023)
> at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
> at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:524)
> at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:427)
> at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:421)
> at java.base/java.security.AccessController.doPrivileged(AccessController.java:714)
> at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:420)
> at LoadAlternativeJVMCI$1.loadClass(LoadAlternativeJVMCI.java:61)
> at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
> at LoadAlternativeJVMCI.main(LoadAlternativeJVMCI.java:77)
> at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
> at java.base/java.lang.reflect.Method.invoke(Method.java:580)
> at com.sun.javatest.regtest.agent.MainWrapper$MainTask.run(MainWrapper.java:138)
> at java.base/java.lang.Thread.run(Thread.java:1575)
> ```
>
> Test modification:
>
> ```
> diff --git a/test/hotspot/jtreg/compiler/jvmci/LoadAlternativeJVMCI.java b/test/hotspot/jtreg/compiler/jvmci/LoadAlternativeJVMCI.java
> index dd63867e7c2..28a6fedca38 100644
> --- a/test/hotspot/jtreg/compiler/jvmci/LoadAlternativeJVMCI.java
> +++ b/test/hotspot/jtreg/compiler/jvmci/LoadAlternativeJVMCI.java
> @@ -51,7 +51,14 @@ public static void main(String[] args) throws Exception {
> }
>
> ClassLoader pcl = ClassLoader.getPlatformClassLoader();
> - URLClassLoader ucl = new URLClassLoader(cp, null);
> + URLClassLoader ucl = new URLClassLoader(cp, null) {
> + protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
> + if (!name.startsWith("jdk.vm.ci")) {
> + return super.loadClass(name, resolve);
> + }
> + return findClass(name);
> + }
> + };
>
> String[] names = {
> "jdk.vm.ci.meta.ResolvedJavaType",
> ```
It can. You need to check if class is already loaded by trying `findLoadedClass` first.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/17520#issuecomment-1908013421
More information about the core-libs-dev
mailing list