Skip to content

Commit

Permalink
avoid extra VM execution for latest JVMCI version check
Browse files Browse the repository at this point in the history
  • Loading branch information
dougxc committed Jun 23, 2021
1 parent 1b41b6e commit 576d579
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
42 changes: 22 additions & 20 deletions compiler/mx.compiler/mx_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ 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`
_jdk_jvmci_version = None

if jdk.javaCompliance < '1.8':
mx.abort('Graal requires JDK8 or later, got ' + str(jdk))

Expand Down Expand Up @@ -142,7 +145,14 @@ def source_supplier():
with open(unqualified_source_path, 'w') as fp:
fp.write(source_supplier().replace('package org.graalvm.compiler.hotspot;', ''))
mx.run([jdk.javac, '-d', sdu.directory, unqualified_source_path])
mx.run([jdk.java, '-cp', binDir, unqualified_name])

jvmci_version_file = join(binDir, 'jvmci_version.' + str(os.getpid()))
mx.run([jdk.java, '-DJVMCIVersionCheck.jvmci.version.file=' + jvmci_version_file, '-cp', binDir, unqualified_name])
if exists(jvmci_version_file):
with open(jvmci_version_file) as fp:
global _jdk_jvmci_version
_jdk_jvmci_version = tuple((int(n) for n in fp.read().split(',')))
os.remove(jvmci_version_file)

if os.environ.get('JVMCI_VERSION_CHECK', None) != 'ignore':
_check_jvmci_version(jdk)
Expand Down Expand Up @@ -982,26 +992,18 @@ def run_vm_with_jvmci_compiler(args, nonZeroIsFatal=True, out=None, err=None, cw
jvmci_args = ['-XX:+UseJVMCICompiler'] + args
return run_vm(jvmci_args, nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd, timeout=timeout, debugLevel=debugLevel, vmbuild=vmbuild)

def _check_latest_jvmci_version(jdk):
def _check_latest_jvmci_version():
"""
If `jdk` is a JVMCI JDK, checks that its JVMCI version is the same as
the JVMCI version as the JVMCI JDKs in "jdks" section in the top level
``common.json`` file and issues a warning if it is not.
If `_jdk_jvmci_version` is not None, checks that it is the same as
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')

def get_current_jvmci_version():
out = mx.LinesOutputCapture()
mx.run([jdk.java, '-XshowSettings:properties', '-version'], out=out, err=out)
for line in out.lines:
if 'java.vm.version = ' in line:
version = line.split('=', 1)[1].strip()
m = jvmci_re.match(version)
if m:
return tuple(int(n) for n in m.group(1, 2, 3))
break
return None
if _jdk_jvmci_version is None:
# Not using a JVMCI JDK
return

def get_latest_jvmci_version():
with open(common_path) as common_file:
Expand All @@ -1025,12 +1027,12 @@ def jvmci_version_str(version):
major, minor, build = version
return 'jvmci-{}.{}-b{:02d}'.format(major, minor, build)

current, latest = get_current_jvmci_version(), get_latest_jvmci_version()
if current is not None and latest is not None and current < latest:
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(current),
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))
Expand Down Expand Up @@ -1101,7 +1103,7 @@ def __closing__(self):
# Check if we're using the same JVMCI JDK as the CI system does.
# This only done when building the GRAAL distribution so as to
# not be too intrusive.
_check_latest_jvmci_version(jdk)
_check_latest_jvmci_version()

mx.add_argument('--vmprefix', action='store', dest='vm_prefix', help='prefix for running the VM (e.g. "gdb --args")', metavar='<prefix>')
mx.add_argument('--gdb', action='store_const', const='gdb --args', dest='vm_prefix', help='alias for --vmprefix "gdb --args"')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
*/
package org.graalvm.compiler.hotspot;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Formatter;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -62,6 +66,14 @@ static Version parse(String vmVersion) {
int major = Integer.parseInt(m.group(1));
int minor = Integer.parseInt(m.group(2));
int build = Integer.parseInt(m.group(3));
String jvmciVersionFile = System.getProperty("JVMCIVersionCheck.jvmci.version.file");
if (jvmciVersionFile != null) {
try {
Files.write(Paths.get(jvmciVersionFile), String.format("%d,%d,%d", major, minor, build).getBytes());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
return new Version3(major, minor, build);
} catch (NumberFormatException e) {
// ignore
Expand Down

0 comments on commit 576d579

Please sign in to comment.