< prev index next >

src/hotspot/share/utilities/ostream.cpp

Print this page

 648   // if +LogVMOutput is used, because the flags haven't been parsed yet)
 649   // For safer printing during fatal error handling, do not init logfile
 650   // if a VM error has been reported.
 651   if (!_inited && !VMError::is_error_reported())  init();
 652   return _log_file != nullptr;
 653 }
 654 
 655 fileStream* defaultStream::open_file(const char* log_name) {
 656   const char* try_name = make_log_name(log_name, nullptr);
 657   if (try_name == nullptr) {
 658     warning("Cannot open file %s: file name is too long.\n", log_name);
 659     return nullptr;
 660   }
 661 
 662   fileStream* file = new (mtInternal) fileStream(try_name);
 663   FREE_C_HEAP_ARRAY(char, try_name);
 664   if (file->is_open()) {
 665     return file;
 666   }
 667 




 668   // Try again to open the file in the temp directory.
 669   delete file;
 670   // Note: This feature is for maintainer use only.  No need for L10N.
 671   jio_printf("Warning:  Cannot open log file: %s\n", log_name);
 672   try_name = make_log_name(log_name, os::get_temp_directory());
 673   if (try_name == nullptr) {
 674     warning("Cannot open file %s: file name is too long for directory %s.\n", log_name, os::get_temp_directory());
 675     return nullptr;
 676   }
 677 
 678   jio_printf("Warning:  Forcing option -XX:LogFile=%s\n", try_name);
 679 
 680   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   delete file;
 687   return nullptr;

 703     LogCompilation = false;
 704   }
 705 }
 706 
 707 void defaultStream::start_log() {
 708   xmlStream*xs = _outer_xmlStream;
 709     if (this == tty)  xtty = xs;
 710     // Write XML header.
 711     xs->print_cr("<?xml version='1.0' encoding='UTF-8'?>");
 712     // (For now, don't bother to issue a DTD for this private format.)
 713 
 714     // Calculate the start time of the log as ms since the epoch: this is
 715     // the current time in ms minus the uptime in ms.
 716     jlong time_ms = os::javaTimeMillis() - tty->time_stamp().milliseconds();
 717     xs->head("hotspot_log version='%d %d'"
 718              " process='%d' time_ms='" INT64_FORMAT "'",
 719              LOG_MAJOR_VERSION, LOG_MINOR_VERSION,
 720              os::current_process_id(), (int64_t)time_ms);
 721     // Write VM version header immediately.
 722     xs->head("vm_version");
 723     xs->head("name"); xs->text("%s", VM_Version::vm_name()); xs->cr();

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

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

 728     xs->tail("info");
 729     xs->tail("vm_version");
 730     // Record information about the command-line invocation.
 731     xs->head("vm_arguments");  // Cf. Arguments::print_on()
 732     if (Arguments::num_jvm_flags() > 0) {
 733       xs->head("flags");
 734       Arguments::print_jvm_flags_on(xs->text());
 735       xs->tail("flags");
 736     }
 737     if (Arguments::num_jvm_args() > 0) {
 738       xs->head("args");
 739       Arguments::print_jvm_args_on(xs->text());
 740       xs->tail("args");
 741     }
 742     if (Arguments::java_command() != nullptr) {
 743       xs->head("command"); xs->text()->print_cr("%s", Arguments::java_command());
 744       xs->tail("command");
 745     }
 746     if (Arguments::sun_java_launcher() != nullptr) {
 747       xs->head("launcher"); xs->text()->print_cr("%s", Arguments::sun_java_launcher());
 748       xs->tail("launcher");
 749     }
 750     if (Arguments::system_properties() !=  nullptr) {
 751       xs->head("properties");
 752       // Print it as a java-style property list.
 753       // System properties don't generally contain newlines, so don't bother with unparsing.
 754       outputStream *text = xs->text();
 755       for (SystemProperty* p = Arguments::system_properties(); p != nullptr; p = p->next()) {
 756         assert(p->key() != nullptr, "p->key() is null");
 757         if (p->readable()) {
 758           // Print in two stages to avoid problems with long
 759           // keys/values.
 760           text->print_raw(p->key());
 761           text->put('=');
 762           assert(p->value() != nullptr, "p->value() is null");
 763           text->print_raw_cr(p->value());
 764         }
 765       }
 766       xs->tail("properties");
 767     }
 768     xs->tail("vm_arguments");
 769     // tty output per se is grouped under the <tty>...</tty> element.
 770     xs->head("tty");
 771     // All further non-markup text gets copied to the tty:
 772     xs->_text = this;  // requires friend declaration!

 773 }
 774 
 775 // finish_log() is called during normal VM shutdown. finish_log_on_error() is
 776 // called by ostream_abort() after a fatal error.
 777 //
 778 void defaultStream::finish_log() {
 779   xmlStream* xs = _outer_xmlStream;
 780   xs->done("tty");
 781 
 782   // Other log forks are appended here, at the End of Time:
 783   CompileLog::finish_log(xs->out());  // write compile logging, if any, now
 784 
 785   xs->done("hotspot_log");
 786   xs->flush();
 787 
 788   fileStream* file = _log_file;
 789   _log_file = nullptr;
 790 
 791   delete _outer_xmlStream;
 792   _outer_xmlStream = nullptr;

 648   // if +LogVMOutput is used, because the flags haven't been parsed yet)
 649   // For safer printing during fatal error handling, do not init logfile
 650   // if a VM error has been reported.
 651   if (!_inited && !VMError::is_error_reported())  init();
 652   return _log_file != nullptr;
 653 }
 654 
 655 fileStream* defaultStream::open_file(const char* log_name) {
 656   const char* try_name = make_log_name(log_name, nullptr);
 657   if (try_name == nullptr) {
 658     warning("Cannot open file %s: file name is too long.\n", log_name);
 659     return nullptr;
 660   }
 661 
 662   fileStream* file = new (mtInternal) fileStream(try_name);
 663   FREE_C_HEAP_ARRAY(char, try_name);
 664   if (file->is_open()) {
 665     return file;
 666   }
 667 
 668   if (RecordTraining) {
 669     vm_exit_during_initialization("cannot create log file for RecordTraining mode: %s", try_name);
 670   }
 671 
 672   // Try again to open the file in the temp directory.
 673   delete file;
 674   // Note: This feature is for maintainer use only.  No need for L10N.
 675   jio_printf("Warning:  Cannot open log file: %s\n", log_name);
 676   try_name = make_log_name(log_name, os::get_temp_directory());
 677   if (try_name == nullptr) {
 678     warning("Cannot open file %s: file name is too long for directory %s.\n", log_name, os::get_temp_directory());
 679     return nullptr;
 680   }
 681 
 682   jio_printf("Warning:  Forcing option -XX:LogFile=%s\n", try_name);
 683 
 684   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   delete file;
 691   return nullptr;

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