Skip to content

Commit 1943ce8

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

File tree

17 files changed

+87
-94
lines changed

17 files changed

+87
-94
lines changed

compiler/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
This changelog summarizes newly introduced optimizations and other compiler related changes.
44

55
## GraalVM for JDK 25 (Internal Version 25.0.0)
6+
* [(JDK-8345826)](https://bugs.openjdk.org/browse/JDK-8345826): To run jargraal now requires specifying `--add-modules=jdk.internal.vm.ci`
7+
to the `java` launcher as `-XX:+EnableJVMCI` no longer automatically adds this module to the root module set.
68
* (GR-60088): This PR adds the `org.graalvm.nativeimage.libgraal` SDK module. With this module, all logic for building
79
libgraal has been moved into the compiler suite in a new `jdk.graal.compiler.libgraal` module
810
which has no dependency on Native Image internals. This

compiler/mx.compiler/mx_compiler.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def _ctw_jvmci_export_args(arg_prefix='--'):
264264
def _ctw_system_properties_suffix():
265265
out = mx.OutputCapture()
266266
out.data = 'System properties for CTW:\n\n'
267-
args = ['-XX:+EnableJVMCI'] + _ctw_jvmci_export_args()
267+
args = ['--add-modules=jdk.internal.vm.ci'] + _ctw_jvmci_export_args()
268268
cp = _remove_redundant_entries(mx.classpath('GRAAL_TEST', jdk=jdk))
269269
args.extend(['-cp', cp, '-DCompileTheWorld.Help=true', 'jdk.graal.compiler.hotspot.test.CompileTheWorld'])
270270
run_java(args, out=out, addDefaultArgs=False)
@@ -280,7 +280,7 @@ def ctw(args, extraVMarguments=None):
280280
args, vmargs = parser.parse_known_args(args)
281281
vmargs.extend(_remove_empty_entries(extraVMarguments))
282282

283-
vmargs.append('-XX:+EnableJVMCI')
283+
vmargs.append('--add-modules=jdk.internal.vm.ci')
284284

285285
# Disable JVMCICompiler by default if not specified
286286
if _get_XX_option_value(vmargs, 'UseJVMCICompiler', None) is None:
@@ -1154,7 +1154,7 @@ def collate_metrics(args):
11541154
def run_java(args, out=None, err=None, addDefaultArgs=True, command_mapper_hooks=None, jdk=None, **kw_args):
11551155
graaljdk = jdk or get_graaljdk()
11561156
vm_args = _parseVmArgs(args, addDefaultArgs=addDefaultArgs)
1157-
args = ['-XX:+UnlockExperimentalVMOptions', '-XX:+EnableJVMCI', '--add-exports=java.base/jdk.internal.misc=jdk.graal.compiler'] + vm_args
1157+
args = ['-XX:+UnlockExperimentalVMOptions', '--add-modules=jdk.internal.vm.ci', '--add-exports=java.base/jdk.internal.misc=jdk.graal.compiler'] + vm_args
11581158
_check_bootstrap_config(args)
11591159
cmd = get_vm_prefix() + [graaljdk.java] + ['-server'] + args
11601160
map_file = join(graaljdk.home, 'proguard.map')

compiler/mx.compiler/mx_graal_benchmark.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,21 @@
5959
('avx2', ['-XX:UseAVX=2'], 11),
6060
('avx3', ['-XX:UseAVX=3'], 11),
6161
]
62-
mx_sdk_benchmark.build_jvmci_vm_variants('server', 'graal-core', ['-server', '-XX:+EnableJVMCI', '-Djdk.graal.CompilerConfiguration=community', '-Djvmci.Compiler=graal'], _graal_variants, suite=_suite, priority=15)
62+
mx_sdk_benchmark.build_jvmci_vm_variants('server', 'graal-core', ['-server', '--add-modules=jdk.internal.vm.ci', '-Djdk.graal.CompilerConfiguration=community', '-Djvmci.Compiler=graal'], _graal_variants, suite=_suite, priority=15)
6363

