660 // function directly. Currently, it is safe to rotate log at safepoint through VMThread. |
660 // function directly. Currently, it is safe to rotate log at safepoint through VMThread. |
661 // That is, no mutator threads and concurrent GC threads run parallel with VMThread to |
661 // That is, no mutator threads and concurrent GC threads run parallel with VMThread to |
662 // write to gc log file at safepoint. If in future, changes made for mutator threads or |
662 // write to gc log file at safepoint. If in future, changes made for mutator threads or |
663 // concurrent GC threads to run parallel with VMThread at safepoint, write and rotate_log |
663 // concurrent GC threads to run parallel with VMThread at safepoint, write and rotate_log |
664 // must be synchronized. |
664 // must be synchronized. |
665 void gcLogFileStream::rotate_log() { |
665 void gcLogFileStream::rotate_log(bool force, outputStream* out) { |
666 char time_msg[FILENAMEBUFLEN]; |
666 char time_msg[FILENAMEBUFLEN]; |
667 char time_str[EXTRACHARLEN]; |
667 char time_str[EXTRACHARLEN]; |
668 char current_file_name[FILENAMEBUFLEN]; |
668 char current_file_name[FILENAMEBUFLEN]; |
669 char renamed_file_name[FILENAMEBUFLEN]; |
669 char renamed_file_name[FILENAMEBUFLEN]; |
670 |
670 |
671 if (_bytes_written < (jlong)GCLogFileSize) { |
671 if (!should_rotate(force)) { |
672 return; |
672 return; |
673 } |
673 } |
674 |
674 |
675 #ifdef ASSERT |
675 #ifdef ASSERT |
676 Thread *thread = Thread::current(); |
676 Thread *thread = Thread::current(); |
683 rewind(); |
683 rewind(); |
684 _bytes_written = 0L; |
684 _bytes_written = 0L; |
685 jio_snprintf(time_msg, sizeof(time_msg), "File %s rotated at %s\n", |
685 jio_snprintf(time_msg, sizeof(time_msg), "File %s rotated at %s\n", |
686 _file_name, os::local_time_string((char *)time_str, sizeof(time_str))); |
686 _file_name, os::local_time_string((char *)time_str, sizeof(time_str))); |
687 write(time_msg, strlen(time_msg)); |
687 write(time_msg, strlen(time_msg)); |
|
688 |
|
689 if (out != NULL) { |
|
690 out->print(time_msg); |
|
691 } |
|
692 |
688 dump_loggc_header(); |
693 dump_loggc_header(); |
689 return; |
694 return; |
690 } |
695 } |
691 |
696 |
692 #if defined(_WINDOWS) |
697 #if defined(_WINDOWS) |
704 if (_file != NULL) { |
709 if (_file != NULL) { |
705 jio_snprintf(renamed_file_name, filename_len + EXTRACHARLEN, "%s.%d", |
710 jio_snprintf(renamed_file_name, filename_len + EXTRACHARLEN, "%s.%d", |
706 _file_name, _cur_file_num); |
711 _file_name, _cur_file_num); |
707 jio_snprintf(current_file_name, filename_len + EXTRACHARLEN, "%s.%d" CURRENTAPPX, |
712 jio_snprintf(current_file_name, filename_len + EXTRACHARLEN, "%s.%d" CURRENTAPPX, |
708 _file_name, _cur_file_num); |
713 _file_name, _cur_file_num); |
709 jio_snprintf(time_msg, sizeof(time_msg), "%s GC log file has reached the" |
714 |
710 " maximum size. Saved as %s\n", |
715 const char* msg = force ? "GC log rotation request has been received." |
711 os::local_time_string((char *)time_str, sizeof(time_str)), |
716 : "GC log file has reached the maximum size."; |
712 renamed_file_name); |
717 jio_snprintf(time_msg, sizeof(time_msg), "%s %s Saved as %s\n", |
|
718 os::local_time_string((char *)time_str, sizeof(time_str)), |
|
719 msg, renamed_file_name); |
713 write(time_msg, strlen(time_msg)); |
720 write(time_msg, strlen(time_msg)); |
|
721 |
|
722 if (out != NULL) { |
|
723 out->print(time_msg); |
|
724 } |
714 |
725 |
715 fclose(_file); |
726 fclose(_file); |
716 _file = NULL; |
727 _file = NULL; |
717 |
728 |
718 bool can_rename = true; |
729 bool can_rename = true; |
750 "%s.%d", _file_name, _cur_file_num); |
761 "%s.%d", _file_name, _cur_file_num); |
751 jio_snprintf(time_msg, sizeof(time_msg), "%s GC log file created %s\n", |
762 jio_snprintf(time_msg, sizeof(time_msg), "%s GC log file created %s\n", |
752 os::local_time_string((char *)time_str, sizeof(time_str)), |
763 os::local_time_string((char *)time_str, sizeof(time_str)), |
753 current_file_name); |
764 current_file_name); |
754 write(time_msg, strlen(time_msg)); |
765 write(time_msg, strlen(time_msg)); |
|
766 |
|
767 if (out != NULL) { |
|
768 out->print(time_msg); |
|
769 } |
|
770 |
755 dump_loggc_header(); |
771 dump_loggc_header(); |
756 // remove the existing file |
772 // remove the existing file |
757 if (access(current_file_name, F_OK) == 0) { |
773 if (access(current_file_name, F_OK) == 0) { |
758 if (remove(current_file_name) != 0) { |
774 if (remove(current_file_name) != 0) { |
759 warning("Could not delete existing file %s\n", current_file_name); |
775 warning("Could not delete existing file %s\n", current_file_name); |