6985422: flush the output streams before OnError commands
authorvlivanov
Fri, 15 Jan 2016 21:56:42 +0300
changeset 35568 8dfb205a2886
parent 35567 4b293ebd9ef9
child 35569 a2cdb4062a5d
6985422: flush the output streams before OnError commands Reviewed-by: kvn
hotspot/src/share/vm/utilities/vmError.cpp
--- a/hotspot/src/share/vm/utilities/vmError.cpp	Fri Jan 15 21:56:40 2016 +0300
+++ b/hotspot/src/share/vm/utilities/vmError.cpp	Fri Jan 15 21:56:42 2016 +0300
@@ -1234,38 +1234,6 @@
     log_done = true;
   }
 
-
-  static bool skip_OnError = false;
-  if (!skip_OnError && OnError && OnError[0]) {
-    skip_OnError = true;
-
-    out.print_raw_cr("#");
-    out.print_raw   ("# -XX:OnError=\"");
-    out.print_raw   (OnError);
-    out.print_raw_cr("\"");
-
-    char* cmd;
-    const char* ptr = OnError;
-    while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr)) != NULL){
-      out.print_raw   ("#   Executing ");
-#if defined(LINUX) || defined(_ALLBSD_SOURCE)
-      out.print_raw   ("/bin/sh -c ");
-#elif defined(SOLARIS)
-      out.print_raw   ("/usr/bin/sh -c ");
-#endif
-      out.print_raw   ("\"");
-      out.print_raw   (cmd);
-      out.print_raw_cr("\" ...");
-
-      if (os::fork_and_exec(cmd) < 0) {
-        out.print_cr("os::fork_and_exec failed: %s (%d)", strerror(errno), errno);
-      }
-    }
-
-    // done with OnError
-    OnError = NULL;
-  }
-
   static bool skip_replay = ReplayCompiles; // Do not overwrite file during replay
   if (DumpReplayDataOnError && _thread && _thread->is_Compiler_thread() && !skip_replay) {
     skip_replay = true;
@@ -1295,6 +1263,40 @@
     print_bug_submit_message(&out, _thread);
   }
 
+  static bool skip_OnError = false;
+  if (!skip_OnError && OnError && OnError[0]) {
+    skip_OnError = true;
+
+    // Flush output and finish logs before running OnError commands.
+    ostream_abort();
+
+    out.print_raw_cr("#");
+    out.print_raw   ("# -XX:OnError=\"");
+    out.print_raw   (OnError);
+    out.print_raw_cr("\"");
+
+    char* cmd;
+    const char* ptr = OnError;
+    while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr)) != NULL){
+      out.print_raw   ("#   Executing ");
+#if defined(LINUX) || defined(_ALLBSD_SOURCE)
+      out.print_raw   ("/bin/sh -c ");
+#elif defined(SOLARIS)
+      out.print_raw   ("/usr/bin/sh -c ");
+#endif
+      out.print_raw   ("\"");
+      out.print_raw   (cmd);
+      out.print_raw_cr("\" ...");
+
+      if (os::fork_and_exec(cmd) < 0) {
+        out.print_cr("os::fork_and_exec failed: %s (%d)", strerror(errno), errno);
+      }
+    }
+
+    // done with OnError
+    OnError = NULL;
+  }
+
   if (!UseOSErrorReporting) {
     // os::abort() will call abort hooks, try it first.
     static bool skip_os_abort = false;