Mercurial > hg > truffle
annotate src/share/vm/utilities/vmError.cpp @ 2130:34d64ad817f4
7009828: Fix for 6938627 breaks visualvm monitoring when -Djava.io.tmpdir is defined
Summary: Change get_temp_directory() back to /tmp and %TEMP% like it always was and where the tools expect it to be.
Reviewed-by: phh, dcubed, kamg, alanb
author | coleenp |
---|---|
date | Wed, 12 Jan 2011 13:59:18 -0800 |
parents | 36c186bcc085 |
children | d8a72fbc4be7 |
rev | line source |
---|---|
0 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1490
diff
changeset
|
2 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1490
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1490
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1490
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "compiler/compileBroker.hpp" | |
27 #include "gc_interface/collectedHeap.hpp" | |
28 #include "runtime/arguments.hpp" | |
29 #include "runtime/frame.inline.hpp" | |
30 #include "runtime/init.hpp" | |
31 #include "runtime/os.hpp" | |
32 #include "runtime/thread.hpp" | |
33 #include "runtime/vmThread.hpp" | |
34 #include "runtime/vm_operations.hpp" | |
35 #include "utilities/debug.hpp" | |
2022
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
36 #include "utilities/decoder.hpp" |
1972 | 37 #include "utilities/defaultStream.hpp" |
38 #include "utilities/top.hpp" | |
39 #include "utilities/vmError.hpp" | |
0 | 40 |
41 // List of environment variables that should be reported in error log file. | |
42 const char *env_list[] = { | |
43 // All platforms | |
44 "JAVA_HOME", "JRE_HOME", "JAVA_TOOL_OPTIONS", "_JAVA_OPTIONS", "CLASSPATH", | |
45 "JAVA_COMPILER", "PATH", "USERNAME", | |
46 | |
47 // Env variables that are defined on Solaris/Linux | |
48 "LD_LIBRARY_PATH", "LD_PRELOAD", "SHELL", "DISPLAY", | |
49 "HOSTTYPE", "OSTYPE", "ARCH", "MACHTYPE", | |
50 | |
51 // defined on Linux | |
52 "LD_ASSUME_KERNEL", "_JAVA_SR_SIGNUM", | |
53 | |
54 // defined on Windows | |
55 "OS", "PROCESSOR_IDENTIFIER", "_ALT_JAVA_HOME_DIR", | |
56 | |
57 (const char *)0 | |
58 }; | |
59 | |
60 // Fatal error handler for internal errors and crashes. | |
61 // | |
62 // The default behavior of fatal error handler is to print a brief message | |
63 // to standard out (defaultStream::output_fd()), then save detailed information | |
64 // into an error report file (hs_err_pid<pid>.log) and abort VM. If multiple | |
65 // threads are having troubles at the same time, only one error is reported. | |
66 // The thread that is reporting error will abort VM when it is done, all other | |
67 // threads are blocked forever inside report_and_die(). | |
68 | |
69 // Constructor for crashes | |
2095
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
70 VMError::VMError(Thread* thread, unsigned int sig, address pc, void* siginfo, void* context) { |
0 | 71 _thread = thread; |
72 _id = sig; | |
73 _pc = pc; | |
74 _siginfo = siginfo; | |
75 _context = context; | |
76 | |
77 _verbose = false; | |
78 _current_step = 0; | |
79 _current_step_info = NULL; | |
80 | |
1490
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
81 _message = NULL; |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
82 _detail_msg = NULL; |
0 | 83 _filename = NULL; |
84 _lineno = 0; | |
85 | |
86 _size = 0; | |
87 } | |
88 | |
89 // Constructor for internal errors | |
1490
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
90 VMError::VMError(Thread* thread, const char* filename, int lineno, |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
91 const char* message, const char * detail_msg) |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
92 { |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
93 _thread = thread; |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
94 _id = internal_error; // Value that's not an OS exception/signal |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
95 _filename = filename; |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
96 _lineno = lineno; |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
97 _message = message; |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
98 _detail_msg = detail_msg; |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
99 |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
100 _verbose = false; |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
101 _current_step = 0; |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
102 _current_step_info = NULL; |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
103 |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
104 _pc = NULL; |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
105 _siginfo = NULL; |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
106 _context = NULL; |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
107 |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
108 _size = 0; |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
109 } |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
110 |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
111 // Constructor for OOM errors |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
112 VMError::VMError(Thread* thread, const char* filename, int lineno, size_t size, |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
113 const char* message) { |
0 | 114 _thread = thread; |
1490
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
115 _id = oom_error; // Value that's not an OS exception/signal |
0 | 116 _filename = filename; |
117 _lineno = lineno; | |
118 _message = message; | |
1490
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
119 _detail_msg = NULL; |
0 | 120 |
121 _verbose = false; | |
122 _current_step = 0; | |
123 _current_step_info = NULL; | |
124 | |
125 _pc = NULL; | |
126 _siginfo = NULL; | |
127 _context = NULL; | |
128 | |
129 _size = size; | |
130 } | |
131 | |
132 | |
133 // Constructor for non-fatal errors | |
134 VMError::VMError(const char* message) { | |
135 _thread = NULL; | |
1490
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
136 _id = internal_error; // Value that's not an OS exception/signal |
0 | 137 _filename = NULL; |
138 _lineno = 0; | |
139 _message = message; | |
1490
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
140 _detail_msg = NULL; |
0 | 141 |
142 _verbose = false; | |
143 _current_step = 0; | |
144 _current_step_info = NULL; | |
145 | |
146 _pc = NULL; | |
147 _siginfo = NULL; | |
148 _context = NULL; | |
149 | |
150 _size = 0; | |
151 } | |
152 | |
153 // -XX:OnError=<string>, where <string> can be a list of commands, separated | |
154 // by ';'. "%p" is replaced by current process id (pid); "%%" is replaced by | |
155 // a single "%". Some examples: | |
156 // | |
157 // -XX:OnError="pmap %p" // show memory map | |
158 // -XX:OnError="gcore %p; dbx - %p" // dump core and launch debugger | |
159 // -XX:OnError="cat hs_err_pid%p.log | mail my_email@sun.com" | |
160 // -XX:OnError="kill -9 %p" // ?#!@# | |
161 | |
162 // A simple parser for -XX:OnError, usage: | |
163 // ptr = OnError; | |
164 // while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr) != NULL) | |
165 // ... ... | |
166 static char* next_OnError_command(char* buf, int buflen, const char** ptr) { | |
167 if (ptr == NULL || *ptr == NULL) return NULL; | |
168 | |
169 const char* cmd = *ptr; | |
170 | |
171 // skip leading blanks or ';' | |
172 while (*cmd == ' ' || *cmd == ';') cmd++; | |
173 | |
174 if (*cmd == '\0') return NULL; | |
175 | |
176 const char * cmdend = cmd; | |
177 while (*cmdend != '\0' && *cmdend != ';') cmdend++; | |
178 | |
179 Arguments::copy_expand_pid(cmd, cmdend - cmd, buf, buflen); | |
180 | |
181 *ptr = (*cmdend == '\0' ? cmdend : cmdend + 1); | |
182 return buf; | |
183 } | |
184 | |
185 | |
186 static void print_bug_submit_message(outputStream *out, Thread *thread) { | |
187 if (out == NULL) return; | |
188 out->print_raw_cr("# If you would like to submit a bug report, please visit:"); | |
189 out->print_raw ("# "); | |
190 out->print_raw_cr(Arguments::java_vendor_url_bug()); | |
191 // If the crash is in native code, encourage user to submit a bug to the | |
192 // provider of that code. | |
56
31d829b33f26
6549844: Wording problems in "An unexpected error ..."
coleenp
parents:
0
diff
changeset
|
193 if (thread && thread->is_Java_thread() && |
31d829b33f26
6549844: Wording problems in "An unexpected error ..."
coleenp
parents:
0
diff
changeset
|
194 !thread->is_hidden_from_external_view()) { |
0 | 195 JavaThread* jt = (JavaThread*)thread; |
196 if (jt->thread_state() == _thread_in_native) { | |
197 out->print_cr("# The crash happened outside the Java Virtual Machine in native code.\n# See problematic frame for where to report the bug."); | |
198 } | |
199 } | |
200 out->print_raw_cr("#"); | |
201 } | |
202 | |
203 | |
204 // Return a string to describe the error | |
205 char* VMError::error_string(char* buf, int buflen) { | |
206 char signame_buf[64]; | |
207 const char *signame = os::exception_name(_id, signame_buf, sizeof(signame_buf)); | |
208 | |
209 if (signame) { | |
210 jio_snprintf(buf, buflen, | |
211 "%s (0x%x) at pc=" PTR_FORMAT ", pid=%d, tid=" UINTX_FORMAT, | |
212 signame, _id, _pc, | |
213 os::current_process_id(), os::current_thread_id()); | |
1490
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
214 } else if (_filename != NULL && _lineno > 0) { |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
215 // skip directory names |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
216 char separator = os::file_separator()[0]; |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
217 const char *p = strrchr(_filename, separator); |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
218 int n = jio_snprintf(buf, buflen, |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
219 "Internal Error at %s:%d, pid=%d, tid=" UINTX_FORMAT, |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
220 p ? p + 1 : _filename, _lineno, |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
221 os::current_process_id(), os::current_thread_id()); |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
222 if (n >= 0 && n < buflen && _message) { |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
223 if (_detail_msg) { |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
224 jio_snprintf(buf + n, buflen - n, "%s%s: %s", |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
225 os::line_separator(), _message, _detail_msg); |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
226 } else { |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
227 jio_snprintf(buf + n, buflen - n, "%sError: %s", |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
228 os::line_separator(), _message); |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
229 } |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
230 } |
0 | 231 } else { |
1490
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
232 jio_snprintf(buf, buflen, |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
233 "Internal Error (0x%x), pid=%d, tid=" UINTX_FORMAT, |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1384
diff
changeset
|
234 _id, os::current_process_id(), os::current_thread_id()); |
0 | 235 } |
236 | |
237 return buf; | |
238 } | |
239 | |
1384 | 240 void VMError::print_stack_trace(outputStream* st, JavaThread* jt, |
241 char* buf, int buflen, bool verbose) { | |
242 #ifdef ZERO | |
243 if (jt->zero_stack()->sp() && jt->top_zero_frame()) { | |
244 // StackFrameStream uses the frame anchor, which may not have | |
245 // been set up. This can be done at any time in Zero, however, | |
246 // so if it hasn't been set up then we just set it up now and | |
247 // clear it again when we're done. | |
248 bool has_last_Java_frame = jt->has_last_Java_frame(); | |
249 if (!has_last_Java_frame) | |
250 jt->set_last_Java_frame(); | |
251 st->print("Java frames:"); | |
252 | |
253 // If the top frame is a Shark frame and the frame anchor isn't | |
254 // set up then it's possible that the information in the frame | |
255 // is garbage: it could be from a previous decache, or it could | |
256 // simply have never been written. So we print a warning... | |
257 StackFrameStream sfs(jt); | |
258 if (!has_last_Java_frame && !sfs.is_done()) { | |
259 if (sfs.current()->zeroframe()->is_shark_frame()) { | |
260 st->print(" (TOP FRAME MAY BE JUNK)"); | |
261 } | |
262 } | |
263 st->cr(); | |
264 | |
265 // Print the frames | |
266 for(int i = 0; !sfs.is_done(); sfs.next(), i++) { | |
267 sfs.current()->zero_print_on_error(i, st, buf, buflen); | |
268 st->cr(); | |
269 } | |
270 | |
271 // Reset the frame anchor if necessary | |
272 if (!has_last_Java_frame) | |
273 jt->reset_last_Java_frame(); | |
274 } | |
275 #else | |
276 if (jt->has_last_Java_frame()) { | |
277 st->print_cr("Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)"); | |
278 for(StackFrameStream sfs(jt); !sfs.is_done(); sfs.next()) { | |
279 sfs.current()->print_on_error(st, buf, buflen, verbose); | |
280 st->cr(); | |
281 } | |
282 } | |
283 #endif // ZERO | |
284 } | |
0 | 285 |
286 // This is the main function to report a fatal error. Only one thread can | |
287 // call this function, so we don't need to worry about MT-safety. But it's | |
288 // possible that the error handler itself may crash or die on an internal | |
289 // error, for example, when the stack/heap is badly damaged. We must be | |
290 // able to handle recursive errors that happen inside error handler. | |
291 // | |
292 // Error reporting is done in several steps. If a crash or internal error | |
293 // occurred when reporting an error, the nested signal/exception handler | |
294 // can skip steps that are already (or partially) done. Error reporting will | |
295 // continue from the next step. This allows us to retrieve and print | |
296 // information that may be unsafe to get after a fatal error. If it happens, | |
297 // you may find nested report_and_die() frames when you look at the stack | |
298 // in a debugger. | |
299 // | |
300 // In general, a hang in error handler is much worse than a crash or internal | |
301 // error, as it's harder to recover from a hang. Deadlock can happen if we | |
302 // try to grab a lock that is already owned by current thread, or if the | |
303 // owner is blocked forever (e.g. in os::infinite_sleep()). If possible, the | |
304 // error handler and all the functions it called should avoid grabbing any | |
305 // lock. An important thing to notice is that memory allocation needs a lock. | |
306 // | |
307 // We should avoid using large stack allocated buffers. Many errors happen | |
308 // when stack space is already low. Making things even worse is that there | |
309 // could be nested report_and_die() calls on stack (see above). Only one | |
310 // thread can report error, so large buffers are statically allocated in data | |
311 // segment. | |
312 | |
313 void VMError::report(outputStream* st) { | |
314 # define BEGIN if (_current_step == 0) { _current_step = 1; | |
315 # define STEP(n, s) } if (_current_step < n) { _current_step = n; _current_step_info = s; | |
316 # define END } | |
317 | |
318 // don't allocate large buffer on stack | |
319 static char buf[O_BUFLEN]; | |
320 | |
321 BEGIN | |
322 | |
56
31d829b33f26
6549844: Wording problems in "An unexpected error ..."
coleenp
parents:
0
diff
changeset
|
323 STEP(10, "(printing fatal error message)") |
0 | 324 |
2095
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
325 st->print_cr("#"); |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
326 if (should_report_bug(_id)) { |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
327 st->print_cr("# A fatal error has been detected by the Java Runtime Environment:"); |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
328 } else { |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
329 st->print_cr("# There is insufficient memory for the Java " |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
330 "Runtime Environment to continue."); |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
331 } |
0 | 332 |
333 STEP(15, "(printing type of error)") | |
334 | |
335 switch(_id) { | |
336 case oom_error: | |
337 if (_size) { | |
2095
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
338 st->print("# Native memory allocation (malloc) failed to allocate "); |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
339 jio_snprintf(buf, sizeof(buf), SIZE_FORMAT, _size); |
0 | 340 st->print(buf); |
341 st->print(" bytes"); | |
342 if (_message != NULL) { | |
343 st->print(" for "); | |
344 st->print(_message); | |
345 } | |
2095
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
346 st->cr(); |
0 | 347 } else { |
348 if (_message != NULL) | |
2095
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
349 st->print("# "); |
0 | 350 st->print_cr(_message); |
351 } | |
2095
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
352 // In error file give some solutions |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
353 if (_verbose) { |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
354 st->print_cr("# Possible reasons:"); |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
355 st->print_cr("# The system is out of physical RAM or swap space"); |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
356 st->print_cr("# In 32 bit mode, the process size limit was hit"); |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
357 st->print_cr("# Possible solutions:"); |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
358 st->print_cr("# Reduce memory load on the system"); |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
359 st->print_cr("# Increase physical memory or swap space"); |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
360 st->print_cr("# Check if swap backing store is full"); |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
361 st->print_cr("# Use 64 bit Java on a 64 bit OS"); |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
362 st->print_cr("# Decrease Java heap size (-Xmx/-Xms)"); |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
363 st->print_cr("# Decrease number of Java threads"); |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
364 st->print_cr("# Decrease Java thread stack sizes (-Xss)"); |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
365 st->print_cr("# Set larger code cache with -XX:ReservedCodeCacheSize="); |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
366 st->print_cr("# This output file may be truncated or incomplete."); |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
367 } else { |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
368 return; // that's enough for the screen |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
369 } |
0 | 370 break; |
371 case internal_error: | |
372 default: | |
373 break; | |
374 } | |
375 | |
376 STEP(20, "(printing exception/signal name)") | |
377 | |
378 st->print_cr("#"); | |
379 st->print("# "); | |
380 // Is it an OS exception/signal? | |
381 if (os::exception_name(_id, buf, sizeof(buf))) { | |
382 st->print("%s", buf); | |
383 st->print(" (0x%x)", _id); // signal number | |
384 st->print(" at pc=" PTR_FORMAT, _pc); | |
385 } else { | |
2095
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
386 if (should_report_bug(_id)) { |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
387 st->print("Internal Error"); |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
388 } else { |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
389 st->print("Out of Memory Error"); |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
390 } |
0 | 391 if (_filename != NULL && _lineno > 0) { |
392 #ifdef PRODUCT | |
393 // In product mode chop off pathname? | |
394 char separator = os::file_separator()[0]; | |
395 const char *p = strrchr(_filename, separator); | |
396 const char *file = p ? p+1 : _filename; | |
397 #else | |
398 const char *file = _filename; | |
399 #endif | |
400 size_t len = strlen(file); | |
401 size_t buflen = sizeof(buf); | |
402 | |
403 strncpy(buf, file, buflen); | |
404 if (len + 10 < buflen) { | |
603
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
511
diff
changeset
|
405 sprintf(buf + len, ":%d", _lineno); |
0 | 406 } |
407 st->print(" (%s)", buf); | |
408 } else { | |
409 st->print(" (0x%x)", _id); | |
410 } | |
411 } | |
412 | |
413 STEP(30, "(printing current thread and pid)") | |
414 | |
415 // process id, thread id | |
416 st->print(", pid=%d", os::current_process_id()); | |
417 st->print(", tid=" UINTX_FORMAT, os::current_thread_id()); | |
418 st->cr(); | |
419 | |
420 STEP(40, "(printing error message)") | |
421 | |
2095
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
422 if (should_report_bug(_id)) { // already printed the message. |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
423 // error message |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
424 if (_detail_msg) { |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
425 st->print_cr("# %s: %s", _message ? _message : "Error", _detail_msg); |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
426 } else if (_message) { |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
427 st->print_cr("# Error: %s", _message); |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
428 } |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
429 } |
0 | 430 |
431 STEP(50, "(printing Java version string)") | |
432 | |
433 // VM version | |
434 st->print_cr("#"); | |
473
3ad2b8576c4a
6689685: Hotspot crash error message should include libraries version
coleenp
parents:
420
diff
changeset
|
435 JDK_Version::current().to_string(buf, sizeof(buf)); |
3ad2b8576c4a
6689685: Hotspot crash error message should include libraries version
coleenp
parents:
420
diff
changeset
|
436 st->print_cr("# JRE version: %s", buf); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
56
diff
changeset
|
437 st->print_cr("# Java VM: %s (%s %s %s %s)", |
0 | 438 Abstract_VM_Version::vm_name(), |
439 Abstract_VM_Version::vm_release(), | |
440 Abstract_VM_Version::vm_info_string(), | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
56
diff
changeset
|
441 Abstract_VM_Version::vm_platform_string(), |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
56
diff
changeset
|
442 UseCompressedOops ? "compressed oops" : "" |
0 | 443 ); |
444 | |
445 STEP(60, "(printing problematic frame)") | |
446 | |
447 // Print current frame if we have a context (i.e. it's a crash) | |
448 if (_context) { | |
449 st->print_cr("# Problematic frame:"); | |
450 st->print("# "); | |
451 frame fr = os::fetch_frame_from_context(_context); | |
452 fr.print_on_error(st, buf, sizeof(buf)); | |
453 st->cr(); | |
454 st->print_cr("#"); | |
455 } | |
456 | |
457 STEP(65, "(printing bug submit message)") | |
458 | |
2095
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
459 if (should_report_bug(_id) && _verbose) { |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
460 print_bug_submit_message(st, _thread); |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
461 } |
0 | 462 |
463 STEP(70, "(printing thread)" ) | |
464 | |
465 if (_verbose) { | |
466 st->cr(); | |
467 st->print_cr("--------------- T H R E A D ---------------"); | |
468 st->cr(); | |
469 } | |
470 | |
471 STEP(80, "(printing current thread)" ) | |
472 | |
473 // current thread | |
474 if (_verbose) { | |
475 if (_thread) { | |
476 st->print("Current thread (" PTR_FORMAT "): ", _thread); | |
477 _thread->print_on_error(st, buf, sizeof(buf)); | |
478 st->cr(); | |
479 } else { | |
480 st->print_cr("Current thread is native thread"); | |
481 } | |
482 st->cr(); | |
483 } | |
484 | |
485 STEP(90, "(printing siginfo)" ) | |
486 | |
487 // signal no, signal code, address that caused the fault | |
488 if (_verbose && _siginfo) { | |
489 os::print_siginfo(st, _siginfo); | |
490 st->cr(); | |
491 } | |
492 | |
493 STEP(100, "(printing registers, top of stack, instructions near pc)") | |
494 | |
495 // registers, top of stack, instructions near pc | |
496 if (_verbose && _context) { | |
497 os::print_context(st, _context); | |
498 st->cr(); | |
499 } | |
500 | |
1907 | 501 STEP(105, "(printing register info)") |
502 | |
503 // decode register contents if possible | |
504 if (_verbose && _context && Universe::is_fully_initialized()) { | |
505 os::print_register_info(st, _context); | |
506 st->cr(); | |
507 } | |
508 | |
0 | 509 STEP(110, "(printing stack bounds)" ) |
510 | |
511 if (_verbose) { | |
512 st->print("Stack: "); | |
513 | |
514 address stack_top; | |
515 size_t stack_size; | |
516 | |
517 if (_thread) { | |
518 stack_top = _thread->stack_base(); | |
519 stack_size = _thread->stack_size(); | |
520 } else { | |
521 stack_top = os::current_stack_base(); | |
522 stack_size = os::current_stack_size(); | |
523 } | |
524 | |
525 address stack_bottom = stack_top - stack_size; | |
526 st->print("[" PTR_FORMAT "," PTR_FORMAT "]", stack_bottom, stack_top); | |
527 | |
528 frame fr = _context ? os::fetch_frame_from_context(_context) | |
529 : os::current_frame(); | |
530 | |
531 if (fr.sp()) { | |
532 st->print(", sp=" PTR_FORMAT, fr.sp()); | |
1684
66c5dadb4d61
6973308: Missing zero length check before repne scas in check_klass_subtype_slow_path()
kvn
parents:
1552
diff
changeset
|
533 size_t free_stack_size = pointer_delta(fr.sp(), stack_bottom, 1024); |
66c5dadb4d61
6973308: Missing zero length check before repne scas in check_klass_subtype_slow_path()
kvn
parents:
1552
diff
changeset
|
534 st->print(", free space=" SIZE_FORMAT "k", free_stack_size); |
0 | 535 } |
536 | |
537 st->cr(); | |
538 } | |
539 | |
540 STEP(120, "(printing native stack)" ) | |
541 | |
542 if (_verbose) { | |
543 frame fr = _context ? os::fetch_frame_from_context(_context) | |
544 : os::current_frame(); | |
545 | |
546 // see if it's a valid frame | |
547 if (fr.pc()) { | |
548 st->print_cr("Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)"); | |
549 | |
2022
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
550 // initialize decoder to decode C frames |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
551 Decoder decoder; |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
552 |
0 | 553 int count = 0; |
554 while (count++ < StackPrintLimit) { | |
555 fr.print_on_error(st, buf, sizeof(buf)); | |
556 st->cr(); | |
557 if (os::is_first_C_frame(&fr)) break; | |
558 fr = os::get_sender_for_C_frame(&fr); | |
559 } | |
560 | |
561 if (count > StackPrintLimit) { | |
562 st->print_cr("...<more frames>..."); | |
563 } | |
564 | |
565 st->cr(); | |
566 } | |
567 } | |
568 | |
569 STEP(130, "(printing Java stack)" ) | |
570 | |
571 if (_verbose && _thread && _thread->is_Java_thread()) { | |
1384 | 572 print_stack_trace(st, (JavaThread*)_thread, buf, sizeof(buf)); |
0 | 573 } |
574 | |
1119
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1010
diff
changeset
|
575 STEP(135, "(printing target Java thread stack)" ) |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1010
diff
changeset
|
576 |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1010
diff
changeset
|
577 // printing Java thread stack trace if it is involved in GC crash |
1907 | 578 if (_verbose && _thread && (_thread->is_Named_thread())) { |
1119
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1010
diff
changeset
|
579 JavaThread* jt = ((NamedThread *)_thread)->processed_thread(); |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1010
diff
changeset
|
580 if (jt != NULL) { |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1010
diff
changeset
|
581 st->print_cr("JavaThread " PTR_FORMAT " (nid = " UINTX_FORMAT ") was being processed", jt, jt->osthread()->thread_id()); |
1384 | 582 print_stack_trace(st, jt, buf, sizeof(buf), true); |
1119
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1010
diff
changeset
|
583 } |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1010
diff
changeset
|
584 } |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1010
diff
changeset
|
585 |
0 | 586 STEP(140, "(printing VM operation)" ) |
587 | |
588 if (_verbose && _thread && _thread->is_VM_thread()) { | |
589 VMThread* t = (VMThread*)_thread; | |
590 VM_Operation* op = t->vm_operation(); | |
591 if (op) { | |
592 op->print_on_error(st); | |
593 st->cr(); | |
594 st->cr(); | |
595 } | |
596 } | |
597 | |
598 STEP(150, "(printing current compile task)" ) | |
599 | |
600 if (_verbose && _thread && _thread->is_Compiler_thread()) { | |
601 CompilerThread* t = (CompilerThread*)_thread; | |
602 if (t->task()) { | |
603 st->cr(); | |
604 st->print_cr("Current CompileTask:"); | |
605 t->task()->print_line_on_error(st, buf, sizeof(buf)); | |
606 st->cr(); | |
607 } | |
608 } | |
609 | |
610 STEP(160, "(printing process)" ) | |
611 | |
612 if (_verbose) { | |
613 st->cr(); | |
614 st->print_cr("--------------- P R O C E S S ---------------"); | |
615 st->cr(); | |
616 } | |
617 | |
618 STEP(170, "(printing all threads)" ) | |
619 | |
620 // all threads | |
621 if (_verbose && _thread) { | |
622 Threads::print_on_error(st, _thread, buf, sizeof(buf)); | |
623 st->cr(); | |
624 } | |
625 | |
626 STEP(175, "(printing VM state)" ) | |
627 | |
628 if (_verbose) { | |
629 // Safepoint state | |
630 st->print("VM state:"); | |
631 | |
632 if (SafepointSynchronize::is_synchronizing()) st->print("synchronizing"); | |
633 else if (SafepointSynchronize::is_at_safepoint()) st->print("at safepoint"); | |
634 else st->print("not at safepoint"); | |
635 | |
636 // Also see if error occurred during initialization or shutdown | |
637 if (!Universe::is_fully_initialized()) { | |
638 st->print(" (not fully initialized)"); | |
639 } else if (VM_Exit::vm_exited()) { | |
640 st->print(" (shutting down)"); | |
641 } else { | |
642 st->print(" (normal execution)"); | |
643 } | |
644 st->cr(); | |
645 st->cr(); | |
646 } | |
647 | |
648 STEP(180, "(printing owned locks on error)" ) | |
649 | |
650 // mutexes/monitors that currently have an owner | |
651 if (_verbose) { | |
652 print_owned_locks_on_error(st); | |
653 st->cr(); | |
654 } | |
655 | |
656 STEP(190, "(printing heap information)" ) | |
657 | |
658 if (_verbose && Universe::is_fully_initialized()) { | |
659 // print heap information before vm abort | |
660 Universe::print_on(st); | |
661 st->cr(); | |
662 } | |
663 | |
1907 | 664 STEP(195, "(printing code cache information)" ) |
665 | |
666 if (_verbose && Universe::is_fully_initialized()) { | |
667 // print code cache information before vm abort | |
668 CodeCache::print_bounds(st); | |
669 st->cr(); | |
670 } | |
671 | |
0 | 672 STEP(200, "(printing dynamic libraries)" ) |
673 | |
674 if (_verbose) { | |
675 // dynamic libraries, or memory map | |
676 os::print_dll_info(st); | |
677 st->cr(); | |
678 } | |
679 | |
680 STEP(210, "(printing VM options)" ) | |
681 | |
682 if (_verbose) { | |
683 // VM options | |
684 Arguments::print_on(st); | |
685 st->cr(); | |
686 } | |
687 | |
688 STEP(220, "(printing environment variables)" ) | |
689 | |
690 if (_verbose) { | |
691 os::print_environment_variables(st, env_list, buf, sizeof(buf)); | |
692 st->cr(); | |
693 } | |
694 | |
695 STEP(225, "(printing signal handlers)" ) | |
696 | |
697 if (_verbose) { | |
698 os::print_signal_handlers(st, buf, sizeof(buf)); | |
699 st->cr(); | |
700 } | |
701 | |
702 STEP(230, "" ) | |
703 | |
704 if (_verbose) { | |
705 st->cr(); | |
706 st->print_cr("--------------- S Y S T E M ---------------"); | |
707 st->cr(); | |
708 } | |
709 | |
710 STEP(240, "(printing OS information)" ) | |
711 | |
712 if (_verbose) { | |
713 os::print_os_info(st); | |
714 st->cr(); | |
715 } | |
716 | |
717 STEP(250, "(printing CPU info)" ) | |
718 if (_verbose) { | |
719 os::print_cpu_info(st); | |
720 st->cr(); | |
721 } | |
722 | |
723 STEP(260, "(printing memory info)" ) | |
724 | |
725 if (_verbose) { | |
726 os::print_memory_info(st); | |
727 st->cr(); | |
728 } | |
729 | |
730 STEP(270, "(printing internal vm info)" ) | |
731 | |
732 if (_verbose) { | |
733 st->print_cr("vm_info: %s", Abstract_VM_Version::internal_vm_info_string()); | |
734 st->cr(); | |
735 } | |
736 | |
737 STEP(280, "(printing date and time)" ) | |
738 | |
739 if (_verbose) { | |
740 os::print_date_and_time(st); | |
741 st->cr(); | |
742 } | |
743 | |
744 END | |
745 | |
746 # undef BEGIN | |
747 # undef STEP | |
748 # undef END | |
749 } | |
750 | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1552
diff
changeset
|
751 VMError* volatile VMError::first_error = NULL; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1552
diff
changeset
|
752 volatile jlong VMError::first_error_tid = -1; |
0 | 753 |
754 void VMError::report_and_die() { | |
755 // Don't allocate large buffer on stack | |
756 static char buffer[O_BUFLEN]; | |
757 | |
758 // An error could happen before tty is initialized or after it has been | |
759 // destroyed. Here we use a very simple unbuffered fdStream for printing. | |
760 // Only out.print_raw() and out.print_raw_cr() should be used, as other | |
761 // printing methods need to allocate large buffer on stack. To format a | |
762 // string, use jio_snprintf() with a static buffer or use staticBufferStream. | |
763 static fdStream out(defaultStream::output_fd()); | |
764 | |
765 // How many errors occurred in error handler when reporting first_error. | |
766 static int recursive_error_count; | |
767 | |
768 // We will first print a brief message to standard out (verbose = false), | |
769 // then save detailed information in log file (verbose = true). | |
770 static bool out_done = false; // done printing to standard out | |
771 static bool log_done = false; // done saving error log | |
772 static fdStream log; // error log | |
773 | |
774 if (SuppressFatalErrorMessage) { | |
775 os::abort(); | |
776 } | |
777 jlong mytid = os::current_thread_id(); | |
778 if (first_error == NULL && | |
779 Atomic::cmpxchg_ptr(this, &first_error, NULL) == NULL) { | |
780 | |
781 // first time | |
782 first_error_tid = mytid; | |
783 set_error_reported(); | |
784 | |
785 if (ShowMessageBoxOnError) { | |
786 show_message_box(buffer, sizeof(buffer)); | |
787 | |
788 // User has asked JVM to abort. Reset ShowMessageBoxOnError so the | |
789 // WatcherThread can kill JVM if the error handler hangs. | |
790 ShowMessageBoxOnError = false; | |
791 } | |
792 | |
793 // reset signal handlers or exception filter; make sure recursive crashes | |
794 // are handled properly. | |
795 reset_signal_handlers(); | |
796 | |
797 } else { | |
511
dabd8d202164
4997835: RFE: crash dump will only be created when running w/ -XX:+ShowMessageBoxOnError
coleenp
parents:
473
diff
changeset
|
798 // If UseOsErrorReporting we call this for each level of the call stack |
dabd8d202164
4997835: RFE: crash dump will only be created when running w/ -XX:+ShowMessageBoxOnError
coleenp
parents:
473
diff
changeset
|
799 // while searching for the exception handler. Only the first level needs |
dabd8d202164
4997835: RFE: crash dump will only be created when running w/ -XX:+ShowMessageBoxOnError
coleenp
parents:
473
diff
changeset
|
800 // to be reported. |
dabd8d202164
4997835: RFE: crash dump will only be created when running w/ -XX:+ShowMessageBoxOnError
coleenp
parents:
473
diff
changeset
|
801 if (UseOSErrorReporting && log_done) return; |
dabd8d202164
4997835: RFE: crash dump will only be created when running w/ -XX:+ShowMessageBoxOnError
coleenp
parents:
473
diff
changeset
|
802 |
0 | 803 // This is not the first error, see if it happened in a different thread |
804 // or in the same thread during error reporting. | |
805 if (first_error_tid != mytid) { | |
806 jio_snprintf(buffer, sizeof(buffer), | |
807 "[thread " INT64_FORMAT " also had an error]", | |
808 mytid); | |
809 out.print_raw_cr(buffer); | |
810 | |
811 // error reporting is not MT-safe, block current thread | |
812 os::infinite_sleep(); | |
813 | |
814 } else { | |
815 if (recursive_error_count++ > 30) { | |
816 out.print_raw_cr("[Too many errors, abort]"); | |
817 os::die(); | |
818 } | |
819 | |
820 jio_snprintf(buffer, sizeof(buffer), | |
821 "[error occurred during error reporting %s, id 0x%x]", | |
822 first_error ? first_error->_current_step_info : "", | |
823 _id); | |
824 if (log.is_open()) { | |
825 log.cr(); | |
826 log.print_raw_cr(buffer); | |
827 log.cr(); | |
828 } else { | |
829 out.cr(); | |
830 out.print_raw_cr(buffer); | |
831 out.cr(); | |
832 } | |
833 } | |
834 } | |
835 | |
836 // print to screen | |
837 if (!out_done) { | |
838 first_error->_verbose = false; | |
839 | |
840 staticBufferStream sbs(buffer, sizeof(buffer), &out); | |
841 first_error->report(&sbs); | |
842 | |
843 out_done = true; | |
844 | |
845 first_error->_current_step = 0; // reset current_step | |
846 first_error->_current_step_info = ""; // reset current_step string | |
847 } | |
848 | |
849 // print to error log file | |
850 if (!log_done) { | |
851 first_error->_verbose = true; | |
852 | |
853 // see if log file is already open | |
854 if (!log.is_open()) { | |
855 // open log file | |
856 int fd = -1; | |
857 | |
858 if (ErrorFile != NULL) { | |
859 bool copy_ok = | |
860 Arguments::copy_expand_pid(ErrorFile, strlen(ErrorFile), buffer, sizeof(buffer)); | |
861 if (copy_ok) { | |
862 fd = open(buffer, O_WRONLY | O_CREAT | O_TRUNC, 0666); | |
863 } | |
864 } | |
865 | |
866 if (fd == -1) { | |
867 const char *cwd = os::get_current_directory(buffer, sizeof(buffer)); | |
868 size_t len = strlen(cwd); | |
869 // either user didn't specify, or the user's location failed, | |
870 // so use the default name in the current directory | |
871 jio_snprintf(&buffer[len], sizeof(buffer)-len, "%shs_err_pid%u.log", | |
872 os::file_separator(), os::current_process_id()); | |
873 fd = open(buffer, O_WRONLY | O_CREAT | O_TRUNC, 0666); | |
874 } | |
875 | |
876 if (fd == -1) { | |
877 const char * tmpdir = os::get_temp_directory(); | |
2130
34d64ad817f4
7009828: Fix for 6938627 breaks visualvm monitoring when -Djava.io.tmpdir is defined
coleenp
parents:
2095
diff
changeset
|
878 // try temp directory if it exists. |
34d64ad817f4
7009828: Fix for 6938627 breaks visualvm monitoring when -Djava.io.tmpdir is defined
coleenp
parents:
2095
diff
changeset
|
879 if (tmpdir != NULL && tmpdir[0] != '\0') { |
34d64ad817f4
7009828: Fix for 6938627 breaks visualvm monitoring when -Djava.io.tmpdir is defined
coleenp
parents:
2095
diff
changeset
|
880 jio_snprintf(buffer, sizeof(buffer), "%s%shs_err_pid%u.log", |
34d64ad817f4
7009828: Fix for 6938627 breaks visualvm monitoring when -Djava.io.tmpdir is defined
coleenp
parents:
2095
diff
changeset
|
881 tmpdir, os::file_separator(), os::current_process_id()); |
34d64ad817f4
7009828: Fix for 6938627 breaks visualvm monitoring when -Djava.io.tmpdir is defined
coleenp
parents:
2095
diff
changeset
|
882 fd = open(buffer, O_WRONLY | O_CREAT | O_TRUNC, 0666); |
34d64ad817f4
7009828: Fix for 6938627 breaks visualvm monitoring when -Djava.io.tmpdir is defined
coleenp
parents:
2095
diff
changeset
|
883 } |
0 | 884 } |
885 | |
886 if (fd != -1) { | |
887 out.print_raw("# An error report file with more information is saved as:\n# "); | |
888 out.print_raw_cr(buffer); | |
889 os::set_error_file(buffer); | |
890 | |
891 log.set_fd(fd); | |
892 } else { | |
893 out.print_raw_cr("# Can not save log file, dump to screen.."); | |
894 log.set_fd(defaultStream::output_fd()); | |
895 } | |
896 } | |
897 | |
898 staticBufferStream sbs(buffer, O_BUFLEN, &log); | |
899 first_error->report(&sbs); | |
900 first_error->_current_step = 0; // reset current_step | |
901 first_error->_current_step_info = ""; // reset current_step string | |
902 | |
903 if (log.fd() != defaultStream::output_fd()) { | |
904 close(log.fd()); | |
905 } | |
906 | |
907 log.set_fd(-1); | |
908 log_done = true; | |
909 } | |
910 | |
911 | |
912 static bool skip_OnError = false; | |
913 if (!skip_OnError && OnError && OnError[0]) { | |
914 skip_OnError = true; | |
915 | |
916 out.print_raw_cr("#"); | |
917 out.print_raw ("# -XX:OnError=\""); | |
918 out.print_raw (OnError); | |
919 out.print_raw_cr("\""); | |
920 | |
921 char* cmd; | |
922 const char* ptr = OnError; | |
923 while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr)) != NULL){ | |
924 out.print_raw ("# Executing "); | |
925 #if defined(LINUX) | |
926 out.print_raw ("/bin/sh -c "); | |
927 #elif defined(SOLARIS) | |
928 out.print_raw ("/usr/bin/sh -c "); | |
929 #endif | |
930 out.print_raw ("\""); | |
931 out.print_raw (cmd); | |
932 out.print_raw_cr("\" ..."); | |
933 | |
934 os::fork_and_exec(cmd); | |
935 } | |
936 | |
937 // done with OnError | |
938 OnError = NULL; | |
939 } | |
940 | |
2095
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
941 static bool skip_bug_url = !should_report_bug(first_error->_id); |
0 | 942 if (!skip_bug_url) { |
943 skip_bug_url = true; | |
944 | |
945 out.print_raw_cr("#"); | |
946 print_bug_submit_message(&out, _thread); | |
947 } | |
948 | |
949 if (!UseOSErrorReporting) { | |
950 // os::abort() will call abort hooks, try it first. | |
951 static bool skip_os_abort = false; | |
952 if (!skip_os_abort) { | |
953 skip_os_abort = true; | |
2095
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
954 bool dump_core = should_report_bug(first_error->_id); |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
2022
diff
changeset
|
955 os::abort(dump_core); |
0 | 956 } |
957 | |
958 // if os::abort() doesn't abort, try os::die(); | |
959 os::die(); | |
960 } | |
961 } | |
962 | |
963 /* | |
964 * OnOutOfMemoryError scripts/commands executed while VM is a safepoint - this | |
965 * ensures utilities such as jmap can observe the process is a consistent state. | |
966 */ | |
967 class VM_ReportJavaOutOfMemory : public VM_Operation { | |
968 private: | |
969 VMError *_err; | |
970 public: | |
971 VM_ReportJavaOutOfMemory(VMError *err) { _err = err; } | |
972 VMOp_Type type() const { return VMOp_ReportJavaOutOfMemory; } | |
973 void doit(); | |
974 }; | |
975 | |
976 void VM_ReportJavaOutOfMemory::doit() { | |
977 // Don't allocate large buffer on stack | |
978 static char buffer[O_BUFLEN]; | |
979 | |
980 tty->print_cr("#"); | |
981 tty->print_cr("# java.lang.OutOfMemoryError: %s", _err->message()); | |
982 tty->print_cr("# -XX:OnOutOfMemoryError=\"%s\"", OnOutOfMemoryError); | |
983 | |
984 // make heap parsability | |
985 Universe::heap()->ensure_parsability(false); // no need to retire TLABs | |
986 | |
987 char* cmd; | |
988 const char* ptr = OnOutOfMemoryError; | |
989 while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr)) != NULL){ | |
990 tty->print("# Executing "); | |
991 #if defined(LINUX) | |
992 tty->print ("/bin/sh -c "); | |
993 #elif defined(SOLARIS) | |
994 tty->print ("/usr/bin/sh -c "); | |
995 #endif | |
996 tty->print_cr("\"%s\"...", cmd); | |
997 | |
998 os::fork_and_exec(cmd); | |
999 } | |
1000 } | |
1001 | |
1002 void VMError::report_java_out_of_memory() { | |
1003 if (OnOutOfMemoryError && OnOutOfMemoryError[0]) { | |
1004 MutexLocker ml(Heap_lock); | |
1005 VM_ReportJavaOutOfMemory op(this); | |
1006 VMThread::execute(&op); | |
1007 } | |
1008 } |