comparison src/share/vm/utilities/vmError.cpp @ 10195:e12c9b3740db

8012260: ciReplay: Include PID into the name of replay data file Reviewed-by: kvn, twisti
author vlivanov
date Thu, 25 Apr 2013 11:02:32 -0700
parents 7b835924c31c
children 9ce110b1d14a
comparison
equal deleted inserted replaced
10141:47766e2d2527 10195:e12c9b3740db
794 } 794 }
795 795
796 VMError* volatile VMError::first_error = NULL; 796 VMError* volatile VMError::first_error = NULL;
797 volatile jlong VMError::first_error_tid = -1; 797 volatile jlong VMError::first_error_tid = -1;
798 798
799 /** Expand a pattern into a buffer starting at pos and open a file using constructed path */
800 static int expand_and_open(const char* pattern, char* buf, size_t buflen, size_t pos) {
801 int fd = -1;
802 if (Arguments::copy_expand_pid(pattern, strlen(pattern), &buf[pos], buflen - pos)) {
803 fd = open(buf, O_RDWR | O_CREAT | O_TRUNC, 0666);
804 }
805 return fd;
806 }
807
808 /**
809 * Construct file name for a log file and return it's file descriptor.
810 * Name and location depends on pattern, default_pattern params and access
811 * permissions.
812 */
813 static int prepare_log_file(const char* pattern, const char* default_pattern, char* buf, size_t buflen) {
814 int fd = -1;
815
816 // If possible, use specified pattern to construct log file name
817 if (pattern != NULL) {
818 fd = expand_and_open(pattern, buf, buflen, 0);
819 }
820
821 // Either user didn't specify, or the user's location failed,
822 // so use the default name in the current directory
823 if (fd == -1) {
824 const char* cwd = os::get_current_directory(buf, buflen);
825 if (cwd != NULL) {
826 size_t pos = strlen(cwd);
827 int fsep_len = jio_snprintf(&buf[pos], buflen-pos, "%s", os::file_separator());
828 pos += fsep_len;
829 if (fsep_len > 0) {
830 fd = expand_and_open(default_pattern, buf, buflen, pos);
831 }
832 }
833 }
834
835 // try temp directory if it exists.
836 if (fd == -1) {
837 const char* tmpdir = os::get_temp_directory();
838 if (tmpdir != NULL && strlen(tmpdir) > 0) {
839 int pos = jio_snprintf(buf, buflen, "%s%s", tmpdir, os::file_separator());
840 if (pos > 0) {
841 fd = expand_and_open(default_pattern, buf, buflen, pos);
842 }
843 }
844 }
845
846 return fd;
847 }
848
799 void VMError::report_and_die() { 849 void VMError::report_and_die() {
800 // Don't allocate large buffer on stack 850 // Don't allocate large buffer on stack
801 static char buffer[O_BUFLEN]; 851 static char buffer[O_BUFLEN];
802 852
803 // An error could happen before tty is initialized or after it has been 853 // An error could happen before tty is initialized or after it has been
903 first_error->_verbose = true; 953 first_error->_verbose = true;
904 954
905 // see if log file is already open 955 // see if log file is already open
906 if (!log.is_open()) { 956 if (!log.is_open()) {
907 // open log file 957 // open log file
908 int fd = -1; 958 int fd = prepare_log_file(ErrorFile, "hs_err_pid%p.log", buffer, sizeof(buffer));
909
910 if (ErrorFile != NULL) {
911 bool copy_ok =
912 Arguments::copy_expand_pid(ErrorFile, strlen(ErrorFile), buffer, sizeof(buffer));
913 if (copy_ok) {
914 fd = open(buffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
915 }
916 }
917
918 if (fd == -1) {
919 const char *cwd = os::get_current_directory(buffer, sizeof(buffer));
920 size_t len = strlen(cwd);
921 // either user didn't specify, or the user's location failed,
922 // so use the default name in the current directory
923 jio_snprintf(&buffer[len], sizeof(buffer)-len, "%shs_err_pid%u.log",
924 os::file_separator(), os::current_process_id());
925 fd = open(buffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
926 }
927
928 if (fd == -1) {
929 const char * tmpdir = os::get_temp_directory();
930 // try temp directory if it exists.
931 if (tmpdir != NULL && tmpdir[0] != '\0') {
932 jio_snprintf(buffer, sizeof(buffer), "%s%shs_err_pid%u.log",
933 tmpdir, os::file_separator(), os::current_process_id());
934 fd = open(buffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
935 }
936 }
937
938 if (fd != -1) { 959 if (fd != -1) {
939 out.print_raw("# An error report file with more information is saved as:\n# "); 960 out.print_raw("# An error report file with more information is saved as:\n# ");
940 out.print_raw_cr(buffer); 961 out.print_raw_cr(buffer);
941 os::set_error_file(buffer); 962 os::set_error_file(buffer);
942 963
956 first_error->_current_step_info = ""; // reset current_step string 977 first_error->_current_step_info = ""; // reset current_step string
957 978
958 // Run error reporting to determine whether or not to report the crash. 979 // Run error reporting to determine whether or not to report the crash.
959 if (!transmit_report_done && should_report_bug(first_error->_id)) { 980 if (!transmit_report_done && should_report_bug(first_error->_id)) {
960 transmit_report_done = true; 981 transmit_report_done = true;
961 FILE* hs_err = ::fdopen(log.fd(), "r"); 982 FILE* hs_err = os::open(log.fd(), "r");
962 if (NULL != hs_err) { 983 if (NULL != hs_err) {
963 ErrorReporter er; 984 ErrorReporter er;
964 er.call(hs_err, buffer, O_BUFLEN); 985 er.call(hs_err, buffer, O_BUFLEN);
965 } 986 }
966 } 987 }
1006 static bool skip_replay = false; 1027 static bool skip_replay = false;
1007 if (DumpReplayDataOnError && _thread && _thread->is_Compiler_thread() && !skip_replay) { 1028 if (DumpReplayDataOnError && _thread && _thread->is_Compiler_thread() && !skip_replay) {
1008 skip_replay = true; 1029 skip_replay = true;
1009 ciEnv* env = ciEnv::current(); 1030 ciEnv* env = ciEnv::current();
1010 if (env != NULL) { 1031 if (env != NULL) {
1011 env->dump_replay_data(); 1032 int fd = prepare_log_file(ReplayDataFile, "replay_pid%p.log", buffer, sizeof(buffer));
1033 if (fd != -1) {
1034 FILE* replay_data_file = os::open(fd, "w");
1035 if (replay_data_file != NULL) {
1036 fileStream replay_data_stream(replay_data_file, /*need_close=*/true);
1037 env->dump_replay_data(&replay_data_stream);
1038 out.print_raw("#\n# Compiler replay data is saved as:\n# ");
1039 out.print_raw_cr(buffer);
1040 } else {
1041 out.print_raw("#\n# Can't open file to dump replay data. Error: ");
1042 out.print_raw_cr(strerror(os::get_last_error()));
1043 }
1044 }
1012 } 1045 }
1013 } 1046 }
1014 1047
1015 static bool skip_bug_url = !should_report_bug(first_error->_id); 1048 static bool skip_bug_url = !should_report_bug(first_error->_id);
1016 if (!skip_bug_url) { 1049 if (!skip_bug_url) {