162 look = foundp + 1;
163 }
164 if (!match) continue;
165 }
166 // got a match!
167 if (noisy) {
168 fdStream out(defaultStream::output_fd());
169 out.print_raw("[error suppressed at ");
170 out.print_raw(base_name);
171 char buf[16];
172 jio_snprintf(buf, sizeof(buf), ":%d]", line_no);
173 out.print_raw_cr(buf);
174 } else {
175 // update 1-element cache for fast silent matches
176 last_file_name = file_name;
177 last_line_no = line_no;
178 }
179 return true;
180 }
181
182 if (!is_error_reported() && !SuppressFatalErrorMessage) {
183 // print a friendly hint:
184 fdStream out(defaultStream::output_fd());
185 out.print_raw_cr("# To suppress the following error report, specify this argument");
186 out.print_raw ("# after -XX: or in .hotspotrc: SuppressErrorAt=");
187 out.print_raw (base_name);
188 char buf[16];
189 jio_snprintf(buf, sizeof(buf), ":%d", line_no);
190 out.print_raw_cr(buf);
191 }
192 return false;
193 }
194
195 #undef is_token_break
196
197 #else
198
199 // Place-holder for non-existent suppression check:
200 #define error_is_suppressed(file_name, line_no) (false)
201
202 #endif // !PRODUCT
324 tty->print_cr("java.lang.OutOfMemoryError: %s", message);
325 HeapDumper::dump_heap_from_oome();
326 }
327
328 if (OnOutOfMemoryError && OnOutOfMemoryError[0]) {
329 VMError::report_java_out_of_memory(message);
330 }
331
332 if (CrashOnOutOfMemoryError) {
333 tty->print_cr("Aborting due to java.lang.OutOfMemoryError: %s", message);
334 fatal("OutOfMemory encountered: %s", message);
335 }
336
337 if (ExitOnOutOfMemoryError) {
338 tty->print_cr("Terminating due to java.lang.OutOfMemoryError: %s", message);
339 os::exit(3);
340 }
341 }
342 }
343
344 static bool error_reported = false;
345
346 // call this when the VM is dying--it might loosen some asserts
347 void set_error_reported() {
348 error_reported = true;
349 }
350
351 bool is_error_reported() {
352 return error_reported;
353 }
354
355 #ifndef PRODUCT
356 #include <signal.h>
357
358 typedef void (*voidfun_t)();
359 // Crash with an authentic sigfpe
360 static void crash_with_sigfpe() {
361 // generate a native synchronous SIGFPE where possible;
362 // if that did not cause a signal (e.g. on ppc), just
363 // raise the signal.
364 volatile int x = 0;
365 volatile int y = 1/x;
366 #ifndef _WIN32
367 // OSX implements raise(sig) incorrectly so we need to
368 // explicitly target the current thread
369 pthread_kill(pthread_self(), SIGFPE);
370 #endif
371 } // end: crash_with_sigfpe
372
373 // crash with sigsegv at non-null address.
374 static void crash_with_segfault() {
375
376 char* const crash_addr = (char*) get_segfault_address();
377 *crash_addr = 'X';
378
379 } // end: crash_with_segfault
380
381 // returns an address which is guaranteed to generate a SIGSEGV on read,
382 // for test purposes, which is not NULL and contains bits in every word
383 void* get_segfault_address() {
384 return (void*)
385 #ifdef _LP64
386 0xABC0000000000ABCULL;
387 #else
388 0x00000ABC;
389 #endif
390 }
391
392 void test_error_handler() {
393 controlled_crash(ErrorHandlerTest);
394 }
395
396 void controlled_crash(int how) {
397 if (how == 0) return;
398
399 // If asserts are disabled, use the corresponding guarantee instead.
400 NOT_DEBUG(if (how <= 2) how += 2);
401
402 const char* const str = "hello";
403 const size_t num = (size_t)os::vm_page_size();
404
405 const char* const eol = os::line_separator();
406 const char* const msg = "this message should be truncated during formatting";
407 char * const dataPtr = NULL; // bad data pointer
408 const void (*funcPtr)(void) = (const void(*)()) 0xF; // bad function pointer
409
410 // Keep this in sync with test/runtime/ErrorHandling/ErrorHandler.java
411 switch (how) {
412 case 1: vmassert(str == NULL, "expected null");
413 case 2: vmassert(num == 1023 && *str == 'X',
414 "num=" SIZE_FORMAT " str=\"%s\"", num, str);
415 case 3: guarantee(str == NULL, "expected null");
416 case 4: guarantee(num == 1023 && *str == 'X',
417 "num=" SIZE_FORMAT " str=\"%s\"", num, str);
418 case 5: fatal("expected null");
419 case 6: fatal("num=" SIZE_FORMAT " str=\"%s\"", num, str);
420 case 7: fatal("%s%s# %s%s# %s%s# %s%s# %s%s# "
421 "%s%s# %s%s# %s%s# %s%s# %s%s# "
422 "%s%s# %s%s# %s%s# %s%s# %s",
423 msg, eol, msg, eol, msg, eol, msg, eol, msg, eol,
424 msg, eol, msg, eol, msg, eol, msg, eol, msg, eol,
425 msg, eol, msg, eol, msg, eol, msg, eol, msg);
426 case 8: vm_exit_out_of_memory(num, OOM_MALLOC_ERROR, "ChunkPool::allocate");
427 case 9: ShouldNotCallThis();
428 case 10: ShouldNotReachHere();
429 case 11: Unimplemented();
430 // There's no guarantee the bad data pointer will crash us
431 // so "break" out to the ShouldNotReachHere().
432 case 12: *dataPtr = '\0'; break;
433 // There's no guarantee the bad function pointer will crash us
434 // so "break" out to the ShouldNotReachHere().
435 case 13: (*funcPtr)(); break;
436 case 14: crash_with_segfault(); break;
437 case 15: crash_with_sigfpe(); break;
438
439 default: tty->print_cr("ERROR: %d: unexpected test_num value.", how);
440 }
441 ShouldNotReachHere();
442 }
443 #endif // !PRODUCT
444
445 // ------ helper functions for debugging go here ------------
446
447 // All debug entries should be wrapped with a stack allocated
448 // Command object. It makes sure a resource mark is set and
449 // flushes the logfile to prevent file sharing problems.
450
451 class Command : public StackObj {
452 private:
453 ResourceMark rm;
454 ResetNoHandleMark rnhm;
455 HandleMark hm;
456 bool debug_save;
457 public:
458 static int level;
459 Command(const char* str) {
460 debug_save = Debugging;
461 Debugging = true;
462 if (level++ > 0) return;
463 tty->cr();
464 tty->print_cr("\"Executing %s\"", str);
578 JavaThread* p = JavaThread::active();
579 tty->print(" for thread: ");
580 p->print();
581 tty->cr();
582
583 if (p->has_last_Java_frame()) {
584 // If the last_Java_fp is set we are in C land and
585 // can call the standard stack_trace function.
586 #ifdef PRODUCT
587 p->print_stack();
588 } else {
589 tty->print_cr("Cannot find the last Java frame, printing stack disabled.");
590 #else // !PRODUCT
591 p->trace_stack();
592 } else {
593 frame f = os::current_frame();
594 RegisterMap reg_map(p);
595 f = f.sender(®_map);
596 tty->print("(guessing starting frame id=" PTR_FORMAT " based on current fp)\n", p2i(f.id()));
597 p->trace_stack_from(vframe::new_vframe(&f, ®_map, p));
598 pd_ps(f);
599 #endif // PRODUCT
600 }
601
602 }
603
604 extern "C" void pfl() {
605 // print frame layout
606 Command c("pfl");
607 JavaThread* p = JavaThread::active();
608 tty->print(" for thread: ");
609 p->print();
610 tty->cr();
611 if (p->has_last_Java_frame()) {
612 p->print_frame_layout();
613 }
614 }
615
616 #ifndef PRODUCT
617
618 extern "C" void psf() { // print stack frames
|
162 look = foundp + 1;
163 }
164 if (!match) continue;
165 }
166 // got a match!
167 if (noisy) {
168 fdStream out(defaultStream::output_fd());
169 out.print_raw("[error suppressed at ");
170 out.print_raw(base_name);
171 char buf[16];
172 jio_snprintf(buf, sizeof(buf), ":%d]", line_no);
173 out.print_raw_cr(buf);
174 } else {
175 // update 1-element cache for fast silent matches
176 last_file_name = file_name;
177 last_line_no = line_no;
178 }
179 return true;
180 }
181
182 if (!VMError::is_error_reported() && !SuppressFatalErrorMessage) {
183 // print a friendly hint:
184 fdStream out(defaultStream::output_fd());
185 out.print_raw_cr("# To suppress the following error report, specify this argument");
186 out.print_raw ("# after -XX: or in .hotspotrc: SuppressErrorAt=");
187 out.print_raw (base_name);
188 char buf[16];
189 jio_snprintf(buf, sizeof(buf), ":%d", line_no);
190 out.print_raw_cr(buf);
191 }
192 return false;
193 }
194
195 #undef is_token_break
196
197 #else
198
199 // Place-holder for non-existent suppression check:
200 #define error_is_suppressed(file_name, line_no) (false)
201
202 #endif // !PRODUCT
324 tty->print_cr("java.lang.OutOfMemoryError: %s", message);
325 HeapDumper::dump_heap_from_oome();
326 }
327
328 if (OnOutOfMemoryError && OnOutOfMemoryError[0]) {
329 VMError::report_java_out_of_memory(message);
330 }
331
332 if (CrashOnOutOfMemoryError) {
333 tty->print_cr("Aborting due to java.lang.OutOfMemoryError: %s", message);
334 fatal("OutOfMemory encountered: %s", message);
335 }
336
337 if (ExitOnOutOfMemoryError) {
338 tty->print_cr("Terminating due to java.lang.OutOfMemoryError: %s", message);
339 os::exit(3);
340 }
341 }
342 }
343
344 // ------ helper functions for debugging go here ------------
345
346 // All debug entries should be wrapped with a stack allocated
347 // Command object. It makes sure a resource mark is set and
348 // flushes the logfile to prevent file sharing problems.
349
350 class Command : public StackObj {
351 private:
352 ResourceMark rm;
353 ResetNoHandleMark rnhm;
354 HandleMark hm;
355 bool debug_save;
356 public:
357 static int level;
358 Command(const char* str) {
359 debug_save = Debugging;
360 Debugging = true;
361 if (level++ > 0) return;
362 tty->cr();
363 tty->print_cr("\"Executing %s\"", str);
477 JavaThread* p = JavaThread::active();
478 tty->print(" for thread: ");
479 p->print();
480 tty->cr();
481
482 if (p->has_last_Java_frame()) {
483 // If the last_Java_fp is set we are in C land and
484 // can call the standard stack_trace function.
485 #ifdef PRODUCT
486 p->print_stack();
487 } else {
488 tty->print_cr("Cannot find the last Java frame, printing stack disabled.");
489 #else // !PRODUCT
490 p->trace_stack();
491 } else {
492 frame f = os::current_frame();
493 RegisterMap reg_map(p);
494 f = f.sender(®_map);
495 tty->print("(guessing starting frame id=" PTR_FORMAT " based on current fp)\n", p2i(f.id()));
496 p->trace_stack_from(vframe::new_vframe(&f, ®_map, p));
497 f.pd_ps();
498 #endif // PRODUCT
499 }
500
501 }
502
503 extern "C" void pfl() {
504 // print frame layout
505 Command c("pfl");
506 JavaThread* p = JavaThread::active();
507 tty->print(" for thread: ");
508 p->print();
509 tty->cr();
510 if (p->has_last_Java_frame()) {
511 p->print_frame_layout();
512 }
513 }
514
515 #ifndef PRODUCT
516
517 extern "C" void psf() { // print stack frames
|