Mercurial > hg > graal-compiler
comparison mx/commands.py @ 4506:ab7c258e1cef
Merge.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sun, 05 Feb 2012 05:40:36 +0100 |
parents | 0312460af9fc |
children | 7d6490436b57 |
comparison
equal
deleted
inserted
replaced
4505:5d9c4796912d | 4506:ab7c258e1cef |
---|---|
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 |
427 vm(['-XX:-BootstrapGraal', '-esa', '-Xbootclasspath/a:' + mx.classpath(proj), 'org.junit.runner.JUnitCore'] + classes) | 449 vm(['-XX:-BootstrapGraal', '-esa', '-Xbootclasspath/a:' + mx.classpath(proj), 'org.junit.runner.JUnitCore'] + classes) |
428 | 450 |
429 def gate(args): | 451 def gate(args): |
430 """run the tests used to validate a push | 452 """run the tests used to validate a push |
431 | 453 |
432 If this commands exits with a 0 exit code, then the source code is in | 454 If this command exits with a 0 exit code, then the source code is in |
433 a state that would be accepted for integration into the main repository.""" | 455 a state that would be accepted for integration into the main repository.""" |
456 | |
457 | |
434 | 458 |
435 class Task: | 459 class Task: |
436 def __init__(self, title): | 460 def __init__(self, title): |
437 self.start = time.time() | 461 self.start = time.time() |
438 self.title = title | 462 self.title = title |
463 self.end = None | |
464 self.duration = None | |
439 mx.log(time.strftime('gate: %d %b %Y %H:%M:%S: BEGIN: ') + title) | 465 mx.log(time.strftime('gate: %d %b %Y %H:%M:%S: BEGIN: ') + title) |
440 def stop(self): | 466 def stop(self): |
441 duration = datetime.timedelta(seconds=time.time() - self.start) | 467 self.end = time.time() |
442 mx.log(time.strftime('gate: %d %b %Y %H:%M:%S: END: ') + self.title + ' [' + str(duration) + ']') | 468 self.duration = datetime.timedelta(seconds=self.end - self.start) |
469 mx.log(time.strftime('gate: %d %b %Y %H:%M:%S: END: ') + self.title + ' [' + str(self.duration) + ']') | |
470 return self | |
443 def abort(self, codeOrMessage): | 471 def abort(self, codeOrMessage): |
444 duration = datetime.timedelta(seconds=time.time() - self.start) | 472 self.end = time.time() |
445 mx.log(time.strftime('gate: %d %b %Y %H:%M:%S: ABORT: ') + self.title + ' [' + str(duration) + ']') | 473 self.duration = datetime.timedelta(seconds=self.end - self.start) |
474 mx.log(time.strftime('gate: %d %b %Y %H:%M:%S: ABORT: ') + self.title + ' [' + str(self.duration) + ']') | |
446 mx.abort(codeOrMessage) | 475 mx.abort(codeOrMessage) |
476 return self | |
447 | 477 |
478 tasks = [] | |
448 total = Task('Gate') | 479 total = Task('Gate') |
449 try: | 480 try: |
450 | 481 |
451 t = Task('CleanJava') | 482 t = Task('Clean') |
452 clean(['--no-native']) | 483 clean([]) |
453 t.stop() | 484 tasks.append(t.stop()) |
454 | 485 |
455 t = Task('Checkstyle') | 486 t = Task('Checkstyle') |
456 if mx.checkstyle([]) != 0: | 487 if mx.checkstyle([]) != 0: |
457 t.abort('Checkstyle warnings were found') | 488 t.abort('Checkstyle warnings were found') |
458 t.stop() | 489 tasks.append(t.stop()) |
459 | 490 |
460 t = Task('Canonicalization Check') | 491 t = Task('Canonicalization Check') |
461 mx.log(time.strftime('%d %b %Y %H:%M:%S - Ensuring mx/projects files are canonicalized...')) | 492 mx.log(time.strftime('%d %b %Y %H:%M:%S - Ensuring mx/projects files are canonicalized...')) |
462 if mx.canonicalizeprojects([]) != 0: | 493 if mx.canonicalizeprojects([]) != 0: |
463 t.abort('Rerun "mx canonicalizeprojects" and check-in the modified mx/projects files.') | 494 t.abort('Rerun "mx canonicalizeprojects" and check-in the modified mx/projects files.') |
464 t.stop() | 495 tasks.append(t.stop()) |
465 | 496 |
466 t = Task('BuildJava') | 497 t = Task('BuildJava') |
467 build(['--no-native']) | 498 build(['--no-native']) |
468 t.stop() | 499 tasks.append(t.stop()) |
469 | 500 |
470 for vmbuild in ['product', 'fastdebug']: | 501 for vmbuild in ['product', 'fastdebug']: |
471 global _vmbuild | 502 global _vmbuild |
472 _vmbuild = vmbuild | 503 _vmbuild = vmbuild |
473 | 504 |
474 t = Task('BuildHotSpot:' + vmbuild) | 505 t = Task('BuildHotSpot:' + vmbuild) |
475 build(['--no-java', vmbuild]) | 506 build(['--no-java', vmbuild]) |
476 t.stop() | 507 tasks.append(t.stop()) |
477 | 508 |
478 t = Task('BootstrapWithSystemAssertions:' + vmbuild) | 509 t = Task('BootstrapWithSystemAssertions:' + vmbuild) |
479 vm(['-esa', '-version']) | 510 vm(['-esa', '-version']) |
480 t.stop() | 511 tasks.append(t.stop()) |
481 | 512 |
482 t = Task('UnitTests:' + vmbuild) | 513 t = Task('UnitTests:' + vmbuild) |
483 unittest([]) | 514 unittest([]) |
484 t.stop() | 515 tasks.append(t.stop()) |
485 | 516 |
486 for test in sanitycheck.getDacapos(level=sanitycheck.SanityCheckLevel.Gate, gateBuildLevel=vmbuild): | 517 for test in sanitycheck.getDacapos(level=sanitycheck.SanityCheckLevel.Gate, gateBuildLevel=vmbuild): |
487 t = Task(str(test) + ':' + vmbuild) | 518 t = Task(str(test) + ':' + vmbuild) |
488 if not test.test('-graal'): | 519 if not test.test('graal'): |
489 t.abort(test.group + ' ' + test.name + ' Failed') | 520 t.abort(test.group + ' ' + test.name + ' Failed') |
490 t.stop() | 521 tasks.append(t.stop()) |
491 except KeyboardInterrupt: | 522 except KeyboardInterrupt: |
492 total.abort(1) | 523 total.abort(1) |
493 | 524 |
494 except Exception as e: | 525 except Exception as e: |
495 import traceback | 526 import traceback |
496 traceback.print_exc() | 527 traceback.print_exc() |
497 total.abort(str(e)) | 528 total.abort(str(e)) |
498 | 529 |
499 total.stop() | 530 total.stop() |
531 | |
532 mx.log('Gate task times:') | |
533 for t in tasks: | |
534 mx.log(' ' + str(t.duration) + '\t' + t.title) | |
535 mx.log(' =======') | |
536 mx.log(' ' + str(total.duration)) | |
500 | 537 |
501 def bench(args): | 538 def bench(args): |
502 """run benchmarks and parse their output for results | 539 """run benchmarks and parse their output for results |
503 | 540 |
504 Results are JSON formated : {group : {benchmark : score}}.""" | 541 Results are JSON formated : {group : {benchmark : score}}.""" |
547 benchmarks += [sanitycheck.getSPECjvm2008([specjvm], True, 120, 120)] | 584 benchmarks += [sanitycheck.getSPECjvm2008([specjvm], True, 120, 120)] |
548 | 585 |
549 for test in benchmarks: | 586 for test in benchmarks: |
550 if not results.has_key(test.group): | 587 if not results.has_key(test.group): |
551 results[test.group] = {} | 588 results[test.group] = {} |
552 results[test.group].update(test.bench('-' + vm)) | 589 results[test.group].update(test.bench(vm)) |
553 mx.log(json.dumps(results)) | 590 mx.log(json.dumps(results)) |
554 if resultFile: | 591 if resultFile: |
555 with open(resultFile, 'w') as f: | 592 with open(resultFile, 'w') as f: |
556 f.write(json.dumps(results)) | 593 f.write(json.dumps(results)) |
557 | 594 |
558 def specjvm2008(args): | 595 def specjvm2008(args): |
559 benchArgs = [a[1:] for a in args if a[0] == '@'] | 596 benchArgs = [a[1:] for a in args if a[0] == '@'] |
560 vmArgs = [a for a in args if a[0] != '@'] | 597 vmArgs = [a for a in args if a[0] != '@'] |
561 sanitycheck.getSPECjvm2008(benchArgs).bench('-graal', opts=vmArgs) | 598 sanitycheck.getSPECjvm2008(benchArgs).bench('graal', opts=vmArgs) |
562 | 599 |
563 def mx_init(): | 600 def mx_init(): |
564 _vmbuild = 'product' | 601 _vmbuild = 'product' |
565 commands = { | 602 commands = { |
566 'build': [build, '[-options]'], | 603 'build': [build, '[-options]'], |
574 'unittest' : [unittest, '[filters...]'], | 611 'unittest' : [unittest, '[filters...]'], |
575 'vm': [vm, '[-options] class [args...]'] | 612 'vm': [vm, '[-options] class [args...]'] |
576 } | 613 } |
577 | 614 |
578 if (_vmSourcesAvailable): | 615 if (_vmSourcesAvailable): |
579 mx.add_argument('--product', action='store_const', dest='vmbuild', const='product', help='select the product VM') | 616 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') | 617 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') | 618 mx.add_argument('--debug', action='store_const', dest='vmbuild', const='debug', help='select the debug build of the VM') |
619 mx.add_argument('--fastdebug', action='store_const', dest='vmbuild', const='fastdebug', help='select the fast debug build of the VM') | |
582 | 620 |
583 commands.update({ | 621 commands.update({ |
584 'export': [export, '[-options] [zipfile]'], | 622 'export': [export, '[-options] [zipfile]'], |
585 'build': [build, '[-options] [product|debug|fastdebug]...'] | 623 'build': [build, '[-options] [product|debug|fastdebug]...'] |
586 }) | 624 }) |
595 major = int(parts[1]) | 633 major = int(parts[1]) |
596 if not major >= 7: | 634 if not major >= 7: |
597 mx.abort('Requires Java version 1.7 or greater, got version ' + version) | 635 mx.abort('Requires Java version 1.7 or greater, got version ' + version) |
598 | 636 |
599 if (_vmSourcesAvailable): | 637 if (_vmSourcesAvailable): |
638 global _vm | |
639 _vm = opts.vm | |
600 if hasattr(opts, 'vmbuild') and opts.vmbuild is not None: | 640 if hasattr(opts, 'vmbuild') and opts.vmbuild is not None: |
601 global _vmbuild | 641 global _vmbuild |
602 _vmbuild = opts.vmbuild | 642 _vmbuild = opts.vmbuild |