Skip to content

Commit dce8fca

Browse files
committed
remove the custom zippy options from our mx file, move some truffle debug options into the launcher for convenience
1 parent 7062b23 commit dce8fca

File tree

2 files changed

+80
-95
lines changed

2 files changed

+80
-95
lines changed

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

Lines changed: 78 additions & 7 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,21 @@ 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+
inputArgs.remove("-debug-perf");
155+
break;
156+
case "-dump":
157+
subprocessArgs.add("Dgraal.Dump=");
158+
inputArgs.remove("-dump");
159+
break;
160+
case "-compile-truffle-immediately":
161+
subprocessArgs.add("Dgraal.TruffleCompileImmediately=true");
162+
subprocessArgs.add("Dgraal.TruffleCompilationExceptionsAreThrown=true");
163+
inputArgs.remove("-compile-truffle-immediately");
164+
break;
146165
default:
147166
if (!arg.startsWith("-")) {
148167
inputFile = arg;
@@ -167,6 +186,10 @@ protected List<String> preprocessArguments(List<String> arguments, Map<String, S
167186
programArgs.add("");
168187
}
169188

189+
if (!subprocessArgs.isEmpty()) {
190+
subExec(inputArgs, subprocessArgs);
191+
}
192+
170193
return unrecognized;
171194
}
172195

@@ -486,7 +509,7 @@ protected void printHelp(OptionCategory maxCategory) {
486509
// " a defense against denial-of-service attacks\n" +
487510
// "-Q arg : division options: -Qold (default), -Qwarn, -Qwarnall, -Qnew\n"
488511
// +
489-
"-q : don't print version and copyright messages on interactive startup" +
512+
"-q : don't print version and copyright messages on interactive startup\n" +
490513
"-s : don't add user site directory to sys.path; also PYTHONNOUSERSITE\n" +
491514
"-S : don't imply 'import site' on initialization\n" +
492515
// "-t : issue warnings about inconsistent tab usage (-tt: issue errors)\n"
@@ -496,7 +519,7 @@ protected void printHelp(OptionCategory maxCategory) {
496519
"-v : verbose (trace import statements); also PYTHONVERBOSE=x\n" +
497520
" can be supplied multiple times to increase verbosity\n" +
498521
"-V : print the Python version number and exit (also --version)\n" +
499-
" when given twice, print more information about the build" +
522+
" when given twice, print more information about the build\n" +
500523
// "-W arg : warning control; arg is
501524
// action:message:category:module:lineno\n" +
502525
// " also PYTHONWARNINGS=arg\n" +
@@ -509,11 +532,14 @@ protected void printHelp(OptionCategory maxCategory) {
509532
"arg ...: arguments passed to program in sys.argv[1:]\n" +
510533
"\n" +
511534
"Arguments specific to GraalPython.\n" +
512-
"--show-version : print the Python version number and continue.\n" +
513-
"-CC : run the C compiler used for generating GraalPython C extensions.\n" +
514-
" All following arguments are passed to the compiler.\n" +
515-
"-LD : run the linker used for generating GraalPython C extensions.\n" +
516-
" All following arguments are passed to the linker.\n" +
535+
"--show-version : print the Python version number and continue.\n" +
536+
"-CC : run the C compiler used for generating GraalPython C extensions.\n" +
537+
" All following arguments are passed to the compiler.\n" +
538+
"-LD : run the linker used for generating GraalPython C extensions.\n" +
539+
" All following arguments are passed to the linker.\n" +
540+
"-debug-perf : Enable tracing of Truffle compilations and its warnings\n" +
541+
"-dump : Enable dumping of compilation graphs to IGV\n" +
542+
"-compile-truffle-immediately : Start compiling on first invocation and throw compilation exceptions\n" +
517543
"\n" +
518544
"Other environment variables:\n" +
519545
"PYTHONSTARTUP: file executed on interactive startup (no default)\n" +
@@ -678,6 +704,51 @@ private void setupREPL(Context context, ConsoleHandler consoleHandler) {
678704
}
679705
}
680706

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