6464
# On 64 bit systems -client is not supported. Nevertheless, when running with -server, we can
6565
# force the VM to just compile code with C1 but not with C2 by adding option -XX:TieredStopAtLevel=1.
6666
# This behavior is the closest we can get to the -client vm configuration.
6767
mx_benchmark.add_java_vm(JvmciJdkVm('client', 'default', ['-server', '-XX:-EnableJVMCI', '-XX:TieredStopAtLevel=1']), suite=_suite, priority=1)
68-
mx_benchmark.add_java_vm(JvmciJdkVm('client', 'hosted', ['-server', '-XX:+EnableJVMCI', '-XX:TieredStopAtLevel=1']), suite=_suite, priority=1)
68+
mx_benchmark.add_java_vm(JvmciJdkVm('client', 'hosted', ['-server', '--add-modules=jdk.internal.vm.ci', '-XX:TieredStopAtLevel=1']), suite=_suite, priority=1)
6969

7070

7171
mx_benchmark.add_java_vm(JvmciJdkVm('server', 'default', ['-server', '-XX:-EnableJVMCI']), _suite, 2)
7272
mx_benchmark.add_java_vm(JvmciJdkVm('server', 'default-serialgc', ['-server', '-XX:-EnableJVMCI', '-XX:+UseSerialGC']), _suite, 2)
7373
mx_benchmark.add_java_vm(JvmciJdkVm('server', 'default-pargc', ['-server', '-XX:-EnableJVMCI', '-XX:+UseParallelGC']), _suite, 2)
7474
mx_benchmark.add_java_vm(JvmciJdkVm('server', 'default-zgc', ['-server', '-XX:-EnableJVMCI', '-XX:+UseZGC']), _suite, 2)
7575
mx_benchmark.add_java_vm(JvmciJdkVm('server', 'default-no-tiered-comp', ['-server', '-XX:-EnableJVMCI', '-XX:-TieredCompilation']), _suite, 2)
76-
mx_benchmark.add_java_vm(JvmciJdkVm('server', 'hosted', ['-server', '-XX:+EnableJVMCI']), _suite, 3)
76+
mx_benchmark.add_java_vm(JvmciJdkVm('server', 'hosted', ['-server', '--add-modules=jdk.internal.vm.ci']), _suite, 3)
7777

7878

7979
class CompilerMetricsBenchmarkMixin:

