diff --git a/src/hotspot/share/jvmci/jvmciCompiler.cpp b/src/hotspot/share/jvmci/jvmciCompiler.cpp index 38bf9c438e7d0..cf70e251b1429 100644 --- a/src/hotspot/share/jvmci/jvmciCompiler.cpp +++ b/src/hotspot/share/jvmci/jvmciCompiler.cpp @@ -48,7 +48,7 @@ JVMCICompiler::JVMCICompiler() : AbstractCompiler(compiler_jvmci) { JVMCICompiler* JVMCICompiler::instance(bool require_non_null, TRAPS) { if (!EnableJVMCI) { - THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "JVMCI is not enabled") + THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), JVMCI_NOT_ENABLED_ERROR_MESSAGE) } if (_instance == nullptr && require_non_null) { THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "The JVMCI compiler instance has not been created"); diff --git a/src/hotspot/share/jvmci/jvmciRuntime.cpp b/src/hotspot/share/jvmci/jvmciRuntime.cpp index 6f1fa52576e41..f02ef57de3486 100644 --- a/src/hotspot/share/jvmci/jvmciRuntime.cpp +++ b/src/hotspot/share/jvmci/jvmciRuntime.cpp @@ -720,7 +720,7 @@ JRT_END JVM_ENTRY_NO_ENV(jobject, JVM_GetJVMCIRuntime(JNIEnv *libjvmciOrHotspotEnv, jclass c)) JVMCIENV_FROM_JNI(thread, libjvmciOrHotspotEnv); if (!EnableJVMCI) { - JVMCI_THROW_MSG_NULL(InternalError, "JVMCI is not enabled"); + JVMCI_THROW_MSG_NULL(InternalError, JVMCI_NOT_ENABLED_ERROR_MESSAGE); } JVMCIENV->runtime()->initialize_HotSpotJVMCIRuntime(JVMCI_CHECK_NULL); JVMCIObject runtime = JVMCIENV->runtime()->get_HotSpotJVMCIRuntime(JVMCI_CHECK_NULL); @@ -732,7 +732,7 @@ JVM_END JVM_ENTRY_NO_ENV(jlong, JVM_ReadSystemPropertiesInfo(JNIEnv *env, jclass c, jintArray offsets_handle)) JVMCIENV_FROM_JNI(thread, env); if (!EnableJVMCI) { - JVMCI_THROW_MSG_0(InternalError, "JVMCI is not enabled"); + JVMCI_THROW_MSG_0(InternalError, JVMCI_NOT_ENABLED_ERROR_MESSAGE); } JVMCIPrimitiveArray offsets = JVMCIENV->wrap(offsets_handle); JVMCIENV->put_int_at(offsets, 0, SystemProperty::next_offset_in_bytes()); @@ -1515,7 +1515,7 @@ JVM_ENTRY_NO_ENV(void, JVM_RegisterJVMCINatives(JNIEnv *libjvmciOrHotspotEnv, jc JVMCIENV_FROM_JNI(thread, libjvmciOrHotspotEnv); if (!EnableJVMCI) { - JVMCI_THROW_MSG(InternalError, "JVMCI is not enabled"); + JVMCI_THROW_MSG(InternalError, JVMCI_NOT_ENABLED_ERROR_MESSAGE); } JVMCIENV->runtime()->initialize(JVMCIENV); diff --git a/src/hotspot/share/jvmci/jvmciRuntime.hpp b/src/hotspot/share/jvmci/jvmciRuntime.hpp index 884d11f792e2a..c35813eb16ffc 100644 --- a/src/hotspot/share/jvmci/jvmciRuntime.hpp +++ b/src/hotspot/share/jvmci/jvmciRuntime.hpp @@ -35,6 +35,8 @@ #include "gc/g1/g1CardTable.hpp" #endif // INCLUDE_G1GC +#define JVMCI_NOT_ENABLED_ERROR_MESSAGE "JVMCI is not enabled. Must specify '-XX:+EnableJVMCI' or '--add-modules=jdk.internal.vm.ci' to the java launcher." + class JVMCIEnv; class JVMCICompiler; class JVMCICompileState; diff --git a/src/hotspot/share/jvmci/jvmci_globals.hpp b/src/hotspot/share/jvmci/jvmci_globals.hpp index 5bcead9ff7b32..a81391af96a44 100644 --- a/src/hotspot/share/jvmci/jvmci_globals.hpp +++ b/src/hotspot/share/jvmci/jvmci_globals.hpp @@ -45,7 +45,16 @@ class fileStream; constraint) \ \ product(bool, EnableJVMCI, false, EXPERIMENTAL, \ - "Enable JVMCI. Defaults to true if UseJVMCICompiler is true.") \ + "Enable JVMCI support in the VM. " \ + "Defaults to true if UseJVMCICompiler is true or " \ + "--add-modules=jdk.internal.vm.ci was specified. " \ + "The behavior of --add-modules=jdk.internal.vm.ci is triggered " \ + "if any of the following is true: " \ + "1. -XX:+EnableJVMCI is set to true on the command line. " \ + "2. -XX:+EnableJVMCI is set to true by jdk/internal/vm/options " \ + " in the java.base module. " \ + "3. EnableJVMCI is defaulted to true by UseJVMCICompiler and " \ + " libjvmci is not enabled") \ \ product(bool, UseGraalJIT, false, EXPERIMENTAL, \ "Select the Graal JVMCI compiler. This is an alias for: " \ diff --git a/src/hotspot/share/runtime/arguments.cpp b/src/hotspot/share/runtime/arguments.cpp index 69d37a11e45ab..bf927564abbe3 100644 --- a/src/hotspot/share/runtime/arguments.cpp +++ b/src/hotspot/share/runtime/arguments.cpp @@ -85,6 +85,9 @@ int Arguments::_num_jvm_flags = 0; char** Arguments::_jvm_args_array = nullptr; int Arguments::_num_jvm_args = 0; unsigned int Arguments::_addmods_count = 0; +#if INCLUDE_JVMCI +bool Arguments::_jvmci_module_added = false; +#endif char* Arguments::_java_command = nullptr; SystemProperty* Arguments::_system_properties = nullptr; size_t Arguments::_conservative_max_heap_alignment = 0; @@ -1798,9 +1801,9 @@ bool Arguments::check_vm_args_consistency() { status = CompilerConfig::check_args_consistency(status); #if INCLUDE_JVMCI if (status && EnableJVMCI) { - PropertyList_unique_add(&_system_properties, "jdk.internal.vm.ci.enabled", "true", - AddProperty, UnwriteableProperty, InternalProperty); - if (ClassLoader::is_module_observable("jdk.internal.vm.ci")) { + // Add the JVMCI module if not using libjvmci or EnableJVMCI + // was explicitly set on the command line or in the jimage. + if ((!UseJVMCINativeLibrary || FLAG_IS_CMDLINE(EnableJVMCI) || FLAG_IS_JIMAGE_RESOURCE(EnableJVMCI)) && ClassLoader::is_module_observable("jdk.internal.vm.ci") && !_jvmci_module_added) { if (!create_numbered_module_property("jdk.module.addmods", "jdk.internal.vm.ci", _addmods_count++)) { return false; } @@ -2247,6 +2250,19 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, JVMFlagOrigin if (!create_numbered_module_property("jdk.module.addmods", tail, _addmods_count++)) { return JNI_ENOMEM; } +#if INCLUDE_JVMCI + if (!_jvmci_module_added) { + const char *jvmci_module = strstr(tail, "jdk.internal.vm.ci"); + if (jvmci_module != nullptr) { + char before = *(jvmci_module - 1); + char after = *(jvmci_module + strlen("jdk.internal.vm.ci")); + if ((before == '=' || before == ',') && (after == '\0' || after == ',')) { + FLAG_SET_DEFAULT(EnableJVMCI, true); + _jvmci_module_added = true; + } + } + } +#endif } else if (match_option(option, "--enable-native-access=", &tail)) { if (!create_numbered_module_property("jdk.module.enable.native.access", tail, enable_native_access_count++)) { return JNI_ENOMEM; diff --git a/src/hotspot/share/runtime/arguments.hpp b/src/hotspot/share/runtime/arguments.hpp index a18996f85e805..55667df2c591f 100644 --- a/src/hotspot/share/runtime/arguments.hpp +++ b/src/hotspot/share/runtime/arguments.hpp @@ -197,6 +197,10 @@ class Arguments : AllStatic { static char* _java_command; // number of unique modules specified in the --add-modules option static unsigned int _addmods_count; +#if INCLUDE_JVMCI + // was jdk.internal.vm.ci module specified in the --add-modules option? + static bool _jvmci_module_added; +#endif // Property list static SystemProperty* _system_properties; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/JVMCIServiceLocator.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/JVMCIServiceLocator.java index 265b8c24f3e23..d5ff0bba9b300 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/JVMCIServiceLocator.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/JVMCIServiceLocator.java @@ -59,7 +59,6 @@ private JVMCIServiceLocator(Void ignore) { */ protected JVMCIServiceLocator() { this(checkPermission()); - Services.checkJVMCIEnabled(); Services.openJVMCITo(getClass().getModule()); } @@ -85,7 +84,6 @@ protected JVMCIServiceLocator() { * {@link JVMCIPermission} */ public static List getProviders(Class service) { - Services.checkJVMCIEnabled(); @SuppressWarnings("removal") SecurityManager sm = System.getSecurityManager(); if (sm != null) { diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/Services.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/Services.java index d16a788eb1476..22f8eec7d120f 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/Services.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/Services.java @@ -64,17 +64,6 @@ private Services() { */ private static volatile Map savedProperties; - static final boolean JVMCI_ENABLED = Boolean.parseBoolean(VM.getSavedProperties().get("jdk.internal.vm.ci.enabled")); - - /** - * Checks that JVMCI is enabled in the VM and throws an error if it isn't. - */ - static void checkJVMCIEnabled() { - if (!JVMCI_ENABLED) { - throw new Error("The EnableJVMCI VM option must be true (i.e., -XX:+EnableJVMCI) to use JVMCI"); - } - } - /** * Gets an unmodifiable copy of the system properties as of VM startup. * @@ -84,7 +73,6 @@ static void checkJVMCIEnabled() { * on the command line are ignored. */ public static Map getSavedProperties() { - checkJVMCIEnabled(); if (savedProperties == null) { synchronized (Services.class) { if (savedProperties == null) { @@ -113,7 +101,6 @@ public static String getSavedProperty(String name) { * Causes the JVMCI subsystem to be initialized if it isn't already initialized. */ public static void initializeJVMCI() { - checkJVMCIEnabled(); try { Class.forName("jdk.vm.ci.runtime.JVMCI"); } catch (ClassNotFoundException e) {