667 // if +LogVMOutput is used, because the flags haven't been parsed yet)
668 // For safer printing during fatal error handling, do not init logfile
669 // if a VM error has been reported.
670 if (!_inited && !VMError::is_error_reported()) init();
671 return _log_file != nullptr;
672 }
673
674 fileStream* defaultStream::open_file(const char* log_name) {
675 const char* try_name = make_log_name(log_name, nullptr);
676 if (try_name == nullptr) {
677 warning("Cannot open file %s: file name is too long.\n", log_name);
678 return nullptr;
679 }
680
681 fileStream* file = new (mtInternal) fileStream(try_name);
682 FREE_C_HEAP_ARRAY(char, try_name);
683 if (file->is_open()) {
684 return file;
685 }
686
687 // Try again to open the file in the temp directory.
688 delete file;
689 // Note: This feature is for maintainer use only. No need for L10N.
690 jio_printf("Warning: Cannot open log file: %s\n", log_name);
691 try_name = make_log_name(log_name, os::get_temp_directory());
692 if (try_name == nullptr) {
693 warning("Cannot open file %s: file name is too long for directory %s.\n", log_name, os::get_temp_directory());
694 return nullptr;
695 }
696
697 jio_printf("Warning: Forcing option -XX:LogFile=%s\n", try_name);
698
699 file = new (mtInternal) fileStream(try_name);
700 FREE_C_HEAP_ARRAY(char, try_name);
701 if (file->is_open()) {
702 return file;
703 }
704
705 delete file;
706 return nullptr;
722 LogCompilation = false;
723 }
724 }
725
726 void defaultStream::start_log() {
727 xmlStream*xs = _outer_xmlStream;
728 if (this == tty) xtty = xs;
729 // Write XML header.
730 xs->print_cr("<?xml version='1.0' encoding='UTF-8'?>");
731 // (For now, don't bother to issue a DTD for this private format.)
732
733 // Calculate the start time of the log as ms since the epoch: this is
734 // the current time in ms minus the uptime in ms.
735 jlong time_ms = os::javaTimeMillis() - tty->time_stamp().milliseconds();
736 xs->head("hotspot_log version='%d %d'"
737 " process='%d' time_ms='" INT64_FORMAT "'",
738 LOG_MAJOR_VERSION, LOG_MINOR_VERSION,
739 os::current_process_id(), (int64_t)time_ms);
740 // Write VM version header immediately.
741 xs->head("vm_version");
742 xs->head("name"); xs->text("%s", VM_Version::vm_name()); xs->cr();
743 xs->tail("name");
744 xs->head("release"); xs->text("%s", VM_Version::vm_release()); xs->cr();
745 xs->tail("release");
746 xs->head("info"); xs->text("%s", VM_Version::internal_vm_info_string()); xs->cr();
747 xs->tail("info");
748 xs->tail("vm_version");
749 // Record information about the command-line invocation.
750 xs->head("vm_arguments"); // Cf. Arguments::print_on()
751 if (Arguments::num_jvm_flags() > 0) {
752 xs->head("flags");
753 Arguments::print_jvm_flags_on(xs->text());
754 xs->tail("flags");
755 }
756 if (Arguments::num_jvm_args() > 0) {
757 xs->head("args");
758 Arguments::print_jvm_args_on(xs->text());
759 xs->tail("args");
760 }
761 if (Arguments::java_command() != nullptr) {
762 xs->head("command"); xs->text()->print_cr("%s", Arguments::java_command());
763 xs->tail("command");
764 }
765 if (Arguments::sun_java_launcher() != nullptr) {
766 xs->head("launcher"); xs->text()->print_cr("%s", Arguments::sun_java_launcher());
767 xs->tail("launcher");
768 }
769 if (Arguments::system_properties() != nullptr) {
770 xs->head("properties");
771 // Print it as a java-style property list.
772 // System properties don't generally contain newlines, so don't bother with unparsing.
773 outputStream *text = xs->text();
774 for (SystemProperty* p = Arguments::system_properties(); p != nullptr; p = p->next()) {
775 assert(p->key() != nullptr, "p->key() is null");
776 if (p->readable()) {
777 // Print in two stages to avoid problems with long
778 // keys/values.
779 text->print_raw(p->key());
780 text->put('=');
781 assert(p->value() != nullptr, "p->value() is null");
782 text->print_raw_cr(p->value());
783 }
784 }
785 xs->tail("properties");
786 }
787 xs->tail("vm_arguments");
788 // tty output per se is grouped under the <tty>...</tty> element.
789 xs->head("tty");
790 // All further non-markup text gets copied to the tty:
791 xs->_text = this; // requires friend declaration!
792 }
793
794 // finish_log() is called during normal VM shutdown. finish_log_on_error() is
795 // called by ostream_abort() after a fatal error.
796 //
797 void defaultStream::finish_log() {
798 xmlStream* xs = _outer_xmlStream;
799 xs->done("tty");
800
801 // Other log forks are appended here, at the End of Time:
802 CompileLog::finish_log(xs->out()); // write compile logging, if any, now
803
804 xs->done("hotspot_log");
805 xs->flush();
806
807 fileStream* file = _log_file;
808 _log_file = nullptr;
809
810 delete _outer_xmlStream;
811 _outer_xmlStream = nullptr;
|
667 // if +LogVMOutput is used, because the flags haven't been parsed yet)
668 // For safer printing during fatal error handling, do not init logfile
669 // if a VM error has been reported.
670 if (!_inited && !VMError::is_error_reported()) init();
671 return _log_file != nullptr;
672 }
673
674 fileStream* defaultStream::open_file(const char* log_name) {
675 const char* try_name = make_log_name(log_name, nullptr);
676 if (try_name == nullptr) {
677 warning("Cannot open file %s: file name is too long.\n", log_name);
678 return nullptr;
679 }
680
681 fileStream* file = new (mtInternal) fileStream(try_name);
682 FREE_C_HEAP_ARRAY(char, try_name);
683 if (file->is_open()) {
684 return file;
685 }
686
687 if (RecordTraining) {
688 vm_exit_during_initialization("cannot create log file for RecordTraining mode: %s", try_name);
689 }
690
691 // Try again to open the file in the temp directory.
692 delete file;
693 // Note: This feature is for maintainer use only. No need for L10N.
694 jio_printf("Warning: Cannot open log file: %s\n", log_name);
695 try_name = make_log_name(log_name, os::get_temp_directory());
696 if (try_name == nullptr) {
697 warning("Cannot open file %s: file name is too long for directory %s.\n", log_name, os::get_temp_directory());
698 return nullptr;
699 }
700
701 jio_printf("Warning: Forcing option -XX:LogFile=%s\n", try_name);
702
703 file = new (mtInternal) fileStream(try_name);
704 FREE_C_HEAP_ARRAY(char, try_name);
705 if (file->is_open()) {
706 return file;
707 }
708
709 delete file;
710 return nullptr;
726 LogCompilation = false;
727 }
728 }
729
730 void defaultStream::start_log() {
731 xmlStream*xs = _outer_xmlStream;
732 if (this == tty) xtty = xs;
733 // Write XML header.
734 xs->print_cr("<?xml version='1.0' encoding='UTF-8'?>");
735 // (For now, don't bother to issue a DTD for this private format.)
736
737 // Calculate the start time of the log as ms since the epoch: this is
738 // the current time in ms minus the uptime in ms.
739 jlong time_ms = os::javaTimeMillis() - tty->time_stamp().milliseconds();
740 xs->head("hotspot_log version='%d %d'"
741 " process='%d' time_ms='" INT64_FORMAT "'",
742 LOG_MAJOR_VERSION, LOG_MINOR_VERSION,
743 os::current_process_id(), (int64_t)time_ms);
744 // Write VM version header immediately.
745 xs->head("vm_version");
746 xs->head("name"); // FIXME: should be an elem attr, not head/tail pair
747 xs->log_only()->print_cr("%s", VM_Version::vm_name());
748 xs->tail("name");
749 xs->head("release");
750 xs->log_only()->print_cr("%s", VM_Version::vm_release());
751 xs->tail("release");
752 xs->head("info");
753 xs->log_only()->print_cr("%s", VM_Version::internal_vm_info_string());
754 xs->tail("info");
755 xs->tail("vm_version");
756 // Record information about the command-line invocation.
757 xs->head("vm_arguments"); // Cf. Arguments::print_on()
758 if (Arguments::num_jvm_flags() > 0) {
759 xs->head("flags");
760 Arguments::print_jvm_flags_on(xs->log_only());
761 xs->tail("flags");
762 }
763 if (Arguments::num_jvm_args() > 0) {
764 xs->head("args");
765 Arguments::print_jvm_args_on(xs->log_only());
766 xs->tail("args");
767 }
768 if (Arguments::java_command() != nullptr) {
769 xs->head("command"); xs->log_only()->print_cr("%s", Arguments::java_command());
770 xs->tail("command");
771 }
772 if (Arguments::sun_java_launcher() != nullptr) {
773 xs->head("launcher"); xs->log_only()->print_cr("%s", Arguments::sun_java_launcher());
774 xs->tail("launcher");
775 }
776 if (Arguments::system_properties() != nullptr) {
777 xs->head("properties");
778 // Print it as a java-style property list.
779 // System properties don't generally contain newlines, so don't bother with unparsing.
780 outputStream *text = xs->log_only();
781 for (SystemProperty* p = Arguments::system_properties(); p != nullptr; p = p->next()) {
782 assert(p->key() != nullptr, "p->key() is null");
783 if (p->readable()) {
784 // Print in two stages to avoid problems with long
785 // keys/values.
786 text->print_raw(p->key());
787 text->put('=');
788 assert(p->value() != nullptr, "p->value() is null");
789 text->print_raw_cr(p->value());
790 }
791 }
792 xs->tail("properties");
793 }
794 xs->tail("vm_arguments");
795 // tty output per se is grouped under the <tty>...</tty> element.
796 xs->head("tty");
797 // All further non-markup text gets copied to the tty:
798 xs->_text = this; // requires friend declaration!
799 // (And xtty->log_only() remains as a back door to the non-tty log file.)
800 }
801
802 // finish_log() is called during normal VM shutdown. finish_log_on_error() is
803 // called by ostream_abort() after a fatal error.
804 //
805 void defaultStream::finish_log() {
806 xmlStream* xs = _outer_xmlStream;
807 xs->done("tty");
808
809 // Other log forks are appended here, at the End of Time:
810 CompileLog::finish_log(xs->out()); // write compile logging, if any, now
811
812 xs->done("hotspot_log");
813 xs->flush();
814
815 fileStream* file = _log_file;
816 _log_file = nullptr;
817
818 delete _outer_xmlStream;
819 _outer_xmlStream = nullptr;
|