Mercurial > hg > graal-jvmci-8
changeset 23692:93be30973b26
don't crash if Services is used but -XX:-EnableJVMCI - just return null
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 16 Jun 2016 18:23:03 +0200 |
parents | 4a8e3af4a0b1 |
children | 0d09e13523b4 |
files | jvmci/jdk.vm.ci.services/src/jdk/vm/ci/services/Services.java src/share/vm/jvmci/jvmciRuntime.cpp |
diffstat | 2 files changed, 22 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- 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 <jre>/jvmci/services/*} file is missing. - */ - private static final boolean SuppressNoClassDefFoundError = Boolean.getBoolean(SUPPRESS_PROPERTY_NAME); + private static boolean jvmciEnabled = true; private static final ClassValue<List<?>> cache = new ClassValue<List<?>>() { @Override protected List<?> computeValue(Class<?> type) { - try { - List<Object> 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<Object> 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(); }
--- 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();