This repository has been archived by the owner on Mar 22, 2019. It is now read-only.
forked from smarr/SOMns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
som
executable file
·376 lines (314 loc) · 16.5 KB
/
som
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
#!/usr/bin/env python2.7
import argparse
import sys
import os
import shlex
BASE_DIR = os.path.dirname(os.path.realpath(__file__))
TRUFFLE_DIR = BASE_DIR + '/libs/truffle'
JAVA_HOME = os.getenv('JAVA_HOME', None)
JVMCI_BIN = os.getenv('JVMCI_BIN', None)
GRAAL_HOME = os.getenv('GRAAL_HOME', None)
GRAAL_FLAGS = os.getenv('GRAAL_FLAGS', None)
GRAAL_LOCATIONS = ['~/.local/graal-core/',
BASE_DIR + '/../graal/graal-jvmci-8']
##
## Defining Argument Parsing
##
parser = argparse.ArgumentParser(
description='Helper script to run SOMns with/without Graal')
parser.add_argument('-d', '--debug', help='wait for debugger to attach',
dest='debug', action='store_true', default=False)
parser.add_argument('-t', '--num-threads', help='number of threads to be used',
dest='threads', default=None)
parser.add_argument('-p', '--platform', help='SOM Platform file, default: core-lib/Platform.ns',
dest='som_platform', default=BASE_DIR + '/core-lib/Platform.ns')
parser.add_argument('-k', '--kernel', help='SOM Kernel file, default: core-lib/Kernel.ns',
dest='som_kernel', default=BASE_DIR + '/core-lib/Kernel.ns')
parser.add_argument('-dnu', '--stack-trace-on-dnu', help='Print a stack trace on #doesNotUnderstand:',
dest='som_dnu', action='store_true', default=False)
parser.add_argument('-vmd', '--vmdebug', help='enables debug mode (additional output)',
dest='vmdebug', action='store_true', default=False)
explore = parser.add_argument_group('Explore', 'Investigate Execution')
explore.add_argument('-i', '--igv', help='dump compilation details to IGV',
dest='igv', action='store_true', default=False)
explore.add_argument('-im', '--igv-parsed-methods', help='dump methods after parsing to IGV',
dest='igv_methods', action='store_true', default=False)
explore.add_argument('-if', '--igv-to-file', help='dump compilation details to file to be loaded by IGV',
dest='igv_to_file', action='store_true', default=False)
explore.add_argument('-io', '--igv-only', help='only dump named method, use of * allowed. Uses Invokable.toString()',
dest='only_igv', default=None)
explore.add_argument('-l', '--low-level', help='enable low-level optimization output',
dest='low_level', action='store_true', default=False)
explore.add_argument('-ti', '--trace-invalidation', help='trace assumption invalidation and transfers to interpreter',
dest='trace_invalidation', action='store_true', default=False)
explore.add_argument('-w', '--perf-warnings', help='enable performance warnings',
dest='perf_warnings', action='store_true', default=False)
explore.add_argument('-f', '--fail-on-missing-optimizations', help='fail execution on missing optimizations',
dest='fail_missing_opts', action='store_true', default=False)
explore.add_argument('-v', '--visual-vm', help='connect to VisualVM for profiling',
dest='visual_vm', action='store_true', default=False)
profile = parser.add_argument_group('Profile', 'Profile Execution')
profile.add_argument('-gp', '--graal-profile', help='enable Graal-level profiling after warmup',
dest='graal_profile', action='store_true', default=False)
profile.add_argument('-ga', '--graal-profile-allocations', help='enable Graal-level profiling after warmup, and profile allocations',
dest='graal_profile_allocations', action='store_true', default=False)
profile.add_argument('-gi', '--graal-profile-intervals', help='enable Graal-level profiling after certain time intervals',
dest='graal_profile_timed', action='store_true', default=False)
profile.add_argument('-gb', '--graal-branch-profile', help='enable Graal-level branch profiling',
dest='graal_branch_profile', action='store_true', default=False)
profile.add_argument('-tp', '--truffle-profile', help='enable Graal-level profiling after warmup',
dest='truffle_profile', action='store_true', default=False)
tools = parser.add_argument_group('Tools', 'Additional Tools')
tools.add_argument('-wd', '--web-debugger', help='start Web debugger',
dest='web_debugger', action='store_true', default=False)
tools.add_argument('-dm', '--dynamic-metrics', help='Capture Dynamic Metrics',
dest='dynamic_metrics', action='store_true', default=False)
tools.add_argument('-si', '--si-candidates', help='Identify candidates for super-instructions',
dest='si_candidates', action='store_true', default=False)
tools.add_argument('-at', '--actor-tracing', help='enable tracing of actor operations',
dest='actor_tracing', action='store_true', default=False)
tools.add_argument('-atcfg', '--actor-tracing-cfg', help='Configuration string for actor tracing',
dest='actor_tracing_cfg', default='')
tools.add_argument('-mt', '--memory-tracing', help='enable tracing of memory usage and GC',
dest='memory_tracing', action='store_true', default=False)
tools.add_argument('-tf', '--trace-file', help='Trace file destination, default: traces/trace',
dest='trace_file', default=BASE_DIR + '/traces/trace')
tools.add_argument('-TF', '--disable-trace-file', help='trace file wont be written to disk',
dest='disable_trace_file', action='store_true', default=False)
tools.add_argument('-r', '--replay', help='execution of the program is guided by an existing trace file',
dest='replay', action='store_true', default=False)
tools.add_argument('--coverage', help='determine SOMns code coverage and store in given file',
dest='coverage', default=None)
tools.add_argument('--java-coverage', help='determine Java code coverage and store in given file',
dest='java_coverage', default=None)
parser.add_argument('-o', '--only', help='only compile give methods, comma separated list',
dest='only_compile', default=None)
parser.add_argument('-A', '--no-assert', help='execute with assertions disabled',
dest='assert_', action='store_false', default=True)
parser.add_argument('-B', '--no-background', help='disable background compilation',
dest='background_compilation', action='store_false', default=True)
parser.add_argument('-C', '--no-compilation', help='disable Truffle compilation',
dest='no_compilation', action='store_true', default=False)
parser.add_argument('-G', '--interpreter', help='run without Graal',
dest='interpreter', action='store_true', default=False)
parser.add_argument('-EG', '--no-embedded-graal', help='run without the embedded Graal',
dest='embedded_graal', action='store_false', default=True)
parser.add_argument('-X', '--java-interpreter', help='run without Graal, and only the Java interpreter',
dest='java_interpreter', action='store_true', default=False)
parser.add_argument('-T', '--no-trace', help='do not print truffle compilation info',
dest='no_trace', action='store_false', default=True)
parser.add_argument('--no-graph-pe', help='disable Graph PE',
dest='graph_pe', action='store_false', default=True)
parser.add_argument('-vv', '--verbose', action='store_true', default=False,
dest='verbose', help="print command-line before executing")
parser.add_argument('--print-graal-options', action='store_true', default=False,
dest='print_graal_options', help="print all Graal options")
parser.add_argument('-J', help="Java VM Argument prefix",
dest="java_args", action='append')
parser.add_argument('-D', help="define a Java property",
dest="java_properties", action='append')
parser.add_argument('-ac', '--ansi-coloring', help='Enable ANSI coloring for output from interpreter with true, or disable with false',
dest='use_ansi_coloring', action='store', default=hasattr(sys.stdout, 'isatty') and sys.stdout.isatty())
parser.add_argument('args', nargs=argparse.REMAINDER,
help='arguments passed to SOMns')
if len(sys.argv) < 2:
parser.print_help()
sys.exit(1)
args = parser.parse_args()
if args.dynamic_metrics:
args.interpreter = True
if args.java_interpreter:
args.interpreter = True
graal_home = GRAAL_HOME
java_bin = None
if JAVA_HOME:
java_bin = JAVA_HOME + '/bin/java'
if JVMCI_BIN:
java_bin = JVMCI_BIN
if not java_bin:
if not graal_home:
# search known Graal locations
for d in GRAAL_LOCATIONS:
d = os.path.expanduser(d)
if os.path.isdir(d):
graal_home = d
break
if graal_home and os.path.isdir(graal_home + '/bin'):
java_bin = graal_home + '/bin/java'
if java_bin is graal_home or not os.path.isfile(java_bin):
java_bin = "java"
JAVA_MAJOR_VERSION = None
try:
j_ver_str = os.popen(java_bin + " -version 2>&1").read()
j_arr = j_ver_str.split("\"")
if j_arr[1].startswith("1.8"):
JAVA_MAJOR_VERSION = 8
else:
JAVA_MAJOR_VERSION = int(j_arr[1].split(".")[0])
except:
pass
if java_bin == "java" and (not JAVA_MAJOR_VERSION or JAVA_MAJOR_VERSION < 9):
print "No compatible JDK found. Please set the GRAAL_HOME or JVMCI_BIN environment variables."
sys.exit(1)
##
## Defining Necessary Parameter Bits
##
CLASSPATH = (BASE_DIR + '/build/classes:'
+ BASE_DIR + '/libs/black-diamonds/build/classes:'
+ TRUFFLE_DIR + '/truffle/mxbuild/dists/truffle-debug.jar:'
+ BASE_DIR + '/libs/somns-deps.jar')
BOOT_CLASSPATH = ('-Xbootclasspath/a:'
+ TRUFFLE_DIR + '/sdk/mxbuild/dists/graal-sdk.jar:'
+ TRUFFLE_DIR + '/truffle/mxbuild/dists/truffle-api.jar')
GRAAL_JAVA_8_FLAGS = ['-Djvmci.Compiler=graal',
'-Djvmci.class.path.append=' + TRUFFLE_DIR + '/compiler/mxbuild/dists/graal.jar']
GRAAL_JAVA_9_FLAGS = [
'--module-path=' + TRUFFLE_DIR + '/sdk/mxbuild/modules/org.graalvm.graal_sdk.jar:' +
TRUFFLE_DIR + '/truffle/mxbuild/modules/com.oracle.truffle.truffle_api.jar',
'--upgrade-module-path=' + TRUFFLE_DIR + '/compiler/mxbuild/modules/jdk.internal.vm.compiler.jar']
SOM_ARGS = ['-Dbd.settings=som.vm.VmSettings', 'som.VM',
'--platform', args.som_platform, '--kernel', args.som_kernel]
# == Compiler Settings
TWEAK_INLINING = ['-Dgraal.TruffleCompilationThreshold=191',
'-Dgraal.TruffleInliningMaxCallerSize=10000',
'-Dgraal.TruffleSplittingMaxCalleeSize=100000']
GRAAL_JVMCI_FLAGS = ['-XX:+UnlockExperimentalVMOptions', '-XX:+EnableJVMCI', '-XX:-UseJVMCICompiler']
JAVA_ARGS = ['-server']
if JAVA_MAJOR_VERSION == 8:
JAVA_ARGS += ['-d64']
GRAAL_EMBEDDED_FLAGS = GRAAL_JAVA_8_FLAGS
if JAVA_MAJOR_VERSION > 8:
GRAAL_EMBEDDED_FLAGS = GRAAL_JAVA_9_FLAGS
##
## Processing Parameters and Assembling Command Line
##
if not args.interpreter and GRAAL_FLAGS:
flags = shlex.split(str.strip(GRAAL_FLAGS))
else:
flags = []
if args.interpreter:
flags += ['-Dtruffle.TruffleRuntime=com.oracle.truffle.api.impl.DefaultTruffleRuntime']
else:
flags += GRAAL_JVMCI_FLAGS
if args.embedded_graal:
flags += GRAAL_EMBEDDED_FLAGS
if args.som_dnu:
flags += ['-Dsom.printStackTraceOnDNU=true']
if args.use_ansi_coloring:
flags += ['-Dsom.useAnsiColoring=' + str(args.use_ansi_coloring).lower()]
# Handle executable names
if sys.argv[0].endswith('fast'):
args.assert_ = False
args.no_trace = True
if sys.argv[0].endswith('debug'):
args.perf_warnings = True
args.background_compilation = False
if args.only_igv or args.igv_methods:
args.igv = True
if not args.interpreter:
# Make sure everything gets compiled
flags += ['-Dgraal.TruffleTimeThreshold=10000000']
if args.debug:
flags += ['-Xdebug',
'-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000']
if not args.interpreter and (args.igv or args.igv_to_file):
flags += ['-Dgraal.Dump=Truffle,TruffleTree:2']
if not args.interpreter and args.only_igv:
flags += ['-Dgraal.MethodFilter=' + args.only_igv]
if not args.interpreter and args.igv_to_file:
flags += ['-Dgraal.PrintIdealGraphFile=true']
if args.igv_methods:
flags += ['-Dsom.igvDumpAfterParsing=true']
if args.low_level:
flags += ['-XX:+UnlockDiagnosticVMOptions', '-XX:+LogCompilation',
'-XX:+TraceDeoptimization']
if not args.interpreter and (args.graal_profile or args.graal_profile_allocations or args.graal_profile_timed):
flags += ['-XX:JVMCICounterSize=5000', '-Dgraal.ProfileCompiledMethods=true',
'-DProfileCompiledMethodsPhase.WITH_SECTION_HEADER=true']
if args.graal_profile_allocations:
flags += ['-Dgraal.ProfileAllocations=true']
if args.graal_profile_timed:
flags += ['-Dgraal.TimedDynamicCounters=1000']
if args.graal_profile:
flags += ['-Dgraal.BenchmarkDynamicCounters=out,completed,total']
if not args.interpreter and args.graal_branch_profile:
flags += ['-Dgraal.TruffleInstrumentBranches=true',
'-Dgraal.TruffleInstrumentBranchesFilter=*',
'-Dgraal.TruffleInstrumentBranchesPerInlineSite=true']
if args.truffle_profile:
flags += ['-Dtruffle.profiling.enabled=true']
SOM_ARGS += ['--profile']
if args.coverage:
SOM_ARGS += ['--coverage', args.coverage]
if args.java_coverage:
flags += ['-javaagent:' + BASE_DIR + '/libs/jacoco/lib/jacocoagent.jar=inclbootstrapclasses=true,destfile=' + args.java_coverage]
if args.web_debugger:
SOM_ARGS += ['--web-debug']
if args.dynamic_metrics:
SOM_ARGS += ['--dynamic-metrics']
flags += ['-Dsom.dynamicMetrics=true']
if args.si_candidates:
SOM_ARGS += ['--si-candidates']
if args.vmdebug:
flags += ['-Dsom.debugMode=true']
if args.actor_tracing:
flags += ['-Dsom.actorTracing=true']
if args.actor_tracing_cfg:
flags += ['-Dsom.actorTracingCfg=%s' % args.actor_tracing_cfg ]
if args.trace_file:
flags += ['-Dsom.traceFile=%s' % args.trace_file ]
if args.memory_tracing:
flags += ['-Dsom.memoryTracing=true']
if args.disable_trace_file:
flags += ['-Dsom.disableTraceFile=true']
if args.replay:
flags += ['-Dsom.replay=true']
if (args.truffle_profile or args.web_debugger or
args.dynamic_metrics or args.coverage or args.si_candidates):
flags += ['-Dsom.instrumentation=true']
if args.web_debugger:
flags += ['-Dsom.truffleDebugger=true']
if not args.interpreter and args.perf_warnings:
flags += ['-Dgraal.TruffleCompilationExceptionsAreFatal=true',
'-Dgraal.TraceTrufflePerformanceWarnings=true',
'-Dgraal.TraceTruffleCompilation=true',
'-Dgraal.TraceTruffleCompilationDetails=true',
'-Dgraal.TraceTruffleExpansionSource=true']
if not args.fail_missing_opts:
flags += ['-DfailOnMissingOptimization=true']
if not args.interpreter and args.trace_invalidation:
flags += ['-Dgraal.TraceTruffleTransferToInterpreter=true',
'-Dgraal.TraceTruffleAssumptions=true']
if not args.interpreter and args.only_compile:
flags.append("-Dgraal.TruffleCompileOnly=%s" % args.only_compile)
if args.visual_vm:
flags += ['-agentpath:/Users/smarr/Downloads/visualvm_138/profiler/lib/deployed/jdk16/mac/libprofilerinterface.jnilib=/Users/smarr/Downloads/visualvm_138/profiler/lib,5140']
if args.assert_:
flags += ['-esa', '-ea']
else:
flags += ['-dsa', '-da']
if not args.interpreter and not args.background_compilation:
flags += ['-Dgraal.TruffleBackgroundCompilation=false']
if not args.interpreter and args.no_compilation:
flags.append('-Dgraal.TruffleCompileOnly=__FAKE_METHOD_NON_EXISTING__')
if not args.interpreter and args.no_trace and not args.perf_warnings:
flags += ['-Dgraal.TraceTruffleInlining=false', '-Dgraal.TraceTruffleCompilation=false']
if not args.interpreter and not args.graph_pe:
flags += ['-Dgraal.GraphPE=false']
if args.threads:
flags += ['-Dsom.threads=%s' % args.threads ]
if args.java_interpreter:
flags += ['-Xint']
if args.print_graal_options:
flags += ['-XX:+JVMCIPrintProperties']
if args.java_properties:
flags += ['-D' + property for property in args.java_properties]
if args.java_args:
JAVA_ARGS += ['-' + property for property in args.java_args]
flags += ['-Dsom.tools=' + BASE_DIR + '/tools']
all_args = JAVA_ARGS + ['-classpath', CLASSPATH] + [BOOT_CLASSPATH] + flags + SOM_ARGS + args.args
if args.verbose:
print "CMD: " + java_bin + ' ' + ' '.join(all_args)
env = dict(os.environ)
env['JVMCI_VERSION_CHECK'] = 'ignore'
os.execvpe(java_bin, all_args, env)