compiler/src/jdk.graal.compiler.libgraal/src/jdk/graal/compiler/libgraal/GetCompilerConfig.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,12 @@ public static Result from(Path javaHome) {
115115
List<String> command = new ArrayList<>(List.of(
116116
javaExe.toFile().getAbsolutePath(),
117117
"-XX:+UnlockExperimentalVMOptions",
118-
"-XX:+EnableJVMCI",
118+
"--add-modules=jdk.internal.vm.ci",
119119
"-XX:-UseJVMCICompiler", // avoid deadlock with jargraal
120120

121121
// Required to use Modules class
122122
"--add-exports=java.base/jdk.internal.module=jdk.graal.compiler",
123123
addExports,
124-
"-Djdk.vm.ci.services.aot=true", // Remove after JDK-8346781
125124
"-D%s=%s".formatted(ImageInfo.PROPERTY_IMAGE_CODE_KEY, ImageInfo.PROPERTY_IMAGE_CODE_VALUE_BUILDTIME)));
126125

127126
for (var e : opens.entrySet()) {

compiler/src/jdk.graal.compiler.libgraal/src/jdk/graal/compiler/libgraal/GetJNIConfig.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private GetJNIConfig(ClassLoader loader, Path libgraalJavaHome) {
8383
Path javaExe = getJavaExe(libgraalJavaHome);
8484
configFilePath = Path.of("libgraal_jniconfig.txt");
8585

86-
String[] command = {javaExe.toFile().getAbsolutePath(), "-XX:+UnlockExperimentalVMOptions", "-XX:+EnableJVMCI", "-XX:JVMCILibDumpJNIConfig=" + configFilePath};
86+
String[] command = {javaExe.toFile().getAbsolutePath(), "-XX:+UnlockExperimentalVMOptions", "--add-modules=jdk.internal.vm.ci", "-XX:JVMCILibDumpJNIConfig=" + configFilePath};
8787
quotedCommand = Stream.of(command).map(e -> e.indexOf(' ') == -1 ? e : '\'' + e + '\'').collect(Collectors.joining(" "));
8888
ProcessBuilder pb = new ProcessBuilder(command);
8989
pb.redirectErrorStream(true);

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/replacements/test/InvokerSignatureMismatchTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void test() throws Throwable {
5151
args.add("--patch-module=java.base=" + temp);
5252
args.add("-XX:-TieredCompilation");
5353
args.add("-XX:+UnlockExperimentalVMOptions");
54-
args.add("-XX:+EnableJVMCI");
54+
args.add("--add-modules=jdk.internal.vm.ci");
5555
args.add("-XX:+UseJVMCICompiler");
5656

5757
Path invokeDir = Files.createDirectories(temp.path.resolve(Paths.get("java", "lang", "invoke")));

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ This table shows the level of optimizations the Java runtimes currently provide:
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 if enabled via experimental VM option:** Optimization is not enabled by default and must be enabled using the `--add-modules=jdk.internal.vm.ci` virtual machine option. In addition, to support compilation on OpenJDK, 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.
427427
* **No runtime optimizations:** With no runtime optimizations or if JVMCI is not enabled, the guest application code is executed in interpreter-only mode.
428428
* **JVMCI:** Refers to the [Java-Level JVM Compiler Interface](https://openjdk.org/jeps/243) supported by most Java runtimes.
429429

sdk/mx.sdk/mx_sdk.py

+1-2
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

+61-68
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,63 @@ 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-
])
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+
vm_options.append('-XX:+UseJVMCINativeLibrary')
861834
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'])
835+
# As of JDK-8345826, jdk.internal.vm.ci must also be explicitly added.
836+
vm_options.append('--add-modules=jdk.internal.vm.ci')
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+
])
855+
866856
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')
857+
# Don't default to using JVMCI as JIT unless Graal is being updated in the image.
858+
# This avoids unexpected issues with using the out-of-date Graal compiler in
859+
# the JDK itself.
860+
vm_options.extend(['-XX:+UnlockExperimentalVMOptions', '-XX:+EnableJVMCIProduct', '--add-modules=jdk.internal.vm.ci', '-XX:-UseJVMCICompiler', '-XX:-UnlockExperimentalVMOptions'])
861+
else:
862+
mx.logv('[Creating JDK without -XX:+EnableJVMCIProduct]')
863+
if modules and use_upgrade_module_path:
864+
vm_options.append('--upgrade-module-path=' + os.pathsep.join((synthetic_modules.get(m, m.jarpath) for m in modules)))
872865
return vm_options
873866

874867
def _copy_src_zip(from_jdk, to_jdk, extra_modules, extra_modules_predicate):
@@ -1043,7 +1036,7 @@ def jlink_new_jdk(jdk, dst_jdk_dir, module_dists, ignore_dists,
10431036
jlink_persist = []
10441037

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

10491042
jlink.append('--add-modules=' + ','.join(_get_image_root_modules(root_module_names, module_names, jdk_modules.keys(), use_upgrade_module_path)))
@@ -1120,7 +1113,7 @@ def get_jmod_path_with_specified_module_info(self, m):
11201113
jlink.append(f'--add-options={" ".join(vm_options)}')
11211114
jlink_persist.append(f'--add-options="{" ".join(vm_options)}"')
11221115

1123-
if jlink_supports_8232080(jdk) and vendor_info is not None:
1116+
if vendor_info is not None:
11241117
for name, value in vendor_info.items():
11251118
jlink.append(f'--{name}={value}')
11261119
jlink_persist.append(f'--{name}="{value}"')

substratevm/docs/module-system/ModuleSystemSupportHosted.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ USE_NATIVE_IMAGE_JAVA_PLATFORM_MODULE_SYSTEM=true \
129129
/home/graaluser/OLabs/main/graal/sdk/mxbuild/linux-amd64/GRAALVM_427B7851E4_JAVA21/graalvm-427b7851e4-java21-24.0.0-dev/bin/java \
130130
-XX:+UseParallelGC \
131131
-XX:+UnlockExperimentalVMOptions \
132-
-XX:+EnableJVMCI \
132+
--add-modules=jdk.internal.vm.ci \
133133
-Dtruffle.TrustAllTruffleRuntimeProviders=true \
134134
-Dtruffle.TruffleRuntime=com.oracle.truffle.api.impl.DefaultTruffleRuntime \
135135
-Dgraalvm.ForcePolyglotInvalid=true \

0 commit comments

Comments
 (0)