-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8323832: Load JVMCI with the platform class loader #17520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| /* | ||
| * Copyright (c) 2024, 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 | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. | ||
| * | ||
| * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| * or visit www.oracle.com if you need additional information or have any | ||
| * questions. | ||
| */ | ||
|
|
||
| /* | ||
| * @test | ||
| * @summary Tests that it is possible to load JVMCI classes from a custom class loader and | ||
| * that the loaded class is different than the classes loaded by the platform loader. | ||
| * This test also ensures that only JVMCI classes loaded by the platform loader | ||
| * will have their native methods linked to implementations in the JVM. | ||
| * @modules java.base/jdk.internal.loader:+open | ||
| * @compile alt/ResolvedJavaType.java | ||
| * @compile alt/HotSpotJVMCIRuntime.java | ||
| * @compile alt/CompilerToVM.java | ||
| * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI LoadAlternativeJVMCI | ||
| */ | ||
| import java.io.File; | ||
| import java.net.URL; | ||
| import java.net.URI; | ||
| import java.net.URLClassLoader; | ||
|
|
||
| public class LoadAlternativeJVMCI { | ||
| public static void main(String[] args) throws Exception { | ||
| String[] testClasses = System.getProperty("test.classes").split(File.pathSeparator); | ||
| URL[] cp = new URL[testClasses.length]; | ||
| for (int i = 0; i < testClasses.length; i++) { | ||
| String e = testClasses[i]; | ||
| if (new File(e).isDirectory()) { | ||
| e = e + File.separator; | ||
| } | ||
| cp[i] = new URI("file:" + e).toURL(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be |
||
| } | ||
|
|
||
| ClassLoader pcl = ClassLoader.getPlatformClassLoader(); | ||
| URLClassLoader ucl = new URLClassLoader(cp, null); | ||
|
Comment on lines
+53
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am missing something here, a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. <face-palm> Thanks Doug. |
||
|
|
||
| String[] names = { | ||
| "jdk.vm.ci.meta.ResolvedJavaType", | ||
| "jdk.vm.ci.hotspot.CompilerToVM", | ||
| "jdk.vm.ci.hotspot.HotSpotJVMCIRuntime" | ||
| }; | ||
| for (String name : names) { | ||
| Class<?> customClass = ucl.loadClass(name); | ||
| Class<?> platformClass = pcl.loadClass(name); | ||
| if (customClass.equals(platformClass)) { | ||
| throw new AssertionError(String.format("%s loaded by %s should be distinct from version loaded by %s", | ||
| name, ucl, pcl)); | ||
| } | ||
| Class<?> customClassAgain = ucl.loadClass(name); | ||
| if (!customClassAgain.equals(customClass)) { | ||
| throw new AssertionError(String.format("%s loaded twice by %s should produce the same class", | ||
| name, ucl)); | ||
| } | ||
|
|
||
| if (name.equals("jdk.vm.ci.hotspot.CompilerToVM")) { | ||
| // Detect refactoring of CompilerToVM.registerNatives so that alt/CompilerToVM.java | ||
| // can be adjusted accordingly. | ||
| try { | ||
| platformClass.getDeclaredMethod("registerNatives"); | ||
| } catch (NoSuchMethodException e) { | ||
| throw new AssertionError("missing method in platform JVMCI class: " + e); | ||
| } | ||
|
|
||
| // Only JVMCI classes loaded by the platform class loader can link to native | ||
| // method implementations in HotSpot. | ||
| try { | ||
| Class.forName(name, true, ucl); | ||
| throw new AssertionError("expected UnsatisfiedLinkError"); | ||
| } catch (UnsatisfiedLinkError e) { | ||
| if (!e.getMessage().contains(name + ".registerNatives")) { | ||
| throw new AssertionError("unexpected message: " + e.getMessage()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /* | ||
| * Copyright (c) 2024, 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 | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. | ||
| * | ||
| * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| * or visit www.oracle.com if you need additional information or have any | ||
| * questions. | ||
| */ | ||
| package jdk.vm.ci.hotspot; | ||
|
|
||
| /** | ||
| * Alternative version of CompilerToVM | ||
| * @see LoadAlternativeJVMCI | ||
| */ | ||
| public class CompilerToVM { | ||
|
|
||
| private static native void registerNatives(); | ||
|
|
||
| static { | ||
| registerNatives(); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * Copyright (c) 2024, 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 | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. | ||
| * | ||
| * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| * or visit www.oracle.com if you need additional information or have any | ||
| * questions. | ||
| */ | ||
| package jdk.vm.ci.hotspot; | ||
|
|
||
| /** | ||
| * Alternative version of HotSpotJVMCIRuntime | ||
| * @see LoadAlternativeJVMCI | ||
| */ | ||
| public class HotSpotJVMCIRuntime { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * Copyright (c) 2024, 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 | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. | ||
| * | ||
| * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| * or visit www.oracle.com if you need additional information or have any | ||
| * questions. | ||
| */ | ||
| package jdk.vm.ci.meta; | ||
|
|
||
| /** | ||
| * Alternative version of HotSpotJVMCIRuntime | ||
| * @see LoadAlternativeJVMCI | ||
| */ | ||
| public class ResolvedJavaType { | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is required as JVMCI is no longer loaded by the boot loader but should retain all permissions.