Skip to content

Commit 8153683

Browse files
author
Doug Simon
committed
8345826: Do not automatically resolve jdk.internal.vm.ci when libgraal is used
Reviewed-by: iklam, never, kvn
1 parent 400c935 commit 8153683

File tree

8 files changed

+39
-23
lines changed

8 files changed

+39
-23
lines changed

src/hotspot/share/jvmci/jvmciCompiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ JVMCICompiler::JVMCICompiler() : AbstractCompiler(compiler_jvmci) {
4848

4949
JVMCICompiler* JVMCICompiler::instance(bool require_non_null, TRAPS) {
5050
if (!EnableJVMCI) {
51-
THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "JVMCI is not enabled")
51+
THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), JVMCI_NOT_ENABLED_ERROR_MESSAGE)
5252
}
5353
if (_instance == nullptr && require_non_null) {
5454
THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "The JVMCI compiler instance has not been created");

src/hotspot/share/jvmci/jvmciRuntime.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ JRT_END
720720
JVM_ENTRY_NO_ENV(jobject, JVM_GetJVMCIRuntime(JNIEnv *libjvmciOrHotspotEnv, jclass c))
721721
JVMCIENV_FROM_JNI(thread, libjvmciOrHotspotEnv);
722722
if (!EnableJVMCI) {
723-
JVMCI_THROW_MSG_NULL(InternalError, "JVMCI is not enabled");
723+
JVMCI_THROW_MSG_NULL(InternalError, JVMCI_NOT_ENABLED_ERROR_MESSAGE);
724724
}
725725
JVMCIENV->runtime()->initialize_HotSpotJVMCIRuntime(JVMCI_CHECK_NULL);
726726
JVMCIObject runtime = JVMCIENV->runtime()->get_HotSpotJVMCIRuntime(JVMCI_CHECK_NULL);
@@ -732,7 +732,7 @@ JVM_END
732732
JVM_ENTRY_NO_ENV(jlong, JVM_ReadSystemPropertiesInfo(JNIEnv *env, jclass c, jintArray offsets_handle))
733733
JVMCIENV_FROM_JNI(thread, env);
734734
if (!EnableJVMCI) {
735-
JVMCI_THROW_MSG_0(InternalError, "JVMCI is not enabled");
735+
JVMCI_THROW_MSG_0(InternalError, JVMCI_NOT_ENABLED_ERROR_MESSAGE);
736736
}
737737
JVMCIPrimitiveArray offsets = JVMCIENV->wrap(offsets_handle);
738738
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
15151515
JVMCIENV_FROM_JNI(thread, libjvmciOrHotspotEnv);
15161516

15171517
if (!EnableJVMCI) {
1518-
JVMCI_THROW_MSG(InternalError, "JVMCI is not enabled");
1518+
JVMCI_THROW_MSG(InternalError, JVMCI_NOT_ENABLED_ERROR_MESSAGE);
15191519
}
15201520

15211521
JVMCIENV->runtime()->initialize(JVMCIENV);

src/hotspot/share/jvmci/jvmciRuntime.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#include "gc/g1/g1CardTable.hpp"
3636
#endif // INCLUDE_G1GC
3737

38+
#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."
39+
3840
class JVMCIEnv;
3941
class JVMCICompiler;
4042
class JVMCICompileState;

