1 /*
2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
781 st->print_cr("vm_info: %s", Abstract_VM_Version::internal_vm_info_string());
782 st->cr();
783 }
784
785 STEP(280, "(printing date and time)" )
786
787 if (_verbose) {
788 os::print_date_and_time(st);
789 st->cr();
790 }
791
792 END
793
794 # undef BEGIN
795 # undef STEP
796 # undef END
797 }
798
799 VMError* volatile VMError::first_error = NULL;
800 volatile jlong VMError::first_error_tid = -1;
801
802 /** Expand a pattern into a buffer starting at pos and open a file using constructed path */
803 static int expand_and_open(const char* pattern, char* buf, size_t buflen, size_t pos) {
804 int fd = -1;
805 if (Arguments::copy_expand_pid(pattern, strlen(pattern), &buf[pos], buflen - pos)) {
806 fd = open(buf, O_RDWR | O_CREAT | O_TRUNC, 0666);
807 }
808 return fd;
809 }
810
811 /**
812 * Construct file name for a log file and return it's file descriptor.
813 * Name and location depends on pattern, default_pattern params and access
814 * permissions.
815 */
816 static int prepare_log_file(const char* pattern, const char* default_pattern, char* buf, size_t buflen) {
817 int fd = -1;
818
819 // If possible, use specified pattern to construct log file name
820 if (pattern != NULL) {
841 if (tmpdir != NULL && strlen(tmpdir) > 0) {
842 int pos = jio_snprintf(buf, buflen, "%s%s", tmpdir, os::file_separator());
843 if (pos > 0) {
844 fd = expand_and_open(default_pattern, buf, buflen, pos);
845 }
846 }
847 }
848
849 return fd;
850 }
851
852 void VMError::report_and_die() {
853 // Don't allocate large buffer on stack
854 static char buffer[O_BUFLEN];
855
856 // An error could happen before tty is initialized or after it has been
857 // destroyed. Here we use a very simple unbuffered fdStream for printing.
858 // Only out.print_raw() and out.print_raw_cr() should be used, as other
859 // printing methods need to allocate large buffer on stack. To format a
860 // string, use jio_snprintf() with a static buffer or use staticBufferStream.
861 static fdStream out(defaultStream::output_fd());
862
863 // How many errors occurred in error handler when reporting first_error.
864 static int recursive_error_count;
865
866 // We will first print a brief message to standard out (verbose = false),
867 // then save detailed information in log file (verbose = true).
868 static bool out_done = false; // done printing to standard out
869 static bool log_done = false; // done saving error log
870 static bool transmit_report_done = false; // done error reporting
871 static fdStream log; // error log
872
873 // disble NMT to avoid further exception
874 MemTracker::shutdown(MemTracker::NMT_error_reporting);
875
876 if (SuppressFatalErrorMessage) {
877 os::abort();
878 }
879 jlong mytid = os::current_thread_id();
880 if (first_error == NULL &&
881 Atomic::cmpxchg_ptr(this, &first_error, NULL) == NULL) {
882
883 // first time
884 first_error_tid = mytid;
885 set_error_reported();
886
887 if (ShowMessageBoxOnError || PauseAtExit) {
888 show_message_box(buffer, sizeof(buffer));
889
890 // User has asked JVM to abort. Reset ShowMessageBoxOnError so the
891 // WatcherThread can kill JVM if the error handler hangs.
|
1 /*
2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
781 st->print_cr("vm_info: %s", Abstract_VM_Version::internal_vm_info_string());
782 st->cr();
783 }
784
785 STEP(280, "(printing date and time)" )
786
787 if (_verbose) {
788 os::print_date_and_time(st);
789 st->cr();
790 }
791
792 END
793
794 # undef BEGIN
795 # undef STEP
796 # undef END
797 }
798
799 VMError* volatile VMError::first_error = NULL;
800 volatile jlong VMError::first_error_tid = -1;
801 fdStream VMError::out(defaultStream::output_fd());
802 fdStream VMError::log; // error log used by VMError::report_and_die()
803
804 /** Expand a pattern into a buffer starting at pos and open a file using constructed path */
805 static int expand_and_open(const char* pattern, char* buf, size_t buflen, size_t pos) {
806 int fd = -1;
807 if (Arguments::copy_expand_pid(pattern, strlen(pattern), &buf[pos], buflen - pos)) {
808 fd = open(buf, O_RDWR | O_CREAT | O_TRUNC, 0666);
809 }
810 return fd;
811 }
812
813 /**
814 * Construct file name for a log file and return it's file descriptor.
815 * Name and location depends on pattern, default_pattern params and access
816 * permissions.
817 */
818 static int prepare_log_file(const char* pattern, const char* default_pattern, char* buf, size_t buflen) {
819 int fd = -1;
820
821 // If possible, use specified pattern to construct log file name
822 if (pattern != NULL) {
843 if (tmpdir != NULL && strlen(tmpdir) > 0) {
844 int pos = jio_snprintf(buf, buflen, "%s%s", tmpdir, os::file_separator());
845 if (pos > 0) {
846 fd = expand_and_open(default_pattern, buf, buflen, pos);
847 }
848 }
849 }
850
851 return fd;
852 }
853
854 void VMError::report_and_die() {
855 // Don't allocate large buffer on stack
856 static char buffer[O_BUFLEN];
857
858 // An error could happen before tty is initialized or after it has been
859 // destroyed. Here we use a very simple unbuffered fdStream for printing.
860 // Only out.print_raw() and out.print_raw_cr() should be used, as other
861 // printing methods need to allocate large buffer on stack. To format a
862 // string, use jio_snprintf() with a static buffer or use staticBufferStream.
863
864 // How many errors occurred in error handler when reporting first_error.
865 static int recursive_error_count;
866
867 // We will first print a brief message to standard out (verbose = false),
868 // then save detailed information in log file (verbose = true).
869 static bool out_done = false; // done printing to standard out
870 static bool log_done = false; // done saving error log
871 static bool transmit_report_done = false; // done error reporting
872
873 // disble NMT to avoid further exception
874 MemTracker::shutdown(MemTracker::NMT_error_reporting);
875
876 if (SuppressFatalErrorMessage) {
877 os::abort();
878 }
879 jlong mytid = os::current_thread_id();
880 if (first_error == NULL &&
881 Atomic::cmpxchg_ptr(this, &first_error, NULL) == NULL) {
882
883 // first time
884 first_error_tid = mytid;
885 set_error_reported();
886
887 if (ShowMessageBoxOnError || PauseAtExit) {
888 show_message_box(buffer, sizeof(buffer));
889
890 // User has asked JVM to abort. Reset ShowMessageBoxOnError so the
891 // WatcherThread can kill JVM if the error handler hangs.
|