# HG changeset patch # User Doug Simon # Date 1466094183 -7200 # Node ID 93be30973b26b53bb3c63b24840508fb48fa170a # Parent 4a8e3af4a0b13bb65461d463896dd8414becb98c don't crash if Services is used but -XX:-EnableJVMCI - just return null diff -r 4a8e3af4a0b1 -r 93be30973b26 jvmci/jdk.vm.ci.services/src/jdk/vm/ci/services/Services.java --- a/jvmci/jdk.vm.ci.services/src/jdk/vm/ci/services/Services.java Thu Jun 16 11:25:15 2016 +0200 +++ b/jvmci/jdk.vm.ci.services/src/jdk/vm/ci/services/Services.java Thu Jun 16 18:23:03 2016 +0200 @@ -40,34 +40,26 @@ private Services() { } - private static final String SUPPRESS_PROPERTY_NAME = "jvmci.service.suppressNoClassDefFoundError"; - - /** - * Determines whether to suppress the {@link NoClassDefFoundError} raised if a service provider - * class specified in a {@code /jvmci/services/*} file is missing. - */ - private static final boolean SuppressNoClassDefFoundError = Boolean.getBoolean(SUPPRESS_PROPERTY_NAME); + private static boolean jvmciEnabled = true; private static final ClassValue> cache = new ClassValue>() { @Override protected List computeValue(Class type) { - try { - List impls = new ArrayList<>(); - for (Object impl : ServiceLoader.load(type, getJVMCIClassLoader())) { - impls.add(impl); - } - return impls; - } catch (NoClassDefFoundError e) { - if (SuppressNoClassDefFoundError) { - return Collections.emptyList(); - } else { - NoClassDefFoundError newEx = new NoClassDefFoundError(e.getMessage() + " (suppress with -D" + SUPPRESS_PROPERTY_NAME + "=true)"); - if (e.getCause() != null) { - newEx.initCause(e.getCause()); + List impls = new ArrayList<>(); + if (jvmciEnabled) { + try { + for (Object impl : ServiceLoader.load(type, getJVMCIClassLoader())) { + impls.add(impl); } - throw newEx; + } catch (InternalError e) { + if (e.getMessage().equals("JVMCI is not enabled")) { + jvmciEnabled = false; + } else { + throw e; + } } } + return impls; } }; @@ -151,5 +143,11 @@ Reflection.registerFieldsToFilter(Services.class, "cache"); } + /** + * 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 native ClassLoader getJVMCIClassLoader(); } diff -r 4a8e3af4a0b1 -r 93be30973b26 src/share/vm/jvmci/jvmciRuntime.cpp --- a/src/share/vm/jvmci/jvmciRuntime.cpp Thu Jun 16 11:25:15 2016 +0200 +++ b/src/share/vm/jvmci/jvmciRuntime.cpp Thu Jun 16 18:23:03 2016 +0200 @@ -623,6 +623,9 @@ // private static ClassLoader Services.getJVMCIClassLoader() JVM_ENTRY(jobject, JVM_GetJVMCIClassLoader(JNIEnv *env, jclass c)) if (!EnableJVMCI) { + // This message must not change - it is used by the Java code to + // distinguish an InternalError due to -EnableJVMCI from other + // InternalErrors that may be raised below. THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "JVMCI is not enabled") } JVMCIRuntime::ensure_jvmci_class_loader_is_initialized();