src/hotspot/share/jvmci/jvmci_globals.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,16 @@ class fileStream;
4545
constraint) \
4646
\
4747
product(bool, EnableJVMCI, false, EXPERIMENTAL, \
48-
"Enable JVMCI. Defaults to true if UseJVMCICompiler is true.") \
48+
"Enable JVMCI support in the VM. " \
49+
"Defaults to true if UseJVMCICompiler is true or " \
50+
"--add-modules=jdk.internal.vm.ci was specified. " \
51+
"The behavior of --add-modules=jdk.internal.vm.ci is triggered " \
52+
"if any of the following is true: " \
53+
"1. -XX:+EnableJVMCI is set to true on the command line. " \
54+
"2. -XX:+EnableJVMCI is set to true by jdk/internal/vm/options " \
55+
" in the java.base module. " \
56+
"3. EnableJVMCI is defaulted to true by UseJVMCICompiler and " \
57+
" libjvmci is not enabled") \
4958
\
5059
product(bool, UseGraalJIT, false, EXPERIMENTAL, \
5160
"Select the Graal JVMCI compiler. This is an alias for: " \

src/hotspot/share/runtime/arguments.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ int Arguments::_num_jvm_flags = 0;
8686
char** Arguments::_jvm_args_array = nullptr;
8787
int Arguments::_num_jvm_args = 0;
8888
unsigned int Arguments::_addmods_count = 0;
89+
#if INCLUDE_JVMCI
90+
bool Arguments::_jvmci_module_added = false;
91+
#endif
8992
char* Arguments::_java_command = nullptr;
9093
SystemProperty* Arguments::_system_properties = nullptr;
9194
size_t Arguments::_conservative_max_heap_alignment = 0;
@@ -1799,9 +1802,9 @@ bool Arguments::check_vm_args_consistency() {
17991802
status = CompilerConfig::check_args_consistency(status);
18001803
#if INCLUDE_JVMCI
18011804
if (status && EnableJVMCI) {
1802-
PropertyList_unique_add(&_system_properties, "jdk.internal.vm.ci.enabled", "true",
1803-
AddProperty, UnwriteableProperty, InternalProperty);
1804-
if (ClassLoader::is_module_observable("jdk.internal.vm.ci")) {
1805+
// Add the JVMCI module if not using libjvmci or EnableJVMCI
1806+
// was explicitly set on the command line or in the jimage.
1807+
if ((!UseJVMCINativeLibrary || FLAG_IS_CMDLINE(EnableJVMCI) || FLAG_IS_JIMAGE_RESOURCE(EnableJVMCI)) && ClassLoader::is_module_observable("jdk.internal.vm.ci") && !_jvmci_module_added) {
18051808
if (!create_numbered_module_property("jdk.module.addmods", "jdk.internal.vm.ci", _addmods_count++)) {
18061809
return false;
18071810
}
@@ -2248,6 +2251,19 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, JVMFlagOrigin
22482251
if (!create_numbered_module_property("jdk.module.addmods", tail, _addmods_count++)) {
22492252
return JNI_ENOMEM;
22502253
}
2254+
#if INCLUDE_JVMCI
2255+
if (!_jvmci_module_added) {
2256+
const char *jvmci_module = strstr(tail, "jdk.internal.vm.ci");
2257+
if (jvmci_module != nullptr) {
2258+
char before = *(jvmci_module - 1);
2259+
char after = *(jvmci_module + strlen("jdk.internal.vm.ci"));
2260+
if ((before == '=' || before == ',') && (after == '\0' || after == ',')) {
2261+
FLAG_SET_DEFAULT(EnableJVMCI, true);
2262+
_jvmci_module_added = true;
2263+
}
2264+
}
2265+
}
2266+
#endif
22512267
} else if (match_option(option, "--enable-native-access=", &tail)) {
22522268
if (!create_numbered_module_property("jdk.module.enable.native.access", tail, enable_native_access_count++)) {
22532269
return JNI_ENOMEM;

src/hotspot/share/runtime/arguments.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ class Arguments : AllStatic {
197197
static char* _java_command;
198198
// number of unique modules specified in the --add-modules option
199199
static unsigned int _addmods_count;
200+
#if INCLUDE_JVMCI
201+
// was jdk.internal.vm.ci module specified in the --add-modules option?
202+
static bool _jvmci_module_added;
203+
#endif
200204

201205
// Property list
202206
static SystemProperty* _system_properties;

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/JVMCIServiceLocator.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ private JVMCIServiceLocator(Void ignore) {
5959
*/
6060
protected JVMCIServiceLocator() {
6161
this(checkPermission());
62-
Services.checkJVMCIEnabled();
6362
Services.openJVMCITo(getClass().getModule());
6463
}
6564

@@ -85,7 +84,6 @@ protected JVMCIServiceLocator() {
8584
* {@link JVMCIPermission}
8685
*/
8786
public static <S> List<S> getProviders(Class<S> service) {
88-
Services.checkJVMCIEnabled();
8987
@SuppressWarnings("removal")
9088
SecurityManager sm = System.getSecurityManager();
9189
if (sm != null) {

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/services/Services.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,6 @@ private Services() {
6464
*/
6565
private static volatile Map<String, String> savedProperties;
6666

67-
static final boolean JVMCI_ENABLED = Boolean.parseBoolean(VM.getSavedProperties().get("jdk.internal.vm.ci.enabled"));
68-
69-
/**
70-
* Checks that JVMCI is enabled in the VM and throws an error if it isn't.
71-
*/
72-
static void checkJVMCIEnabled() {
73-
if (!JVMCI_ENABLED) {
74-
throw new Error("The EnableJVMCI VM option must be true (i.e., -XX:+EnableJVMCI) to use JVMCI");
75-
}
76-
}
77-
7867
/**
7968
* Gets an unmodifiable copy of the system properties as of VM startup.
8069
*
@@ -84,7 +73,6 @@ static void checkJVMCIEnabled() {
8473
* on the command line are ignored.
8574
*/
8675
public static Map<String, String> getSavedProperties() {
87-
checkJVMCIEnabled();
8876
if (savedProperties == null) {
8977
synchronized (Services.class) {
9078
if (savedProperties == null) {
@@ -113,7 +101,6 @@ public static String getSavedProperty(String name) {
113101
* Causes the JVMCI subsystem to be initialized if it isn't already initialized.
114102
*/
115103
public static void initializeJVMCI() {
116-
checkJVMCIEnabled();
117104
try {
118105
Class.forName("jdk.vm.ci.runtime.JVMCI");
119106
} catch (ClassNotFoundException e) {

0 commit comments

Comments
 (0)