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