Mercurial > hg > graal-jvmci-8
annotate mx/commands.py @ 3721:71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 16 Dec 2011 15:17:17 +0100 |
parents | 42e655a6a6f3 |
children | 7c5524a4e86e |
rev | line source |
---|---|
3718 | 1 # |
2 # commands.py - the default commands available to gl.py | |
3 # | |
4 # ---------------------------------------------------------------------------------------------------- | |
5 # | |
6 # Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. | |
7 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
8 # | |
9 # This code is free software; you can redistribute it and/or modify it | |
10 # under the terms of the GNU General Public License version 2 only, as | |
11 # published by the Free Software Foundation. | |
12 # | |
13 # This code is distributed in the hope that it will be useful, but WITHOUT | |
14 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 # version 2 for more details (a copy is included in the LICENSE file that | |
17 # accompanied this code). | |
18 # | |
19 # You should have received a copy of the GNU General Public License version | |
20 # 2 along with this work; if not, write to the Free Software Foundation, | |
21 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
22 # | |
23 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
24 # or visit www.oracle.com if you need additional information or have any | |
25 # questions. | |
26 # | |
27 # ---------------------------------------------------------------------------------------------------- | |
28 | |
3721
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
29 import os, sys, shutil |
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
30 from os.path import join, exists, dirname, isfile, isdir |
3718 | 31 |
32 graal_home = dirname(dirname(__file__)) | |
33 | |
34 def clean(env, args): | |
35 """cleans the GraalVM source tree""" | |
36 os.environ.update(ARCH_DATA_MODEL='64', LANG='C', HOTSPOT_BUILD_JOBS='16') | |
37 env.run([env.gmake_cmd(), 'clean'], cwd=join(graal_home, 'make')) | |
38 | |
39 def example(env, args): | |
40 """run some or all Graal examples""" | |
41 examples = { | |
42 'safeadd': ['com.oracle.max.graal.examples.safeadd', 'com.oracle.max.graal.examples.safeadd.Main'], | |
43 'vectorlib': ['com.oracle.max.graal.examples.vectorlib', 'com.oracle.max.graal.examples.vectorlib.Main'], | |
44 } | |
45 | |
46 def run_example(env, verbose, project, mainClass): | |
47 cp = env.pdb.classpath(project) | |
48 sharedArgs = ['-Xcomp', '-XX:CompileOnly=Main', mainClass] | |
49 | |
50 res = [] | |
51 env.log("=== Server VM ===") | |
52 printArg = '-XX:+PrintCompilation' if verbose else '-XX:-PrintCompilation' | |
53 res.append(vm(env, ['-cp', cp, printArg] + sharedArgs, vm="-server")) | |
54 env.log("=== Graal VM ===") | |
55 printArg = '-G:+PrintCompilation' if verbose else '-G:-PrintCompilation' | |
56 res.append(vm(env, ['-cp', cp, printArg, '-G:-Extend', '-G:-Inline'] + sharedArgs)) | |
57 env.log("=== Graal VM with extensions ===") | |
58 res.append(vm(env, ['-cp', cp, printArg, '-G:+Extend', '-G:-Inline'] + sharedArgs)) | |
59 | |
60 if len([x for x in res if x != 0]) != 0: | |
61 return 1 | |
62 return 0 | |
63 | |
64 verbose = False | |
65 if '-v' in args: | |
66 verbose = True | |
67 args = [a for a in args if a != '-v'] | |
68 | |
69 if len(args) == 0: | |
70 args = examples.keys() | |
71 for a in args: | |
72 config = examples.get(a) | |
73 if config is None: | |
74 env.log('unknown example: ' + a + ' {available examples = ' + str(examples.keys()) + '}') | |
75 else: | |
76 env.log('--------- ' + a + ' ------------') | |
77 project, mainClass = config | |
78 run_example(env, verbose, project, mainClass) | |
79 | |
80 def dacapo(env, args): | |
81 """run a DaCapo benchmark""" | |
82 | |
83 benchmarks = { | |
84 'avrora': ['-n', '5'], | |
85 'batik': ['-n', '5'], | |
86 'eclipse': ['-n', '5'], | |
87 'fop': ['-n', '5'], | |
88 'h2': ['-n', '5'], | |
89 'jython': ['-n', '5'], | |
90 'luindex': ['-n', '5'], | |
91 'lusearch': ['-n', '5'], | |
92 'pmd': ['-n', '5'], | |
93 'sunflow': ['-n', '5'], | |
94 'tomcat': ['-n', '5'], | |
95 'tradebeans': ['-n', '5'], | |
96 'tradesoap': ['-n', '5'], | |
97 'xalan': ['-n', '5'], | |
98 } | |
99 | |
100 if len(args) == 0: | |
101 args = args[0:] | |
102 for bm in benchmarks: | |
103 run_dacapo(env, args + ['Harness', '-n', '2'] + [bm]) | |
104 return | |
105 else: | |
106 bm = args[0] | |
107 config = benchmarks.get(bm) | |
108 if (config is None): | |
109 env.abort('unknown benchmark: ' + bm + '\nselect one of: ' + str(benchmarks.keys())) | |
110 args = args[1:] | |
111 return run_dacapo(env, args + ['Harness'] + config + [bm]) | |
112 | |
113 def tests(env, args): | |
114 """run a selection of the Maxine JTT tests in Graal""" | |
115 | |
116 maxine = env.check_get_env('MAXINE_HOME') | |
117 def jtt(name): | |
118 return join(maxine, 'com.oracle.max.vm', 'test', 'jtt', name) | |
119 | |
120 return vm(env, ['-ea', '-esa', '-Xcomp', '-XX:+PrintCompilation', '-XX:CompileOnly=jtt'] + args + | |
121 ['-Xbootclasspath/p:' + join(maxine, 'com.oracle.max.vm', 'bin'), | |
122 '-Xbootclasspath/p:' + join(maxine, 'com.oracle.max.base', 'bin'), | |
123 'test.com.sun.max.vm.compiler.JavaTester', | |
124 '-verbose=1', '-gen-run-scheme=false', '-run-scheme-package=all', | |
125 jtt('bytecode'), | |
126 jtt('except'), | |
127 jtt('jdk'), | |
128 jtt('hotpath'), | |
129 jtt('jdk'), | |
130 jtt('lang'), | |
131 jtt('loop'), | |
132 jtt('micro'), | |
133 jtt('optimize'), | |
134 jtt('reflect'), | |
135 jtt('threads'), | |
136 jtt('hotspot')]) | |
137 | |
3721
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
138 def _jdk7(env, build='product', create=False): |
3718 | 139 jdk7 = env.check_get_env('JDK7') |
3721
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
140 jre = join(jdk7, 'jre') |
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
141 if not exists(jre) or not isdir(jre): |
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
142 env.abort(jdk7 + ' does not appear to be a valid JDK directory ("jre" sub-directory is missing)') |
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
143 |
3718 | 144 if build == 'product': |
3721
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
145 return jdk7 |
3718 | 146 elif build in ['debug', 'fastdebug', 'optimized']: |
3721
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
147 res = join(jdk7, build) |
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
148 if not exists(res): |
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
149 if not create: |
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
150 env.abort('The ' + build + ' VM has not been created - run \'mx clean; mx make ' + build + '\'') |
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
151 env.log('[creating ' + res + '...]') |
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
152 os.mkdir(res) |
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
153 for d in ['jre', 'lib', 'bin', 'include']: |
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
154 shutil.copytree(join(jdk7, d), join(res, d)) |
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
155 return res |
3718 | 156 else: |
157 env.abort('Unknown build type: ' + build) | |
158 | |
159 def make(env, args): | |
3721
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
160 """builds the GraalVM binary |
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
161 |
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
162 The optional argument specifies what type of VM to build. |
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
163 """ |
3718 | 164 |
165 def fix_jvm_cfg(env, jdk): | |
166 jvmCfg = join(jdk, 'jre', 'lib', 'amd64', 'jvm.cfg') | |
167 found = False | |
168 if not exists(jvmCfg): | |
169 env.abort(jvmCfg + ' does not exist') | |
170 | |
171 with open(jvmCfg) as f: | |
172 for line in f: | |
173 if '-graal KNOWN' in line: | |
174 found = True | |
175 break | |
176 if not found: | |
177 env.log('Appending "-graal KNOWN" to ' + jvmCfg) | |
178 with open(jvmCfg, 'a') as f: | |
179 f.write('-graal KNOWN\n') | |
180 | |
181 build = 'product' if len(args) == 0 else args[0] | |
3721
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
182 jdk7 = _jdk7(env, build, True) |
3718 | 183 if build == 'debug': |
184 build = 'jvmg' | |
185 | |
186 fix_jvm_cfg(env, jdk7) | |
187 | |
188 graalVmDir = join(jdk7, 'jre', 'lib', 'amd64', 'graal') | |
189 if not exists(graalVmDir): | |
190 env.log('Creating Graal directory in JDK7: ' + graalVmDir) | |
191 os.makedirs(graalVmDir) | |
192 | |
193 def filterXusage(line): | |
194 if not 'Xusage.txt' in line: | |
195 sys.stderr.write(line + os.linesep) | |
196 | |
197 os.environ.update(ARCH_DATA_MODEL='64', LANG='C', HOTSPOT_BUILD_JOBS='3', ALT_BOOTDIR=jdk7, INSTALL='y') | |
198 env.run([env.gmake_cmd(), build + 'graal'], cwd=join(graal_home, 'make'), err=filterXusage) | |
199 | |
3721
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
200 def vm(env, args, vm='-graal'): |
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
201 """run the GraalVM |
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
202 |
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
203 The optional leading argument specifies an alternative to the |
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
204 product build should be run: @g = debug, @f = fastdebug, @o = optimized""" |
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
205 |
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
206 build = 'product' |
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
207 buildOpts = { |
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
208 '@g': 'debug', |
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
209 '@f': 'fastdebug', |
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
210 '@o': 'optimized' |
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
211 } |
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
212 |
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
213 if len(args) and args[0] in buildOpts.iterkeys(): |
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
214 build = buildOpts[args[0]] |
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
215 del args[0] |
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
216 |
3718 | 217 if env.java_dbg: |
218 args = ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000'] + args | |
219 os.environ['MAXINE'] = env.check_get_env('GRAAL_HOME') | |
220 exe = join(_jdk7(env, build), 'bin', env.exe_suffix('java')) | |
221 return env.run([exe, vm] + args) | |
222 | |
223 def mx_init(env): | |
224 commands = { | |
225 'dacapo': [dacapo, 'benchmark [VM options]'], | |
226 'example': [example, '[-v] example names...'], | |
227 'clean': [clean, ''], | |
3721
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
228 'make': [make, '[product|debug|fastdebug|optimized]'], |
3718 | 229 'tests': [tests, ''], |
3721
71b1204a74b4
Automated creation of debug, fastdebug and optimized subdirectories of the JDK.
Doug Simon <doug.simon@oracle.com>
parents:
3718
diff
changeset
|
230 'vm': [vm, '[@g|@f|@o] [-options] class [args...]'], |
3718 | 231 } |
232 env.commands.update(commands) | |
233 | |
234 def run_dacapo(env, args): | |
235 dacapo = env.check_get_env('DACAPO_CP') | |
236 if not isfile(dacapo) or not dacapo.endswith('.jar'): | |
237 env.abort('Specified DaCapo jar file does not exist or is not a jar file: ' + dacapo) | |
238 return vm(env, ['-Xms1g', '-Xmx2g', '-esa', '-cp', dacapo] + args) |