721
722 // rotate_log must be called from VMThread at safepoint. In case need change parameters
723 // for gc log rotation from thread other than VMThread, a sub type of VM_Operation
724 // should be created and be submitted to VMThread's operation queue. DO NOT call this
725 // function directly. Currently, it is safe to rotate log at safepoint through VMThread.
726 // That is, no mutator threads and concurrent GC threads run parallel with VMThread to
727 // write to gc log file at safepoint. If in future, changes made for mutator threads or
728 // concurrent GC threads to run parallel with VMThread at safepoint, write and rotate_log
729 // must be synchronized.
730 void gcLogFileStream::rotate_log(bool force, outputStream* out) {
731 char time_msg[O_BUFLEN];
732 char time_str[EXTRACHARLEN];
733 char current_file_name[JVM_MAXPATHLEN];
734 char renamed_file_name[JVM_MAXPATHLEN];
735
736 if (!should_rotate(force)) {
737 return;
738 }
739
740 #ifdef ASSERT
741 Thread *thread = Thread::current();
742 assert(thread == NULL ||
743 (thread->is_VM_thread() && SafepointSynchronize::is_at_safepoint()),
744 "Must be VMThread at safepoint");
745 #endif
746 if (NumberOfGCLogFiles == 1) {
747 // rotate in same file
748 rewind();
749 _bytes_written = 0L;
750 jio_snprintf(time_msg, sizeof(time_msg), "File %s rotated at %s\n",
751 _file_name, os::local_time_string((char *)time_str, sizeof(time_str)));
752 write(time_msg, strlen(time_msg));
753
754 if (out != NULL) {
755 out->print("%s", time_msg);
756 }
757
758 dump_loggc_header();
759 return;
760 }
761
1041 _outer_xmlStream = NULL;
1042
1043 if (file) {
1044 file->flush();
1045
1046 // Can't delete or close the file because delete and fclose aren't
1047 // async-safe. We are about to die, so leave it to the kernel.
1048 // delete file;
1049 }
1050 }
1051 }
1052
1053 intx defaultStream::hold(intx writer_id) {
1054 bool has_log = has_log_file(); // check before locking
1055 if (// impossible, but who knows?
1056 writer_id == NO_WRITER ||
1057
1058 // bootstrap problem
1059 tty_lock == NULL ||
1060
1061 // can't grab a lock or call Thread::current() if TLS isn't initialized
1062 ThreadLocalStorage::thread() == NULL ||
1063
1064 // developer hook
1065 !SerializeVMOutput ||
1066
1067 // VM already unhealthy
1068 is_error_reported() ||
1069
1070 // safepoint == global lock (for VM only)
1071 (SafepointSynchronize::is_synchronizing() &&
1072 Thread::current()->is_VM_thread())
1073 ) {
1074 // do not attempt to lock unless we know the thread and the VM is healthy
1075 return NO_WRITER;
1076 }
1077 if (_writer == writer_id) {
1078 // already held, no need to re-grab the lock
1079 return NO_WRITER;
1080 }
1081 tty_lock->lock_without_safepoint_check();
1082 // got the lock
|
721
722 // rotate_log must be called from VMThread at safepoint. In case need change parameters
723 // for gc log rotation from thread other than VMThread, a sub type of VM_Operation
724 // should be created and be submitted to VMThread's operation queue. DO NOT call this
725 // function directly. Currently, it is safe to rotate log at safepoint through VMThread.
726 // That is, no mutator threads and concurrent GC threads run parallel with VMThread to
727 // write to gc log file at safepoint. If in future, changes made for mutator threads or
728 // concurrent GC threads to run parallel with VMThread at safepoint, write and rotate_log
729 // must be synchronized.
730 void gcLogFileStream::rotate_log(bool force, outputStream* out) {
731 char time_msg[O_BUFLEN];
732 char time_str[EXTRACHARLEN];
733 char current_file_name[JVM_MAXPATHLEN];
734 char renamed_file_name[JVM_MAXPATHLEN];
735
736 if (!should_rotate(force)) {
737 return;
738 }
739
740 #ifdef ASSERT
741 Thread *thread = Thread::current_or_null();
742 assert(thread == NULL ||
743 (thread->is_VM_thread() && SafepointSynchronize::is_at_safepoint()),
744 "Must be VMThread at safepoint");
745 #endif
746 if (NumberOfGCLogFiles == 1) {
747 // rotate in same file
748 rewind();
749 _bytes_written = 0L;
750 jio_snprintf(time_msg, sizeof(time_msg), "File %s rotated at %s\n",
751 _file_name, os::local_time_string((char *)time_str, sizeof(time_str)));
752 write(time_msg, strlen(time_msg));
753
754 if (out != NULL) {
755 out->print("%s", time_msg);
756 }
757
758 dump_loggc_header();
759 return;
760 }
761
1041 _outer_xmlStream = NULL;
1042
1043 if (file) {
1044 file->flush();
1045
1046 // Can't delete or close the file because delete and fclose aren't
1047 // async-safe. We are about to die, so leave it to the kernel.
1048 // delete file;
1049 }
1050 }
1051 }
1052
1053 intx defaultStream::hold(intx writer_id) {
1054 bool has_log = has_log_file(); // check before locking
1055 if (// impossible, but who knows?
1056 writer_id == NO_WRITER ||
1057
1058 // bootstrap problem
1059 tty_lock == NULL ||
1060
1061 // can't grab a lock if current Thread isn't set
1062 Thread::current_or_null() == NULL ||
1063
1064 // developer hook
1065 !SerializeVMOutput ||
1066
1067 // VM already unhealthy
1068 is_error_reported() ||
1069
1070 // safepoint == global lock (for VM only)
1071 (SafepointSynchronize::is_synchronizing() &&
1072 Thread::current()->is_VM_thread())
1073 ) {
1074 // do not attempt to lock unless we know the thread and the VM is healthy
1075 return NO_WRITER;
1076 }
1077 if (_writer == writer_id) {
1078 // already held, no need to re-grab the lock
1079 return NO_WRITER;
1080 }
1081 tty_lock->lock_without_safepoint_check();
1082 // got the lock
|