2525
2626from __future__ import print_function
2727import os
28+ from functools import total_ordering
2829from os .path import join , exists , basename , dirname , isdir
2930import argparse
3031from argparse import ArgumentParser , RawDescriptionHelpFormatter , REMAINDER
@@ -79,7 +80,7 @@ def get_vm_prefix(asList=True):
7980
8081
8182class JavaLangRuntimeVersion (mx .Comparable ):
82- """Wrapper for by java.lang.Runtime.Version"""
83+ """Wrapper for java.lang.Runtime.Version"""
8384
8485 _cmp_cache = {}
8586 _feature_re = re .compile ('[1-9][0-9]*' )
@@ -124,10 +125,48 @@ def feature(self):
124125 self ._feature = int (JavaLangRuntimeVersion ._feature_re .match (self .version ).group (0 ))
125126 return self ._feature
126127
128+ @total_ordering
129+ class JVMCIVersionCheckVersion (object ):
130+ def __init__ (self , jdk_version , jvmci_major , jvmci_minor , jvmci_build ):
131+ """
132+ Python version of jdk.graal.compiler.hotspot.JVMCIVersionCheck.Version
133+
134+ jdk_version is a JavaLangRuntimeVersion
135+ jvmci_major and jvmci_minor might be 0 if not needed (JDK 22+)
136+ """
137+ assert isinstance (jdk_version , JavaLangRuntimeVersion )
138+ assert isinstance (jvmci_major , int )
139+ assert isinstance (jvmci_minor , int )
140+ assert isinstance (jvmci_build , int )
141+ self .jdk_version = jdk_version
142+ self .jvmci_major = jvmci_major
143+ self .jvmci_minor = jvmci_minor
144+ self .jvmci_build = jvmci_build
145+
146+ def _as_tuple (self ):
147+ return (self .jdk_version , self .jvmci_major , self .jvmci_minor , self .jvmci_build )
148+
149+ def __eq__ (self , other ):
150+ if not isinstance (other , JVMCIVersionCheckVersion ):
151+ return False
152+ return self ._as_tuple () == other ._as_tuple ()
153+
154+ def __lt__ (self , other ):
155+ if not isinstance (other , JVMCIVersionCheckVersion ):
156+ return NotImplemented
157+ return self ._as_tuple () < other ._as_tuple ()
158+
159+ def __str__ (self ):
160+ jdk_version , jvmci_major , jvmci_minor , jvmci_build = self ._as_tuple ()
161+ if jvmci_major == 0 :
162+ if jvmci_build == 0 :
163+ return f'(openjdk|oraclejdk)-{ jdk_version } '
164+ else :
165+ return f'labsjdk-(ce|ee)-{ jdk_version } -jvmci-b{ jvmci_build :02d} '
166+ else :
167+ return f'labsjdk-(ce|ee)-{ jdk_version } -jvmci-{ jvmci_major } .{ jvmci_minor } -b{ jvmci_build :02d} '
168+
127169
128- #: 4-tuple (jdk_version, jvmci_major, jvmci_minor, jvmci_build) of JVMCI version, if any, denoted by `jdk`
129- # jdk_version is a JavaLangRuntimeVersion
130- # jvmci_major and jvmci_minor might be 0 if not needed (JDK 22+)
131170_jdk_jvmci_version = None
132171_jdk_min_jvmci_version = None
133172
@@ -145,7 +184,7 @@ def _capture_jvmci_version(args=None):
145184 if out .data :
146185 try :
147186 (jdk_version , jvmci_major , jvmci_minor , jvmci_build ) = out .data .split (',' )
148- return (JavaLangRuntimeVersion (jdk_version ), int (jvmci_major ), int (jvmci_minor ), int (jvmci_build ))
187+ return JVMCIVersionCheckVersion (JavaLangRuntimeVersion (jdk_version ), int (jvmci_major ), int (jvmci_minor ), int (jvmci_build ))
149188 except ValueError :
150189 mx .warn (f'Could not parse jvmci version from JVMCIVersionCheck output:\n { out .data } ' )
151190 return None
@@ -1165,7 +1204,7 @@ def _check_latest_jvmci_version():
11651204 ``common.json`` file and issues a warning if not.
11661205 """
11671206 jvmci_re = re .compile (r'(?:ce|ee)-(?P<jdk_version>.+)-jvmci(?:-(?P<jvmci_major>\d+)\.(?P<jvmci_minor>\d+))?-b(?P<jvmci_build>\d+)' )
1168- common_path = join (_suite .dir , '..' , 'common.json' )
1207+ common_path = os . path . normpath ( join (_suite .dir , '..' , 'common.json' ) )
11691208
11701209 if _jdk_jvmci_version is None :
11711210 # Not using a JVMCI JDK
@@ -1183,8 +1222,13 @@ def get_latest_jvmci_version():
11831222 if not match :
11841223 mx .abort (f'Cannot parse version { version } ' )
11851224 (jdk_version , jvmci_major , jvmci_minor , jvmci_build ) = match .groups (default = 0 )
1186- current = (JavaLangRuntimeVersion (jdk_version ), int (jvmci_major ), int (jvmci_minor ), int (jvmci_build ))
1187- if current [0 ].feature () == _jdk_jvmci_version [0 ].feature ():
1225+ if _jdk_jvmci_version .jvmci_build == 0 :
1226+ # jvmci_build == 0 indicates an OpenJDK version has been specified in JVMCIVersionCheck.java.
1227+ # The JDK does not know the jvmci_build number that might have been specified in common.json,
1228+ # as it is only a repackaged JDK. Thus, we reset the jvmci_build because we cannot validate it.
1229+ jvmci_build = 0
1230+ current = JVMCIVersionCheckVersion (JavaLangRuntimeVersion (jdk_version ), int (jvmci_major ), int (jvmci_minor ), int (jvmci_build ))
1231+ if current .jdk_version .feature () == _jdk_jvmci_version .jdk_version .feature ():
11881232 # only compare the same major versions
11891233 if latest == 'not found' :
11901234 latest = current
@@ -1196,28 +1240,21 @@ def get_latest_jvmci_version():
11961240 return False , distribution
11971241 return not isinstance (latest , str ), latest
11981242
1199- def jvmci_version_str (version ):
1200- jdk_version , jvmci_major , jvmci_minor , jvmci_build = version
1201- if jvmci_major == 0 :
1202- return f'labsjdk-(ce|ee)-{ jdk_version } -jvmci-b{ jvmci_build :02d} '
1203- else :
1204- return f'labsjdk-(ce|ee)-{ jdk_version } -jvmci-{ jvmci_major } .{ jvmci_minor } -b{ jvmci_build :02d} '
1205-
12061243 version_check_setting = os .environ .get ('JVMCI_VERSION_CHECK' , None )
12071244
12081245 success , latest = get_latest_jvmci_version ()
12091246
12101247 if version_check_setting == 'strict' and _jdk_jvmci_version != _jdk_min_jvmci_version :
12111248 msg = f'JVMCI_MIN_VERSION specified in JVMCIVersionCheck.java is older than in { common_path } :'
1212- msg += os .linesep + f'{ jvmci_version_str ( _jdk_min_jvmci_version ) } < { jvmci_version_str ( _jdk_jvmci_version ) } '
1249+ msg += os .linesep + f'{ _jdk_min_jvmci_version } < { _jdk_jvmci_version } '
12131250 msg += os .linesep + f'Did you forget to update JVMCI_MIN_VERSION after updating { common_path } ?'
12141251 msg += os .linesep + 'Set the JVMCI_VERSION_CHECK environment variable to something else then "strict" to'
12151252 msg += ' suppress this error.'
12161253 mx .abort (msg )
12171254
12181255 if version_check_setting == 'strict' and not success :
12191256 if latest == 'not found' :
1220- msg = f'No JVMCI JDK found in { common_path } that matches { jvmci_version_str ( _jdk_jvmci_version ) } .'
1257+ msg = f'No JVMCI JDK found in { common_path } that matches { _jdk_jvmci_version } .'
12211258 msg += os .linesep + f'Check that { latest } matches the versions of the other JVMCI JDKs.'
12221259 else :
12231260 msg = f'Version mismatch in { common_path } :'
@@ -1227,10 +1264,9 @@ def jvmci_version_str(version):
12271264 mx .abort (msg )
12281265
12291266 if success and _jdk_jvmci_version < latest :
1230- common_path = os .path .normpath (common_path )
1231- msg = f'JVMCI version of JAVA_HOME is older than in { common_path } : { jvmci_version_str (_jdk_jvmci_version )} < { jvmci_version_str (latest )} '
1267+ msg = f'JVMCI version of JAVA_HOME is older than in { common_path } : { _jdk_jvmci_version } < { latest } '
12321268 msg += os .linesep + 'This poses the risk of hitting JVMCI bugs that have already been fixed.'
1233- msg += os .linesep + f'Consider using { jvmci_version_str ( latest ) } , which you can get via:'
1269+ msg += os .linesep + f'Consider using { latest } , which you can get via:'
12341270 msg += os .linesep + f'mx fetch-jdk --configuration { common_path } '
12351271 mx .abort_or_warn (msg , version_check_setting == 'strict' )
12361272
0 commit comments