aboutsummaryrefslogtreecommitdiff
path: root/src/share/vm/utilities
diff options
context:
space:
mode:
authorkamg <none@none>2011-02-08 17:20:45 -0500
committerkamg <none@none>2011-02-08 17:20:45 -0500
commit84c39585e2595528419df2bd833a1830b460cc54 (patch)
treea1819cb9b0fdd412a9432d03a9e4fbe34b25ffaa /src/share/vm/utilities
parent6ac28a06d97031b9e0a226fb1f8e39eaf0868a27 (diff)
7003401: Implement VM error-reporting functionality on erroneous termination
Summary: Add support for distribution-specific error reporting Reviewed-by: coleenp, phh, jcoomes, ohair --HG-- rename : make/closed.make => make/altsrc.make
Diffstat (limited to 'src/share/vm/utilities')
-rw-r--r--src/share/vm/utilities/errorReporter.cpp32
-rw-r--r--src/share/vm/utilities/errorReporter.hpp39
-rw-r--r--src/share/vm/utilities/ostream.cpp24
-rw-r--r--src/share/vm/utilities/ostream.hpp7
-rw-r--r--src/share/vm/utilities/vmError.cpp21
5 files changed, 120 insertions, 3 deletions
diff --git a/src/share/vm/utilities/errorReporter.cpp b/src/share/vm/utilities/errorReporter.cpp
new file mode 100644
index 000000000..9d1045394
--- /dev/null
+++ b/src/share/vm/utilities/errorReporter.cpp
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "utilities/errorReporter.hpp"
+
+ErrorReporter::ErrorReporter() {}
+
+void ErrorReporter::call(FILE* fd, char* buffer, int length) {
+}
+
diff --git a/src/share/vm/utilities/errorReporter.hpp b/src/share/vm/utilities/errorReporter.hpp
new file mode 100644
index 000000000..e7fae5fba
--- /dev/null
+++ b/src/share/vm/utilities/errorReporter.hpp
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef SHARE_VM_UTILITIES_ERRORREPORTER_HPP
+#define SHARE_VM_UTILITIES_ERRORREPORTER_HPP
+
+#include "utilities/globalDefinitions.hpp"
+
+class ErrorReporter : public StackObj {
+
+public:
+ ErrorReporter();
+ ~ErrorReporter(){};
+
+ void call(FILE* fd, char *buffer, int length);
+};
+
+#endif // ndef SHARE_VM_UTILITIES_ERRORREPORTER_HPP
diff --git a/src/share/vm/utilities/ostream.cpp b/src/share/vm/utilities/ostream.cpp
index acad5fda1..897dba137 100644
--- a/src/share/vm/utilities/ostream.cpp
+++ b/src/share/vm/utilities/ostream.cpp
@@ -314,6 +314,11 @@ fileStream::fileStream(const char* file_name) {
_need_close = true;
}
+fileStream::fileStream(const char* file_name, const char* opentype) {
+ _file = fopen(file_name, opentype);
+ _need_close = true;
+}
+
void fileStream::write(const char* s, size_t len) {
if (_file != NULL) {
// Make an unused local variable to avoid warning from gcc 4.x compiler.
@@ -322,6 +327,25 @@ void fileStream::write(const char* s, size_t len) {
update_position(s, len);
}
+long fileStream::fileSize() {
+ long size = -1;
+ if (_file != NULL) {
+ long pos = ::ftell(_file);
+ if (::fseek(_file, 0, SEEK_END) == 0) {
+ size = ::ftell(_file);
+ }
+ ::fseek(_file, pos, SEEK_SET);
+ }
+ return size;
+}
+
+char* fileStream::readln(char *data, int count ) {
+ char * ret = ::fgets(data, count, _file);
+ //Get rid of annoying \n char
+ data[::strlen(data)-1] = '\0';
+ return ret;
+}
+
fileStream::~fileStream() {
if (_file != NULL) {
if (_need_close) fclose(_file);
diff --git a/src/share/vm/utilities/ostream.hpp b/src/share/vm/utilities/ostream.hpp
index fd86a8da9..1776a5b98 100644
--- a/src/share/vm/utilities/ostream.hpp
+++ b/src/share/vm/utilities/ostream.hpp
@@ -159,10 +159,17 @@ class fileStream : public outputStream {
bool _need_close;
public:
fileStream(const char* file_name);
+ fileStream(const char* file_name, const char* opentype);
fileStream(FILE* file) { _file = file; _need_close = false; }
~fileStream();
bool is_open() const { return _file != NULL; }
+ void set_need_close(bool b) { _need_close = b;}
virtual void write(const char* c, size_t len);
+ size_t read(void *data, size_t size, size_t count) { return ::fread(data, size, count, _file); }
+ char* readln(char *data, int count);
+ int eof() { return feof(_file); }
+ long fileSize();
+ void rewind() { ::rewind(_file); }
void flush();
};
diff --git a/src/share/vm/utilities/vmError.cpp b/src/share/vm/utilities/vmError.cpp
index 662e5a7c9..af05eed8a 100644
--- a/src/share/vm/utilities/vmError.cpp
+++ b/src/share/vm/utilities/vmError.cpp
@@ -35,6 +35,7 @@
#include "utilities/debug.hpp"
#include "utilities/decoder.hpp"
#include "utilities/defaultStream.hpp"
+#include "utilities/errorReporter.hpp"
#include "utilities/top.hpp"
#include "utilities/vmError.hpp"
@@ -769,6 +770,7 @@ void VMError::report_and_die() {
// then save detailed information in log file (verbose = true).
static bool out_done = false; // done printing to standard out
static bool log_done = false; // done saving error log
+ static bool transmit_report_done = false; // done error reporting
static fdStream log; // error log
if (SuppressFatalErrorMessage) {
@@ -859,7 +861,7 @@ void VMError::report_and_die() {
bool copy_ok =
Arguments::copy_expand_pid(ErrorFile, strlen(ErrorFile), buffer, sizeof(buffer));
if (copy_ok) {
- fd = open(buffer, O_WRONLY | O_CREAT | O_TRUNC, 0666);
+ fd = open(buffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
}
}
@@ -870,7 +872,7 @@ void VMError::report_and_die() {
// so use the default name in the current directory
jio_snprintf(&buffer[len], sizeof(buffer)-len, "%shs_err_pid%u.log",
os::file_separator(), os::current_process_id());
- fd = open(buffer, O_WRONLY | O_CREAT | O_TRUNC, 0666);
+ fd = open(buffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
}
if (fd == -1) {
@@ -879,7 +881,7 @@ void VMError::report_and_die() {
if (tmpdir != NULL && tmpdir[0] != '\0') {
jio_snprintf(buffer, sizeof(buffer), "%s%shs_err_pid%u.log",
tmpdir, os::file_separator(), os::current_process_id());
- fd = open(buffer, O_WRONLY | O_CREAT | O_TRUNC, 0666);
+ fd = open(buffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
}
}
@@ -892,6 +894,9 @@ void VMError::report_and_die() {
} else {
out.print_raw_cr("# Can not save log file, dump to screen..");
log.set_fd(defaultStream::output_fd());
+ /* Error reporting currently needs dumpfile.
+ * Maybe implement direct streaming in the future.*/
+ transmit_report_done = true;
}
}
@@ -900,6 +905,16 @@ void VMError::report_and_die() {
first_error->_current_step = 0; // reset current_step
first_error->_current_step_info = ""; // reset current_step string
+ // Run error reporting to determine whether or not to report the crash.
+ if (!transmit_report_done && should_report_bug(first_error->_id)) {
+ transmit_report_done = true;
+ FILE* hs_err = ::fdopen(log.fd(), "r");
+ if (NULL != hs_err) {
+ ErrorReporter er;
+ er.call(hs_err, buffer, O_BUFLEN);
+ }
+ }
+
if (log.fd() != defaultStream::output_fd()) {
close(log.fd());
}