336 void VMError::report(outputStream* st) {
337 # define BEGIN if (_current_step == 0) { _current_step = 1;
338 # define STEP(n, s) } if (_current_step < n) { _current_step = n; _current_step_info = s;
339 # define END }
340
341 // don't allocate large buffer on stack
342 static char buf[O_BUFLEN];
343
344 BEGIN
345
346 STEP(10, "(printing fatal error message)")
347
348 st->print_cr("#");
349 if (should_report_bug(_id)) {
350 st->print_cr("# A fatal error has been detected by the Java Runtime Environment:");
351 } else {
352 st->print_cr("# There is insufficient memory for the Java "
353 "Runtime Environment to continue.");
354 }
355
356 STEP(15, "(printing type of error)")
357
358 switch(_id) {
359 case OOM_MALLOC_ERROR:
360 case OOM_MMAP_ERROR:
361 if (_size) {
362 st->print("# Native memory allocation ");
363 st->print((_id == (int)OOM_MALLOC_ERROR) ? "(malloc) failed to allocate " :
364 "(mmap) failed to map ");
365 jio_snprintf(buf, sizeof(buf), SIZE_FORMAT, _size);
366 st->print("%s", buf);
367 st->print(" bytes");
368 if (_message != NULL) {
369 st->print(" for ");
370 st->print("%s", _message);
371 }
372 st->cr();
373 } else {
374 if (_message != NULL)
375 st->print("# ");
769
770 if (_verbose) {
771 os::print_memory_info(st);
772 st->cr();
773 }
774
775 STEP(270, "(printing internal vm info)" )
776
777 if (_verbose) {
778 st->print_cr("vm_info: %s", Abstract_VM_Version::internal_vm_info_string());
779 st->cr();
780 }
781
782 STEP(280, "(printing date and time)" )
783
784 if (_verbose) {
785 os::print_date_and_time(st);
786 st->cr();
787 }
788
789 END
790
791 # undef BEGIN
792 # undef STEP
793 # undef END
794 }
795
796 VMError* volatile VMError::first_error = NULL;
797 volatile jlong VMError::first_error_tid = -1;
798
799 // An error could happen before tty is initialized or after it has been
800 // destroyed. Here we use a very simple unbuffered fdStream for printing.
801 // Only out.print_raw() and out.print_raw_cr() should be used, as other
802 // printing methods need to allocate large buffer on stack. To format a
803 // string, use jio_snprintf() with a static buffer or use staticBufferStream.
804 fdStream VMError::out(defaultStream::output_fd());
805 fdStream VMError::log; // error log used by VMError::report_and_die()
806
807 /** Expand a pattern into a buffer starting at pos and open a file using constructed path */
808 static int expand_and_open(const char* pattern, char* buf, size_t buflen, size_t pos) {
|
336 void VMError::report(outputStream* st) {
337 # define BEGIN if (_current_step == 0) { _current_step = 1;
338 # define STEP(n, s) } if (_current_step < n) { _current_step = n; _current_step_info = s;
339 # define END }
340
341 // don't allocate large buffer on stack
342 static char buf[O_BUFLEN];
343
344 BEGIN
345
346 STEP(10, "(printing fatal error message)")
347
348 st->print_cr("#");
349 if (should_report_bug(_id)) {
350 st->print_cr("# A fatal error has been detected by the Java Runtime Environment:");
351 } else {
352 st->print_cr("# There is insufficient memory for the Java "
353 "Runtime Environment to continue.");
354 }
355
356 #ifndef PRODUCT
357 // Error handler self tests
358
359 // test secondary error handling. Test it twice, to test that resetting
360 // error handler after a secondary crash works.
361 STEP(13, "(test secondary crash 1)")
362 if (_verbose && TestCrashInErrorHandler != 0) {
363 st->print_cr("Will crash now (TestCrashInErrorHandler=%d)...",
364 TestCrashInErrorHandler);
365 controlled_crash(TestCrashInErrorHandler);
366 }
367
368 STEP(14, "(test secondary crash 2)")
369 if (_verbose && TestCrashInErrorHandler != 0) {
370 st->print_cr("Will crash now (TestCrashInErrorHandler=%d)...",
371 TestCrashInErrorHandler);
372 controlled_crash(TestCrashInErrorHandler);
373 }
374 #endif // PRODUCT
375
376 STEP(15, "(printing type of error)")
377
378 switch(_id) {
379 case OOM_MALLOC_ERROR:
380 case OOM_MMAP_ERROR:
381 if (_size) {
382 st->print("# Native memory allocation ");
383 st->print((_id == (int)OOM_MALLOC_ERROR) ? "(malloc) failed to allocate " :
384 "(mmap) failed to map ");
385 jio_snprintf(buf, sizeof(buf), SIZE_FORMAT, _size);
386 st->print("%s", buf);
387 st->print(" bytes");
388 if (_message != NULL) {
389 st->print(" for ");
390 st->print("%s", _message);
391 }
392 st->cr();
393 } else {
394 if (_message != NULL)
395 st->print("# ");
789
790 if (_verbose) {
791 os::print_memory_info(st);
792 st->cr();
793 }
794
795 STEP(270, "(printing internal vm info)" )
796
797 if (_verbose) {
798 st->print_cr("vm_info: %s", Abstract_VM_Version::internal_vm_info_string());
799 st->cr();
800 }
801
802 STEP(280, "(printing date and time)" )
803
804 if (_verbose) {
805 os::print_date_and_time(st);
806 st->cr();
807 }
808
809 #ifndef PRODUCT
810 // print a defined marker to show that error handling finished correctly.
811 STEP(290, "(printing end marker)" )
812
813 if (_verbose) {
814 st->print_cr("END.");
815 }
816 #endif
817
818 END
819
820 # undef BEGIN
821 # undef STEP
822 # undef END
823 }
824
825 VMError* volatile VMError::first_error = NULL;
826 volatile jlong VMError::first_error_tid = -1;
827
828 // An error could happen before tty is initialized or after it has been
829 // destroyed. Here we use a very simple unbuffered fdStream for printing.
830 // Only out.print_raw() and out.print_raw_cr() should be used, as other
831 // printing methods need to allocate large buffer on stack. To format a
832 // string, use jio_snprintf() with a static buffer or use staticBufferStream.
833 fdStream VMError::out(defaultStream::output_fd());
834 fdStream VMError::log; // error log used by VMError::report_and_die()
835
836 /** Expand a pattern into a buffer starting at pos and open a file using constructed path */
837 static int expand_and_open(const char* pattern, char* buf, size_t buflen, size_t pos) {
|