< prev index next >

src/hotspot/share/utilities/ostream.cpp

Print this page

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




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

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

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

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

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

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

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

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