diff 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
line wrap: on
line diff
--- a/mx/commands.py	Sun Feb 05 05:37:52 2012 +0100
+++ b/mx/commands.py	Sun Feb 05 05:40:36 2012 +0100
@@ -34,7 +34,16 @@
 import json
 
 _graal_home = dirname(dirname(__file__))
+
+""" Used to distinguish an exported GraalVM (see 'mx export'). """
 _vmSourcesAvailable = exists(join(_graal_home, 'make')) and exists(join(_graal_home, 'src')) 
+
+""" The VM that will be run by the 'vm' command: graal(default), client or server.
+    This can be set via the global '--vm' option. """
+_vm = 'graal'
+
+""" The VM build that will be run by the 'vm' command: product(default), fastdebug or debug.
+    This can be set via the global '--fastdebug' and '--debug' options. """
 _vmbuild = 'product'
 
 _copyrightTemplate = """/*
@@ -133,7 +142,7 @@
         res = []
         mx.log("=== Server VM ===")
         printArg = '-XX:+PrintCompilation' if verbose else '-XX:-PrintCompilation'
-        res.append(vm(['-cp', cp, printArg] + sharedArgs, vm="-server"))
+        res.append(vm(['-cp', cp, printArg] + sharedArgs, vm='server'))
         mx.log("=== Graal VM ===")
         printArg = '-G:+PrintCompilation' if verbose else '-G:-PrintCompilation'
         res.append(vm(['-cp', cp, printArg, '-G:-Extend', '-G:-Inline'] + sharedArgs))
@@ -204,7 +213,7 @@
     
     failed = []
     for (test, n) in numTests.items():
-        if not sanitycheck.getDacapo(test, n, dacapoArgs).test('-graal', opts=vmOpts):
+        if not sanitycheck.getDacapo(test, n, dacapoArgs).test('graal', opts=vmOpts):
             failed.append(test)
     
     if len(failed) != 0:
@@ -304,6 +313,7 @@
 
 
     parser = ArgumentParser(prog='mx build');
+    parser.add_argument('--vm', action='store', dest='vm', default='graal', choices=['graal', 'server', 'client'], help='the VM to be built')
     
     # Call mx.build to compile the Java sources        
     opts = mx.build(['--source', '1.7'] + args, parser=parser)
@@ -315,16 +325,25 @@
     if len(builds) == 0:
         builds = ['product']
 
+    vm = opts.vm
+    if vm == 'server':
+        buildSuffix = ''
+    elif vm == 'client':
+        buildSuffix = '1'
+    else:
+        assert vm is 'graal'
+        buildSuffix = 'graal'
+        
     for build in builds:
 
         jdk = _jdk(build, True)
         if build == 'debug':
             build = 'jvmg'
-        
-        graalVmDir = join(jdk, 'jre', 'lib', 'amd64', 'graal')
-        if not exists(graalVmDir):
-            mx.log('Creating Graal directory in JDK7: ' + graalVmDir)
-            os.makedirs(graalVmDir)
+            
+        vmDir = join(jdk, 'jre', 'lib', 'amd64', vm)
+        if not exists(vmDir):
+            mx.log('Creating VM directory in JDK7: ' + vmDir)
+            os.makedirs(vmDir)
     
         def filterXusage(line):
             if not 'Xusage.txt' in line:
@@ -353,17 +372,20 @@
             env.setdefault('HOTSPOT_BUILD_JOBS', '3')
             env['ALT_BOOTDIR'] = jdk
             env.setdefault('INSTALL', 'y')
-            mx.run([mx.gmake_cmd(), build + 'graal'], cwd=join(_graal_home, 'make'), err=filterXusage)
+            mx.run([mx.gmake_cmd(), build + buildSuffix], cwd=join(_graal_home, 'make'), err=filterXusage)
     
-def vm(args, vm='-graal', nonZeroIsFatal=True, out=None, err=None, cwd=None, timeout=None, vmbuild=None):
+def vm(args, vm=None, nonZeroIsFatal=True, out=None, err=None, cwd=None, timeout=None, vmbuild=None):
     """run the GraalVM"""
 
+    if vm is None:
+        vm = _vm
+        
     build = vmbuild if vmbuild is not None else _vmbuild if _vmSourcesAvailable else 'product'
     mx.expand_project_in_args(args)  
     if mx.java().debug:
         args = ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000'] + args
     exe = join(_jdk(build), 'bin', mx.exe_suffix('java'))
-    return mx.run([exe, vm] + args, nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd, timeout=timeout)
+    return mx.run([exe, '-' + vm] + args, nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd, timeout=timeout)
 
 
 # Table of unit tests.
@@ -429,43 +451,52 @@
 def gate(args):
     """run the tests used to validate a push
 
