30
30
import java .io .IOException ;
31
31
import java .io .InputStream ;
32
32
import java .io .OutputStream ;
33
+ import java .lang .management .ManagementFactory ;
33
34
import java .nio .file .Files ;
34
35
import java .nio .file .NoSuchFileException ;
35
36
import java .nio .file .Paths ;
41
42
import java .util .Set ;
42
43
43
44
import org .graalvm .launcher .AbstractLanguageLauncher ;
45
+ import org .graalvm .nativeimage .ProcessProperties ;
44
46
import org .graalvm .options .OptionCategory ;
45
47
import org .graalvm .polyglot .Context ;
46
48
import org .graalvm .polyglot .Context .Builder ;
@@ -78,6 +80,8 @@ public static void main(String[] args) {
78
80
@ Override
79
81
protected List <String > preprocessArguments (List <String > arguments , Map <String , String > polyglotOptions ) {
80
82
ArrayList <String > unrecognized = new ArrayList <>();
83
+ List <String > inputArgs = new ArrayList <>(arguments );
84
+ List <String > subprocessArgs = new ArrayList <>();
81
85
programArgs = new ArrayList <>();
82
86
for (int i = 0 ; i < arguments .size (); i ++) {
83
87
String arg = arguments .get (i );
@@ -143,6 +147,21 @@ protected List<String> preprocessArguments(List<String> arguments, Map<String, S
143
147
runLD = true ;
144
148
programArgs .addAll (arguments .subList (i + 1 , arguments .size ()));
145
149
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 ;
146
165
default :
147
166
if (!arg .startsWith ("-" )) {
148
167
inputFile = arg ;
@@ -167,6 +186,10 @@ protected List<String> preprocessArguments(List<String> arguments, Map<String, S
167
186
programArgs .add ("" );
168
187
}
169
188
189
+ if (!subprocessArgs .isEmpty ()) {
190
+ subExec (inputArgs , subprocessArgs );
191
+ }
192
+
170
193
return unrecognized ;
171
194
}
172
195
@@ -486,7 +509,7 @@ protected void printHelp(OptionCategory maxCategory) {
486
509
// " a defense against denial-of-service attacks\n" +
487
510
// "-Q arg : division options: -Qold (default), -Qwarn, -Qwarnall, -Qnew\n"
488
511
// +
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 " +
490
513
"-s : don't add user site directory to sys.path; also PYTHONNOUSERSITE\n " +
491
514
"-S : don't imply 'import site' on initialization\n " +
492
515
// "-t : issue warnings about inconsistent tab usage (-tt: issue errors)\n"
@@ -496,7 +519,7 @@ protected void printHelp(OptionCategory maxCategory) {
496
519
"-v : verbose (trace import statements); also PYTHONVERBOSE=x\n " +
497
520
" can be supplied multiple times to increase verbosity\n " +
498
521
"-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 " +
500
523
// "-W arg : warning control; arg is
501
524
// action:message:category:module:lineno\n" +
502
525
// " also PYTHONWARNINGS=arg\n" +
@@ -509,11 +532,14 @@ protected void printHelp(OptionCategory maxCategory) {
509
532
"arg ...: arguments passed to program in sys.argv[1:]\n " +
510
533
"\n " +
511
534
"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 " +
517
543
"\n " +
518
544
"Other environment variables:\n " +
519
545
"PYTHONSTARTUP: file executed on interactive startup (no default)\n " +
@@ -678,6 +704,51 @@ private void setupREPL(Context context, ConsoleHandler consoleHandler) {
678
704
}
679
705
}
680
706
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
+
681
752
private static final class ExitException extends RuntimeException {
682
753
private static final long serialVersionUID = 1L ;
683
754
private final int code ;
0 commit comments