Skip to content

Commit c3c6760

Browse files
committed
default to running jython jar with different jvm configs
1 parent 78a0354 commit c3c6760

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

mx.graalpython/mx_graalpython_benchmark.py

Lines changed: 37 additions & 5 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,54 @@ 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):
258260
return 2
259261

262+
def hosting_registry(self):
263+
return java_vm_registry
264+
260265
@property
261266
def interpreter(self):
262267
try:
263268
return subprocess.check_output("which %s" % JythonVm.JYTHON_INTERPRETER, shell=True).decode().strip()
264269
except OSError 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+
cmd = vm_args + args
286+
287+
if not self._env:
288+
self._env = dict()
289+
with environ(self._env):
290+
return host_vm.run(cwd, cmd)
291+
else:
292+
return AbstractPythonIterationsControlVm.run(self, cwd, args)
293+
294+
def config_name(self):
295+
return self._config_name
296+
297+
def with_host_vm(self, host_vm):
298+
return self.__class__(config_name=self._config_name, options=self._options, env=self._env,
299+
iterations=self._iterations, host_vm=host_vm)
267300

268301
def name(self):
269302
return VM_NAME_JYTHON
@@ -657,4 +690,3 @@ def rules(self, output, benchmarks, bm_suite_args):
657690
}
658691
),
659692
]
660-

0 commit comments

Comments
 (0)