Skip to content

Commit 566e30a

Browse files
committed
replace +EnableJVMCI with --add-modules=jdk.internal.vm.ci
1 parent 4e53f71 commit 566e30a

File tree

6 files changed

+77
-75
lines changed

6 files changed

+77
-75
lines changed

docs/reference-manual/embedding/embed-languages.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,15 +415,17 @@ This table shows the level of optimizations the Java runtimes currently provide:
415415
|-----------------------------------------------|---------------------------------------------------|
416416
| Oracle GraalVM | Optimized with additional compiler passes |
417417
| GraalVM Community Edition | Optimized |
418-
| Oracle JDK | Optimized if enabled via experimental VM option |
419-
| OpenJDK | Optimized if enabled via experimental VM option |
418+
| Oracle JDK | Optimized via VM option |
419+
| OpenJDK | Optimized via VM option and upgrade-module-path |
420420
| JDK without JVMCI capability | No runtime optimizations (interpreter-only) |
421421
422422
### Explanations
423423
424424
* **Optimized:** Executed guest application code can be compiled and executed as highly efficient machine code at run time.
425425
* **Optimized with additional compiler passes:** Oracle GraalVM implements additional optimizations performed during runtime compilation. For example, it uses a more advanced inlining heuristic. This typically leads to better runtime performance and memory consumption.
426-
* **Optimized if enabled via experimental VM option:** Optimization is not enabled by default and must be enabled using `-XX:+EnableJVMCI` virtual machine option. In addition, to support compilation, the Graal compiler must be downloaded as a JAR file and put on the `--upgrade-module-path`. In this mode, the compiler runs as a Java application and may negatively affect the execution performance of the host application.
426+
* **Optimized via VM option:** Optimization is enabled by specifying `-XX:+EnableJVMCI` to the `java` launcher.
427+
* **Optimized via VM option and upgrade-module-path:** Optimization is enabled by specifying `-XX:+EnableJVMCI` to the `java` launcher.
428+
In addition, the Graal compiler must be downloaded as a JAR file and put on the `--upgrade-module-path`. In this mode, the compiler runs as a Java application and may negatively affect the execution performance of the host application.
427429
* **No runtime optimizations:** With no runtime optimizations or if JVMCI is not enabled, the guest application code is executed in interpreter-only mode.
428430
* **JVMCI:** Refers to the [Java-Level JVM Compiler Interface](https://openjdk.org/jeps/243) supported by most Java runtimes.
429431

sdk/mx.sdk/mx_sdk.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,7 @@ def __init__(self):
273273
# Oracle JDK includes the libjvmci compiler, allowing it to function as GraalVM.
274274
# However, the Graal compiler is disabled by default and must be explicitly enabled using the -XX:+UseJVMCICompiler option.
275275
graalvm_home = default_jdk.home
276-
# GR-58388: Switch '-XX:+UseJVMCINativeLibrary' to '-XX:+UseGraalJIT'
277-
additional_vm_args = ['-XX:+UnlockExperimentalVMOptions', '-XX:+EnableJVMCI', '-XX:+UseJVMCINativeLibrary', '-XX:-UnlockExperimentalVMOptions']
276+
additional_vm_args = ['-XX:+UnlockExperimentalVMOptions', '-XX:+UseGraalJIT', '-XX:-UnlockExperimentalVMOptions']
278277
else:
279278
graalvm_home = mx_sdk_vm.graalvm_home(fatalIfMissing=True)
280279
additional_vm_args = []

sdk/mx.sdk/mx_sdk_vm.py

Lines changed: 61 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -619,29 +619,21 @@ def get_JVMCIThreadsPerNativeLibraryRuntime(jdk):
619619
def _probe_jlink_info(jdk, attribute_name):
620620
"""
621621
Determines if the jlink executable in `jdk` supports various options such
622-
as those added by JDK-8232080 and JDK-8237467.
622+
as those added by JDK-8237467.
623623
"""
624-
if not hasattr(jdk, '.supports_JDK_8232080'):
624+
if not hasattr(jdk, '.supports_JDK_8237467'):
625625
output = mx.OutputCapture()
626626
jlink_exe = jdk.javac.replace('javac', 'jlink')
627627
mx.run([jlink_exe, '--list-plugins'], out=output)
628-
setattr(jdk, '.supports_JDK_8232080', '--add-options=' in output.data or '--add-options ' in output.data)
629-
setattr(jdk, '.supports_save_jlink_argfiles', '--save-jlink-argfiles=' in output.data or '--save-jlink-argfiles ' in output.data)
628+
setattr(jdk, '.supports_JDK_8237467', '--save-jlink-argfiles=' in output.data or '--save-jlink-argfiles ' in output.data)
630629
setattr(jdk, '.supports_copy_files', '--copy-files=' in output.data or '--copy-files ' in output.data)
631630
return getattr(jdk, attribute_name)
632631

633-
def jlink_supports_8232080(jdk):
634-
"""
635-
Determines if the jlink executable in `jdk` supports ``--add-options`` and
636-
``--vendor-[bug-url|vm-bug-url|version]`` added by JDK-8232080.
637-
"""
638-
return _probe_jlink_info(jdk, '.supports_JDK_8232080')
639-
640632
def jlink_has_save_jlink_argfiles(jdk):
641633
"""
642634
Determines if the jlink executable in `jdk` supports ``--save-jlink-argfiles``.
643635
"""
644-
return _probe_jlink_info(jdk, '.supports_save_jlink_argfiles')
636+
return _probe_jlink_info(jdk, '.supports_JDK_8237467')
645637

646638
def _jdk_omits_warning_for_jlink_set_ThreadPriorityPolicy(jdk): # pylint: disable=invalid-name
647639
"""
@@ -813,62 +805,62 @@ def _get_image_vm_options(jdk, use_upgrade_module_path, modules, synthetic_modul
813805
:return list: the list of VM options to cook into the image
814806
"""
815807
vm_options = []
816-
if jlink_supports_8232080(jdk):
817-
if mx.get_env('CONTINUOUS_INTEGRATION', None) == 'true':
818-
is_gate = mx.get_env('BUILD_TARGET', None) == 'gate'
819-
is_bench = 'bench-' in mx.get_env('BUILD_NAME', '')
820-
if is_gate or is_bench:
821-
# For gate and benchmark jobs, we want to know about each compilation failure
822-
# but only exit the VM on systemic compilation failure for gate jobs.
823-
vm_options.append('-Djdk.graal.CompilationFailureAction=Diagnose')
824-
mx.log('Adding -Djdk.graal.CompilationFailureAction=Diagnose VM option to image')
825-
if is_gate:
826-
mx.log('Adding -Djdk.graal.SystemicCompilationFailureRate=-1 VM option to image')
827-
vm_options.append('-Djdk.graal.SystemicCompilationFailureRate=-1')
828-
829-
if use_upgrade_module_path or _jdk_omits_warning_for_jlink_set_ThreadPriorityPolicy(jdk):
830-
vm_options.append('-XX:ThreadPriorityPolicy=1')
831-
else:
832-
mx.logv('[Creating JDK without -XX:ThreadPriorityPolicy=1]')
833-
834-
if jdk_supports_enablejvmciproduct(jdk):
835-
non_synthetic_modules = [m.name for m in modules if m not in synthetic_modules]
836-
if default_to_jvmci or 'jdk.graal.compiler' in non_synthetic_modules:
837-
threads = get_JVMCIThreadsPerNativeLibraryRuntime(jdk)
838-
vm_options.extend(['-XX:+UnlockExperimentalVMOptions', '-XX:+EnableJVMCIProduct'])
839-
if threads is not None and threads != 1:
840-
vm_options.append('-XX:JVMCIThreadsPerNativeLibraryRuntime=1')
841-
if default_to_jvmci == 'lib':
842-
vm_options.append('-XX:+UseJVMCINativeLibrary')
843-
vm_options.extend(['-XX:-UnlockExperimentalVMOptions'])
844-
import mx_sdk_vm_impl
845-
if 'jdk.graal.compiler' in non_synthetic_modules and mx_sdk_vm_impl._get_libgraal_component() is None:
846-
# If libgraal is absent, jargraal is used by default.
847-
# Use of jargraal requires exporting jdk.internal.misc to
848-
# Graal as it uses jdk.internal.misc.Unsafe. To avoid warnings
849-
# about unknown modules (e.g. in `-Xint` mode), the export target
850-
# modules must be explicitly added to the root set with `--add-modules`.
851-
if 'com.oracle.graal.graal_enterprise' in non_synthetic_modules:
852-
vm_options.extend([
853-
'--add-modules=jdk.graal.compiler,com.oracle.graal.graal_enterprise',
854-
'--add-exports=java.base/jdk.internal.misc=jdk.graal.compiler,com.oracle.graal.graal_enterprise'
855-
])
856-
else:
857-
vm_options.extend([
858-
'--add-modules=jdk.graal.compiler',
859-
'--add-exports=java.base/jdk.internal.misc=jdk.graal.compiler'
860-
])
861-
else:
862-
# Don't default to using JVMCI as JIT unless Graal is being updated in the image.
863-
# This avoids unexpected issues with using the out-of-date Graal compiler in
864-
# the JDK itself.
865-
vm_options.extend(['-XX:+UnlockExperimentalVMOptions', '-XX:+EnableJVMCIProduct', '-XX:-UseJVMCICompiler', '-XX:-UnlockExperimentalVMOptions'])
808+
if mx.get_env('CONTINUOUS_INTEGRATION', None) == 'true':
809+
is_gate = mx.get_env('BUILD_TARGET', None) == 'gate'
810+
is_bench = 'bench-' in mx.get_env('BUILD_NAME', '')
811+
if is_gate or is_bench:
812+
# For gate and benchmark jobs, we want to know about each compilation failure
813+
# but only exit the VM on systemic compilation failure for gate jobs.
814+
vm_options.append('-Djdk.graal.CompilationFailureAction=Diagnose')
815+
mx.log('Adding -Djdk.graal.CompilationFailureAction=Diagnose VM option to image')
816+
if is_gate:
817+
mx.log('Adding -Djdk.graal.SystemicCompilationFailureRate=-1 VM option to image')
818+
vm_options.append('-Djdk.graal.SystemicCompilationFailureRate=-1')
819+
820+
if use_upgrade_module_path or _jdk_omits_warning_for_jlink_set_ThreadPriorityPolicy(jdk):
821+
vm_options.append('-XX:ThreadPriorityPolicy=1')
822+
else:
823+
mx.logv('[Creating JDK without -XX:ThreadPriorityPolicy=1]')
824+
825+
if jdk_supports_enablejvmciproduct(jdk):
826+
non_synthetic_modules = [m.name for m in modules if m not in synthetic_modules]
827+
if default_to_jvmci or 'jdk.graal.compiler' in non_synthetic_modules:
828+
threads = get_JVMCIThreadsPerNativeLibraryRuntime(jdk)
829+
vm_options.extend(['-XX:+UnlockExperimentalVMOptions', '-XX:+EnableJVMCIProduct'])
830+
if threads is not None and threads != 1:
831+
vm_options.append('-XX:JVMCIThreadsPerNativeLibraryRuntime=1')
832+
if default_to_jvmci == 'lib':
833+
# As of JDK-8345826, the JVMCI module must be explicitly
834+
# added to the root set if libgraal is in use
835+
vm_options.append('--add-modules=jdk.internal.vm.ci')
836+
vm_options.append('-XX:+UseJVMCINativeLibrary')
837+
vm_options.extend(['-XX:-UnlockExperimentalVMOptions'])
838+
import mx_sdk_vm_impl
839+
if 'jdk.graal.compiler' in non_synthetic_modules and mx_sdk_vm_impl._get_libgraal_component() is None:
840+
# If libgraal is absent, jargraal is used by default.
841+
# Use of jargraal requires exporting jdk.internal.misc to
842+
# Graal as it uses jdk.internal.misc.Unsafe. To avoid warnings
843+
# about unknown modules (e.g. in `-Xint` mode), the export target
844+
# modules must be explicitly added to the root set with `--add-modules`.
845+
if 'com.oracle.graal.graal_enterprise' in non_synthetic_modules:
846+
vm_options.extend([
847+
'--add-modules=jdk.graal.compiler,com.oracle.graal.graal_enterprise',
848+
'--add-exports=java.base/jdk.internal.misc=jdk.graal.compiler,com.oracle.graal.graal_enterprise'
849+
])
850+
else:
851+
vm_options.extend([
852+
'--add-modules=jdk.graal.compiler',
853+
'--add-exports=java.base/jdk.internal.misc=jdk.graal.compiler'
854+
])
866855
else:
867-
mx.logv('[Creating JDK without -XX:+EnableJVMCIProduct]')
868-
if modules and use_upgrade_module_path:
869-
vm_options.append('--upgrade-module-path=' + os.pathsep.join((synthetic_modules.get(m, m.jarpath) for m in modules)))
870-
elif use_upgrade_module_path:
871-
mx.abort('Cannot create an image with an --upgrade-module-path setting since jlink does not support the --add-options flag')
856+
# Don't default to using JVMCI as JIT unless Graal is being updated in the image.
857+
# This avoids unexpected issues with using the out-of-date Graal compiler in
858+
# the JDK itself.
859+
vm_options.extend(['-XX:+UnlockExperimentalVMOptions', '-XX:+EnableJVMCIProduct', '-XX:-UseJVMCICompiler', '-XX:-UnlockExperimentalVMOptions'])
860+
else:
861+
mx.logv('[Creating JDK without -XX:+EnableJVMCIProduct]')
862+
if modules and use_upgrade_module_path:
863+
vm_options.append('--upgrade-module-path=' + os.pathsep.join((synthetic_modules.get(m, m.jarpath) for m in modules)))
872864
return vm_options
873865

874866
def _copy_src_zip(from_jdk, to_jdk, extra_modules, extra_modules_predicate):
@@ -1043,7 +1035,7 @@ def jlink_new_jdk(jdk, dst_jdk_dir, module_dists, ignore_dists,
10431035
jlink_persist = []
10441036

10451037
if jdk_enables_jvmci_by_default(jdk):
1046-
# On JDK 9+, +EnableJVMCI forces jdk.internal.vm.ci to be in the root set
1038+
# +EnableJVMCI forces jdk.internal.vm.ci to be in the root set
10471039
jlink += ['-J-XX:-EnableJVMCI', '-J-XX:-UseJVMCICompiler']
10481040

10491041
jlink.append('--add-modules=' + ','.join(_get_image_root_modules(root_module_names, module_names, jdk_modules.keys(), use_upgrade_module_path)))
@@ -1120,7 +1112,7 @@ def get_jmod_path_with_specified_module_info(self, m):
11201112
jlink.append(f'--add-options={" ".join(vm_options)}')
11211113
jlink_persist.append(f'--add-options="{" ".join(vm_options)}"')
11221114

1123-
if jlink_supports_8232080(jdk) and vendor_info is not None:
1115+
if vendor_info is not None:
11241116
for name, value in vendor_info.items():
11251117
jlink.append(f'--{name}={value}')
11261118
jlink_persist.append(f'--{name}="{value}"')

sdk/src/org.graalvm.launcher.native/src/launcher.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,9 @@ static int jvm_main_thread(struct MainThreadArgs& parsedArgs) {
824824
// GR-59703: Migrate sun.misc.* usages.
825825
vmArgs.push_back("--sun-misc-unsafe-memory-access=allow");
826826
}
827+
828+
// Required as of JDK-8345826, harmless on earlier versions.
829+
vmArgs.push_back("-XX:+EnableJVMCI");
827830
}
828831

829832
// Convert vmArgs to JavaVMInitArgs

truffle/mx.truffle/mx_truffle.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,13 @@ def _truffle_gate_runner(args, tasks):
494494

495495

496496
def gate_truffle_jvm(tasks):
497-
if mx_sdk.GraalVMJDKConfig.is_libgraal_jdk(mx.get_jdk(tag='default').home):
497+
default_jdk = mx.get_jdk(tag='default')
498+
if mx_sdk.GraalVMJDKConfig.is_libgraal_jdk(default_jdk.home):
498499
additional_jvm_args = ['-XX:+UnlockExperimentalVMOptions', '-XX:+EnableJVMCI', '-XX:+UseJVMCINativeLibrary', '-XX:-UnlockExperimentalVMOptions']
500+
elif default_jdk.javaCompliance >= '25':
501+
# As of JDK-8345826, -XX:+EnableJVMCI must be on the command line
502+
# to load the JVMCI module if libgraal is in use
503+
additional_jvm_args = ['-XX:+EnableJVMCI']
499504
else:
500505
additional_jvm_args = []
501506
# GR-62632: Debug VM exception translation failure

vm/mx.vm/mx_vm_gate.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ def _test_libgraal_CompilationTimeout_Truffle(extra_vm_arguments):
406406
f'-Dpolyglot.log.file={truffle_log_file}',
407407
'-Ddebug.graal.CompilationWatchDog=true', # helps debug failure
408408
'-Dgraalvm.locatorDisabled=true',
409+
'-XX:+EnableJVMCI', # JDK-8345826: Required to load the JVMCI module if libgraal is in use
409410
'-XX:-UseJVMCICompiler', # Stop compilation timeout being applied to JIT
410411
'-XX:+UseJVMCINativeLibrary'] # but ensure libgraal is still used by Truffle
411412

0 commit comments

Comments
 (0)