3434import jdk .test .lib .process .ProcessTools ;
3535import jdk .test .lib .process .OutputAnalyzer ;
3636
37+ import java .nio .file .Files ;
38+ import java .nio .file .Path ;
39+ import java .util .List ;
40+ import java .util .stream .Collectors ;
41+
3742public class TestEnableJVMCIProduct {
3843
3944 static class Expectation {
@@ -52,10 +57,11 @@ static class Expectation {
5257 public static void main (String [] args ) throws Exception {
5358 if (args .length != 0 ) {
5459 // Called as subprocess. Print system properties named by
55- // `args` and then exit.
56- for (String arg : args ) {
57- System .out .printf ("%s=%s%n" , arg , System .getProperty (arg ));
58- }
60+ // `args[1..]` to the file `args[0]` and then exit.
61+ Files .writeString (Path .of (args [0 ]),
62+ List .of (args ).subList (1 , args .length ).stream ()
63+ .map (a -> "%s=%s" .formatted (a , System .getProperty (a )))
64+ .collect (Collectors .joining ("," )));
5965 return ;
6066 }
6167 // Test EnableJVMCIProduct without any other explicit JVMCI option
@@ -80,16 +86,19 @@ public static void main(String[] args) throws Exception {
8086 new Expectation ("UseJVMCICompiler" , "true" , "default" ));
8187 }
8288
89+ static int id ;
90+
8391 static void test (String explicitFlag , Expectation ... expectations ) throws Exception {
8492 String [] flags = {"-XX:+EnableJVMCIProduct" , "-XX:+UseGraalJIT" };
8593 String cwd = System .getProperty ("user.dir" );
8694 for (String flag : flags ) {
95+ Path propsPath = Path .of ("props." + id ++);
8796 ProcessBuilder pb = ProcessTools .createLimitedTestJavaProcessBuilder (
8897 "-XX:+UnlockExperimentalVMOptions" , flag , "-XX:-UnlockExperimentalVMOptions" ,
8998 explicitFlag ,
9099 "-XX:+PrintFlagsFinal" ,
91100 "--class-path=" + System .getProperty ("java.class.path" ),
92- "TestEnableJVMCIProduct" , "jvmci.Compiler" );
101+ "TestEnableJVMCIProduct" , propsPath . toString (), "jvmci.Compiler" );
93102 OutputAnalyzer output = new OutputAnalyzer (pb .start ());
94103 for (Expectation expectation : expectations ) {
95104 output .stdoutShouldMatch (expectation .pattern );
@@ -103,7 +112,11 @@ static void test(String explicitFlag, Expectation... expectations) throws Except
103112 output .stdoutShouldMatch ("No JVMCI compiler found" );
104113 }
105114 } else if (flag .equals ("-XX:+UseGraalJIT" )) {
106- output .shouldContain ("jvmci.Compiler=graal" );
115+ String props = Files .readString (propsPath );
116+ String expect = "jvmci.Compiler=graal" ;
117+ if (!props .contains (expect )) {
118+ throw new RuntimeException ("\" %s\" does not contain \" %s\" " .formatted (props , expect ));
119+ }
107120 }
108121 }
109122 }
0 commit comments