From a02b78424486559b004979d77b852b8ff9622d2f Mon Sep 17 00:00:00 2001 From: Doug Simon Date: Tue, 29 Jun 2021 22:04:16 +0200 Subject: [PATCH] dump stdout and stderr logs for dacapo executions that exit with non-zero --- compiler/mx.compiler/mx_compiler.py | 41 ++++++++++++++++++++++++++--- vm/mx.vm/mx_vm_gate.py | 7 +++-- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/compiler/mx.compiler/mx_compiler.py b/compiler/mx.compiler/mx_compiler.py index e0d2203f1398..c0cf3c838af9 100644 --- a/compiler/mx.compiler/mx_compiler.py +++ b/compiler/mx.compiler/mx_compiler.py @@ -396,6 +396,35 @@ def _is_batik_supported(jdk): mx.warn('Batik uses Sun internal class com.sun.image.codec.jpeg.TruncatedFileException which is not present in ' + jdk.home) return False +class DaCapoWrapper(object): + """ + A context manager that dumps the stdout and stderr logs of DaCapo and ScalaDacapo + executions return with a non-zero exit code. + """ + + def __init__(self, scratch_dir): + """ + :param str scratch_dir: the directory in which the [Scala]DaCapo logs will be written + """ + self.scratch_dir = scratch_dir + + def __enter__(self): + self._logs = self._gather_logs() + return self + + def __exit__(self, exc_type, exc_value, traceback): + if exc_value is not None: + for before, after in zip(self._logs, self._gather_logs()): + if after.isNewerThan(before): + mx.log('Dumping ' + after.path) + mx.log('```') + with open(after.path) as fp: + mx.log(fp.read()) + mx.log('```') + + def _gather_logs(self): + return [mx.TimeStampFile(join(self.scratch_dir, name + '.log')) for name in ('stdout', 'stderr')] + def _gate_dacapo(name, iterations, extraVMarguments=None, force_serial_gc=True, set_start_heap_size=True, threads=None): vmargs = ['-XX:+UseSerialGC'] if force_serial_gc else [] if set_start_heap_size: @@ -404,10 +433,12 @@ def _gate_dacapo(name, iterations, extraVMarguments=None, force_serial_gc=True, dacapoJar = mx.library('DACAPO').get_path(True) if name == 'batik' and not _is_batik_supported(jdk): return - args = ['-n', str(iterations)] + scratch_dir = join(os.getcwd(), 'scratch') + args = ['-n', str(iterations), '--preserve', '--scratch-directory', scratch_dir] if threads is not None: args += ['-t', str(threads)] - _gate_java_benchmark(vmargs + ['-jar', dacapoJar, name] + args, r'^===== DaCapo 9\.12 ([a-zA-Z0-9_]+) PASSED in ([0-9]+) msec =====') + with DaCapoWrapper(scratch_dir): + _gate_java_benchmark(vmargs + ['-jar', dacapoJar, name] + args, r'^===== DaCapo 9\.12 ([a-zA-Z0-9_]+) PASSED in ([0-9]+) msec =====') def jdk_includes_corba(jdk): # corba has been removed since JDK11 (http://openjdk.java.net/jeps/320) @@ -418,8 +449,10 @@ def _gate_scala_dacapo(name, iterations, extraVMarguments=None): if name == 'actors' and jdk.javaCompliance >= '9' and jdk_includes_corba(jdk): vmargs += ['--add-modules', 'java.corba'] scalaDacapoJar = mx.library('DACAPO_SCALA').get_path(True) - _gate_java_benchmark(vmargs + ['-jar', scalaDacapoJar, name, '-n', str(iterations)], r'^===== DaCapo 0\.1\.0(-SNAPSHOT)? ([a-zA-Z0-9_]+) PASSED in ([0-9]+) msec =====') - + scratch_dir = join(os.getcwd(), 'scratch') + with DaCapoWrapper(scratch_dir): + args = ['-jar', scalaDacapoJar, name, '-n', str(iterations), '--preserve', '--scratch-directory', scratch_dir] + _gate_java_benchmark(vmargs + args, r'^===== DaCapo 0\.1\.0(-SNAPSHOT)? ([a-zA-Z0-9_]+) PASSED in ([0-9]+) msec =====') def compiler_gate_runner(suites, unit_test_runs, bootstrap_tests, tasks, extraVMarguments=None, extraUnitTestArguments=None): if jdk.javaCompliance >= '9': diff --git a/vm/mx.vm/mx_vm_gate.py b/vm/mx.vm/mx_vm_gate.py index 004219b3cdd0..eeb4f8f244e7 100644 --- a/vm/mx.vm/mx_vm_gate.py +++ b/vm/mx.vm/mx_vm_gate.py @@ -33,6 +33,7 @@ import functools import re +import os from mx_gate import Task from os import environ, listdir, remove, linesep @@ -96,14 +97,16 @@ def gate_body(args, tasks): # Ensure that fatal errors in libgraal route back to HotSpot testdir = mkdtemp() try: + scratch_dir = join(testdir, 'scratch') cmd = [java_exe, '-XX:+UseJVMCICompiler', '-XX:+UseJVMCINativeLibrary', '-Dlibgraal.CrashAt=length,hashCode', '-Dlibgraal.CrashAtIsFatal=true', - '-jar', mx.library('DACAPO').get_path(True), 'avrora'] + '-jar', mx.library('DACAPO').get_path(True), 'avrora', '--preserve', '--scratch-directory', scratch_dir] out = mx.OutputCapture() - exitcode = mx.run(cmd, cwd=testdir, nonZeroIsFatal=False, out=out) + with mx_compiler.DaCapoWrapper(scratch_dir): + exitcode = mx.run(cmd, cwd=testdir, nonZeroIsFatal=False, out=out) if exitcode == 0: if 'CrashAtIsFatal: no fatalError function pointer installed' in out.data: # Executing a VM that does not configure fatal errors handling