@@ -101,32 +101,51 @@ private static Map<String, Long> wordCount(List<String> sentences) {
101101 return sentences .stream ().flatMap (sentence -> Arrays .stream (sentence .split ("\\ s+" ))).collect (Collectors .groupingBy (Function .identity (), Collectors .counting ()));
102102 }
103103
104+ private static List <String > reverseAndUppercase (List <String > input ) {
105+ return input .stream ().map (s -> new StringBuilder (s ).reverse ().toString ().toUpperCase ()).collect (Collectors .toList ());
106+ }
107+
104108 @ Test
105109 public void recordsOnRetryAndReplays () throws Throwable {
106110 lengthsSquared (List .of ("foo" , "bar" , "baz" ));
107111 runTest ((temp ) -> {
108112 String methodName = "lengthsSquared" ;
109113 ResolvedJavaMethod method = getResolvedJavaMethod (methodName );
110- OptionValues initialOptions = getInitialOptions ();
114+ OptionValues crashOptions = new OptionValues ( getInitialOptions (), GraalCompilerOptions . CrashAt , methodName );
111115 String diagnoseOptionValue = DebugOptions .RecordForReplay .getName () + "=" + methodName ;
112- OptionValues crashAndDiagnoseOptions = new OptionValues (initialOptions , DebugOptions .DumpPath , temp .toString (),
116+ OptionValues crashAndDiagnoseOptions = new OptionValues (crashOptions , DebugOptions .DumpPath , temp .toString (),
113117 GraalCompilerOptions .CompilationFailureAction , CompilationWrapper .ExceptionAction .Diagnose ,
114- DebugOptions .DiagnoseOptions , diagnoseOptionValue , GraalCompilerOptions .CrashAt , methodName );
115- /*
116- * Run a regular compilation with a forced crash, then retry and record the compilation.
117- * We need to run in a new compiler instance to override the dump path for diagnostics,
118- * where the recorded compilation unit is saved.
119- */
118+ DebugOptions .DiagnoseOptions , diagnoseOptionValue );
119+ // Run a regular compilation with a forced crash.
120120 HotSpotCompilationRequestResult regularResult = runRegularCompilation (method , crashAndDiagnoseOptions );
121121 assertTrue (regularResult .getFailure () != null );
122+ // Replay and check that the compilation task ends with the same exception.
123+ replayCompilation (findReplayCompFile (temp .path ), crashOptions , false );
124+ });
125+ }
122126
123- // Replay the compilation without forcing a crash and enable diagnostic options.
127+ @ Test
128+ public void recordsAndReplaysWithDiagnosticOptions () throws Throwable {
129+ reverseAndUppercase (List .of ("foo" , "bar" , "baz" ));
130+ runTest ((temp ) -> {
131+ ResolvedJavaMethod method = getResolvedJavaMethod ("reverseAndUppercase" );
132+ OptionValues initialOptions = getInitialOptions ();
133+ OptionValues recordOptions = new OptionValues (initialOptions , DebugOptions .RecordForReplay , "*" ,
134+ DebugOptions .DumpPath , temp .toString ());
135+ runRegularCompilation (method , recordOptions );
136+ // Replay with the same options and verify the graphs are equal.
137+ Path replayFile = findReplayCompFile (temp .path );
138+ replayCompilation (replayFile , initialOptions , true );
139+ /*
140+ * Replay with diagnostic options. Do not check graph equality, since enabling graph
141+ * dumps typically changes the graphs.
142+ */
124143 EconomicSet <DebugOptions .OptimizationLogTarget > logTargets = EconomicSet .create ();
125144 logTargets .add (DebugOptions .OptimizationLogTarget .Stdout );
126- OptionValues replayOptions = new OptionValues (initialOptions , DebugOptions .DumpPath , temp .toString (),
145+ OptionValues diagnosticOptions = new OptionValues (initialOptions , DebugOptions .DumpPath , temp .toString (),
127146 DebugOptions .PrintGraph , DebugOptions .PrintGraphTarget .File , DebugOptions .Dump , ":1" ,
128147 DebugOptions .OptimizationLog , logTargets , DebugOptions .Log , "" , DebugOptions .PrintBackendCFG , true );
129- replayCompilation (findReplayCompFile ( temp . path ), replayOptions );
148+ replayCompilation (replayFile , diagnosticOptions , false );
130149 });
131150 }
132151
@@ -204,14 +223,14 @@ private static HotSpotCompilationRequestResult runRegularCompilation(ResolvedJav
204223 return task .runCompilation (options );
205224 }
206225
207- private static void replayCompilation (Path replayCompFile , OptionValues options ) throws ReplayCompilationRunner .ReplayLauncherFailure {
226+ private static void replayCompilation (Path replayCompFile , OptionValues options , boolean compareGraphs ) throws ReplayCompilationRunner .ReplayLauncherFailure {
208227 CompilerInterfaceDeclarations declarations = CompilerInterfaceDeclarations .build ();
209228 HotSpotJVMCIRuntime jvmciRuntime = HotSpotJVMCIRuntime .runtime ();
210229 RuntimeProvider runtimeProvider = Graal .getRequiredCapability (RuntimeProvider .class );
211230 CompilerConfigurationFactory configFactory = CompilerConfigurationFactory .selectFactory (runtimeProvider .getCompilerConfigurationName (), options , jvmciRuntime );
212231 try (ReplayCompilationRunner .Reproducer reproducer = ReplayCompilationRunner .Reproducer .initializeFromFile (replayCompFile .toString (),
213232 declarations , jvmciRuntime , options , configFactory , new GlobalMetrics (), TTY .out ().out (), EconomicMap .create ())) {
214- reproducer .compile ().verify ( false );
233+ reproducer .compile ().compareCompilationProducts ( compareGraphs );
215234 }
216235 }
217236
0 commit comments