Skip to content

Commit 86182b4

Browse files
committed
[GR-27525] Allow running some benchmarks against Jython
PullRequest: graalpython/1398
2 parents 7192258 + c34add4 commit 86182b4

File tree

3 files changed

+50
-12
lines changed

3 files changed

+50
-12
lines changed

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "overlay": "24ab0c3d875432abb2e9f7da123ae440d0bea32f" }
1+
{ "overlay": "481a7d5f2aa66914f27e9d8b1be83d26b1c92b33" }

graalpython/com.oracle.graal.python.benchmarks/python/harness.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@
4747
import sys
4848
import types
4949

50-
GRAALPYTHON = sys.implementation.name == "graalpython"
50+
try:
51+
import statistics
52+
except ImportError:
53+
statistics = None
54+
55+
# for compatibility with Jython 2.7
56+
GRAALPYTHON = getattr(getattr(sys, "implementation", None), "name", None) == "graalpython"
5157

5258
# Try to use the timer with best accuracy. Unfortunately, 'monotonic_ns' is not available everywhere.
5359
if GRAALPYTHON:
@@ -57,7 +63,7 @@
5763
else:
5864
monotonic_best_accuracy = time
5965
UNITS_PER_SECOND = 1.0
60-
66+
6167
_HRULE = '-'.join(['' for i in range(80)])
6268

6369
#: this function is used to pre-process the arguments as expected by the __benchmark__ and __setup__ entry points
@@ -329,8 +335,7 @@ def run(self):
329335
# a bit of fuzzy logic to avoid timing out on configurations
330336
# that are slow, without having to rework our logic for getting
331337
# default iterations
332-
if os.environ.get("CI") and iteration >= 4 and duration > 20:
333-
import statistics
338+
if statistics and os.environ.get("CI") and iteration >= 4 and duration > 20:
334339
v = durations[-4:]
335340
if statistics.stdev(v) / min(v) < 0.03:
336341
# with less than 3 percent variance across ~20s

mx.graalpython/mx_graalpython_benchmark.py

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#
4949
# ----------------------------------------------------------------------------------------------------------------------
5050
ENV_PYPY_HOME = "PYPY_HOME"
51+
ENV_JYTHON_JAR = "JYTHON_JAR"
5152
VM_NAME_GRAALPYTHON = "graalpython"
5253
VM_NAME_CPYTHON = "cpython"
5354
VM_NAME_PYPY = "pypy"
@@ -248,22 +249,55 @@ def name(self):
248249
return VM_NAME_PYPY
249250

250251

251-
class JythonVm(AbstractPythonIterationsControlVm):
252+
class JythonVm(AbstractPythonIterationsControlVm, GuestVm):
252253
JYTHON_INTERPRETER = "jython"
253254

254-
def __init__(self, config_name, options=None, env=None, iterations=None):
255-
super(JythonVm, self).__init__(config_name, options=options, env=env, iterations=iterations)
255+
def __init__(self, config_name, options=None, env=None, iterations=None, host_vm=None):
256+
AbstractPythonIterationsControlVm.__init__(self, config_name, options=options, env=env, iterations=iterations)
257+
GuestVm.__init__(self, host_vm=host_vm)
256258

257259
def override_iterations(self, requested_iterations):
258-
return 2
260+
return 3
261+
262+
def hosting_registry(self):
263+
return java_vm_registry
259264

260265
@property
261266
def interpreter(self):
262267
try:
263268
return subprocess.check_output("which %s" % JythonVm.JYTHON_INTERPRETER, shell=True).decode().strip()
264-
except OSError as e:
269+
except Exception as e:
265270
mx.log_error(e)
266-
mx.abort("Error when executing `which jython`!\n")
271+
mx.abort("`jython` is neither on the path, nor is {} set!\n".format(ENV_JYTHON_JAR))
272+
273+
def run(self, cwd, args):
274+
jar = mx.get_env(ENV_JYTHON_JAR)
275+
if jar:
276+
_check_vm_args(self.name(), args)
277+
host_vm = self.host_vm()
278+
279+
vm_args = mx.get_runtime_jvm_args([])
280+
vm_args += ["-jar", jar]
281+
for a in args[:]:
282+
if a.startswith("-D") or a.startswith("-XX"):
283+
vm_args.insert(0, a)
284+
args.remove(a)
285+
args = self._override_iterations_args(args)
286+
cmd = vm_args + args
287+
288+
if not self._env:
289+
self._env = dict()
290+
with environ(self._env):
291+
return host_vm.run(cwd, cmd)
292+
else:
293+
return AbstractPythonIterationsControlVm.run(self, cwd, args)
294+
295+
def config_name(self):
296+
return self._config_name
297+
298+
def with_host_vm(self, host_vm):
299+
return self.__class__(config_name=self._config_name, options=self._options, env=self._env,
300+
iterations=self._iterations, host_vm=host_vm)
267301

268302
def name(self):
269303
return VM_NAME_JYTHON
@@ -657,4 +691,3 @@ def rules(self, output, benchmarks, bm_suite_args):
657691
}
658692
),
659693
]
660-

0 commit comments

Comments
 (0)