< prev index next >

src/hotspot/share/utilities/ostream.cpp

Print this page

   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 

  25 #include "cds/classListWriter.hpp"
  26 #include "compiler/compileLog.hpp"
  27 #include "jvm.h"
  28 #include "memory/allocation.inline.hpp"
  29 #include "oops/oop.inline.hpp"
  30 #include "runtime/arguments.hpp"
  31 #include "runtime/mutexLocker.hpp"
  32 #include "runtime/orderAccess.hpp"
  33 #include "runtime/os.inline.hpp"
  34 #include "runtime/safepoint.hpp"
  35 #include "runtime/vm_version.hpp"
  36 #include "utilities/defaultStream.hpp"
  37 #include "utilities/macros.hpp"
  38 #include "utilities/ostream.hpp"
  39 #include "utilities/vmError.hpp"
  40 #include "utilities/xmlstream.hpp"
  41 
  42 // Declarations of jvm methods
  43 extern "C" void jio_print(const char* s, size_t len);
  44 extern "C" int jio_printf(const char *fmt, ...);

 669   // if +LogVMOutput is used, because the flags haven't been parsed yet)
 670   // For safer printing during fatal error handling, do not init logfile
 671   // if a VM error has been reported.
 672   if (!_inited && !VMError::is_error_reported())  init();
 673   return _log_file != nullptr;
 674 }
 675 
 676 fileStream* defaultStream::open_file(const char* log_name) {
 677   const char* try_name = make_log_name(log_name, nullptr);
 678   if (try_name == nullptr) {
 679     warning("Cannot open file %s: file name is too long.\n", log_name);
 680     return nullptr;
 681   }
 682 
 683   fileStream* file = new (mtInternal) fileStream(try_name);
 684   FREE_C_HEAP_ARRAY(char, try_name);
 685   if (file->is_open()) {
 686     return file;
 687   }
 688 




 689   // Try again to open the file in the temp directory.
 690   delete file;
 691   // Note: This feature is for maintainer use only.  No need for L10N.
 692   jio_printf("Warning:  Cannot open log file: %s\n", log_name);
 693   try_name = make_log_name(log_name, os::get_temp_directory());
 694   if (try_name == nullptr) {
 695     warning("Cannot open file %s: file name is too long for directory %s.\n", log_name, os::get_temp_directory());
 696     return nullptr;
 697   }
 698 
 699   jio_printf("Warning:  Forcing option -XX:LogFile=%s\n", try_name);
 700 
 701   file = new (mtInternal) fileStream(try_name);
 702   FREE_C_HEAP_ARRAY(char, try_name);
 703   if (file->is_open()) {
 704     return file;
 705   }
 706 
 707   delete file;
 708   return nullptr;

 724     LogCompilation = false;
 725   }
 726 }
 727 
 728 void defaultStream::start_log() {
 729   xmlStream*xs = _outer_xmlStream;
 730     if (this == tty)  xtty = xs;
 731     // Write XML header.
 732     xs->print_cr("<?xml version='1.0' encoding='UTF-8'?>");
 733     // (For now, don't bother to issue a DTD for this private format.)
 734 
 735     // Calculate the start time of the log as ms since the epoch: this is
 736     // the current time in ms minus the uptime in ms.
 737     jlong time_ms = os::javaTimeMillis() - tty->time_stamp().milliseconds();
 738     xs->head("hotspot_log version='%d %d'"
 739              " process='%d' time_ms='" INT64_FORMAT "'",
 740              LOG_MAJOR_VERSION, LOG_MINOR_VERSION,
 741              os::current_process_id(), (int64_t)time_ms);
 742     // Write VM version header immediately.
 743     xs->head("vm_version");
 744     xs->head("name"); xs->text("%s", VM_Version::vm_name()); xs->cr();

 745     xs->tail("name");
 746     xs->head("release"); xs->text("%s", VM_Version::vm_release()); xs->cr();

 747     xs->tail("release");
 748     xs->head("info"); xs->text("%s", VM_Version::internal_vm_info_string()); xs->cr();

 749     xs->tail("info");
 750     xs->tail("vm_version");
 751     // Record information about the command-line invocation.
 752     xs->head("vm_arguments");  // Cf. Arguments::print_on()
 753     if (Arguments::num_jvm_flags() > 0) {
 754       xs->head("flags");
 755       Arguments::print_jvm_flags_on(xs->text());
 756       xs->tail("flags");
 757     }
 758     if (Arguments::num_jvm_args() > 0) {
 759       xs->head("args");
 760       Arguments::print_jvm_args_on(xs->text());
 761       xs->tail("args");
 762     }
 763     if (Arguments::java_command() != nullptr) {
 764       xs->head("command"); xs->text()->print_cr("%s", Arguments::java_command());
 765       xs->tail("command");
 766     }
 767     if (Arguments::sun_java_launcher() != nullptr) {
 768       xs->head("launcher"); xs->text()->print_cr("%s", Arguments::sun_java_launcher());
 769       xs->tail("launcher");
 770     }
 771     if (Arguments::system_properties() !=  nullptr) {
 772       xs->head("properties");
 773       // Print it as a java-style property list.
 774       // System properties don't generally contain newlines, so don't bother with unparsing.
 775       outputStream *text = xs->text();
 776       for (SystemProperty* p = Arguments::system_properties(); p != nullptr; p = p->next()) {
 777         assert(p->key() != nullptr, "p->key() is null");
 778         if (p->readable()) {
 779           // Print in two stages to avoid problems with long
 780           // keys/values.
 781           text->print_raw(p->key());
 782           text->put('=');
 783           assert(p->value() != nullptr, "p->value() is null");
 784           text->print_raw_cr(p->value());
 785         }
 786       }
 787       xs->tail("properties");
 788     }
 789     xs->tail("vm_arguments");
 790     // tty output per se is grouped under the <tty>...</tty> element.
 791     xs->head("tty");
 792     // All further non-markup text gets copied to the tty:
 793     xs->_text = this;  // requires friend declaration!

 794 }
 795 
 796 // finish_log() is called during normal VM shutdown. finish_log_on_error() is
 797 // called by ostream_abort() after a fatal error.
 798 //
 799 void defaultStream::finish_log() {
 800   xmlStream* xs = _outer_xmlStream;
 801   xs->done("tty");
 802 
 803   // Other log forks are appended here, at the End of Time:
 804   CompileLog::finish_log(xs->out());  // write compile logging, if any, now
 805 
 806   xs->done("hotspot_log");
 807   xs->flush();
 808 
 809   fileStream* file = _log_file;
 810   _log_file = nullptr;
 811 
 812   delete _outer_xmlStream;
 813   _outer_xmlStream = nullptr;

   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "cds/cds_globals.hpp"
  26 #include "cds/classListWriter.hpp"
  27 #include "compiler/compileLog.hpp"
  28 #include "jvm.h"
  29 #include "memory/allocation.inline.hpp"
  30 #include "oops/oop.inline.hpp"
  31 #include "runtime/arguments.hpp"
  32 #include "runtime/mutexLocker.hpp"
  33 #include "runtime/orderAccess.hpp"
  34 #include "runtime/os.inline.hpp"
  35 #include "runtime/safepoint.hpp"
  36 #include "runtime/vm_version.hpp"
  37 #include "utilities/defaultStream.hpp"
  38 #include "utilities/macros.hpp"
  39 #include "utilities/ostream.hpp"
  40 #include "utilities/vmError.hpp"
  41 #include "utilities/xmlstream.hpp"
  42 
  43 // Declarations of jvm methods
  44 extern "C" void jio_print(const char* s, size_t len);
  45 extern "C" int jio_printf(const char *fmt, ...);

 670   // if +LogVMOutput is used, because the flags haven't been parsed yet)
 671   // For safer printing during fatal error handling, do not init logfile
 672   // if a VM error has been reported.
 673   if (!_inited && !VMError::is_error_reported())  init();
 674   return _log_file != nullptr;
 675 }
 676 
 677 fileStream* defaultStream::open_file(const char* log_name) {
 678   const char* try_name = make_log_name(log_name, nullptr);
 679   if (try_name == nullptr) {
 680     warning("Cannot open file %s: file name is too long.\n", log_name);
 681     return nullptr;
 682   }
 683 
 684   fileStream* file = new (mtInternal) fileStream(try_name);
 685   FREE_C_HEAP_ARRAY(char, try_name);
 686   if (file->is_open()) {
 687     return file;
 688   }
 689 
 690   if (AOTRecordTraining) {
 691     vm_exit_during_initialization("cannot create log file for RecordTraining mode: %s", try_name);
 692   }
 693 
 694   // Try again to open the file in the temp directory.
 695   delete file;
 696   // Note: This feature is for maintainer use only.  No need for L10N.
 697   jio_printf("Warning:  Cannot open log file: %s\n", log_name);
 698   try_name = make_log_name(log_name, os::get_temp_directory());
 699   if (try_name == nullptr) {
 700     warning("Cannot open file %s: file name is too long for directory %s.\n", log_name, os::get_temp_directory());
 701     return nullptr;
 702   }
 703 
 704   jio_printf("Warning:  Forcing option -XX:LogFile=%s\n", try_name);
 705 
 706   file = new (mtInternal) fileStream(try_name);
 707   FREE_C_HEAP_ARRAY(char, try_name);
 708   if (file->is_open()) {
 709     return file;
 710   }
 711 
 712   delete file;
 713   return nullptr;

 729     LogCompilation = false;
 730   }
 731 }
 732 
 733 void defaultStream::start_log() {
 734   xmlStream*xs = _outer_xmlStream;
 735     if (this == tty)  xtty = xs;
 736     // Write XML header.
 737     xs->print_cr("<?xml version='1.0' encoding='UTF-8'?>");
 738     // (For now, don't bother to issue a DTD for this private format.)
 739 
 740     // Calculate the start time of the log as ms since the epoch: this is
 741     // the current time in ms minus the uptime in ms.
 742     jlong time_ms = os::javaTimeMillis() - tty->time_stamp().milliseconds();
 743     xs->head("hotspot_log version='%d %d'"
 744              " process='%d' time_ms='" INT64_FORMAT "'",
 745              LOG_MAJOR_VERSION, LOG_MINOR_VERSION,
 746              os::current_process_id(), (int64_t)time_ms);
 747     // Write VM version header immediately.
 748     xs->head("vm_version");
 749     xs->head("name");  // FIXME: should be an elem attr, not head/tail pair
 750     xs->log_only()->print_cr("%s", VM_Version::vm_name());
 751     xs->tail("name");
 752     xs->head("release");
 753     xs->log_only()->print_cr("%s", VM_Version::vm_release());
 754     xs->tail("release");
 755     xs->head("info");
 756     xs->log_only()->print_cr("%s", VM_Version::internal_vm_info_string());
 757     xs->tail("info");
 758     xs->tail("vm_version");
 759     // Record information about the command-line invocation.
 760     xs->head("vm_arguments");  // Cf. Arguments::print_on()
 761     if (Arguments::num_jvm_flags() > 0) {
 762       xs->head("flags");
 763       Arguments::print_jvm_flags_on(xs->log_only());
 764       xs->tail("flags");
 765     }
 766     if (Arguments::num_jvm_args() > 0) {
 767       xs->head("args");
 768       Arguments::print_jvm_args_on(xs->log_only());
 769       xs->tail("args");
 770     }
 771     if (Arguments::java_command() != nullptr) {
 772       xs->head("command"); xs->log_only()->print_cr("%s", Arguments::java_command());
 773       xs->tail("command");
 774     }
 775     if (Arguments::sun_java_launcher() != nullptr) {
 776       xs->head("launcher"); xs->log_only()->print_cr("%s", Arguments::sun_java_launcher());
 777       xs->tail("launcher");
 778     }
 779     if (Arguments::system_properties() !=  nullptr) {
 780       xs->head("properties");
 781       // Print it as a java-style property list.
 782       // System properties don't generally contain newlines, so don't bother with unparsing.
 783       outputStream *text = xs->log_only();
 784       for (SystemProperty* p = Arguments::system_properties(); p != nullptr; p = p->next()) {
 785         assert(p->key() != nullptr, "p->key() is null");
 786         if (p->readable()) {
 787           // Print in two stages to avoid problems with long
 788           // keys/values.
 789           text->print_raw(p->key());
 790           text->put('=');
 791           assert(p->value() != nullptr, "p->value() is null");
 792           text->print_raw_cr(p->value());
 793         }
 794       }
 795       xs->tail("properties");
 796     }
 797     xs->tail("vm_arguments");
 798     // tty output per se is grouped under the <tty>...</tty> element.
 799     xs->head("tty");
 800     // All further non-markup text gets copied to the tty:
 801     xs->_text = this;  // requires friend declaration!
 802     // (And xtty->log_only() remains as a back door to the non-tty log file.)
 803 }
 804 
 805 // finish_log() is called during normal VM shutdown. finish_log_on_error() is
 806 // called by ostream_abort() after a fatal error.
 807 //
 808 void defaultStream::finish_log() {
 809   xmlStream* xs = _outer_xmlStream;
 810   xs->done("tty");
 811 
 812   // Other log forks are appended here, at the End of Time:
 813   CompileLog::finish_log(xs->out());  // write compile logging, if any, now
 814 
 815   xs->done("hotspot_log");
 816   xs->flush();
 817 
 818   fileStream* file = _log_file;
 819   _log_file = nullptr;
 820 
 821   delete _outer_xmlStream;
 822   _outer_xmlStream = nullptr;
< prev index next >