# HG changeset patch # User dnsimon # Date 1574712500 28800 # Node ID 06970ab040d4f26d2e16349c28d4e668d8221ca9 # Parent 4cf1246fbb9cd41513c91673927fc6a55a934a66 8234681: Remove UseJVMCIClassLoader logic from JVMCI code Reviewed-by: kvn, iignatyev diff -r 4cf1246fbb9c -r 06970ab040d4 src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.services/src/jdk/vm/ci/services/Services.java --- a/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.services/src/jdk/vm/ci/services/Services.java Mon Nov 25 20:18:54 2019 +0100 +++ b/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.services/src/jdk/vm/ci/services/Services.java Mon Nov 25 12:08:20 2019 -0800 @@ -37,7 +37,6 @@ import java.util.Set; import jdk.internal.misc.VM; -import jdk.internal.reflect.Reflection; /** * Provides utilities needed by JVMCI clients. @@ -136,29 +135,6 @@ } } - private static boolean jvmciEnabled = true; - - /** - * When {@code -XX:-UseJVMCIClassLoader} is in use, JVMCI classes are loaded via the boot class - * loader. When {@code null} is the second argument to - * {@link ServiceLoader#load(Class, ClassLoader)}, service lookup will use the system class - * loader and thus find application classes which violates the API of {@link #load} and - * {@link #loadSingle}. To avoid this, a class loader that simply delegates to the boot class - * loader is used. - */ - static class LazyBootClassPath { - static final ClassLoader bootClassPath = new ClassLoader(null) { - }; - } - - private static ClassLoader findBootClassLoaderChild(ClassLoader start) { - ClassLoader cl = start; - while (cl.getParent() != null) { - cl = cl.getParent(); - } - return cl; - } - private static final Map, List> servicesCache = IS_BUILDING_NATIVE_IMAGE ? new HashMap<>() : null; @SuppressWarnings("unchecked") @@ -173,33 +149,7 @@ } } - Iterable providers = Collections.emptyList(); - if (jvmciEnabled) { - ClassLoader cl = null; - try { - cl = getJVMCIClassLoader(); - if (cl == null) { - cl = LazyBootClassPath.bootClassPath; - // JVMCI classes are loaded via the boot class loader. - // If we use null as the second argument to ServiceLoader.load, - // service loading will use the system class loader - // and find classes on the application class path. Since we - // don't want this, we use a loader that is as close to the - // boot class loader as possible (since it is impossible - // to force service loading to use only the boot class loader). - cl = findBootClassLoaderChild(ClassLoader.getSystemClassLoader()); - } - providers = ServiceLoader.load(service, cl); - } catch (UnsatisfiedLinkError e) { - jvmciEnabled = false; - } catch (InternalError e) { - if (e.getMessage().equals("JVMCI is not enabled")) { - jvmciEnabled = false; - } else { - throw e; - } - } - } + Iterable providers = ServiceLoader.load(service, ClassLoader.getSystemClassLoader()); if (IS_BUILDING_NATIVE_IMAGE) { synchronized (servicesCache) { ArrayList providersList = new ArrayList<>(); @@ -278,23 +228,6 @@ return singleProvider; } - static { - Reflection.registerMethodsToFilter(Services.class, Set.of("getJVMCIClassLoader")); - } - - /** - * Gets the JVMCI class loader. - * - * @throws InternalError with the {@linkplain Throwable#getMessage() message} - * {@code "JVMCI is not enabled"} iff JVMCI is not enabled - */ - private static ClassLoader getJVMCIClassLoader() { - if (IS_IN_NATIVE_IMAGE) { - return null; - } - return ClassLoader.getSystemClassLoader(); - } - /** * A Java {@code char} has a maximal UTF8 length of 3. */