64 # endif // _DEBUG
65 #endif // ASSERT
66
67
68 #ifdef _DEBUG
69 # ifndef ASSERT
70 configuration error: ASSERT must be defined in debug version
71 # endif // ASSERT
72 #endif // _DEBUG
73
74
75 #ifdef PRODUCT
76 # if -defined _DEBUG || -defined ASSERT
77 configuration error: ASSERT et al. must not be defined in PRODUCT version
78 # endif
79 #endif // PRODUCT
80
81 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
82
83 FormatBufferResource::FormatBufferResource(const char * format, ...)
84 : FormatBufferBase((char*)resource_allocate_bytes(RES_BUFSZ)) {
85 va_list argp;
86 va_start(argp, format);
87 jio_vsnprintf(_buf, RES_BUFSZ, format, argp);
88 va_end(argp);
89 }
90
91 ATTRIBUTE_PRINTF(1, 2)
92 void warning(const char* format, ...) {
93 if (PrintWarnings) {
94 FILE* const err = defaultStream::error_stream();
95 jio_fprintf(err, "%s warning: ", VM_Version::vm_name());
96 va_list ap;
97 va_start(ap, format);
98 vfprintf(err, format, ap);
99 va_end(ap);
100 fputc('\n', err);
101 }
102 if (BreakAtWarning) BREAKPOINT;
103 }
104
105 #ifndef PRODUCT
106
107 #define is_token_break(ch) (isspace(ch) || (ch) == ',')
190 fdStream out(defaultStream::output_fd());
191 out.print_raw_cr("# To suppress the following error report, specify this argument");
192 out.print_raw ("# after -XX: or in .hotspotrc: SuppressErrorAt=");
193 out.print_raw (base_name);
194 char buf[16];
195 jio_snprintf(buf, sizeof(buf), ":%d", line_no);
196 out.print_raw_cr(buf);
197 }
198 return false;
199 }
200
201 #undef is_token_break
202
203 #else
204
205 // Place-holder for non-existent suppression check:
206 #define error_is_suppressed(file_name, line_no) (false)
207
208 #endif // !PRODUCT
209
210 void report_vm_error(const char* file, int line, const char* error_msg,
211 const char* detail_msg)
212 {
213 if (Debugging || error_is_suppressed(file, line)) return;
214 Thread* const thread = ThreadLocalStorage::get_thread_slow();
215 VMError err(thread, file, line, error_msg, detail_msg);
216 err.report_and_die();
217 }
218
219 void report_fatal(const char* file, int line, const char* message)
220 {
221 report_vm_error(file, line, "fatal error", message);
222 }
223
224 void report_vm_out_of_memory(const char* file, int line, size_t size,
225 VMErrorType vm_err_type, const char* message) {
226 if (Debugging) return;
227
228 Thread* thread = ThreadLocalStorage::get_thread_slow();
229 VMError(thread, file, line, size, vm_err_type, message).report_and_die();
230
231 // The UseOSErrorReporting option in report_and_die() may allow a return
232 // to here. If so then we'll have to figure out how to handle it.
233 guarantee(false, "report_and_die() should not return here");
234 }
235
236 void report_should_not_call(const char* file, int line) {
237 report_vm_error(file, line, "ShouldNotCall()");
238 }
239
240 void report_should_not_reach_here(const char* file, int line) {
241 report_vm_error(file, line, "ShouldNotReachHere()");
242 }
243
244 void report_unimplemented(const char* file, int line) {
245 report_vm_error(file, line, "Unimplemented()");
246 }
247
248 void report_untested(const char* file, int line, const char* message) {
249 #ifndef PRODUCT
278 "or increase the size to at least " SIZE_FORMAT ".\n",
279 MaxMetaspaceSize, required_size);
280 exit(2);
281 }
282
283 void report_java_out_of_memory(const char* message) {
284 static jint out_of_memory_reported = 0;
285
286 // A number of threads may attempt to report OutOfMemoryError at around the
287 // same time. To avoid dumping the heap or executing the data collection
288 // commands multiple times we just do it once when the first threads reports
289 // the error.
290 if (Atomic::cmpxchg(1, &out_of_memory_reported, 0) == 0) {
291 // create heap dump before OnOutOfMemoryError commands are executed
292 if (HeapDumpOnOutOfMemoryError) {
293 tty->print_cr("java.lang.OutOfMemoryError: %s", message);
294 HeapDumper::dump_heap_from_oome();
295 }
296
297 if (OnOutOfMemoryError && OnOutOfMemoryError[0]) {
298 VMError err(message);
299 err.report_java_out_of_memory();
300 }
301 }
302 }
303
304 static bool error_reported = false;
305
306 // call this when the VM is dying--it might loosen some asserts
307 void set_error_reported() {
308 error_reported = true;
309 }
310
311 bool is_error_reported() {
312 return error_reported;
313 }
314
315 #ifndef PRODUCT
316 #include <signal.h>
317
318 typedef void (*voidfun_t)();
319 // Crash with an authentic sigfpe
352 }
353
354 void controlled_crash(int how) {
355 if (how == 0) return;
356
357 // If asserts are disabled, use the corresponding guarantee instead.
358 NOT_DEBUG(if (how <= 2) how += 2);
359
360 const char* const str = "hello";
361 const size_t num = (size_t)os::vm_page_size();
362
363 const char* const eol = os::line_separator();
364 const char* const msg = "this message should be truncated during formatting";
365 char * const dataPtr = NULL; // bad data pointer
366 const void (*funcPtr)(void) = (const void(*)()) 0xF; // bad function pointer
367
368 // Keep this in sync with test/runtime/6888954/vmerrors.sh.
369 switch (how) {
370 case 1: vmassert(str == NULL, "expected null");
371 case 2: vmassert(num == 1023 && *str == 'X',
372 err_msg("num=" SIZE_FORMAT " str=\"%s\"", num, str));
373 case 3: guarantee(str == NULL, "expected null");
374 case 4: guarantee(num == 1023 && *str == 'X',
375 err_msg("num=" SIZE_FORMAT " str=\"%s\"", num, str));
376 case 5: fatal("expected null");
377 case 6: fatal(err_msg("num=" SIZE_FORMAT " str=\"%s\"", num, str));
378 case 7: fatal(err_msg("%s%s# %s%s# %s%s# %s%s# %s%s# "
379 "%s%s# %s%s# %s%s# %s%s# %s%s# "
380 "%s%s# %s%s# %s%s# %s%s# %s",
381 msg, eol, msg, eol, msg, eol, msg, eol, msg, eol,
382 msg, eol, msg, eol, msg, eol, msg, eol, msg, eol,
383 msg, eol, msg, eol, msg, eol, msg, eol, msg));
384 case 8: vm_exit_out_of_memory(num, OOM_MALLOC_ERROR, "ChunkPool::allocate");
385 case 9: ShouldNotCallThis();
386 case 10: ShouldNotReachHere();
387 case 11: Unimplemented();
388 // There's no guarantee the bad data pointer will crash us
389 // so "break" out to the ShouldNotReachHere().
390 case 12: *dataPtr = '\0'; break;
391 // There's no guarantee the bad function pointer will crash us
392 // so "break" out to the ShouldNotReachHere().
393 case 13: (*funcPtr)(); break;
394 case 14: crash_with_segfault(); break;
395 case 15: crash_with_sigfpe(); break;
396
397 default: tty->print_cr("ERROR: %d: unexpected test_num value.", how);
398 }
399 ShouldNotReachHere();
400 }
401 #endif // !PRODUCT
402
403 // ------ helper functions for debugging go here ------------
|
64 # endif // _DEBUG
65 #endif // ASSERT
66
67
68 #ifdef _DEBUG
69 # ifndef ASSERT
70 configuration error: ASSERT must be defined in debug version
71 # endif // ASSERT
72 #endif // _DEBUG
73
74
75 #ifdef PRODUCT
76 # if -defined _DEBUG || -defined ASSERT
77 configuration error: ASSERT et al. must not be defined in PRODUCT version
78 # endif
79 #endif // PRODUCT
80
81 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
82
83 FormatBufferResource::FormatBufferResource(const char * format, ...)
84 : FormatBufferBase((char*)resource_allocate_bytes(FormatBufferBase::BufferSize)) {
85 va_list argp;
86 va_start(argp, format);
87 jio_vsnprintf(_buf, FormatBufferBase::BufferSize, format, argp);
88 va_end(argp);
89 }
90
91 ATTRIBUTE_PRINTF(1, 2)
92 void warning(const char* format, ...) {
93 if (PrintWarnings) {
94 FILE* const err = defaultStream::error_stream();
95 jio_fprintf(err, "%s warning: ", VM_Version::vm_name());
96 va_list ap;
97 va_start(ap, format);
98 vfprintf(err, format, ap);
99 va_end(ap);
100 fputc('\n', err);
101 }
102 if (BreakAtWarning) BREAKPOINT;
103 }
104
105 #ifndef PRODUCT
106
107 #define is_token_break(ch) (isspace(ch) || (ch) == ',')
190 fdStream out(defaultStream::output_fd());
191 out.print_raw_cr("# To suppress the following error report, specify this argument");
192 out.print_raw ("# after -XX: or in .hotspotrc: SuppressErrorAt=");
193 out.print_raw (base_name);
194 char buf[16];
195 jio_snprintf(buf, sizeof(buf), ":%d", line_no);
196 out.print_raw_cr(buf);
197 }
198 return false;
199 }
200
201 #undef is_token_break
202
203 #else
204
205 // Place-holder for non-existent suppression check:
206 #define error_is_suppressed(file_name, line_no) (false)
207
208 #endif // !PRODUCT
209
210 void report_vm_error(const char* file, int line, const char* error_msg)
211 {
212 report_vm_error(file, line, error_msg, "%s", "");
213 }
214
215 void report_vm_error(const char* file, int line, const char* error_msg, const char* detail_fmt, ...)
216 {
217 if (Debugging || error_is_suppressed(file, line)) return;
218 va_list detail_args;
219 va_start(detail_args, detail_fmt);
220 VMError::report_and_die(ThreadLocalStorage::get_thread_slow(), file, line, error_msg, detail_fmt, detail_args);
221 va_end(detail_args);
222 }
223
224 void report_fatal(const char* file, int line, const char* detail_fmt, ...)
225 {
226 if (Debugging || error_is_suppressed(file, line)) return;
227 va_list detail_args;
228 va_start(detail_args, detail_fmt);
229 VMError::report_and_die(ThreadLocalStorage::get_thread_slow(), file, line, "fatal error", detail_fmt, detail_args);
230 va_end(detail_args);
231 }
232
233 void report_vm_out_of_memory(const char* file, int line, size_t size,
234 VMErrorType vm_err_type, const char* detail_fmt, ...) {
235 if (Debugging) return;
236 va_list detail_args;
237 va_start(detail_args, detail_fmt);
238 VMError::report_and_die(ThreadLocalStorage::get_thread_slow(), file, line, size, vm_err_type, detail_fmt, detail_args);
239 va_end(detail_args);
240
241 // The UseOSErrorReporting option in report_and_die() may allow a return
242 // to here. If so then we'll have to figure out how to handle it.
243 guarantee(false, "report_and_die() should not return here");
244 }
245
246 void report_should_not_call(const char* file, int line) {
247 report_vm_error(file, line, "ShouldNotCall()");
248 }
249
250 void report_should_not_reach_here(const char* file, int line) {
251 report_vm_error(file, line, "ShouldNotReachHere()");
252 }
253
254 void report_unimplemented(const char* file, int line) {
255 report_vm_error(file, line, "Unimplemented()");
256 }
257
258 void report_untested(const char* file, int line, const char* message) {
259 #ifndef PRODUCT
288 "or increase the size to at least " SIZE_FORMAT ".\n",
289 MaxMetaspaceSize, required_size);
290 exit(2);
291 }
292
293 void report_java_out_of_memory(const char* message) {
294 static jint out_of_memory_reported = 0;
295
296 // A number of threads may attempt to report OutOfMemoryError at around the
297 // same time. To avoid dumping the heap or executing the data collection
298 // commands multiple times we just do it once when the first threads reports
299 // the error.
300 if (Atomic::cmpxchg(1, &out_of_memory_reported, 0) == 0) {
301 // create heap dump before OnOutOfMemoryError commands are executed
302 if (HeapDumpOnOutOfMemoryError) {
303 tty->print_cr("java.lang.OutOfMemoryError: %s", message);
304 HeapDumper::dump_heap_from_oome();
305 }
306
307 if (OnOutOfMemoryError && OnOutOfMemoryError[0]) {
308 VMError::report_java_out_of_memory(message);
309 }
310 }
311 }
312
313 static bool error_reported = false;
314
315 // call this when the VM is dying--it might loosen some asserts
316 void set_error_reported() {
317 error_reported = true;
318 }
319
320 bool is_error_reported() {
321 return error_reported;
322 }
323
324 #ifndef PRODUCT
325 #include <signal.h>
326
327 typedef void (*voidfun_t)();
328 // Crash with an authentic sigfpe
361 }
362
363 void controlled_crash(int how) {
364 if (how == 0) return;
365
366 // If asserts are disabled, use the corresponding guarantee instead.
367 NOT_DEBUG(if (how <= 2) how += 2);
368
369 const char* const str = "hello";
370 const size_t num = (size_t)os::vm_page_size();
371
372 const char* const eol = os::line_separator();
373 const char* const msg = "this message should be truncated during formatting";
374 char * const dataPtr = NULL; // bad data pointer
375 const void (*funcPtr)(void) = (const void(*)()) 0xF; // bad function pointer
376
377 // Keep this in sync with test/runtime/6888954/vmerrors.sh.
378 switch (how) {
379 case 1: vmassert(str == NULL, "expected null");
380 case 2: vmassert(num == 1023 && *str == 'X',
381 "num=" SIZE_FORMAT " str=\"%s\"", num, str);
382 case 3: guarantee(str == NULL, "expected null");
383 case 4: guarantee(num == 1023 && *str == 'X',
384 "num=" SIZE_FORMAT " str=\"%s\"", num, str);
385 case 5: fatal("expected null");
386 case 6: fatal("num=" SIZE_FORMAT " str=\"%s\"", num, str);
387 case 7: fatal("%s%s# %s%s# %s%s# %s%s# %s%s# "
388 "%s%s# %s%s# %s%s# %s%s# %s%s# "
389 "%s%s# %s%s# %s%s# %s%s# %s",
390 msg, eol, msg, eol, msg, eol, msg, eol, msg, eol,
391 msg, eol, msg, eol, msg, eol, msg, eol, msg, eol,
392 msg, eol, msg, eol, msg, eol, msg, eol, msg);
393 case 8: vm_exit_out_of_memory(num, OOM_MALLOC_ERROR, "ChunkPool::allocate");
394 case 9: ShouldNotCallThis();
395 case 10: ShouldNotReachHere();
396 case 11: Unimplemented();
397 // There's no guarantee the bad data pointer will crash us
398 // so "break" out to the ShouldNotReachHere().
399 case 12: *dataPtr = '\0'; break;
400 // There's no guarantee the bad function pointer will crash us
401 // so "break" out to the ShouldNotReachHere().
402 case 13: (*funcPtr)(); break;
403 case 14: crash_with_segfault(); break;
404 case 15: crash_with_sigfpe(); break;
405
406 default: tty->print_cr("ERROR: %d: unexpected test_num value.", how);
407 }
408 ShouldNotReachHere();
409 }
410 #endif // !PRODUCT
411
412 // ------ helper functions for debugging go here ------------
|