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