8007993: hotspot.log w/ enabled LogCompilation can be an invalid XML
authorthartmann
Wed, 26 Nov 2014 08:06:58 +0100
changeset 27709 e6f02d6fee44
parent 27708 8a8710cb8fc4
child 27710 df32fbcd3215
child 27908 699648af1ee6
8007993: hotspot.log w/ enabled LogCompilation can be an invalid XML Summary: Open compilation log files in write-mode and close before deletion attempt. Reviewed-by: vlivanov
hotspot/src/share/vm/compiler/compileBroker.cpp
hotspot/src/share/vm/compiler/compileLog.cpp
--- a/hotspot/src/share/vm/compiler/compileBroker.cpp	Thu Nov 13 09:19:46 2014 +0100
+++ b/hotspot/src/share/vm/compiler/compileBroker.cpp	Wed Nov 26 08:06:58 2014 +0100
@@ -1807,7 +1807,7 @@
                      os::file_separator(), thread_id, os::current_process_id());
       }
 
-      fp = fopen(file_name, "at");
+      fp = fopen(file_name, "wt");
       if (fp != NULL) {
         if (LogCompilation && Verbose) {
           tty->print_cr("Opening compilation log %s", file_name);
--- a/hotspot/src/share/vm/compiler/compileLog.cpp	Thu Nov 13 09:19:46 2014 +0100
+++ b/hotspot/src/share/vm/compiler/compileLog.cpp	Wed Nov 26 08:06:58 2014 +0100
@@ -56,8 +56,10 @@
 }
 
 CompileLog::~CompileLog() {
-  delete _out;
+  delete _out; // Close fd in fileStream::~fileStream()
   _out = NULL;
+  // Remove partial file after merging in CompileLog::finish_log_on_error
+  unlink(_file);
   FREE_C_HEAP_ARRAY(char, _identities, mtCompiler);
   FREE_C_HEAP_ARRAY(char, _file, mtCompiler);
 }
@@ -278,10 +280,9 @@
       }
       file->print_raw_cr("</compilation_log>");
       close(partial_fd);
-      unlink(partial_file);
     }
     CompileLog* next_log = log->_next;
-    delete log;
+    delete log; // Removes partial file
     log = next_log;
   }
   _first = NULL;