From 28568f65ba2f1e09d74590d74a9570ae023c8ca2 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Mon, 4 Sep 2023 11:28:59 +0200 Subject: [PATCH 01/29] compiler: HeapRegion::LogOfHRGrainBytes changed to type "uint" --- .../src/org/graalvm/compiler/hotspot/GraalHotSpotVMConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/GraalHotSpotVMConfig.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/GraalHotSpotVMConfig.java index 31e9a9d5fa1b..df9a6fc36332 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/GraalHotSpotVMConfig.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/GraalHotSpotVMConfig.java @@ -496,7 +496,7 @@ private static String markWordField(String simpleName) { public final long verifyOopMask = getFieldValue("CompilerToVM::Data::Universe_verify_oop_mask", Long.class, "uintptr_t"); public final long verifyOopBits = getFieldValue("CompilerToVM::Data::Universe_verify_oop_bits", Long.class, "uintptr_t"); - public final int logOfHRGrainBytes = getFieldValue("HeapRegion::LogOfHRGrainBytes", Integer.class, "int"); + public final int logOfHRGrainBytes = getFieldValue("HeapRegion::LogOfHRGrainBytes", Integer.class, JDK >= 22 ? "uint" : "int"); public final int cardtableShift = getFieldValue("CompilerToVM::Data::cardtable_shift", Integer.class, "int"); public final long cardtableStartAddress; From fc4f0ad3a035d1f4c499f4b4640e344a56cd42ac Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Mon, 14 Aug 2023 15:55:41 +0200 Subject: [PATCH 02/29] compiler: the JVMCI version check needs to take the JDK major version into account --- compiler/mx.compiler/mx_compiler.py | 69 ++++++++++++++++++----------- 1 file changed, 42 insertions(+), 27 deletions(-) diff --git a/compiler/mx.compiler/mx_compiler.py b/compiler/mx.compiler/mx_compiler.py index d1f95d7234bf..bfa36662a504 100644 --- a/compiler/mx.compiler/mx_compiler.py +++ b/compiler/mx.compiler/mx_compiler.py @@ -89,15 +89,27 @@ def _check_jvmci_version(jdk): """ Runs a Java utility to check that `jdk` supports the minimum JVMCI API required by Graal. """ - source_path = join(_suite.dir, 'src', 'jdk.internal.vm.compiler', 'src', 'org', 'graalvm', 'compiler', 'hotspot', 'JVMCIVersionCheck.java') - out = mx.OutputCapture() - mx.run([jdk.java, '-Xlog:disable', source_path], out=out) + def _capture_jvmci_version(args=None): + out = mx.OutputCapture() + _run_jvmci_version_check(args, jdk=jdk, out=out) + if out.data: + try: + return tuple([int(jdk.version.versionString)] + [int(n) for n in out.data.split(',')]) + except ValueError: + mx.warn(f'Could not parse jvmci version from JVMCIVersionCheck output:\n{out.data}') + return None + global _jdk_jvmci_version - if out.data: - try: - _jdk_jvmci_version = tuple((int(n) for n in out.data.split(','))) - except ValueError: - mx.warn(f'Could not parse jvmci version from JVMCIVersionCheck output:\n{out.data}') + _jdk_jvmci_version = _capture_jvmci_version() + + + +@mx.command(_suite.name, 'jvmci-version-check') +def _run_jvmci_version_check(args=None, jdk=jdk, **kwargs): + source_path = join(_suite.dir, 'src', 'jdk.internal.vm.compiler', 'src', 'org', 'graalvm', 'compiler', 'hotspot', + 'JVMCIVersionCheck.java') + return mx.run([jdk.java, '-Xlog:disable', source_path] + (args or []), **kwargs) + if os.environ.get('JVMCI_VERSION_CHECK', None) != 'ignore': _check_jvmci_version(jdk) @@ -1085,8 +1097,9 @@ def _check_latest_jvmci_version(): the JVMCI version of the JVMCI JDKs in the "jdks" section of the ``common.json`` file and issues a warning if not. """ - jvmci_re = re.compile(r'.*-jvmci-(\d+)\.(\d+)-b(\d+)') - common_path = join(_suite.dir, '..', 'common.json') + jvmci_re = re.compile(r'(?:ce|ee)-(\d+).*-jvmci-(\d+)\.(\d+)-b(\d+)') + suite = mx.suite('graal-enterprise', fatalIfMissing=False) or _suite + common_path = join(suite.dir, '..', 'common.json') if _jdk_jvmci_version is None: # Not using a JVMCI JDK @@ -1100,31 +1113,33 @@ def get_latest_jvmci_version(): for distribution in common_cfg['jdks']: version = common_cfg['jdks'][distribution].get('version', None) if version and '-jvmci-' in version: - current = tuple(int(n) for n in jvmci_re.match(version).group(1, 2, 3)) - if latest is None: - latest = current - elif latest != current: - # All JVMCI JDKs in common.json are expected to have the same JVMCI version. - # If they don't then the repo is in some transitionary state - # (e.g. making a JVMCI release) so skip the check. - return None + current = tuple(int(n) for n in jvmci_re.match(version).group(1, 2, 3, 4)) + if current[0] == _jdk_jvmci_version[0]: + # only compare the same major versions + if latest is None: + latest = current + elif latest != current: + # All JVMCI JDKs in common.json with the same major version + # are expected to have the same JVMCI version. + # If they don't then the repo is in some transitionary state + # (e.g. making a JVMCI release) so skip the check. + return None return latest def jvmci_version_str(version): - major, minor, build = version - return 'jvmci-{}.{}-b{:02d}'.format(major, minor, build) + jdk_major, major, minor, build = version + return f'labsjdk-(ce|ee)-{jdk_major}-jvmci-{major}.{minor}-b{build:02d}' + + version_check_setting = os.environ.get('JVMCI_VERSION_CHECK', None) latest = get_latest_jvmci_version() if latest is not None and _jdk_jvmci_version < latest: common_path = os.path.normpath(common_path) - msg = 'JVMCI version of JAVA_HOME is older than in {}: {} < {} '.format( - common_path, - jvmci_version_str(_jdk_jvmci_version), - jvmci_version_str(latest)) + msg = f'JVMCI version of JAVA_HOME is older than in {common_path}: {jvmci_version_str(_jdk_jvmci_version)} < {jvmci_version_str(latest)} ' msg += os.linesep + 'This poses the risk of hitting JVMCI bugs that have already been fixed.' - msg += os.linesep + 'Consider using {}, which you can get via:'.format(jvmci_version_str(latest)) - msg += os.linesep + 'mx fetch-jdk --configuration {}'.format(common_path) - mx.warn(msg) + msg += os.linesep + f'Consider using {jvmci_version_str(latest)}, which you can get via:' + msg += os.linesep + f'mx fetch-jdk --configuration {common_path}' + mx.abort_or_warn(msg, version_check_setting == 'strict') class GraalArchiveParticipant: providersRE = re.compile(r'(?:META-INF/versions/([1-9][0-9]*)/)?META-INF/providers/(.+)') From e189bc9f5e866df28b354ceed84cb45374bcb21f Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Mon, 14 Aug 2023 15:56:42 +0200 Subject: [PATCH 03/29] compiler: support checking minimum version in JVMCIVersionCheck --- compiler/mx.compiler/mx_compiler.py | 11 +++++++++++ .../graalvm/compiler/hotspot/JVMCIVersionCheck.java | 10 +++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/compiler/mx.compiler/mx_compiler.py b/compiler/mx.compiler/mx_compiler.py index bfa36662a504..3cdff05719f1 100644 --- a/compiler/mx.compiler/mx_compiler.py +++ b/compiler/mx.compiler/mx_compiler.py @@ -80,6 +80,7 @@ def get_vm_prefix(asList=True): #: 3-tuple (major, minor, build) of JVMCI version, if any, denoted by `jdk` _jdk_jvmci_version = None +_jdk_min_jvmci_version = None if os.environ.get('JDK_VERSION_CHECK', None) != 'ignore' and jdk.javaCompliance < '17': mx.abort('Graal requires JDK17 or later, got ' + str(jdk) + @@ -101,6 +102,8 @@ def _capture_jvmci_version(args=None): global _jdk_jvmci_version _jdk_jvmci_version = _capture_jvmci_version() + global _jdk_min_jvmci_version + _jdk_min_jvmci_version = _capture_jvmci_version(['--min-version']) @@ -1132,6 +1135,14 @@ def jvmci_version_str(version): version_check_setting = os.environ.get('JVMCI_VERSION_CHECK', None) + if version_check_setting == 'strict' and _jdk_jvmci_version != _jdk_min_jvmci_version: + msg = f'JVMCI_MIN_VERSION specified in JVMCIVersionCheck.java is older than in {common_path}:' + msg += os.linesep + f'{jvmci_version_str(_jdk_min_jvmci_version)} < {jvmci_version_str(_jdk_jvmci_version)} ' + msg += os.linesep + f'Did you forget to update JVMCI_MIN_VERSION after updating {common_path}?' + msg += os.linesep + 'Set the JVMCI_VERSION_CHECK environment variable to something else then "strict" to' + msg += ' suppress this error.' + mx.abort(msg) + latest = get_latest_jvmci_version() if latest is not None and _jdk_jvmci_version < latest: common_path = os.path.normpath(common_path) diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java index 91a348dfad7f..6a7b8a1b019b 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java @@ -223,13 +223,21 @@ public static void main(String[] args) { props.put(name, sprops.getProperty(name)); } String format = "%d,%d,%d"; + boolean minVersion = false; for (String arg : args) { if (arg.equals("--as-tag")) { format = Version.AS_TAG_FORMAT; + } else if (arg.equals("--min-version")) { + minVersion = true; } else { throw new IllegalArgumentException("Unknown argument: " + arg); } } - check(props, true, format); + if (minVersion) { + Version v = JVMCI_MIN_VERSION; + System.out.printf(format + "%n", v.major, v.minor, v.build); + } else { + check(props, true, format); + } } } From 2f631d29df25e86dfa6a83f3c84e048753181e45 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Mon, 14 Aug 2023 16:20:48 +0200 Subject: [PATCH 04/29] compiler: support JVMCI_VERSION_CHECK=strict mode --- compiler/mx.compiler/mx_compiler.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/compiler/mx.compiler/mx_compiler.py b/compiler/mx.compiler/mx_compiler.py index 3cdff05719f1..ff3762cb6f13 100644 --- a/compiler/mx.compiler/mx_compiler.py +++ b/compiler/mx.compiler/mx_compiler.py @@ -1112,22 +1112,22 @@ def get_latest_jvmci_version(): with open(common_path) as common_file: common_cfg = json.load(common_file) - latest = None + latest = 'not found' for distribution in common_cfg['jdks']: version = common_cfg['jdks'][distribution].get('version', None) if version and '-jvmci-' in version: current = tuple(int(n) for n in jvmci_re.match(version).group(1, 2, 3, 4)) if current[0] == _jdk_jvmci_version[0]: # only compare the same major versions - if latest is None: + if isinstance(latest, str): latest = current elif latest != current: # All JVMCI JDKs in common.json with the same major version # are expected to have the same JVMCI version. # If they don't then the repo is in some transitionary state # (e.g. making a JVMCI release) so skip the check. - return None - return latest + return False, distribution + return not isinstance(latest, str), latest def jvmci_version_str(version): jdk_major, major, minor, build = version @@ -1135,6 +1135,8 @@ def jvmci_version_str(version): version_check_setting = os.environ.get('JVMCI_VERSION_CHECK', None) + success, latest = get_latest_jvmci_version() + if version_check_setting == 'strict' and _jdk_jvmci_version != _jdk_min_jvmci_version: msg = f'JVMCI_MIN_VERSION specified in JVMCIVersionCheck.java is older than in {common_path}:' msg += os.linesep + f'{jvmci_version_str(_jdk_min_jvmci_version)} < {jvmci_version_str(_jdk_jvmci_version)} ' @@ -1143,8 +1145,18 @@ def jvmci_version_str(version): msg += ' suppress this error.' mx.abort(msg) - latest = get_latest_jvmci_version() - if latest is not None and _jdk_jvmci_version < latest: + if version_check_setting == 'strict' and not success: + if latest == 'not found': + msg = f'No JVMCI JDK found in {common_path} that matches {jvmci_version_str(_jdk_jvmci_version)}.' + msg += os.linesep + f'Check that {latest} matches the versions of the other JVMCI JDKs.' + else: + msg = f'Version mismatch in {common_path}:' + msg += os.linesep + f'Check that {latest} matches the versions of the other JVMCI JDKs.' + msg += os.linesep + 'Set the JVMCI_VERSION_CHECK environment variable to something else then "strict" to' + msg += ' suppress this error.' + mx.abort(msg) + + if success and _jdk_jvmci_version < latest: common_path = os.path.normpath(common_path) msg = f'JVMCI version of JAVA_HOME is older than in {common_path}: {jvmci_version_str(_jdk_jvmci_version)} < {jvmci_version_str(latest)} ' msg += os.linesep + 'This poses the risk of hitting JVMCI bugs that have already been fixed.' From 6873eaf282d9de98a8069220f7667e9598c35237 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Mon, 14 Aug 2023 16:59:53 +0200 Subject: [PATCH 05/29] compiler: run style gate with JVMCI_VERSION_CHECK=strict --- compiler/ci/ci_common/gate.jsonnet | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/ci/ci_common/gate.jsonnet b/compiler/ci/ci_common/gate.jsonnet index c690acd67a80..d9f21897b181 100644 --- a/compiler/ci/ci_common/gate.jsonnet +++ b/compiler/ci/ci_common/gate.jsonnet @@ -435,7 +435,12 @@ ] ], - local style_builds = [self.make_build("21", "linux-amd64", "style").build], + local style_builds = [self.make_build("21", "linux-amd64", "style").build + { + environment+: { + # Run the strict JVMCI version check, i.e., that JVMCIVersionCheck.JVMCI_MIN_VERSION matches the versions in common.json. + JVMCI_VERSION_CHECK: "strict", + } + }], # Builds run on only on linux-amd64-jdk21Debug local linux_amd64_jdk21Debug_builds = [self.make_build("21Debug", "linux-amd64", task).build From 443afa627b8f8a9302b5dbe6e9695e973577095a Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Mon, 14 Aug 2023 17:38:36 +0200 Subject: [PATCH 06/29] compiler: make JDK 21 the minimal supported version --- compiler/mx.compiler/mx_compiler.py | 4 ++-- .../src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/mx.compiler/mx_compiler.py b/compiler/mx.compiler/mx_compiler.py index ff3762cb6f13..1ede4f6571c8 100644 --- a/compiler/mx.compiler/mx_compiler.py +++ b/compiler/mx.compiler/mx_compiler.py @@ -82,8 +82,8 @@ def get_vm_prefix(asList=True): _jdk_jvmci_version = None _jdk_min_jvmci_version = None -if os.environ.get('JDK_VERSION_CHECK', None) != 'ignore' and jdk.javaCompliance < '17': - mx.abort('Graal requires JDK17 or later, got ' + str(jdk) + +if os.environ.get('JDK_VERSION_CHECK', None) != 'ignore' and jdk.javaCompliance < '21': + mx.abort('Graal requires JDK21 or later, got ' + str(jdk) + '. This check can be bypassed by setting env var JDK_VERSION_CHECK=ignore') def _check_jvmci_version(jdk): diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java index 6a7b8a1b019b..7a43f7e8781c 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java @@ -51,7 +51,7 @@ public final class JVMCIVersionCheck { /** * Minimum Java release supported by Graal. */ - private static final int JAVA_MIN_RELEASE = 17; + private static final int JAVA_MIN_RELEASE = 21; public static class Version { private final int major; From 1e8a935bd56638a4a01068b5d6be1f5d1079ea66 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Thu, 17 Aug 2023 14:49:17 +0200 Subject: [PATCH 07/29] Revert "Revert "compiler: support multiple different JDK version in JVMCIVersionCheck"" This reverts commit 488432a68825d01794f526e62e841d0f6cbfa3dd. --- .../compiler/hotspot/JVMCIVersionCheck.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java index 7a43f7e8781c..42f450d15f56 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java @@ -46,7 +46,8 @@ public final class JVMCIVersionCheck { /** * Minimum JVMCI version supported by Graal. */ - private static final Version JVMCI_MIN_VERSION = new Version(23, 1, 15); + private static final Map JVMCI_MIN_VERSIONS = Map.of( + "21", new Version(23, 1, 15)); /** * Minimum Java release supported by Graal. @@ -162,8 +163,9 @@ private JVMCIVersionCheck(Map props, String javaSpecVersion, Str } static void check(Map props, boolean exitOnFailure, String format) { - JVMCIVersionCheck checker = new JVMCIVersionCheck(props, props.get("java.specification.version"), props.get("java.vm.version")); - checker.run(exitOnFailure, JVMCI_MIN_VERSION, format); + String javaSpecVersion = props.get("java.specification.version"); + JVMCIVersionCheck checker = new JVMCIVersionCheck(props, javaSpecVersion, props.get("java.vm.version")); + checker.run(exitOnFailure, JVMCI_MIN_VERSIONS.get(javaSpecVersion), format); } /** @@ -180,6 +182,8 @@ public static void check(Map props, private void run(boolean exitOnFailure, Version minVersion, String format) { if (javaSpecVersion.compareTo(Integer.toString(JAVA_MIN_RELEASE)) < 0) { failVersionCheck(exitOnFailure, "Graal requires JDK " + JAVA_MIN_RELEASE + " or later.%n"); + } else if (minVersion == null) { + failVersionCheck(exitOnFailure, "No minimum JVMCI version specified for JDK version %s.%n", javaSpecVersion); } else { if (vmVersion.contains("SNAPSHOT")) { return; @@ -234,8 +238,13 @@ public static void main(String[] args) { } } if (minVersion) { - Version v = JVMCI_MIN_VERSION; - System.out.printf(format + "%n", v.major, v.minor, v.build); + String javaSpecVersion = props.get("java.specification.version"); + Version v = JVMCI_MIN_VERSIONS.get(javaSpecVersion); + if (v == null) { + System.out.printf("No minimum JVMCI version specified for JDK version %s.%n", javaSpecVersion); + } else { + System.out.printf(format + "%n", v.major, v.minor, v.build); + } } else { check(props, true, format); } From 7564bc0eb2d6797b3951f13b328cd917e4cd4a09 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Thu, 17 Aug 2023 14:50:54 +0200 Subject: [PATCH 08/29] compiler: remove JDK 19 code from JVMCIVersionCheck --- .../org/graalvm/compiler/hotspot/JVMCIVersionCheck.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java index 42f450d15f56..269e85308de9 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java @@ -199,13 +199,8 @@ private void run(boolean exitOnFailure, Version minVersion, String format) { if (format != null) { System.out.printf(format + "%n", v.major, v.minor, v.build); } - Version actualMinVersion = minVersion; - if (javaSpecVersion.equals("19")) { - // Last JVMCI update for JDK 19 - actualMinVersion = new Version(23, 0, 5); - } - if (v.isLessThan(actualMinVersion)) { - failVersionCheck(exitOnFailure, "The VM does not support the minimum JVMCI API version required by Graal: %s < %s.%n", v, actualMinVersion); + if (v.isLessThan(minVersion)) { + failVersionCheck(exitOnFailure, "The VM does not support the minimum JVMCI API version required by Graal: %s < %s.%n", v, minVersion); } return; } From adc8726e9f6e1df8c5ff3a66066945af891ab659 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Thu, 17 Aug 2023 14:59:28 +0200 Subject: [PATCH 09/29] compiler: JVMCIVersionCheck should not fail if there is not minimum version specified --- .../src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java index 269e85308de9..da9e3481bcc8 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java @@ -182,8 +182,6 @@ public static void check(Map props, private void run(boolean exitOnFailure, Version minVersion, String format) { if (javaSpecVersion.compareTo(Integer.toString(JAVA_MIN_RELEASE)) < 0) { failVersionCheck(exitOnFailure, "Graal requires JDK " + JAVA_MIN_RELEASE + " or later.%n"); - } else if (minVersion == null) { - failVersionCheck(exitOnFailure, "No minimum JVMCI version specified for JDK version %s.%n", javaSpecVersion); } else { if (vmVersion.contains("SNAPSHOT")) { return; @@ -194,6 +192,9 @@ private void run(boolean exitOnFailure, Version minVersion, String format) { } if (vmVersion.contains("-jvmci-")) { // A "labsjdk" + if (minVersion == null) { + failVersionCheck(exitOnFailure, "No minimum JVMCI version specified for JDK version %s.%n", javaSpecVersion); + } Version v = Version.parse(vmVersion); if (v != null) { if (format != null) { From 60ca086a031404fd464c7e8535849e89c3437c71 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Thu, 17 Aug 2023 15:35:51 +0200 Subject: [PATCH 10/29] compiler: fix JVMCIVersionCheckTest --- .../graalvm/compiler/hotspot/test/JVMCIVersionCheckTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/JVMCIVersionCheckTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/JVMCIVersionCheckTest.java index aba76cdebdbf..26501fceb41e 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/JVMCIVersionCheckTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/JVMCIVersionCheckTest.java @@ -64,13 +64,13 @@ public void test01() { String javaVmVersion = String.format("prefix-jvmci-%s-suffix", version); if (!version.isLessThan(minVersion)) { try { - JVMCIVersionCheck.check(props, minVersion, "17", javaVmVersion, false); + JVMCIVersionCheck.check(props, minVersion, "21", javaVmVersion, false); } catch (InternalError e) { throw new AssertionError("Failed " + JVMCIVersionCheckTest.class.getSimpleName() + " with -Dtest.seed=" + seed, e); } } else { try { - JVMCIVersionCheck.check(props, minVersion, "17", javaVmVersion, false); + JVMCIVersionCheck.check(props, minVersion, "21", javaVmVersion, false); Assert.fail("expected to fail checking " + javaVmVersion + " against " + minVersion + " (-Dtest.seed=" + seed + ")"); } catch (InternalError e) { // pass From c74d392804a363ae839c3d00c431474d9efa59fc Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Mon, 4 Sep 2023 15:57:21 +0200 Subject: [PATCH 11/29] vm: ignore JDK_VERSION_CHECK for maven deploy jobs --- vm/ci/ci_common/common.jsonnet | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vm/ci/ci_common/common.jsonnet b/vm/ci/ci_common/common.jsonnet index 7b97196500c7..7e58cbea6c61 100644 --- a/vm/ci/ci_common/common.jsonnet +++ b/vm/ci/ci_common/common.jsonnet @@ -457,10 +457,12 @@ local devkits = graal_common.devkits; if (edition == 'ce') then { downloads+: { + # We still need to run on JDK 17 until doclet work on JDK 21 (GR-48400) JAVA_HOME: graal_common.jdks_data['labsjdk-' + edition + '-17'], EXTRA_JAVA_HOMES: graal_common.jdks_data['labsjdk-' + edition + '-21'], }, environment+: { + JDK_VERSION_CHECK: 'ignore', JVMCI_VERSION_CHECK: 'ignore', }, } From 0e83e06158e54c150e9a9db6a54f7bdc6419ab13 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Mon, 11 Sep 2023 11:43:59 +0200 Subject: [PATCH 12/29] ci/run-spec: use jdk-latest instead of jdk22 --- ci/ci_common/run-spec-examples.libsonnet | 4 ++-- ci/ci_common/run-spec.libsonnet | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ci/ci_common/run-spec-examples.libsonnet b/ci/ci_common/run-spec-examples.libsonnet index c7e111551bd2..d3cf79e0b56c 100644 --- a/ci/ci_common/run-spec-examples.libsonnet +++ b/ci/ci_common/run-spec-examples.libsonnet @@ -84,7 +84,7 @@ local r = import "run-spec.libsonnet"; "jdk21": r.task_spec({ "target": "gate", }), - "jdk22": r.task_spec({ + "jdk-latest": r.task_spec({ "target": "gate", }), }, @@ -109,7 +109,7 @@ local r = import "run-spec.libsonnet"; "jdk19": {}, "jdk20": {}, "jdk21": {}, - "jdk22": {}, + "jdk-latest": {}, }, }, }; diff --git a/ci/ci_common/run-spec.libsonnet b/ci/ci_common/run-spec.libsonnet index e8fb18b552f2..23f2cfd0644d 100644 --- a/ci/ci_common/run-spec.libsonnet +++ b/ci/ci_common/run-spec.libsonnet @@ -8,7 +8,7 @@ local examples = (import "run-spec-examples.libsonnet").examples; // Supported platforms supported_oss_names:: ["linux", "darwin", "windows"], supported_archs_names:: ["amd64", "aarch64"], - supported_jdks_names:: ["jdk17", "jdk19", "jdk20", "jdk21", "jdk22"], + supported_jdks_names:: ["jdk17", "jdk19", "jdk20", "jdk21", "jdk-latest"], // This will turn a task dictionary into a list of build objects. process(task_dict):: From 020d3b26f6a58990522a3d0deb5a7233375d64b9 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Mon, 11 Sep 2023 12:32:06 +0200 Subject: [PATCH 13/29] svm/ci: use run_spec jdk specifier instead of jdk_version --- substratevm/ci/ci_common/svm-gate.libsonnet | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substratevm/ci/ci_common/svm-gate.libsonnet b/substratevm/ci/ci_common/svm-gate.libsonnet index 3c06acd8d20e..3f54c02ada5a 100644 --- a/substratevm/ci/ci_common/svm-gate.libsonnet +++ b/substratevm/ci/ci_common/svm-gate.libsonnet @@ -42,7 +42,7 @@ for f in _fields ], mxgate_name:: outer.task_name, - name: std.join("-", [outer.target, suite_short, self.mxgate_name] + config + ["jdk" + outer.jdk_version] + target_arch_suffix + [outer.os, outer.arch]) + batch_suffix, + name: std.join("-", [outer.target, suite_short, self.mxgate_name] + config + [outer.jdk] + target_arch_suffix + [outer.os, outer.arch]) + batch_suffix, run+: [["mx", "--kill-with-sigquit", "--strict-compliance"] + dynamic_imports + ["gate", "--strict-mode", "--tags", std.join(",", outer.mxgate_tags)] + outer.mxgate_extra_args], } })), From 77b71d4a7e32317673a2b9433d77df3310cb9459 Mon Sep 17 00:00:00 2001 From: Marouane El Hallaoui Date: Tue, 5 Sep 2023 16:39:12 +0100 Subject: [PATCH 14/29] Add labsjdk 22 support for GraalVM --- ci/common.jsonnet | 2 +- common.json | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ci/common.jsonnet b/ci/common.jsonnet index d7a92fef9179..9b1516959811 100644 --- a/ci/common.jsonnet +++ b/ci/common.jsonnet @@ -25,7 +25,7 @@ local common_json = import "../common.json"; for name in ["oraclejdk21"] + variants("labsjdk-ce-21") + variants("labsjdk-ee-21") } + { [name]: common_json.jdks[name] + { jdk_version:: 22 } - for name in ["oraclejdk22"] + for name in ["oraclejdk22"] + variants("labsjdk-ce-22") + variants("labsjdk-ee-22") }, assert std.assertEqual(std.objectFields(common_json.jdks), std.objectFields(jdks_data)), diff --git a/common.json b/common.json index 56e5ef002999..8d4b03428130 100644 --- a/common.json +++ b/common.json @@ -42,7 +42,13 @@ "labsjdk-ee-21Debug": {"name": "labsjdk", "version": "ee-21+35-jvmci-23.1-b14-debug", "platformspecific": true }, "labsjdk-ee-21-llvm": {"name": "labsjdk", "version": "ee-21+35-jvmci-23.1-b14-sulong", "platformspecific": true }, - "oraclejdk22": {"name": "jpg-jdk", "version": "22", "build_id": "11", "release": true, "platformspecific": true, "extrabundles": ["static-libs"]} + "oraclejdk22": {"name": "jpg-jdk", "version": "22", "build_id": "11", "release": true, "platformspecific": true, "extrabundles": ["static-libs"]}, + "labsjdk-ce-22": {"name": "labsjdk", "version": "ce-22+13-jvmci-b01", "platformspecific": true }, + "labsjdk-ce-22Debug": {"name": "labsjdk", "version": "ce-22+13-jvmci-b01-debug", "platformspecific": true }, + "labsjdk-ce-22-llvm": {"name": "labsjdk", "version": "ce-22+13-jvmci-b01-sulong", "platformspecific": true }, + "labsjdk-ee-22": {"name": "labsjdk", "version": "ee-22+13-jvmci-b01", "platformspecific": true }, + "labsjdk-ee-22Debug": {"name": "labsjdk", "version": "ee-22+13-jvmci-b01-debug", "platformspecific": true }, + "labsjdk-ee-22-llvm": {"name": "labsjdk", "version": "ee-22+13-jvmci-b01-sulong", "platformspecific": true } }, "eclipse": { From 66f92db44df65079f5b6befd1a522c5dc1e52000 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Tue, 12 Sep 2023 09:36:48 +0200 Subject: [PATCH 15/29] compiler: support for labsjdk 22 versions in JVMCIVersionCheck --- compiler/mx.compiler/mx_compiler.py | 60 +++++++++- .../compiler/hotspot/JVMCIVersionCheck.java | 103 +++++++++++++----- .../compiler/hotspot/JVMCIVersionCompare.java | 38 +++++++ 3 files changed, 166 insertions(+), 35 deletions(-) create mode 100644 compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCompare.java diff --git a/compiler/mx.compiler/mx_compiler.py b/compiler/mx.compiler/mx_compiler.py index 1ede4f6571c8..42c271c8bb4b 100644 --- a/compiler/mx.compiler/mx_compiler.py +++ b/compiler/mx.compiler/mx_compiler.py @@ -78,7 +78,47 @@ def get_vm_prefix(asList=True): #: The JDK used to build and run Graal. jdk = mx.get_jdk(tag='default') -#: 3-tuple (major, minor, build) of JVMCI version, if any, denoted by `jdk` + +class JavaLangRuntimeVersion(mx.Comparable): + """Wrapper for by java.lang.Runtime.Version""" + + _cmp_cache = {} + + def __init__(self, version, jdk=None): + self.version = version + self.jdk = jdk or mx.get_jdk() + + def __str__(self): + return self.version + + def __cmp__(self, other): + if not isinstance(other, JavaLangRuntimeVersion): + raise TypeError(f'Cannot compare {JavaLangRuntimeVersion.__name__} to {type(other).__name__}') + this_version = self.version + other_version = other.version + return JavaLangRuntimeVersion.compare(this_version, other_version, jdk) + + @staticmethod + def compare(this_version, other_version, jdk): + if this_version == other_version: + return 0 + key = (this_version, other_version) + cached = JavaLangRuntimeVersion._cmp_cache.get(key, None) + if cached is not None: + return cached + source_path = join(_suite.dir, 'src', 'jdk.internal.vm.compiler', 'src', 'org', 'graalvm', 'compiler', + 'hotspot', + 'JVMCIVersionCompare.java') + out = mx.OutputCapture() + mx.run([jdk.java, '-Xlog:disable', source_path, this_version, other_version], out=out) + ret = int(out.data) + JavaLangRuntimeVersion._cmp_cache[key] = ret + return ret + + +#: 4-tuple (jdk_version, jvmci_major, jvmci_minor, jvmci_build) of JVMCI version, if any, denoted by `jdk` +# jdk_version is a JavaLangRuntimeVersion +# jvmci_major and jvmci_minor might be 0 if not needed (JDK 22+) _jdk_jvmci_version = None _jdk_min_jvmci_version = None @@ -95,7 +135,8 @@ def _capture_jvmci_version(args=None): _run_jvmci_version_check(args, jdk=jdk, out=out) if out.data: try: - return tuple([int(jdk.version.versionString)] + [int(n) for n in out.data.split(',')]) + (jdk_version, jvmci_major, jvmci_minor, jvmci_build) = out.data.split(',') + return (JavaLangRuntimeVersion(jdk_version), int(jvmci_major), int(jvmci_minor), int(jvmci_build)) except ValueError: mx.warn(f'Could not parse jvmci version from JVMCIVersionCheck output:\n{out.data}') return None @@ -1100,7 +1141,7 @@ def _check_latest_jvmci_version(): the JVMCI version of the JVMCI JDKs in the "jdks" section of the ``common.json`` file and issues a warning if not. """ - jvmci_re = re.compile(r'(?:ce|ee)-(\d+).*-jvmci-(\d+)\.(\d+)-b(\d+)') + jvmci_re = re.compile(r'(?:ce|ee)-(?P.+)-jvmci(?:-(?P\d+)\.(?P\d+))?-b(?P\d+)') suite = mx.suite('graal-enterprise', fatalIfMissing=False) or _suite common_path = join(suite.dir, '..', 'common.json') @@ -1116,7 +1157,11 @@ def get_latest_jvmci_version(): for distribution in common_cfg['jdks']: version = common_cfg['jdks'][distribution].get('version', None) if version and '-jvmci-' in version: - current = tuple(int(n) for n in jvmci_re.match(version).group(1, 2, 3, 4)) + match = jvmci_re.match(version) + if not match: + mx.abort(f'Cannot parse version {version}') + (jdk_version, jvmci_major, jvmci_minor, jvmci_build) = match.groups(default=0) + current = (JavaLangRuntimeVersion(jdk_version), int(jvmci_major), int(jvmci_minor), int(jvmci_build)) if current[0] == _jdk_jvmci_version[0]: # only compare the same major versions if isinstance(latest, str): @@ -1130,8 +1175,11 @@ def get_latest_jvmci_version(): return not isinstance(latest, str), latest def jvmci_version_str(version): - jdk_major, major, minor, build = version - return f'labsjdk-(ce|ee)-{jdk_major}-jvmci-{major}.{minor}-b{build:02d}' + jdk_major, jdk_build, jvmci_major, jvmci_minor, jvmci_build = version + if jvmci_major == 0: + return f'labsjdk-(ce|ee)-{jdk_major}+{jdk_build}-jvmci-b{jvmci_build:02d}' + else: + return f'labsjdk-(ce|ee)-{jdk_major}+{jdk_build}-jvmci-{jvmci_major}.{jvmci_minor}-b{jvmci_build:02d}' version_check_setting = os.environ.get('JVMCI_VERSION_CHECK', None) diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java index da9e3481bcc8..bd2877ae7baf 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java @@ -47,26 +47,30 @@ public final class JVMCIVersionCheck { * Minimum JVMCI version supported by Graal. */ private static final Map JVMCI_MIN_VERSIONS = Map.of( - "21", new Version(23, 1, 15)); + "21", new Version("21+35", 23, 1, 15), + "22", new Version("22+13", JVMCIVersionCheck.NA, JVMCIVersionCheck.NA, 1)); + private static final int NA = 0; /** * Minimum Java release supported by Graal. */ private static final int JAVA_MIN_RELEASE = 21; public static class Version { - private final int major; - private final int minor; - private final int build; + private final Runtime.Version jdkVersion; + private final int jvmciMajor; + private final int jvmciMinor; + private final int jvmciBuild; static Version parse(String vmVersion) { - Matcher m = Pattern.compile(".*-jvmci-(\\d+)\\.(\\d+)-b(\\d+).*").matcher(vmVersion); + Matcher m = Pattern.compile("(.+)-jvmci(-(\\d+)\\.(\\d+))?-b(\\d+).*").matcher(vmVersion); if (m.matches()) { try { - int major = Integer.parseInt(m.group(1)); - int minor = Integer.parseInt(m.group(2)); - int build = Integer.parseInt(m.group(3)); - return new Version(major, minor, build); + Runtime.Version jdkVersion = Runtime.Version.parse(m.group(1)); + int jvmciMajor = parseIntOrZero(m.group(3)); + int jvmciMinor = parseIntOrZero(m.group(4)); + int jvmciBuild = parseIntOrZero(m.group(5)); + return new Version(jdkVersion, jvmciMajor, jvmciMinor, jvmciBuild); } catch (NumberFormatException e) { // ignore } @@ -74,10 +78,30 @@ static Version parse(String vmVersion) { return null; } - public Version(int major, int minor, int build) { - this.major = major; - this.minor = minor; - this.build = build; + private static int parseIntOrZero(String group) { + if (group == null) { + return 0; + } + return Integer.parseInt(group); + } + + /** + * Legacy construction for versions without JDK version. This force sets {@link #jdkVersion} + * to {@code 21}. While this is not entirely correct, it works for our purposes. + */ + public Version(int jvmciMajor, int jvmciMinor, int jvmciBuild) { + this("21", jvmciMajor, jvmciMinor, jvmciBuild); + } + + public Version(String jdkVersionString, int jvmciMajor, int jvmciMinor, int jvmciBuild) { + this(Runtime.Version.parse(jdkVersionString), jvmciMajor, jvmciMinor, jvmciBuild); + } + + public Version(Runtime.Version jdkVersion, int jvmciMajor, int jvmciMinor, int jvmciBuild) { + this.jdkVersion = jdkVersion; + this.jvmciMajor = jvmciMajor; + this.jvmciMinor = jvmciMinor; + this.jvmciBuild = jvmciBuild; } boolean isGreaterThan(Version other) { @@ -88,14 +112,15 @@ boolean isGreaterThan(Version other) { } public boolean isLessThan(Version other) { - if (this.major < other.major) { + int compareTo = this.jdkVersion.compareTo(other.jdkVersion); + if (compareTo < 0) { return true; } - if (this.major == other.major) { - if (this.minor < other.minor) { + if (compareTo == 0 && this.jvmciMajor == other.jvmciMajor) { + if (this.jvmciMinor < other.jvmciMinor) { return true; } - if (this.minor == other.minor && this.build < other.build) { + if (this.jvmciMinor == other.jvmciMinor && this.jvmciBuild < other.jvmciBuild) { return true; } } @@ -104,23 +129,38 @@ public boolean isLessThan(Version other) { @Override public boolean equals(Object obj) { - if (obj instanceof Version) { - Version that = (Version) obj; - return this.major == that.major && this.minor == that.minor && this.build == that.build; + if (obj instanceof Version that) { + return this.jdkVersion.equals(that.jdkVersion) && this.jvmciMajor == that.jvmciMajor && this.jvmciMinor == that.jvmciMinor && this.jvmciBuild == that.jvmciBuild; } return false; } @Override public int hashCode() { - return this.major ^ this.minor ^ this.build; + return this.jdkVersion.hashCode() ^ this.jvmciMajor ^ this.jvmciMinor ^ this.jvmciBuild; } - public static final String AS_TAG_FORMAT = "jvmci-%d.%d-b%02d"; + public static final String AS_TAG_FORMAT_22_AND_LATER = "%s-jvmci-b%02d"; + public static final String AS_TAG_FORMAT_21_AND_EARLIER = "jvmci-%d.%d-b%02d"; @Override public String toString() { - return String.format(AS_TAG_FORMAT, major, minor, build); + if (isJDK22OrLater()) { + return String.format(AS_TAG_FORMAT_22_AND_LATER, jdkVersion, jvmciBuild); + } else { + return String.format(AS_TAG_FORMAT_21_AND_EARLIER, jvmciMajor, jvmciMinor, jvmciBuild); + } + } + + private boolean isJDK22OrLater() { + return jvmciMajor == NA; + } + + public String printFormat(PrintFormat format) { + return switch (format) { + case TUPLE -> String.format("%s,%d,%d,%d", jdkVersion, jvmciMajor, jvmciMinor, jvmciBuild); + case AS_TAG -> toString(); + }; } } @@ -162,7 +202,12 @@ private JVMCIVersionCheck(Map props, String javaSpecVersion, Str this.vmVersion = vmVersion; } - static void check(Map props, boolean exitOnFailure, String format) { + enum PrintFormat { + TUPLE, + AS_TAG + } + + static void check(Map props, boolean exitOnFailure, PrintFormat format) { String javaSpecVersion = props.get("java.specification.version"); JVMCIVersionCheck checker = new JVMCIVersionCheck(props, javaSpecVersion, props.get("java.vm.version")); checker.run(exitOnFailure, JVMCI_MIN_VERSIONS.get(javaSpecVersion), format); @@ -179,7 +224,7 @@ public static void check(Map props, checker.run(exitOnFailure, minVersion, null); } - private void run(boolean exitOnFailure, Version minVersion, String format) { + private void run(boolean exitOnFailure, Version minVersion, PrintFormat format) { if (javaSpecVersion.compareTo(Integer.toString(JAVA_MIN_RELEASE)) < 0) { failVersionCheck(exitOnFailure, "Graal requires JDK " + JAVA_MIN_RELEASE + " or later.%n"); } else { @@ -198,7 +243,7 @@ private void run(boolean exitOnFailure, Version minVersion, String format) { Version v = Version.parse(vmVersion); if (v != null) { if (format != null) { - System.out.printf(format + "%n", v.major, v.minor, v.build); + System.out.println(v.printFormat(format)); } if (v.isLessThan(minVersion)) { failVersionCheck(exitOnFailure, "The VM does not support the minimum JVMCI API version required by Graal: %s < %s.%n", v, minVersion); @@ -222,11 +267,11 @@ public static void main(String[] args) { for (String name : sprops.stringPropertyNames()) { props.put(name, sprops.getProperty(name)); } - String format = "%d,%d,%d"; + PrintFormat format = PrintFormat.TUPLE; boolean minVersion = false; for (String arg : args) { if (arg.equals("--as-tag")) { - format = Version.AS_TAG_FORMAT; + format = PrintFormat.AS_TAG; } else if (arg.equals("--min-version")) { minVersion = true; } else { @@ -239,7 +284,7 @@ public static void main(String[] args) { if (v == null) { System.out.printf("No minimum JVMCI version specified for JDK version %s.%n", javaSpecVersion); } else { - System.out.printf(format + "%n", v.major, v.minor, v.build); + System.out.println(v.printFormat(format)); } } else { check(props, true, format); diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCompare.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCompare.java new file mode 100644 index 000000000000..35803f542d92 --- /dev/null +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCompare.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.graalvm.compiler.hotspot; + +public final class JVMCIVersionCompare { + + public static void main(String[] args) { + if (args.length != 2) { + System.err.println("Expected two arguments"); + System.exit(1); + } + Runtime.Version a = Runtime.Version.parse(args[0]); + Runtime.Version b = Runtime.Version.parse(args[1]); + System.out.print(a.compareTo(b)); + } +} From f8205c839ff64c24681f2c261a4147889ac4c671 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Tue, 12 Sep 2023 12:56:31 +0200 Subject: [PATCH 16/29] compiler: address review comments regarding jvmci version checks in mx --- compiler/mx.compiler/mx_compiler.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/compiler/mx.compiler/mx_compiler.py b/compiler/mx.compiler/mx_compiler.py index 42c271c8bb4b..24395038df26 100644 --- a/compiler/mx.compiler/mx_compiler.py +++ b/compiler/mx.compiler/mx_compiler.py @@ -1142,8 +1142,7 @@ def _check_latest_jvmci_version(): ``common.json`` file and issues a warning if not. """ jvmci_re = re.compile(r'(?:ce|ee)-(?P.+)-jvmci(?:-(?P\d+)\.(?P\d+))?-b(?P\d+)') - suite = mx.suite('graal-enterprise', fatalIfMissing=False) or _suite - common_path = join(suite.dir, '..', 'common.json') + common_path = join(_suite.dir, '..', 'common.json') if _jdk_jvmci_version is None: # Not using a JVMCI JDK @@ -1164,7 +1163,7 @@ def get_latest_jvmci_version(): current = (JavaLangRuntimeVersion(jdk_version), int(jvmci_major), int(jvmci_minor), int(jvmci_build)) if current[0] == _jdk_jvmci_version[0]: # only compare the same major versions - if isinstance(latest, str): + if latest == 'not found': latest = current elif latest != current: # All JVMCI JDKs in common.json with the same major version From 77824e06c4cb3434c23b870da78d88140ca26322 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Tue, 12 Sep 2023 12:57:57 +0200 Subject: [PATCH 17/29] ci: remove oraclejdk22 --- ci/common.jsonnet | 2 +- common.json | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/ci/common.jsonnet b/ci/common.jsonnet index 9b1516959811..25ad1c925245 100644 --- a/ci/common.jsonnet +++ b/ci/common.jsonnet @@ -25,7 +25,7 @@ local common_json = import "../common.json"; for name in ["oraclejdk21"] + variants("labsjdk-ce-21") + variants("labsjdk-ee-21") } + { [name]: common_json.jdks[name] + { jdk_version:: 22 } - for name in ["oraclejdk22"] + variants("labsjdk-ce-22") + variants("labsjdk-ee-22") + for name in variants("labsjdk-ce-22") + variants("labsjdk-ee-22") }, assert std.assertEqual(std.objectFields(common_json.jdks), std.objectFields(jdks_data)), diff --git a/common.json b/common.json index 786da42a49af..3a6f83fdbaa3 100644 --- a/common.json +++ b/common.json @@ -42,7 +42,6 @@ "labsjdk-ee-21Debug": {"name": "labsjdk", "version": "ee-21+35-jvmci-23.1-b15-debug", "platformspecific": true }, "labsjdk-ee-21-llvm": {"name": "labsjdk", "version": "ee-21+35-jvmci-23.1-b15-sulong", "platformspecific": true }, - "oraclejdk22": {"name": "jpg-jdk", "version": "22", "build_id": "11", "release": true, "platformspecific": true, "extrabundles": ["static-libs"]}, "labsjdk-ce-22": {"name": "labsjdk", "version": "ce-22+13-jvmci-b01", "platformspecific": true }, "labsjdk-ce-22Debug": {"name": "labsjdk", "version": "ce-22+13-jvmci-b01-debug", "platformspecific": true }, "labsjdk-ce-22-llvm": {"name": "labsjdk", "version": "ce-22+13-jvmci-b01-sulong", "platformspecific": true }, From 5086f6f3a18970845013c790e826095b2c61c78d Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Tue, 12 Sep 2023 13:02:59 +0200 Subject: [PATCH 18/29] compiler/ci: remove oraclejdk22 build --- vm/ci/ci_common/libgraal.jsonnet | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/vm/ci/ci_common/libgraal.jsonnet b/vm/ci/ci_common/libgraal.jsonnet index afe564d06070..323c0e9ec104 100644 --- a/vm/ci/ci_common/libgraal.jsonnet +++ b/vm/ci/ci_common/libgraal.jsonnet @@ -77,7 +77,6 @@ local utils = import '../../../ci/ci_common/common-utils.libsonnet'; "gate-vm-libgraal_compiler_zgc-labsjdk-21-linux-amd64": {}, "gate-vm-libgraal_compiler_quickbuild-labsjdk-21-linux-amd64": {}, "gate-vm-libgraal_truffle_quickbuild-labsjdk-21-linux-amd64": t("1:10:00"), - "gate-vm-libgraal_compiler-oraclejdk-22-linux-amd64": {}, }, # See definition of `dailies` local variable in ../../compiler/ci_common/gate.jsonnet @@ -130,28 +129,6 @@ local utils = import '../../../ci/ci_common/common-utils.libsonnet'; ] ], - # Builds run on OracleJDK22 - local oraclejdk22_builds = [ - c["gate_vm_" + underscore(os_arch)] + - svm_common(os_arch, jdk) + - vm["custom_vm_" + os(os_arch)] + - g.make_build(jdk, os_arch, task, extra_tasks=self, suite="vm", - include_common_os_arch=false, - jdk_name="oraclejdk", - gates_manifest=gates, - dailies_manifest=dailies, - weeklies_manifest=weeklies, - monthlies_manifest=monthlies).build + - vm["vm_java_" + jdk] - for jdk in [ - "22" - ] - for os_arch in all_os_arches - for task in [ - "libgraal_compiler", - ] - ], - local adjust_windows_version(gate) = ( # replace 2016 with 2019 gate + { capabilities: [ if x == "windows_server_2016" then "windows_server_2019" else x for x in gate.capabilities ] } @@ -207,7 +184,6 @@ local utils = import '../../../ci/ci_common/common-utils.libsonnet'; # Complete set of builds defined in this file local all_builds = all_platforms_builds + - oraclejdk22_builds + all_platforms_zgc_builds + coverage_jdk21_builds, From 420c482273b8b1bb95f741062cd7532f174a853f Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Tue, 12 Sep 2023 13:51:06 +0200 Subject: [PATCH 19/29] add labsjdk22 entries to ci_common/common.jsonnet --- ci/ci_common/common.jsonnet | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ci/ci_common/common.jsonnet b/ci/ci_common/common.jsonnet index e5f79c6b8ae4..8b8179a88975 100644 --- a/ci/ci_common/common.jsonnet +++ b/ci/ci_common/common.jsonnet @@ -71,6 +71,10 @@ common + common.frequencies + { labsjdk21Debug:: self["labsjdk-" + repo_config.graalvm_edition + "-21Debug"], labsjdk21LLVM:: self["labsjdk-" + repo_config.graalvm_edition + "-21-llvm"], + labsjdk22:: self["labsjdk-" + repo_config.graalvm_edition + "-22"], + labsjdk22Debug:: self["labsjdk-" + repo_config.graalvm_edition + "-22Debug"], + labsjdk22LLVM:: self["labsjdk-" + repo_config.graalvm_edition + "-22-llvm"], + // Hardware definitions // ******************** local graal_common_extras = common.deps.pylint + { From def1b1ca94cf6a46921a2065fe9bd29d3806d022 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Tue, 12 Sep 2023 14:22:14 +0200 Subject: [PATCH 20/29] compiler: fix jvmci version check --- compiler/mx.compiler/mx_compiler.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/compiler/mx.compiler/mx_compiler.py b/compiler/mx.compiler/mx_compiler.py index 24395038df26..c2e69e866622 100644 --- a/compiler/mx.compiler/mx_compiler.py +++ b/compiler/mx.compiler/mx_compiler.py @@ -83,6 +83,7 @@ class JavaLangRuntimeVersion(mx.Comparable): """Wrapper for by java.lang.Runtime.Version""" _cmp_cache = {} + _feature_re = re.compile('[1-9][0-9]*') def __init__(self, version, jdk=None): self.version = version @@ -115,6 +116,11 @@ def compare(this_version, other_version, jdk): JavaLangRuntimeVersion._cmp_cache[key] = ret return ret + def feature(self): + if not hasattr(self, '_feature'): + self._feature = int(JavaLangRuntimeVersion._feature_re.match(self.version).group(0)) + return self._feature + #: 4-tuple (jdk_version, jvmci_major, jvmci_minor, jvmci_build) of JVMCI version, if any, denoted by `jdk` # jdk_version is a JavaLangRuntimeVersion @@ -1161,7 +1167,7 @@ def get_latest_jvmci_version(): mx.abort(f'Cannot parse version {version}') (jdk_version, jvmci_major, jvmci_minor, jvmci_build) = match.groups(default=0) current = (JavaLangRuntimeVersion(jdk_version), int(jvmci_major), int(jvmci_minor), int(jvmci_build)) - if current[0] == _jdk_jvmci_version[0]: + if current[0].feature() == _jdk_jvmci_version[0].feature(): # only compare the same major versions if latest == 'not found': latest = current @@ -1174,11 +1180,11 @@ def get_latest_jvmci_version(): return not isinstance(latest, str), latest def jvmci_version_str(version): - jdk_major, jdk_build, jvmci_major, jvmci_minor, jvmci_build = version + jdk_version, jvmci_major, jvmci_minor, jvmci_build = version if jvmci_major == 0: - return f'labsjdk-(ce|ee)-{jdk_major}+{jdk_build}-jvmci-b{jvmci_build:02d}' + return f'labsjdk-(ce|ee)-{jdk_version}-jvmci-b{jvmci_build:02d}' else: - return f'labsjdk-(ce|ee)-{jdk_major}+{jdk_build}-jvmci-{jvmci_major}.{jvmci_minor}-b{jvmci_build:02d}' + return f'labsjdk-(ce|ee)-{jdk_version}-jvmci-{jvmci_major}.{jvmci_minor}-b{jvmci_build:02d}' version_check_setting = os.environ.get('JVMCI_VERSION_CHECK', None) From 0dc51234d4b9082af1fab9cad9a9e04daec3bf32 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Tue, 12 Sep 2023 15:23:33 +0200 Subject: [PATCH 21/29] compiler/ci: add libgraal tests for JDK 22 --- ci/ci_common/common.jsonnet | 6 +++--- ci/common.jsonnet | 2 +- compiler/ci/ci_common/gate.jsonnet | 2 +- vm/ci/ci_common/libgraal.jsonnet | 5 +++-- vm/ci/ci_includes/vm.jsonnet | 4 +++- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/ci/ci_common/common.jsonnet b/ci/ci_common/common.jsonnet index 8b8179a88975..08e56beec1a4 100644 --- a/ci/ci_common/common.jsonnet +++ b/ci/ci_common/common.jsonnet @@ -71,9 +71,9 @@ common + common.frequencies + { labsjdk21Debug:: self["labsjdk-" + repo_config.graalvm_edition + "-21Debug"], labsjdk21LLVM:: self["labsjdk-" + repo_config.graalvm_edition + "-21-llvm"], - labsjdk22:: self["labsjdk-" + repo_config.graalvm_edition + "-22"], - labsjdk22Debug:: self["labsjdk-" + repo_config.graalvm_edition + "-22Debug"], - labsjdk22LLVM:: self["labsjdk-" + repo_config.graalvm_edition + "-22-llvm"], + labsjdkLatest:: self["labsjdk-" + repo_config.graalvm_edition + "-22"], + labsjdkLatestDebug:: self["labsjdk-" + repo_config.graalvm_edition + "-22Debug"], + labsjdkLatestLLVM:: self["labsjdk-" + repo_config.graalvm_edition + "-22-llvm"], // Hardware definitions // ******************** diff --git a/ci/common.jsonnet b/ci/common.jsonnet index 25ad1c925245..c15b0a8b42dc 100644 --- a/ci/common.jsonnet +++ b/ci/common.jsonnet @@ -59,7 +59,7 @@ local common_json = import "../common.json"; "windows-jdk19": { packages+: { "devkit:VS2022-17.1.0+1": "==0" }}, "windows-jdk20": { packages+: { "devkit:VS2022-17.1.0+1": "==0" }}, "windows-jdk21": { packages+: { "devkit:VS2022-17.1.0+1": "==1" }}, - "windows-jdk22": { packages+: { "devkit:VS2022-17.1.0+1": "==1" }}, + "windows-jdkLatest": { packages+: { "devkit:VS2022-17.1.0+1": "==1" }}, "linux-jdk17": { packages+: { "devkit:gcc11.2.0-OL6.4+1": "==0" }}, "linux-jdk19": { packages+: { "devkit:gcc11.2.0-OL6.4+1": "==0" }}, "linux-jdk20": { packages+: { "devkit:gcc11.2.0-OL6.4+1": "==0" }}, diff --git a/compiler/ci/ci_common/gate.jsonnet b/compiler/ci/ci_common/gate.jsonnet index d9f21897b181..3e83731fbb96 100644 --- a/compiler/ci/ci_common/gate.jsonnet +++ b/compiler/ci/ci_common/gate.jsonnet @@ -295,7 +295,7 @@ dailies_manifest=dailies, weeklies_manifest=weeklies, monthlies_manifest=monthlies):: { - local base_name = "%s-%s-%s-%s-%s" % [suite, task, jdk_name, jdk, os_arch], + local base_name = "%s-%s-%s-%s-%s" % [suite, task, jdk_name, if std.startsWith(jdk, "Latest") then "l" + jdk[1:] else jdk, os_arch], local gate_name = "gate-" + base_name, local daily_name = "daily-" + base_name, local weekly_name = "weekly-" + base_name, diff --git a/vm/ci/ci_common/libgraal.jsonnet b/vm/ci/ci_common/libgraal.jsonnet index 323c0e9ec104..a7a9a8822b21 100644 --- a/vm/ci/ci_common/libgraal.jsonnet +++ b/vm/ci/ci_common/libgraal.jsonnet @@ -111,14 +111,15 @@ local utils = import '../../../ci/ci_common/common-utils.libsonnet'; vm["custom_vm_" + os(os_arch)] + g.make_build(jdk, os_arch, task, extra_tasks=self, suite="vm", include_common_os_arch=false, - jdk_name = if jdk == "22" then "oraclejdk" else "labsjdk", + jdk_name = "labsjdk", gates_manifest=gates, dailies_manifest=dailies, weeklies_manifest=weeklies, monthlies_manifest=monthlies).build + vm["vm_java_" + jdk] for jdk in [ - "21" + "21", + "Latest" ] for os_arch in all_os_arches for task in [ diff --git a/vm/ci/ci_includes/vm.jsonnet b/vm/ci/ci_includes/vm.jsonnet index 472d0566c549..a4038b07bf48 100644 --- a/vm/ci/ci_includes/vm.jsonnet +++ b/vm/ci/ci_includes/vm.jsonnet @@ -8,7 +8,9 @@ local graal_common = import '../../../ci/ci_common/common.jsonnet'; { vm_java_21:: graal_common.labsjdk21 + vm_common.vm_env_mixin('21'), - vm_java_22:: graal_common.oraclejdk22 + vm_common.vm_env_mixin('22'), + vm_java_Latest:: + local jdk = graal_common.labsjdkLatest; + jdk + vm_common.vm_env_mixin(std.toString(jdk.jdk_version)), vm_java_21_llvm:: self.vm_java_21 + graal_common['labsjdk-ce-21-llvm'], From dd55529e4035b0b7058dac8006ecc97bc403cf2f Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Tue, 12 Sep 2023 17:16:10 +0200 Subject: [PATCH 22/29] compiler/ci: add labsjdk latest libgraal gate --- vm/ci/ci_common/libgraal.jsonnet | 1 + 1 file changed, 1 insertion(+) diff --git a/vm/ci/ci_common/libgraal.jsonnet b/vm/ci/ci_common/libgraal.jsonnet index a7a9a8822b21..4d780c1c53fd 100644 --- a/vm/ci/ci_common/libgraal.jsonnet +++ b/vm/ci/ci_common/libgraal.jsonnet @@ -77,6 +77,7 @@ local utils = import '../../../ci/ci_common/common-utils.libsonnet'; "gate-vm-libgraal_compiler_zgc-labsjdk-21-linux-amd64": {}, "gate-vm-libgraal_compiler_quickbuild-labsjdk-21-linux-amd64": {}, "gate-vm-libgraal_truffle_quickbuild-labsjdk-21-linux-amd64": t("1:10:00"), + "gate-vm-libgraal_compiler-labsjdk-latest-linux-amd64": {}, }, # See definition of `dailies` local variable in ../../compiler/ci_common/gate.jsonnet From e63c134ca050015f66dda64f884146ac9a21a9c5 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Tue, 12 Sep 2023 17:32:09 +0200 Subject: [PATCH 23/29] compiler/ci: add a build gate for JDK latest to perform a strict JVMCI_VERSION_CHECK --- compiler/ci/ci_common/gate.jsonnet | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/compiler/ci/ci_common/gate.jsonnet b/compiler/ci/ci_common/gate.jsonnet index 3e83731fbb96..93bd08495d78 100644 --- a/compiler/ci/ci_common/gate.jsonnet +++ b/compiler/ci/ci_common/gate.jsonnet @@ -206,6 +206,7 @@ "gate-compiler-test_zgc-labsjdk-21-darwin-aarch64": t("1:00:00"), "gate-compiler-style-labsjdk-21-linux-amd64": t("45:00"), + "gate-compiler-build-labsjdk-latest-linux-amd64": t("25:00"), "gate-compiler-ctw-labsjdk-21-linux-amd64": c.mach5_target, "gate-compiler-ctw-labsjdk-21-windows-amd64": t("1:50:00"), @@ -436,10 +437,16 @@ ], local style_builds = [self.make_build("21", "linux-amd64", "style").build + { - environment+: { - # Run the strict JVMCI version check, i.e., that JVMCIVersionCheck.JVMCI_MIN_VERSION matches the versions in common.json. - JVMCI_VERSION_CHECK: "strict", - } + environment+: { + # Run the strict JVMCI version check, i.e., that JVMCIVersionCheck.JVMCI_MIN_VERSION matches the versions in common.json. + JVMCI_VERSION_CHECK: "strict", + }, + }], + local jdk_latest_version_check_builds = [self.make_build("Latest", "linux-amd64", "build", extra_tasks={build:: s.base("build"),}).build + { + environment+: { + # Run the strict JVMCI version check, i.e., that JVMCIVersionCheck.JVMCI_MIN_VERSION matches the versions in common.json. + JVMCI_VERSION_CHECK: "strict", + }, }], # Builds run on only on linux-amd64-jdk21Debug @@ -455,6 +462,7 @@ all_zgc_builds + all_serialgc_builds + style_builds + + jdk_latest_version_check_builds + linux_amd64_jdk21_builds + linux_amd64_jdk21Debug_builds, From 7e6a00a3b673dc162f6ac132c60a32ac684bd4a5 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Wed, 13 Sep 2023 09:15:00 +0200 Subject: [PATCH 24/29] compiler: update JVMCIVersionCheckTest --- .../test/JVMCIVersionCheckMaxValueTest.java | 50 ++++++++ .../hotspot/test/JVMCIVersionCheckTest.java | 107 ++++++++++++------ 2 files changed, 121 insertions(+), 36 deletions(-) create mode 100644 compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/JVMCIVersionCheckMaxValueTest.java diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/JVMCIVersionCheckMaxValueTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/JVMCIVersionCheckMaxValueTest.java new file mode 100644 index 000000000000..6d9d9abb3bc1 --- /dev/null +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/JVMCIVersionCheckMaxValueTest.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.graalvm.compiler.hotspot.test; + +import java.util.Map; + +import org.graalvm.compiler.core.test.GraalCompilerTest; +import org.graalvm.compiler.hotspot.JVMCIVersionCheck; +import org.junit.Assert; +import org.junit.Test; + +public class JVMCIVersionCheckMaxValueTest extends GraalCompilerTest { + @Test + public void test01() { + Map props = JVMCIVersionCheckTest.props; + // Test handling of version components bigger than Integer.MAX_VALUE + for (String version : new String[]{"20.0." + Long.MAX_VALUE, "20." + Long.MAX_VALUE + ".0", Long.MAX_VALUE + ".0.0"}) { + String javaVmVersion = String.format("prefix-jvmci-%s-suffix", version); + try { + JVMCIVersionCheck.Version minVersion = new JVMCIVersionCheck.Version(20, 0, 1); + JVMCIVersionCheck.check(props, minVersion, "1.8", javaVmVersion, false); + Assert.fail("expected to fail checking " + javaVmVersion + " against " + minVersion); + } catch (InternalError e) { + // pass + } + } + } +} diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/JVMCIVersionCheckTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/JVMCIVersionCheckTest.java index 26501fceb41e..79cc21862c85 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/JVMCIVersionCheckTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/JVMCIVersionCheckTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,7 +24,10 @@ */ package org.graalvm.compiler.hotspot.test; +import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Random; @@ -34,62 +37,94 @@ import org.graalvm.compiler.hotspot.JVMCIVersionCheck.Version; import org.junit.Assert; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; +@RunWith(Parameterized.class) public class JVMCIVersionCheckTest extends GraalCompilerTest { - @Test - public void test01() { + private static final String[] JDK_VERSIONS = { + null, + "21", + "21+3", + "21.0.1+3", + "21-ea+11-790" + }; + + static final Map props; + static { Properties sprops = System.getProperties(); - Map props = new HashMap<>(sprops.size()); + props = new HashMap<>(sprops.size()); for (String name : sprops.stringPropertyNames()) { props.put(name, sprops.getProperty(name)); } - long seed = Long.getLong("test.seed", System.nanoTime()); - Random random = new Random(seed); + } - for (int i = 0; i < 50; i++) { - int minMajor = i; - int minMinor = 50 - i; - for (int j = 0; j < 50; j++) { - int major = j; - int minor = 50 - j; + private static final long SEED = Long.getLong("test.seed", System.nanoTime()); - for (int k = 0; k < 30; k++) { - int minBuild = random.nextInt(100); - int build = random.nextInt(100); + @Parameters(name = "{0} vs {1}") + public static Collection data() { + List ret = new ArrayList<>(); + Random random = new Random(SEED); - Version version = new Version(major, minor, build); - Version minVersion = new Version(minMajor, minMinor, minBuild); - String javaVmVersion = String.format("prefix-jvmci-%s-suffix", version); - if (!version.isLessThan(minVersion)) { - try { - JVMCIVersionCheck.check(props, minVersion, "21", javaVmVersion, false); - } catch (InternalError e) { - throw new AssertionError("Failed " + JVMCIVersionCheckTest.class.getSimpleName() + " with -Dtest.seed=" + seed, e); - } - } else { - try { - JVMCIVersionCheck.check(props, minVersion, "21", javaVmVersion, false); - Assert.fail("expected to fail checking " + javaVmVersion + " against " + minVersion + " (-Dtest.seed=" + seed + ")"); - } catch (InternalError e) { - // pass + for (String minJdkVersion : JDK_VERSIONS) { + for (String jdkVersion : JDK_VERSIONS) { + for (int i = 0; i < (minJdkVersion == null ? 50 : 1); i++) { + int minMajor = i; + int minMinor = 50 - i; + for (int j = 0; j < (jdkVersion == null ? 50 : 1); j++) { + int major = j; + int minor = 50 - j; + + for (int k = 0; k < 30; k++) { + int minBuild = random.nextInt(100); + int build = random.nextInt(100); + + Version version = getVersion(jdkVersion, major, minor, build); + Version minVersion = getVersion(minJdkVersion, minMajor, minMinor, minBuild); + ret.add(new Object[]{version, minVersion}); } } } } } + return ret; + } + + private static Version getVersion(String jdkVersion, int major, int minor, int build) { + if (jdkVersion != null) { + // new version scheme + return new Version(jdkVersion, build); + } else { + // legacy version scheme + return new Version(major, minor, build); + } + } + + @Parameter(value = 0) public Version version; + @Parameter(value = 1) public Version minVersion; - // Test handling of version components bigger than Integer.MAX_VALUE - for (String version : new String[]{"20.0." + Long.MAX_VALUE, "20." + Long.MAX_VALUE + ".0", Long.MAX_VALUE + ".0.0"}) { - String javaVmVersion = String.format("prefix-jvmci-%s-suffix", version); + @Test + public void test01() { + String legacyPrefix = version.toString().startsWith("jvmci") ? "prefix-" : ""; + String javaVmVersion = legacyPrefix + version.toString() + "Suffix"; + if (!version.isLessThan(minVersion)) { try { - Version minVersion = new Version(20, 0, 1); - JVMCIVersionCheck.check(props, minVersion, "1.8", javaVmVersion, false); - Assert.fail("expected to fail checking " + javaVmVersion + " against " + minVersion); + JVMCIVersionCheck.check(props, minVersion, "21", javaVmVersion, false); + } catch (InternalError e) { + throw new AssertionError("Failed " + JVMCIVersionCheckTest.class.getSimpleName() + " with -Dtest.seed=" + SEED, e); + } + } else { + try { + JVMCIVersionCheck.check(props, minVersion, "21", javaVmVersion, false); + Assert.fail("expected to fail checking " + javaVmVersion + " against " + minVersion + " (-Dtest.seed=" + SEED + ")"); } catch (InternalError e) { // pass } } } } + From f69479aaeb960b5d59cae6d2ba300359e46d542e Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Wed, 13 Sep 2023 09:15:17 +0200 Subject: [PATCH 25/29] compiler: fix JVMCIVersionCheck wrt legacy vs new scheme --- .../compiler/hotspot/JVMCIVersionCheck.java | 61 +++++++++++-------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java index bd2877ae7baf..03f0370355fb 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java @@ -47,8 +47,8 @@ public final class JVMCIVersionCheck { * Minimum JVMCI version supported by Graal. */ private static final Map JVMCI_MIN_VERSIONS = Map.of( - "21", new Version("21+35", 23, 1, 15), - "22", new Version("22+13", JVMCIVersionCheck.NA, JVMCIVersionCheck.NA, 1)); + "21", new Version(23, 1, 15), + "22", new Version("22+13", 1)); private static final int NA = 0; /** @@ -61,16 +61,24 @@ public static class Version { private final int jvmciMajor; private final int jvmciMinor; private final int jvmciBuild; + private final boolean legacy; static Version parse(String vmVersion) { Matcher m = Pattern.compile("(.+)-jvmci(-(\\d+)\\.(\\d+))?-b(\\d+).*").matcher(vmVersion); if (m.matches()) { try { - Runtime.Version jdkVersion = Runtime.Version.parse(m.group(1)); - int jvmciMajor = parseIntOrZero(m.group(3)); - int jvmciMinor = parseIntOrZero(m.group(4)); - int jvmciBuild = parseIntOrZero(m.group(5)); - return new Version(jdkVersion, jvmciMajor, jvmciMinor, jvmciBuild); + if (m.group(3) == null) { + assert m.group(4) == null : "if jvmciMajor is null jvmciMinor must also be null"; + String jdkVersion = m.group(1); + int jvmciBuild = Integer.parseInt(m.group(5)); + return new Version(jdkVersion, jvmciBuild); + } else { + int jvmciMajor = Integer.parseInt(m.group(3)); + int jvmciMinor = Integer.parseInt(m.group(4)); + int jvmciBuild = Integer.parseInt(m.group(5)); + return new Version(jvmciMajor, jvmciMinor, jvmciBuild); + } + } catch (NumberFormatException e) { // ignore } @@ -78,11 +86,12 @@ static Version parse(String vmVersion) { return null; } - private static int parseIntOrZero(String group) { - if (group == null) { - return 0; - } - return Integer.parseInt(group); + /** + * Convenience constructor for the current version scheme that only uses the JDK version and + * the JVMCI build number. + */ + public Version(String jdkVersionString, int jvmciBuild) { + this(jdkVersionString, NA, NA, jvmciBuild, false); } /** @@ -90,18 +99,19 @@ private static int parseIntOrZero(String group) { * to {@code 21}. While this is not entirely correct, it works for our purposes. */ public Version(int jvmciMajor, int jvmciMinor, int jvmciBuild) { - this("21", jvmciMajor, jvmciMinor, jvmciBuild); + this("21", jvmciMajor, jvmciMinor, jvmciBuild, true); } - public Version(String jdkVersionString, int jvmciMajor, int jvmciMinor, int jvmciBuild) { - this(Runtime.Version.parse(jdkVersionString), jvmciMajor, jvmciMinor, jvmciBuild); + private Version(String jdkVersionString, int jvmciMajor, int jvmciMinor, int jvmciBuild, boolean legacy) { + this(Runtime.Version.parse(jdkVersionString), jvmciMajor, jvmciMinor, jvmciBuild, legacy); } - public Version(Runtime.Version jdkVersion, int jvmciMajor, int jvmciMinor, int jvmciBuild) { + private Version(Runtime.Version jdkVersion, int jvmciMajor, int jvmciMinor, int jvmciBuild, boolean legacy) { this.jdkVersion = jdkVersion; this.jvmciMajor = jvmciMajor; this.jvmciMinor = jvmciMinor; this.jvmciBuild = jvmciBuild; + this.legacy = legacy; } boolean isGreaterThan(Version other) { @@ -116,12 +126,17 @@ public boolean isLessThan(Version other) { if (compareTo < 0) { return true; } - if (compareTo == 0 && this.jvmciMajor == other.jvmciMajor) { - if (this.jvmciMinor < other.jvmciMinor) { + if (compareTo == 0) { + if (this.jvmciMajor < other.jvmciMajor) { return true; } - if (this.jvmciMinor == other.jvmciMinor && this.jvmciBuild < other.jvmciBuild) { - return true; + if (this.jvmciMajor == other.jvmciMajor) { + if (this.jvmciMinor < other.jvmciMinor) { + return true; + } + if (this.jvmciMinor == other.jvmciMinor && this.jvmciBuild < other.jvmciBuild) { + return true; + } } } return false; @@ -145,17 +160,13 @@ public int hashCode() { @Override public String toString() { - if (isJDK22OrLater()) { + if (!legacy) { return String.format(AS_TAG_FORMAT_22_AND_LATER, jdkVersion, jvmciBuild); } else { return String.format(AS_TAG_FORMAT_21_AND_EARLIER, jvmciMajor, jvmciMinor, jvmciBuild); } } - private boolean isJDK22OrLater() { - return jvmciMajor == NA; - } - public String printFormat(PrintFormat format) { return switch (format) { case TUPLE -> String.format("%s,%d,%d,%d", jdkVersion, jvmciMajor, jvmciMinor, jvmciBuild); From 7d3bc70e2ca0a2127fd3e82c83d2f5952ba1cda0 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Wed, 13 Sep 2023 09:25:47 +0200 Subject: [PATCH 26/29] compiler: fix JVMCIVersionCheckMaxValueTest --- .../hotspot/test/JVMCIVersionCheckMaxValueTest.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/JVMCIVersionCheckMaxValueTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/JVMCIVersionCheckMaxValueTest.java index 6d9d9abb3bc1..def56aee8c6b 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/JVMCIVersionCheckMaxValueTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/JVMCIVersionCheckMaxValueTest.java @@ -40,10 +40,14 @@ public void test01() { String javaVmVersion = String.format("prefix-jvmci-%s-suffix", version); try { JVMCIVersionCheck.Version minVersion = new JVMCIVersionCheck.Version(20, 0, 1); - JVMCIVersionCheck.check(props, minVersion, "1.8", javaVmVersion, false); + // Use a javaSpecVersion that will likely not fail in the near future + JVMCIVersionCheck.check(props, minVersion, "99", javaVmVersion, false); Assert.fail("expected to fail checking " + javaVmVersion + " against " + minVersion); } catch (InternalError e) { - // pass + String expectedMsg = "Cannot read JVMCI version from java.vm.version property"; + if (!e.getMessage().contains(expectedMsg)) { + throw new AssertionError("Unexpected exception message. Expected: " + expectedMsg, e); + } } } } From 8ae450072414b5c1411d022a89e7c3414127a325 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Wed, 13 Sep 2023 09:47:38 +0200 Subject: [PATCH 27/29] compiler: fix JVMCIVersionCheckMaxValueTest and add test for new scheme --- .../test/JVMCIVersionCheckMaxValueTest.java | 44 ++++++++++++------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/JVMCIVersionCheckMaxValueTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/JVMCIVersionCheckMaxValueTest.java index def56aee8c6b..180386e26739 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/JVMCIVersionCheckMaxValueTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/JVMCIVersionCheckMaxValueTest.java @@ -24,30 +24,40 @@ */ package org.graalvm.compiler.hotspot.test; -import java.util.Map; - import org.graalvm.compiler.core.test.GraalCompilerTest; import org.graalvm.compiler.hotspot.JVMCIVersionCheck; import org.junit.Assert; import org.junit.Test; +/** + * Test handling of version components bigger than Integer.MAX_VALUE. + */ public class JVMCIVersionCheckMaxValueTest extends GraalCompilerTest { + + public static final String EXPECTED_MSG = "Cannot read JVMCI version from java.vm.version property"; + + @Test + public void testLegacyVersion() { + for (String version : new String[]{"20.0-b" + Long.MAX_VALUE, "20." + Long.MAX_VALUE + "-b1", Long.MAX_VALUE + ".0-b1"}) { + testVersion(String.format("prefix-jvmci-%s-suffix", version)); + } + } + @Test - public void test01() { - Map props = JVMCIVersionCheckTest.props; - // Test handling of version components bigger than Integer.MAX_VALUE - for (String version : new String[]{"20.0." + Long.MAX_VALUE, "20." + Long.MAX_VALUE + ".0", Long.MAX_VALUE + ".0.0"}) { - String javaVmVersion = String.format("prefix-jvmci-%s-suffix", version); - try { - JVMCIVersionCheck.Version minVersion = new JVMCIVersionCheck.Version(20, 0, 1); - // Use a javaSpecVersion that will likely not fail in the near future - JVMCIVersionCheck.check(props, minVersion, "99", javaVmVersion, false); - Assert.fail("expected to fail checking " + javaVmVersion + " against " + minVersion); - } catch (InternalError e) { - String expectedMsg = "Cannot read JVMCI version from java.vm.version property"; - if (!e.getMessage().contains(expectedMsg)) { - throw new AssertionError("Unexpected exception message. Expected: " + expectedMsg, e); - } + public void testNewVersion() { + // We only want to test jvmciBuild, not Runtime.Version, so we use a fixed jdkVersion string + testVersion(String.format("99.0.1-jvmci-b%s-suffix", Long.MAX_VALUE)); + } + + private static void testVersion(String javaVmVersion) { + try { + JVMCIVersionCheck.Version minVersion = new JVMCIVersionCheck.Version(20, 0, 1); + // Use a javaSpecVersion that will likely not fail in the near future + JVMCIVersionCheck.check(JVMCIVersionCheckTest.props, minVersion, "99", javaVmVersion, false); + Assert.fail("expected to fail checking " + javaVmVersion + " against " + minVersion); + } catch (InternalError e) { + if (!e.getMessage().contains(EXPECTED_MSG)) { + throw new AssertionError("Unexpected exception message. Expected: " + EXPECTED_MSG, e); } } } From 22f44d5bb43357a25af5bd8d48298a955d3f69fc Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Wed, 13 Sep 2023 19:50:50 +0200 Subject: [PATCH 28/29] compiler: ignore jdkVersion for legacy version in JVMCIVersionCheck --- compiler/mx.compiler/mx_compiler.py | 8 +++++-- .../compiler/hotspot/JVMCIVersionCheck.java | 21 ++++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/compiler/mx.compiler/mx_compiler.py b/compiler/mx.compiler/mx_compiler.py index c2e69e866622..bde0c8d3f888 100644 --- a/compiler/mx.compiler/mx_compiler.py +++ b/compiler/mx.compiler/mx_compiler.py @@ -97,12 +97,16 @@ def __cmp__(self, other): raise TypeError(f'Cannot compare {JavaLangRuntimeVersion.__name__} to {type(other).__name__}') this_version = self.version other_version = other.version + if this_version == other_version: + return 0 + if self.feature() == 21 and other.feature() == 21: + # JDK 21 uses the legacy version scheme where the jdkVersion is irrelevant (and imprecise). + # Thus, we do not perform a full version check. + return 0 return JavaLangRuntimeVersion.compare(this_version, other_version, jdk) @staticmethod def compare(this_version, other_version, jdk): - if this_version == other_version: - return 0 key = (this_version, other_version) cached = JavaLangRuntimeVersion._cmp_cache.get(key, None) if cached is not None: diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java index 03f0370355fb..1b5ca3474055 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/JVMCIVersionCheck.java @@ -122,20 +122,25 @@ boolean isGreaterThan(Version other) { } public boolean isLessThan(Version other) { - int compareTo = this.jdkVersion.compareTo(other.jdkVersion); - if (compareTo < 0) { + if (this.legacy && !other.legacy) { return true; } - if (compareTo == 0) { - if (this.jvmciMajor < other.jvmciMajor) { + if (this.legacy == other.legacy) { + int compareTo = this.legacy ? 0 : this.jdkVersion.compareTo(other.jdkVersion); + if (compareTo < 0) { return true; } - if (this.jvmciMajor == other.jvmciMajor) { - if (this.jvmciMinor < other.jvmciMinor) { + if (compareTo == 0) { + if (this.jvmciMajor < other.jvmciMajor) { return true; } - if (this.jvmciMinor == other.jvmciMinor && this.jvmciBuild < other.jvmciBuild) { - return true; + if (this.jvmciMajor == other.jvmciMajor) { + if (this.jvmciMinor < other.jvmciMinor) { + return true; + } + if (this.jvmciMinor == other.jvmciMinor && this.jvmciBuild < other.jvmciBuild) { + return true; + } } } } From 364d981c1ab19bb1ff2383ea946a1ba043add032 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Thu, 14 Sep 2023 08:24:44 +0200 Subject: [PATCH 29/29] fix style --- .../org/graalvm/compiler/hotspot/test/JVMCIVersionCheckTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/JVMCIVersionCheckTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/JVMCIVersionCheckTest.java index 79cc21862c85..234f2e655c91 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/JVMCIVersionCheckTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/JVMCIVersionCheckTest.java @@ -127,4 +127,3 @@ public void test01() { } } } -