11/*
2- * Copyright (c) 2017, 2022 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2017, 2023 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
3434import java .nio .file .Path ;
3535import java .nio .file .Paths ;
3636import java .util .ArrayList ;
37+ import java .util .Arrays ;
3738import java .util .List ;
3839import java .util .concurrent .TimeUnit ;
3940import java .util .function .Predicate ;
@@ -52,6 +53,14 @@ public class CtwRunner {
5253 private static final Predicate <String > IS_CLASS_LINE = Pattern .compile (
5354 "^\\ [\\ d+\\ ]\\ s*\\ S+\\ s*$" ).asPredicate ();
5455
56+ /**
57+ * Value of {@code -Dsun.hotspot.tools.ctwrunner.ctw_extra_args}. Extra
58+ * comma-separated arguments to pass to CTW subprocesses.
59+ */
60+ private static final String CTW_EXTRA_ARGS
61+ = System .getProperty ("sun.hotspot.tools.ctwrunner.ctw_extra_args" , "" );
62+
63+
5564 private static final String USAGE = "Usage: CtwRunner <artifact to compile> [start[%] stop[%]]" ;
5665
5766 public static void main (String [] args ) throws Exception {
@@ -258,43 +267,51 @@ private String[] cmd(long classStart, long classStop) {
258267 String phase = phaseName (classStart );
259268 Path file = Paths .get (phase + ".cmd" );
260269 var rng = Utils .getRandomInstance ();
270+
271+ ArrayList <String > Args = new ArrayList <String >(Arrays .asList (
272+ "-Xbatch" ,
273+ "-XX:-UseCounterDecay" ,
274+ "-XX:-ShowMessageBoxOnError" ,
275+ "-XX:+UnlockDiagnosticVMOptions" ,
276+ // redirect VM output to cerr so it won't collide w/ ctw output
277+ "-XX:+DisplayVMOutputToStderr" ,
278+ // define phase start
279+ "-DCompileTheWorldStartAt=" + classStart ,
280+ "-DCompileTheWorldStopAt=" + classStop ,
281+ // CTW library uses WhiteBox API
282+ "-XX:+WhiteBoxAPI" , "-Xbootclasspath/a:." ,
283+ // export jdk.internal packages used by CTW library
284+ "--add-exports" , "java.base/jdk.internal.jimage=ALL-UNNAMED" ,
285+ "--add-exports" , "java.base/jdk.internal.misc=ALL-UNNAMED" ,
286+ "--add-exports" , "java.base/jdk.internal.reflect=ALL-UNNAMED" ,
287+ "--add-exports" , "java.base/jdk.internal.access=ALL-UNNAMED" ,
288+ // enable diagnostic logging
289+ "-XX:+LogCompilation" ,
290+ // use phase specific log, hs_err and ciReplay files
291+ String .format ("-XX:LogFile=hotspot_%s_%%p.log" , phase ),
292+ String .format ("-XX:ErrorFile=hs_err_%s_%%p.log" , phase ),
293+ String .format ("-XX:ReplayDataFile=replay_%s_%%p.log" , phase ),
294+ // MethodHandle MUST NOT be compiled
295+ "-XX:CompileCommand=exclude,java/lang/invoke/MethodHandle.*" ,
296+ // Stress* are c2-specific stress flags, so IgnoreUnrecognizedVMOptions is needed
297+ "-XX:+IgnoreUnrecognizedVMOptions" ,
298+ "-XX:+StressLCM" ,
299+ "-XX:+StressGCM" ,
300+ "-XX:+StressIGVN" ,
301+ "-XX:+StressCCP" ,
302+ // StressSeed is uint
303+ "-XX:StressSeed=" + Math .abs (rng .nextInt ())));
304+
305+ for (String arg : CTW_EXTRA_ARGS .split ("," )) {
306+ Args .add (arg );
307+ }
308+
309+ // CTW entry point
310+ Args .add (CompileTheWorld .class .getName ());
311+ Args .add (target );
312+
261313 try {
262- Files .write (file , List .of (
263- "-Xbatch" ,
264- "-XX:-UseCounterDecay" ,
265- "-XX:-ShowMessageBoxOnError" ,
266- "-XX:+UnlockDiagnosticVMOptions" ,
267- // redirect VM output to cerr so it won't collide w/ ctw output
268- "-XX:+DisplayVMOutputToStderr" ,
269- // define phase start
270- "-DCompileTheWorldStartAt=" + classStart ,
271- "-DCompileTheWorldStopAt=" + classStop ,
272- // CTW library uses WhiteBox API
273- "-XX:+WhiteBoxAPI" , "-Xbootclasspath/a:." ,
274- // export jdk.internal packages used by CTW library
275- "--add-exports" , "java.base/jdk.internal.jimage=ALL-UNNAMED" ,
276- "--add-exports" , "java.base/jdk.internal.misc=ALL-UNNAMED" ,
277- "--add-exports" , "java.base/jdk.internal.reflect=ALL-UNNAMED" ,
278- "--add-exports" , "java.base/jdk.internal.access=ALL-UNNAMED" ,
279- // enable diagnostic logging
280- "-XX:+LogCompilation" ,
281- // use phase specific log, hs_err and ciReplay files
282- String .format ("-XX:LogFile=hotspot_%s_%%p.log" , phase ),
283- String .format ("-XX:ErrorFile=hs_err_%s_%%p.log" , phase ),
284- String .format ("-XX:ReplayDataFile=replay_%s_%%p.log" , phase ),
285- // MethodHandle MUST NOT be compiled
286- "-XX:CompileCommand=exclude,java/lang/invoke/MethodHandle.*" ,
287- // Stress* are c2-specific stress flags, so IgnoreUnrecognizedVMOptions is needed
288- "-XX:+IgnoreUnrecognizedVMOptions" ,
289- "-XX:+StressLCM" ,
290- "-XX:+StressGCM" ,
291- "-XX:+StressIGVN" ,
292- "-XX:+StressCCP" ,
293- // StressSeed is uint
294- "-XX:StressSeed=" + Math .abs (rng .nextInt ()),
295- // CTW entry point
296- CompileTheWorld .class .getName (),
297- target ));
314+ Files .write (file , Args );
298315 } catch (IOException e ) {
299316 throw new Error ("can't create " + file , e );
300317 }
0 commit comments