-    If this commands exits with a 0 exit code, then the source code is in
+    If this command exits with a 0 exit code, then the source code is in
     a state that would be accepted for integration into the main repository."""
     
+    
+    
     class Task:
         def __init__(self, title):
             self.start = time.time()
             self.title = title
+            self.end = None
+            self.duration = None
             mx.log(time.strftime('gate: %d %b %Y %H:%M:%S: BEGIN: ') + title)
         def stop(self):
-            duration = datetime.timedelta(seconds=time.time() - self.start)
-            mx.log(time.strftime('gate: %d %b %Y %H:%M:%S: END:   ') + self.title + ' [' + str(duration) + ']')
+            self.end = time.time()
+            self.duration = datetime.timedelta(seconds=self.end - self.start)
+            mx.log(time.strftime('gate: %d %b %Y %H:%M:%S: END:   ') + self.title + ' [' + str(self.duration) + ']')
+            return self
         def abort(self, codeOrMessage):
-            duration = datetime.timedelta(seconds=time.time() - self.start)
-            mx.log(time.strftime('gate: %d %b %Y %H:%M:%S: ABORT: ') + self.title + ' [' + str(duration) + ']')
+            self.end = time.time()
+            self.duration = datetime.timedelta(seconds=self.end - self.start)
+            mx.log(time.strftime('gate: %d %b %Y %H:%M:%S: ABORT: ') + self.title + ' [' + str(self.duration) + ']')
             mx.abort(codeOrMessage)
+            return self
              
+    tasks = []             
     total = Task('Gate')
     try:
         
-        t = Task('CleanJava')
-        clean(['--no-native'])
-        t.stop()
+        t = Task('Clean')
+        clean([])
+        tasks.append(t.stop())
         
         t = Task('Checkstyle')
         if mx.checkstyle([]) != 0:
             t.abort('Checkstyle warnings were found')
-        t.stop()
+        tasks.append(t.stop())
     
         t = Task('Canonicalization Check')
         mx.log(time.strftime('%d %b %Y %H:%M:%S - Ensuring mx/projects files are canonicalized...'))
         if mx.canonicalizeprojects([]) != 0:
             t.abort('Rerun "mx canonicalizeprojects" and check-in the modified mx/projects files.')
-        t.stop()
+        tasks.append(t.stop())
     
         t = Task('BuildJava')
         build(['--no-native'])
-        t.stop()
+        tasks.append(t.stop())
     
         for vmbuild in ['product', 'fastdebug']:
             global _vmbuild
@@ -473,21 +504,21 @@
             
             t = Task('BuildHotSpot:' + vmbuild)
             build(['--no-java', vmbuild])
-            t.stop()
+            tasks.append(t.stop())
             
             t = Task('BootstrapWithSystemAssertions:' + vmbuild)
             vm(['-esa', '-version'])
-            t.stop()
+            tasks.append(t.stop())
             
             t = Task('UnitTests:' + vmbuild)
             unittest([])
-            t.stop()
+            tasks.append(t.stop())
             
             for test in sanitycheck.getDacapos(level=sanitycheck.SanityCheckLevel.Gate, gateBuildLevel=vmbuild):
                 t = Task(str(test) + ':' + vmbuild)
-                if not test.test('-graal'):
+                if not test.test('graal'):
                     t.abort(test.group + ' ' + test.name + ' Failed')
-                t.stop()
+                tasks.append(t.stop())
     except KeyboardInterrupt:
         total.abort(1)
     
@@ -497,6 +528,12 @@
         total.abort(str(e))
 
     total.stop()
+    
+    mx.log('Gate task times:')
+    for t in tasks:
+        mx.log('  ' + str(t.duration) + '\t' + t.title)
+    mx.log('  =======')
+    mx.log('  ' + str(total.duration))
 
 def bench(args):
     """run benchmarks and parse their output for results
@@ -549,7 +586,7 @@
     for test in benchmarks:
         if not results.has_key(test.group):
             results[test.group] = {}
-        results[test.group].update(test.bench('-' + vm))
+        results[test.group].update(test.bench(vm))
     mx.log(json.dumps(results))
     if resultFile:
         with open(resultFile, 'w') as f:
@@ -558,7 +595,7 @@
 def specjvm2008(args):
     benchArgs = [a[1:] for a in args if a[0] == '@']
     vmArgs = [a for a in args if a[0] != '@']
-    sanitycheck.getSPECjvm2008(benchArgs).bench('-graal', opts=vmArgs)
+    sanitycheck.getSPECjvm2008(benchArgs).bench('graal', opts=vmArgs)
     
 def mx_init():
     _vmbuild = 'product'
@@ -576,9 +613,10 @@
     }
 
     if (_vmSourcesAvailable):
-        mx.add_argument('--product', action='store_const', dest='vmbuild', const='product', help='select the product VM')
-        mx.add_argument('--debug', action='store_const', dest='vmbuild', const='debug', help='select the debug VM')
-        mx.add_argument('--fastdebug', action='store_const', dest='vmbuild', const='fastdebug', help='select the fast debug VM')
+        mx.add_argument('--vm', action='store', dest='vm', default='graal', choices=['graal', 'server', 'client'], help='the VM to run (default: graal)')
+        mx.add_argument('--product', action='store_const', dest='vmbuild', const='product', help='select the product build of the VM')
+        mx.add_argument('--debug', action='store_const', dest='vmbuild', const='debug', help='select the debug build of the VM')
+        mx.add_argument('--fastdebug', action='store_const', dest='vmbuild', const='fastdebug', help='select the fast debug build of the VM')
         
         commands.update({
             'export': [export, '[-options] [zipfile]'],
@@ -597,6 +635,8 @@
         mx.abort('Requires Java version 1.7 or greater, got version ' + version)
     
     if (_vmSourcesAvailable):
+        global _vm
+        _vm = opts.vm
         if hasattr(opts, 'vmbuild') and opts.vmbuild is not None:
             global _vmbuild
             _vmbuild = opts.vmbuild