Skip to content

Commit 2bfb146

Browse files
committed
[GR-12445] Move some truffle debug options into the launcher for convenience
PullRequest: graalpython/287
2 parents 7062b23 + c2bca93 commit 2bfb146

File tree

2 files changed

+81
-91
lines changed

2 files changed

+81
-91
lines changed

graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/GraalPythonMain.java

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.io.IOException;
3131
import java.io.InputStream;
3232
import java.io.OutputStream;
33+
import java.lang.management.ManagementFactory;
3334
import java.nio.file.Files;
3435
import java.nio.file.NoSuchFileException;
3536
import java.nio.file.Paths;
@@ -41,6 +42,7 @@
4142
import java.util.Set;
4243

4344
import org.graalvm.launcher.AbstractLanguageLauncher;
45+
import org.graalvm.nativeimage.ProcessProperties;
4446
import org.graalvm.options.OptionCategory;
4547
import org.graalvm.polyglot.Context;
4648
import org.graalvm.polyglot.Context.Builder;
@@ -78,6 +80,8 @@ public static void main(String[] args) {
7880
@Override
7981
protected List<String> preprocessArguments(List<String> arguments, Map<String, String> polyglotOptions) {
8082
ArrayList<String> unrecognized = new ArrayList<>();
83+
List<String> inputArgs = new ArrayList<>(arguments);
84+
List<String> subprocessArgs = new ArrayList<>();
8185
programArgs = new ArrayList<>();
8286
for (int i = 0; i < arguments.size(); i++) {
8387
String arg = arguments.get(i);
@@ -143,6 +147,23 @@ protected List<String> preprocessArguments(List<String> arguments, Map<String, S
143147
runLD = true;
144148
programArgs.addAll(arguments.subList(i + 1, arguments.size()));
145149
return unrecognized;
150+
case "-debug-perf":
151+
subprocessArgs.add("Dgraal.TraceTruffleCompilation=true");
152+
subprocessArgs.add("Dgraal.TraceTrufflePerformanceWarnings=true");
153+
subprocessArgs.add("Dgraal.TruffleCompilationExceptionsArePrinted=true");
154+
subprocessArgs.add("Dgraal.TraceTruffleInlining=true");
155+
subprocessArgs.add("Dgraal.TruffleTraceSplittingSummary=true");
156+
inputArgs.remove("-debug-perf");
157+
break;
158+
case "-dump":
159+
subprocessArgs.add("Dgraal.Dump=");
160+
inputArgs.remove("-dump");
161+
break;
162+
case "-compile-truffle-immediately":
163+
subprocessArgs.add("Dgraal.TruffleCompileImmediately=true");
164+
subprocessArgs.add("Dgraal.TruffleCompilationExceptionsAreThrown=true");
165+
inputArgs.remove("-compile-truffle-immediately");
166+
break;
146167
default:
147168
if (!arg.startsWith("-")) {
148169
inputFile = arg;
@@ -167,6 +188,10 @@ protected List<String> preprocessArguments(List<String> arguments, Map<String, S
167188
programArgs.add("");
168189
}
169190

191+
if (!subprocessArgs.isEmpty()) {
192+
subExec(inputArgs, subprocessArgs);
193+
}
194+
170195
return unrecognized;
171196
}
172197

@@ -486,7 +511,7 @@ protected void printHelp(OptionCategory maxCategory) {
486511
// " a defense against denial-of-service attacks\n" +
487512
// "-Q arg : division options: -Qold (default), -Qwarn, -Qwarnall, -Qnew\n"
488513
// +
489-
"-q : don't print version and copyright messages on interactive startup" +
514+
"-q : don't print version and copyright messages on interactive startup\n" +
490515
"-s : don't add user site directory to sys.path; also PYTHONNOUSERSITE\n" +
491516
"-S : don't imply 'import site' on initialization\n" +
492517
// "-t : issue warnings about inconsistent tab usage (-tt: issue errors)\n"
@@ -496,7 +521,7 @@ protected void printHelp(OptionCategory maxCategory) {
496521
"-v : verbose (trace import statements); also PYTHONVERBOSE=x\n" +
497522
" can be supplied multiple times to increase verbosity\n" +
498523
"-V : print the Python version number and exit (also --version)\n" +
499-
" when given twice, print more information about the build" +
524+
" when given twice, print more information about the build\n" +
500525
// "-W arg : warning control; arg is
501526
// action:message:category:module:lineno\n" +
502527
// " also PYTHONWARNINGS=arg\n" +
@@ -508,7 +533,7 @@ protected void printHelp(OptionCategory maxCategory) {
508533
// "- : program read from stdin (default; interactive mode if a tty)\n" +
509534
"arg ...: arguments passed to program in sys.argv[1:]\n" +
510535
"\n" +
511-
"Arguments specific to GraalPython.\n" +
536+
"Arguments specific to GraalPython:\n" +
512537
"--show-version : print the Python version number and continue.\n" +
513538
"-CC : run the C compiler used for generating GraalPython C extensions.\n" +
514539
" All following arguments are passed to the compiler.\n" +
@@ -527,6 +552,12 @@ protected void printHelp(OptionCategory maxCategory) {
527552
" as specifying the -R option: a random value is used to seed the hashes of\n" +
528553
" str, bytes and datetime objects. It can also be set to an integer\n" +
529554
" in the range [0,4294967295] to get hash values with a predictable seed.");
555+
if (maxCategory.compareTo(OptionCategory.DEBUG) >= 0) {
556+
print("\nGraalPython performance debugging options:\n" +
557+
"-debug-perf : Enable tracing of Truffle compilations and its warnings\n" +
558+
"-dump : Enable dumping of compilation graphs to IGV\n" +
559+
"-compile-truffle-immediately : Start compiling on first invocation and throw compilation exceptions");
560+
}
530561
}
531562

532563
@Override
@@ -678,6 +709,51 @@ private void setupREPL(Context context, ConsoleHandler consoleHandler) {
678709
}
679710
}
680711

712+
/**
713+
* Some system properties have already been read at this point, so to change them, we just
714+
* re-execute the process with the additional options.
715+
*/
716+
private static void subExec(List<String> args, List<String> subProcessDefs) {
717+
List<String> cmd = new ArrayList<>();
718+
if (isAOT()) {
719+
cmd.add(ProcessProperties.getExecutableName());
720+
for (String subProcArg : subProcessDefs) {
721+
assert subProcArg.startsWith("D");
722+
cmd.add("--native." + subProcArg);
723+
}
724+
} else {
725+
cmd.add(System.getProperty("java.home") + File.separator + "bin" + File.separator + "java");
726+
switch (System.getProperty("java.vm.name")) {
727+
case "Java HotSpot(TM) 64-Bit Server VM":
728+
cmd.add("-server");
729+
cmd.add("-d64");
730+
break;
731+
case "Java HotSpot(TM) 64-Bit Client VM":
732+
cmd.add("-client");
733+
cmd.add("-d64");
734+
break;
735+
default:
736+
break;
737+
}
738+
cmd.addAll(ManagementFactory.getRuntimeMXBean().getInputArguments());
739+
cmd.add("-cp");
740+
cmd.add(ManagementFactory.getRuntimeMXBean().getClassPath());
741+
for (String subProcArg : subProcessDefs) {
742+
assert subProcArg.startsWith("D");
743+
cmd.add("-" + subProcArg);
744+
}
745+
cmd.add(GraalPythonMain.class.getName());
746+
}
747+
748+
cmd.addAll(args);
749+
try {
750+
System.exit(new ProcessBuilder(cmd.toArray(new String[0])).inheritIO().start().waitFor());
751+
} catch (IOException | InterruptedException e) {
752+
System.err.println(e.getMessage());
753+
System.exit(-1);
754+
}
755+
}
756+
681757
private static final class ExitException extends RuntimeException {
682758
private static final long serialVersionUID = 1L;
683759
private final int code;

mx.graalpython/mx_graalpython.py

Lines changed: 2 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -64,100 +64,16 @@ def __get_svm_binary_from_graalvm():
6464

6565

6666
def _extract_graalpython_internal_options(args):
67-
internal = []
6867
non_internal = []
6968
additional_dists = []
7069
for arg in args:
7170
# Class path extensions
7271
if arg.startswith('-add-dist='):
7372
additional_dists += [arg[10:]]
74-
75-
# Debug flags
76-
elif arg == '-print-ast':
77-
internal += ["-Dcom.oracle.graal.python.PrintAST=true"] # false
78-
79-
elif arg == '-visualize-ast':
80-
internal += ["-Dcom.oracle.graal.python.VisualizedAST=true"] # false
81-
82-
elif arg.startswith('-print-ast='):
83-
internal += ["-Dcom.oracle.graal.python.PrintASTFilter=" + arg.replace('-print-ast=')] # null
84-
85-
elif arg == '-debug-trace':
86-
internal += ["-Dcom.oracle.graal.python.TraceJythonRuntime=true"] # false
87-
internal += ["-Dcom.oracle.graal.python.TraceImports=true"] # false
88-
internal += ["-Dcom.oracle.graal.python.TraceSequenceStorageGeneralization=true"] # false
89-
internal += ["-Dcom.oracle.graal.python.TraceObjectLayoutCreation=true"] # false
90-
internal += ["-Dcom.oracle.graal.python.TraceNodesWithoutSourceSection=true"] # false
91-
internal += ["-Dcom.oracle.graal.python.TraceNodesUsingExistingProbe=true"] # false
92-
93-
elif arg == '-debug-junit':
94-
internal += ["-Dcom.oracle.graal.python.CatchGraalPythonExceptionForUnitTesting=true"] # false
95-
96-
# Object storage allocation """
97-
elif arg == '-instrument-storageAlloc':
98-
internal += ["-Dcom.oracle.graal.python.InstrumentObjectStorageAllocation=true"] # false
99-
100-
# Translation flags """
101-
elif arg == '-print-function':
102-
internal += ["-Dcom.oracle.graal.python.UsePrintFunction=true"] # false
103-
104-
# Runtime flags
105-
elif arg == '-no-sequence-unboxing':
106-
internal += ["-Dcom.oracle.graal.python.disableUnboxSequenceStorage=true"] # true
107-
internal += ["-Dcom.oracle.graal.python.disableUnboxSequenceIteration=true"] # true
108-
109-
elif arg == '-no-intrinsify-calls':
110-
internal += ["-Dcom.oracle.graal.python.disableIntrinsifyBuiltinCalls=true"] # true
111-
112-
elif arg == '-flexible-object-storage':
113-
internal += ["-Dcom.oracle.graal.python.FlexibleObjectStorage=true"] # false
114-
115-
elif arg == '-flexible-storage-evolution':
116-
internal += ["-Dcom.oracle.graal.python.FlexibleObjectStorageEvolution=true"] # false
117-
internal += ["-Dcom.oracle.graal.python.FlexibleObjectStorage=true"] # false
118-
119-
# Generators
120-
elif arg == '-no-inline-generator':
121-
internal += ["-Dcom.oracle.graal.python.disableInlineGeneratorCalls=true"] # true
122-
elif arg == '-no-optimize-genexp':
123-
internal += ["-Dcom.oracle.graal.python.disableOptimizeGeneratorExpressions=true"] # true
124-
elif arg == '-no-generator-peeling':
125-
internal += ["-Dcom.oracle.graal.python.disableInlineGeneratorCalls=true"] # true
126-
internal += ["-Dcom.oracle.graal.python.disableOptimizeGeneratorExpressions=true"] # true
127-
128-
elif arg == '-trace-generator-peeling':
129-
internal += ["-Dcom.oracle.graal.python.TraceGeneratorInlining=true"] # false
130-
131-
# Other
132-
elif arg == '-force-long':
133-
internal += ["-Dcom.oracle.graal.python.forceLongType=true"] # false
134-
135-
elif arg == '-debug-perf' and SUITE_COMPILER:
136-
# internal += ['-Dgraal.InliningDepthError=500']
137-
# internal += ['-Dgraal.EscapeAnalysisIterations=3']
138-
# internal += ['-XX:JVMCINMethodSizeLimit=1000000']
139-
# internal += ['-Xms10g', '-Xmx16g']
140-
internal += ['-Dgraal.TraceTruffleCompilation=true']
141-
internal += ['-Dgraal.Dump=']
142-
# internal += ['-XX:CompileCommand=print,*OptimizedCallTarget.callRoot',
143-
# '-XX:CompileCommand=exclude,*OptimizedCallTarget.callRoot',
144-
# '-Dgraal.TruffleBackgroundCompilation=false']
145-
# internal += ['-Dgraal.TruffleCompileImmediately=true']
146-
internal += ['-Dgraal.TraceTrufflePerformanceWarnings=true']
147-
internal += ['-Dgraal.TruffleCompilationExceptionsArePrinted=true']
148-
# internal += ['-Dgraal.TruffleInliningMaxCallerSize=150']
149-
# internal += ['-Dgraal.InliningDepthError=10']
150-
# internal += ['-Dgraal.MaximumLoopExplosionCount=1000']
151-
# internal += ['-Dgraal.TruffleCompilationThreshold=100000']
152-
153-
elif arg == '-compile-truffle-immediately' and SUITE_COMPILER:
154-
internal += ['-Dgraal.TruffleCompileImmediately=true']
155-
internal += ['-Dgraal.TruffleCompilationExceptionsAreThrown=true']
156-
15773
else:
15874
non_internal += [arg]
15975

160-
return internal, non_internal, additional_dists
76+
return non_internal, additional_dists
16177

16278

16379
def check_vm(vm_warning=True, must_be_jvmci=False):
@@ -197,7 +113,7 @@ def do_run_python(args, extra_vm_args=None, env=None, jdk=None, **kwargs):
197113
dists = ['GRAALPYTHON']
198114

199115
vm_args, graalpython_args = mx.extract_VM_args(args, useDoubleDash=True, defaultAllVMArgs=False)
200-
internal_graalpython_args, graalpython_args, additional_dists = _extract_graalpython_internal_options(graalpython_args)
116+
graalpython_args, additional_dists = _extract_graalpython_internal_options(graalpython_args)
201117
dists += additional_dists
202118
if '--python.WithJavaStacktrace' not in graalpython_args:
203119
graalpython_args.insert(0, '--python.WithJavaStacktrace')
@@ -225,8 +141,6 @@ def _is_user(user, home=None):
225141

226142
vm_args += mx.get_runtime_jvm_args(dists, jdk=jdk)
227143

228-
vm_args += internal_graalpython_args
229-
230144
if not jdk:
231145
jdk = get_jdk()
232146

0 commit comments

Comments
 (0)