comparison mx/commands.py @ 4417:648a7873cea2

Made it possible to build and run the client and server VM with a new '--vm' option to 'mx build' and a global option of the same name.
author Doug Simon <doug.simon@oracle.com>
date Mon, 30 Jan 2012 22:17:01 +0100
parents 3b776fb6ffd9
children 0312460af9fc
comparison
equal deleted inserted replaced
4416:be787de79394 4417:648a7873cea2
32 import mx 32 import mx
33 import sanitycheck 33 import sanitycheck
34 import json 34 import json
35 35
36 _graal_home = dirname(dirname(__file__)) 36 _graal_home = dirname(dirname(__file__))
37
38 """ Used to distinguish an exported GraalVM (see 'mx export'). """
37 _vmSourcesAvailable = exists(join(_graal_home, 'make')) and exists(join(_graal_home, 'src')) 39 _vmSourcesAvailable = exists(join(_graal_home, 'make')) and exists(join(_graal_home, 'src'))
40
41 """ The VM that will be run by the 'vm' command: graal(default), client or server.
42 This can be set via the global '--vm' option. """
43 _vm = 'graal'
44
45 """ The VM build that will be run by the 'vm' command: product(default), fastdebug or debug.
46 This can be set via the global '--fastdebug' and '--debug' options. """
38 _vmbuild = 'product' 47 _vmbuild = 'product'
39 48
40 _copyrightTemplate = """/* 49 _copyrightTemplate = """/*
41 * Copyright (c) {0}, Oracle and/or its affiliates. All rights reserved. 50 * Copyright (c) {0}, Oracle and/or its affiliates. All rights reserved.
42 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 51 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
131 sharedArgs = ['-Xcomp', '-XX:CompileOnly=Main', mainClass] 140 sharedArgs = ['-Xcomp', '-XX:CompileOnly=Main', mainClass]
132 141
133 res = [] 142 res = []
134 mx.log("=== Server VM ===") 143 mx.log("=== Server VM ===")
135 printArg = '-XX:+PrintCompilation' if verbose else '-XX:-PrintCompilation' 144 printArg = '-XX:+PrintCompilation' if verbose else '-XX:-PrintCompilation'
136 res.append(vm(['-cp', cp, printArg] + sharedArgs, vm="-server")) 145 res.append(vm(['-cp', cp, printArg] + sharedArgs, vm='server'))
137 mx.log("=== Graal VM ===") 146 mx.log("=== Graal VM ===")
138 printArg = '-G:+PrintCompilation' if verbose else '-G:-PrintCompilation' 147 printArg = '-G:+PrintCompilation' if verbose else '-G:-PrintCompilation'
139 res.append(vm(['-cp', cp, printArg, '-G:-Extend', '-G:-Inline'] + sharedArgs)) 148 res.append(vm(['-cp', cp, printArg, '-G:-Extend', '-G:-Inline'] + sharedArgs))
140 mx.log("=== Graal VM with extensions ===") 149 mx.log("=== Graal VM with extensions ===")
141 res.append(vm(['-cp', cp, printArg, '-G:+Extend', '-G:-Inline'] + sharedArgs)) 150 res.append(vm(['-cp', cp, printArg, '-G:+Extend', '-G:-Inline'] + sharedArgs))
202 # The remainder are VM options 211 # The remainder are VM options
203 vmOpts = [arg for arg in args if not arg.startswith('@')] 212 vmOpts = [arg for arg in args if not arg.startswith('@')]
204 213
205 failed = [] 214 failed = []
206 for (test, n) in numTests.items(): 215 for (test, n) in numTests.items():
207 if not sanitycheck.getDacapo(test, n, dacapoArgs).test('-graal', opts=vmOpts): 216 if not sanitycheck.getDacapo(test, n, dacapoArgs).test('graal', opts=vmOpts):
208 failed.append(test) 217 failed.append(test)
209 218
210 if len(failed) != 0: 219 if len(failed) != 0:
211 mx.abort('DaCapo failures: ' + str(failed)) 220 mx.abort('DaCapo failures: ' + str(failed))
212 221
302 311
303 The optional last argument specifies what type of VM to build.""" 312 The optional last argument specifies what type of VM to build."""
304 313
305 314
306 parser = ArgumentParser(prog='mx build'); 315 parser = ArgumentParser(prog='mx build');
316 parser.add_argument('--vm', action='store', dest='vm', default='graal', choices=['graal', 'server', 'client'], help='the VM to be built')
307 317
308 # Call mx.build to compile the Java sources 318 # Call mx.build to compile the Java sources
309 opts = mx.build(['--source', '1.7'] + args, parser=parser) 319 opts = mx.build(['--source', '1.7'] + args, parser=parser)
310 320
311 if not _vmSourcesAvailable or not opts.native: 321 if not _vmSourcesAvailable or not opts.native:
313 323
314 builds = opts.remainder 324 builds = opts.remainder
315 if len(builds) == 0: 325 if len(builds) == 0:
316 builds = ['product'] 326 builds = ['product']
317 327
328 vm = opts.vm
329 if vm == 'server':
330 buildSuffix = ''
331 elif vm == 'client':
332 buildSuffix = '1'
333 else:
334 assert vm is 'graal'
335 buildSuffix = 'graal'
336
318 for build in builds: 337 for build in builds:
319 338
320 jdk = _jdk(build, True) 339 jdk = _jdk(build, True)
321 if build == 'debug': 340 if build == 'debug':
322 build = 'jvmg' 341 build = 'jvmg'
323 342
324 graalVmDir = join(jdk, 'jre', 'lib', 'amd64', 'graal') 343 vmDir = join(jdk, 'jre', 'lib', 'amd64', vm)
325 if not exists(graalVmDir): 344 if not exists(vmDir):
326 mx.log('Creating Graal directory in JDK7: ' + graalVmDir) 345 mx.log('Creating VM directory in JDK7: ' + vmDir)
327 os.makedirs(graalVmDir) 346 os.makedirs(vmDir)
328 347
329 def filterXusage(line): 348 def filterXusage(line):
330 if not 'Xusage.txt' in line: 349 if not 'Xusage.txt' in line:
331 sys.stderr.write(line + os.linesep) 350 sys.stderr.write(line + os.linesep)
332 351
351 env.setdefault('ARCH_DATA_MODEL', '64') 370 env.setdefault('ARCH_DATA_MODEL', '64')
352 env.setdefault('LANG', 'C') 371 env.setdefault('LANG', 'C')
353 env.setdefault('HOTSPOT_BUILD_JOBS', '3') 372 env.setdefault('HOTSPOT_BUILD_JOBS', '3')
354 env['ALT_BOOTDIR'] = jdk 373 env['ALT_BOOTDIR'] = jdk
355 env.setdefault('INSTALL', 'y') 374 env.setdefault('INSTALL', 'y')
356 mx.run([mx.gmake_cmd(), build + 'graal'], cwd=join(_graal_home, 'make'), err=filterXusage) 375 mx.run([mx.gmake_cmd(), build + buildSuffix], cwd=join(_graal_home, 'make'), err=filterXusage)
357 376
358 def vm(args, vm='-graal', nonZeroIsFatal=True, out=None, err=None, cwd=None, timeout=None, vmbuild=None): 377 def vm(args, vm=None, nonZeroIsFatal=True, out=None, err=None, cwd=None, timeout=None, vmbuild=None):
359 """run the GraalVM""" 378 """run the GraalVM"""
360 379
380 if vm is None:
381 vm = _vm
382
361 build = vmbuild if vmbuild is not None else _vmbuild if _vmSourcesAvailable else 'product' 383 build = vmbuild if vmbuild is not None else _vmbuild if _vmSourcesAvailable else 'product'
362 mx.expand_project_in_args(args) 384 mx.expand_project_in_args(args)
363 if mx.java().debug: 385 if mx.java().debug:
364 args = ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000'] + args 386 args = ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000'] + args
365 exe = join(_jdk(build), 'bin', mx.exe_suffix('java')) 387 exe = join(_jdk(build), 'bin', mx.exe_suffix('java'))
366 return mx.run([exe, vm] + args, nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd, timeout=timeout) 388 return mx.run([exe, '-' + vm] + args, nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd, timeout=timeout)
367 389
368 390
369 # Table of unit tests. 391 # Table of unit tests.
370 # Keys are project names, values are package name lists. 392 # Keys are project names, values are package name lists.
371 # All source files in the given (project,package) pairs are scanned for lines 393 # All source files in the given (project,package) pairs are scanned for lines
483 unittest([]) 505 unittest([])
484 t.stop() 506 t.stop()
485 507
486 for test in sanitycheck.getDacapos(level=sanitycheck.SanityCheckLevel.Gate, gateBuildLevel=vmbuild): 508 for test in sanitycheck.getDacapos(level=sanitycheck.SanityCheckLevel.Gate, gateBuildLevel=vmbuild):
487 t = Task(str(test) + ':' + vmbuild) 509 t = Task(str(test) + ':' + vmbuild)
488 if not test.test('-graal'): 510 if not test.test('graal'):
489 t.abort(test.group + ' ' + test.name + ' Failed') 511 t.abort(test.group + ' ' + test.name + ' Failed')
490 t.stop() 512 t.stop()
491 except KeyboardInterrupt: 513 except KeyboardInterrupt:
492 total.abort(1) 514 total.abort(1)
493 515
547 benchmarks += [sanitycheck.getSPECjvm2008([specjvm], True, 120, 120)] 569 benchmarks += [sanitycheck.getSPECjvm2008([specjvm], True, 120, 120)]
548 570
549 for test in benchmarks: 571 for test in benchmarks:
550 if not results.has_key(test.group): 572 if not results.has_key(test.group):
551 results[test.group] = {} 573 results[test.group] = {}
552 results[test.group].update(test.bench('-' + vm)) 574 results[test.group].update(test.bench(vm))
553 mx.log(json.dumps(results)) 575 mx.log(json.dumps(results))
554 if resultFile: 576 if resultFile:
555 with open(resultFile, 'w') as f: 577 with open(resultFile, 'w') as f:
556 f.write(json.dumps(results)) 578 f.write(json.dumps(results))
557 579
558 def specjvm2008(args): 580 def specjvm2008(args):
559 benchArgs = [a[1:] for a in args if a[0] == '@'] 581 benchArgs = [a[1:] for a in args if a[0] == '@']
560 vmArgs = [a for a in args if a[0] != '@'] 582 vmArgs = [a for a in args if a[0] != '@']
561 sanitycheck.getSPECjvm2008(benchArgs).bench('-graal', opts=vmArgs) 583 sanitycheck.getSPECjvm2008(benchArgs).bench('graal', opts=vmArgs)
562 584
563 def mx_init(): 585 def mx_init():
564 _vmbuild = 'product' 586 _vmbuild = 'product'
565 commands = { 587 commands = {
566 'build': [build, '[-options]'], 588 'build': [build, '[-options]'],
574 'unittest' : [unittest, '[filters...]'], 596 'unittest' : [unittest, '[filters...]'],
575 'vm': [vm, '[-options] class [args...]'] 597 'vm': [vm, '[-options] class [args...]']
576 } 598 }
577 599
578 if (_vmSourcesAvailable): 600 if (_vmSourcesAvailable):
579 mx.add_argument('--product', action='store_const', dest='vmbuild', const='product', help='select the product VM') 601 mx.add_argument('--vm', action='store', dest='vm', default='graal', choices=['graal', 'server', 'client'], help='the VM to run (default: graal)')
580 mx.add_argument('--debug', action='store_const', dest='vmbuild', const='debug', help='select the debug VM') 602 mx.add_argument('--product', action='store_const', dest='vmbuild', const='product', help='select the product build of the VM')
581 mx.add_argument('--fastdebug', action='store_const', dest='vmbuild', const='fastdebug', help='select the fast debug VM') 603 mx.add_argument('--debug', action='store_const', dest='vmbuild', const='debug', help='select the debug build of the VM')
604 mx.add_argument('--fastdebug', action='store_const', dest='vmbuild', const='fastdebug', help='select the fast debug build of the VM')
582 605
583 commands.update({ 606 commands.update({
584 'export': [export, '[-options] [zipfile]'], 607 'export': [export, '[-options] [zipfile]'],
585 'build': [build, '[-options] [product|debug|fastdebug]...'] 608 'build': [build, '[-options] [product|debug|fastdebug]...']
586 }) 609 })
595 major = int(parts[1]) 618 major = int(parts[1])
596 if not major >= 7: 619 if not major >= 7:
597 mx.abort('Requires Java version 1.7 or greater, got version ' + version) 620 mx.abort('Requires Java version 1.7 or greater, got version ' + version)
598 621
599 if (_vmSourcesAvailable): 622 if (_vmSourcesAvailable):
623 global _vm
624 _vm = opts.vm
600 if hasattr(opts, 'vmbuild') and opts.vmbuild is not None: 625 if hasattr(opts, 'vmbuild') and opts.vmbuild is not None:
601 global _vmbuild 626 global _vmbuild
602 _vmbuild = opts.vmbuild 627 _vmbuild = opts.vmbuild