src/share/vm/utilities/vmError.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 8026324.01 Sdiff src/share/vm/utilities

src/share/vm/utilities/vmError.cpp

Print this page




 289     for(int i = 0; !sfs.is_done(); sfs.next(), i++) {
 290       sfs.current()->zero_print_on_error(i, st, buf, buflen);
 291       st->cr();
 292     }
 293 
 294     // Reset the frame anchor if necessary
 295     if (!has_last_Java_frame)
 296       jt->reset_last_Java_frame();
 297   }
 298 #else
 299   if (jt->has_last_Java_frame()) {
 300     st->print_cr("Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)");
 301     for(StackFrameStream sfs(jt); !sfs.is_done(); sfs.next()) {
 302       sfs.current()->print_on_error(st, buf, buflen, verbose);
 303       st->cr();
 304     }
 305   }
 306 #endif // ZERO
 307 }
 308 
























 309 // This is the main function to report a fatal error. Only one thread can
 310 // call this function, so we don't need to worry about MT-safety. But it's
 311 // possible that the error handler itself may crash or die on an internal
 312 // error, for example, when the stack/heap is badly damaged. We must be
 313 // able to handle recursive errors that happen inside error handler.
 314 //
 315 // Error reporting is done in several steps. If a crash or internal error
 316 // occurred when reporting an error, the nested signal/exception handler
 317 // can skip steps that are already (or partially) done. Error reporting will
 318 // continue from the next step. This allows us to retrieve and print
 319 // information that may be unsafe to get after a fatal error. If it happens,
 320 // you may find nested report_and_die() frames when you look at the stack
 321 // in a debugger.
 322 //
 323 // In general, a hang in error handler is much worse than a crash or internal
 324 // error, as it's harder to recover from a hang. Deadlock can happen if we
 325 // try to grab a lock that is already owned by current thread, or if the
 326 // owner is blocked forever (e.g. in os::infinite_sleep()). If possible, the
 327 // error handler and all the functions it called should avoid grabbing any
 328 // lock. An important thing to notice is that memory allocation needs a lock.


 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(11, "(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(12, "(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 
 375   STEP(13, "(test safefetch in error handler)")
 376     // test whether it is safe to use SafeFetch32 in Crash Handler. Test twice
 377     // to test that resetting the signal handler works correctly.
 378     if (_verbose && TestSafeFetchInErrorHandler) {
 379       st->print_cr("Will test SafeFetch...");
 380       if (CanUseSafeFetch32()) {
 381         int* const invalid_pointer = (int*) get_segfault_address();
 382         const int x = 0x76543210;
 383         int i1 = SafeFetch32(invalid_pointer, x);
 384         int i2 = SafeFetch32(invalid_pointer, x);
 385         if (i1 == x && i2 == x) {
 386           st->print_cr("SafeFetch OK."); // Correctly deflected and returned default pattern
 387         } else {
 388           st->print_cr("??");
 389         }
 390       } else {
 391         st->print_cr("not possible; skipped.");
 392       }
 393     }
 394 #endif // PRODUCT
 395 
 396   STEP(15, "(printing type of error)")
 397 
 398      switch(_id) {
 399        case OOM_MALLOC_ERROR:
 400        case OOM_MMAP_ERROR:
 401          if (_size) {
 402            st->print("# Native memory allocation ");
 403            st->print((_id == (int)OOM_MALLOC_ERROR) ? "(malloc) failed to allocate " :
 404                                                  "(mmap) failed to map ");
 405            jio_snprintf(buf, sizeof(buf), SIZE_FORMAT, _size);
 406            st->print("%s", buf);
 407            st->print(" bytes");
 408            if (_message != NULL) {
 409              st->print(" for ");
 410              st->print("%s", _message);
 411            }
 412            st->cr();
 413          } else {
 414            if (_message != NULL) {
 415              st->print("# ");
 416              st->print_cr("%s", _message);
 417            }
 418          }
 419          // In error file give some solutions
 420          if (_verbose) {
 421            st->print_cr("# Possible reasons:");
 422            st->print_cr("#   The system is out of physical RAM or swap space");
 423            st->print_cr("#   In 32 bit mode, the process size limit was hit");
 424            st->print_cr("# Possible solutions:");
 425            st->print_cr("#   Reduce memory load on the system");
 426            st->print_cr("#   Increase physical memory or swap space");
 427            st->print_cr("#   Check if swap backing store is full");
 428            st->print_cr("#   Use 64 bit Java on a 64 bit OS");
 429            st->print_cr("#   Decrease Java heap size (-Xmx/-Xms)");
 430            st->print_cr("#   Decrease number of Java threads");
 431            st->print_cr("#   Decrease Java thread stack sizes (-Xss)");
 432            st->print_cr("#   Set larger code cache with -XX:ReservedCodeCacheSize=");
 433            st->print_cr("# This output file may be truncated or incomplete.");
 434          } else {
 435            return;  // that's enough for the screen
 436          }
 437          break;
 438        case INTERNAL_ERROR:
 439        default:
 440          break;
 441      }
 442 
 443   STEP(20, "(printing exception/signal name)")
 444 
 445      st->print_cr("#");
 446      st->print("#  ");
 447      // Is it an OS exception/signal?
 448      if (os::exception_name(_id, buf, sizeof(buf))) {
 449        st->print("%s", buf);
 450        st->print(" (0x%x)", _id);                // signal number
 451        st->print(" at pc=" PTR_FORMAT, _pc);
 452      } else {
 453        if (should_report_bug(_id)) {
 454          st->print("Internal Error");
 455        } else {
 456          st->print("Out of Memory Error");
 457        }
 458        if (_filename != NULL && _lineno > 0) {
 459 #ifdef PRODUCT
 460          // In product mode chop off pathname?
 461          char separator = os::file_separator()[0];
 462          const char *p = strrchr(_filename, separator);
 463          const char *file = p ? p+1 : _filename;
 464 #else
 465          const char *file = _filename;
 466 #endif
 467          st->print(" (%s:%d)", file, _lineno);
 468        } else {
 469          st->print(" (0x%x)", _id);
 470        }
 471      }
 472 
 473   STEP(30, "(printing current thread and pid)")
 474 
 475      // process id, thread id
 476      st->print(", pid=%d", os::current_process_id());
 477      st->print(", tid=" INTPTR_FORMAT, os::current_thread_id());
 478      st->cr();
 479 
 480   STEP(40, "(printing error message)")
 481 
 482      if (should_report_bug(_id)) {  // already printed the message.
 483        // error message
 484        if (_detail_msg) {
 485          st->print_cr("#  %s: %s", _message ? _message : "Error", _detail_msg);
 486        } else if (_message) {
 487          st->print_cr("#  Error: %s", _message);
 488        }
 489     }
 490 
 491   STEP(50, "(printing Java version string)")
 492 
 493      // VM version
 494      st->print_cr("#");
 495      JDK_Version::current().to_string(buf, sizeof(buf));
 496      const char* runtime_name = JDK_Version::runtime_name() != NULL ?
 497                                   JDK_Version::runtime_name() : "";
 498      const char* runtime_version = JDK_Version::runtime_version() != NULL ?
 499                                   JDK_Version::runtime_version() : "";
 500      st->print_cr("# JRE version: %s (%s) (build %s)", runtime_name, buf, runtime_version);
 501      st->print_cr("# Java VM: %s (%s %s %s %s)",

 502                    Abstract_VM_Version::vm_name(),
 503                    Abstract_VM_Version::vm_release(),
 504                    Abstract_VM_Version::vm_info_string(),
 505                    Abstract_VM_Version::vm_platform_string(),
 506                    UseCompressedOops ? "compressed oops" : ""


 507                  );
 508 
 509   STEP(60, "(printing problematic frame)")
 510 
 511      // Print current frame if we have a context (i.e. it's a crash)
 512      if (_context) {
 513        st->print_cr("# Problematic frame:");
 514        st->print("# ");
 515        frame fr = os::fetch_frame_from_context(_context);
 516        fr.print_on_error(st, buf, sizeof(buf));
 517        st->cr();
 518        st->print_cr("#");
 519      }
 520   STEP(63, "(printing core file information)")

 521     st->print("# ");
 522     if (CreateCoredumpOnCrash) {
 523       if (coredump_status) {
 524         st->print("Core dump will be written. Default location: %s", coredump_message);
 525       } else {
 526         st->print("No core dump will be written. %s", coredump_message);
 527       }
 528     } else {
 529       st->print("CreateCoredumpOnCrash turned off, no core file dumped");
 530     }
 531     st->cr();
 532     st->print_cr("#");
 533 
 534   STEP(65, "(printing bug submit message)")
 535 
 536      if (should_report_bug(_id) && _verbose) {
 537        print_bug_submit_message(st, _thread);
 538      }
 539 
 540   STEP(70, "(printing thread)" )





























 541 
 542      if (_verbose) {
 543        st->cr();
 544        st->print_cr("---------------  T H R E A D  ---------------");
 545        st->cr();
 546      }
 547 
 548   STEP(80, "(printing current thread)" )
 549 
 550      // current thread
 551      if (_verbose) {
 552        if (_thread) {
 553          st->print("Current thread (" PTR_FORMAT "):  ", _thread);
 554          _thread->print_on_error(st, buf, sizeof(buf));
 555          st->cr();
 556        } else {
 557          st->print_cr("Current thread is native thread");
 558        }
 559        st->cr();
 560      }
 561 
 562   STEP(90, "(printing siginfo)" )
 563 
 564      // signal no, signal code, address that caused the fault
 565      if (_verbose && _siginfo) {
 566        os::print_siginfo(st, _siginfo);
 567        st->cr();
 568      }
 569 
 570   STEP(100, "(printing registers, top of stack, instructions near pc)")
 571 
 572      // registers, top of stack, instructions near pc
 573      if (_verbose && _context) {
 574        os::print_context(st, _context);
 575        st->cr();
 576      }
 577 
 578   STEP(105, "(printing register info)")
 579 
 580      // decode register contents if possible
 581      if (_verbose && _context && Universe::is_fully_initialized()) {
 582        os::print_register_info(st, _context);
 583        st->cr();
 584      }
 585 
 586   STEP(110, "(printing stack bounds)" )

 587 
 588      if (_verbose) {
 589        st->print("Stack: ");
 590 
 591        address stack_top;
 592        size_t stack_size;
 593 
 594        if (_thread) {
 595           stack_top = _thread->stack_base();
 596           stack_size = _thread->stack_size();
 597        } else {
 598           stack_top = os::current_stack_base();
 599           stack_size = os::current_stack_size();
 600        }
 601 
 602        address stack_bottom = stack_top - stack_size;
 603        st->print("[" PTR_FORMAT "," PTR_FORMAT "]", stack_bottom, stack_top);
 604 
 605        frame fr = _context ? os::fetch_frame_from_context(_context)
 606                            : os::current_frame();
 607 
 608        if (fr.sp()) {
 609          st->print(",  sp=" PTR_FORMAT, fr.sp());
 610          size_t free_stack_size = pointer_delta(fr.sp(), stack_bottom, 1024);
 611          st->print(",  free space=" SIZE_FORMAT "k", free_stack_size);
 612        }
 613 
 614        st->cr();
 615      }
 616 
 617   STEP(120, "(printing native stack)" )
 618 
 619    if (_verbose) {
 620      if (os::platform_print_native_stack(st, _context, buf, sizeof(buf))) {
 621        // We have printed the native stack in platform-specific code
 622        // Windows/x64 needs special handling.
 623      } else {
 624        frame fr = _context ? os::fetch_frame_from_context(_context)
 625                            : os::current_frame();
 626 
 627        print_native_stack(st, fr, _thread, buf, sizeof(buf));
 628      }
 629    }
 630 
 631   STEP(130, "(printing Java stack)" )
 632 
 633      if (_verbose && _thread && _thread->is_Java_thread()) {
 634        print_stack_trace(st, (JavaThread*)_thread, buf, sizeof(buf));
 635      }
 636 
 637   STEP(135, "(printing target Java thread stack)" )
 638 
 639      // printing Java thread stack trace if it is involved in GC crash
 640      if (_verbose && _thread && (_thread->is_Named_thread())) {
 641        JavaThread*  jt = ((NamedThread *)_thread)->processed_thread();
 642        if (jt != NULL) {
 643          st->print_cr("JavaThread " PTR_FORMAT " (nid = " UINTX_FORMAT ") was being processed", jt, jt->osthread()->thread_id());
 644          print_stack_trace(st, jt, buf, sizeof(buf), true);
 645        }
 646      }
 647 
 648   STEP(140, "(printing VM operation)" )
 649 
 650      if (_verbose && _thread && _thread->is_VM_thread()) {
 651         VMThread* t = (VMThread*)_thread;
 652         VM_Operation* op = t->vm_operation();
 653         if (op) {
 654           op->print_on_error(st);
 655           st->cr();







 656           st->cr();
 657         }







 658      }
 659 
 660   STEP(150, "(printing current compile task)" )
 661 
 662      if (_verbose && _thread && _thread->is_Compiler_thread()) {
 663         CompilerThread* t = (CompilerThread*)_thread;
 664         if (t->task()) {


 665            st->cr();
 666            st->print_cr("Current CompileTask:");
 667            t->task()->print_line_on_error(st, buf, sizeof(buf));
 668            st->cr();
 669         }
 670      }
 671 
 672   STEP(160, "(printing process)" )
 673 
 674      if (_verbose) {
 675        st->cr();
 676        st->print_cr("---------------  P R O C E S S  ---------------");
 677        st->cr();
 678      }
 679 
 680   STEP(170, "(printing all threads)" )
 681 
 682      // all threads
 683      if (_verbose && _thread) {
 684        Threads::print_on_error(st, _thread, buf, sizeof(buf));
 685        st->cr();
 686      }
 687 
 688   STEP(175, "(printing VM state)" )
 689 
 690      if (_verbose) {
 691        // Safepoint state
 692        st->print("VM state:");
 693 
 694        if (SafepointSynchronize::is_synchronizing()) st->print("synchronizing");
 695        else if (SafepointSynchronize::is_at_safepoint()) st->print("at safepoint");
 696        else st->print("not at safepoint");
 697 
 698        // Also see if error occurred during initialization or shutdown
 699        if (!Universe::is_fully_initialized()) {
 700          st->print(" (not fully initialized)");
 701        } else if (VM_Exit::vm_exited()) {
 702          st->print(" (shutting down)");
 703        } else {
 704          st->print(" (normal execution)");
 705        }
 706        st->cr();
 707        st->cr();
 708      }
 709 
 710   STEP(180, "(printing owned locks on error)" )
 711 
 712      // mutexes/monitors that currently have an owner
 713      if (_verbose) {
 714        print_owned_locks_on_error(st);
 715        st->cr();
 716      }
 717 
 718   STEP(182, "(printing number of OutOfMemoryError and StackOverflow exceptions)")
 719 
 720      if (_verbose && Exceptions::has_exception_counts()) {
 721        st->print_cr("OutOfMemory and StackOverflow Exception counts:");
 722        Exceptions::print_exception_counts_on_error(st);
 723        st->cr();
 724      }
 725 
 726   STEP(185, "(printing compressed oops mode")
 727 
 728      if (_verbose && UseCompressedOops) {
 729        Universe::print_compressed_oops_mode(st);
 730        if (UseCompressedClassPointers) {
 731          Metaspace::print_compressed_class_space(st);
 732        }
 733        st->cr();
 734      }
 735 
 736   STEP(190, "(printing heap information)" )
 737 
 738      if (_verbose && Universe::is_fully_initialized()) {
 739        Universe::heap()->print_on_error(st);
 740        st->cr();
 741 
 742        st->print_cr("Polling page: " INTPTR_FORMAT, os::get_polling_page());
 743        st->cr();
 744      }
 745 
 746   STEP(195, "(printing code cache information)" )
 747 
 748      if (_verbose && Universe::is_fully_initialized()) {
 749        // print code cache information before vm abort
 750        CodeCache::print_summary(st);
 751        st->cr();
 752      }
 753 
 754   STEP(200, "(printing ring buffers)" )
 755 
 756      if (_verbose) {
 757        Events::print_all(st);
 758        st->cr();
 759      }
 760 
 761   STEP(205, "(printing dynamic libraries)" )
 762 
 763      if (_verbose) {
 764        // dynamic libraries, or memory map
 765        os::print_dll_info(st);
 766        st->cr();
 767      }
 768 
 769   STEP(210, "(printing VM options)" )
 770 
 771      if (_verbose) {
 772        // VM options
 773        Arguments::print_on(st);
 774        st->cr();
 775      }
 776 
 777   STEP(215, "(printing warning if internal testing API used)" )

 778 
 779      if (WhiteBox::used()) {
 780        st->print_cr("Unsupported internal testing APIs have been used.");
 781        st->cr();
 782      }
 783 
 784   STEP(220, "(printing environment variables)" )
 785 
 786      if (_verbose) {
 787        os::print_environment_variables(st, env_list);
 788        st->cr();
 789      }
 790 
 791   STEP(225, "(printing signal handlers)" )
 792 
 793      if (_verbose) {
 794        os::print_signal_handlers(st, buf, sizeof(buf));
 795        st->cr();
 796      }
 797 
 798   STEP(228, "(Native Memory Tracking)" )
 799      if (_verbose) {
 800        MemTracker::error_report(st);
 801      }
 802 
 803   STEP(230, "" )
 804 
 805      if (_verbose) {
 806        st->cr();
 807        st->print_cr("---------------  S Y S T E M  ---------------");
 808        st->cr();
 809      }
 810 
 811   STEP(240, "(printing OS information)" )
 812 
 813      if (_verbose) {
 814        os::print_os_info(st);
 815        st->cr();
 816      }
 817 
 818   STEP(250, "(printing CPU info)" )
 819      if (_verbose) {
 820        os::print_cpu_info(st, buf, sizeof(buf));
 821        st->cr();
 822      }
 823 
 824   STEP(260, "(printing memory info)" )
 825 
 826      if (_verbose) {
 827        os::print_memory_info(st);
 828        st->cr();
 829      }
 830 
 831   STEP(270, "(printing internal vm info)" )
 832 
 833      if (_verbose) {
 834        st->print_cr("vm_info: %s", Abstract_VM_Version::internal_vm_info_string());
 835        st->cr();
 836      }
 837 
 838   STEP(280, "(printing date and time)" )
 839 
 840      if (_verbose) {
 841        os::print_date_and_time(st, buf, sizeof(buf));
 842        st->cr();
 843      }
 844 
 845 #ifndef PRODUCT
 846   // print a defined marker to show that error handling finished correctly.
 847   STEP(290, "(printing end marker)" )
 848 
 849      if (_verbose) {
 850        st->print_cr("END.");
 851      }
 852 #endif
 853 
 854   END
 855 
 856 # undef BEGIN
 857 # undef STEP
 858 # undef END
 859 }
 860 
 861 VMError* volatile VMError::first_error = NULL;
 862 volatile jlong VMError::first_error_tid = -1;
 863 
 864 // An error could happen before tty is initialized or after it has been
 865 // destroyed. Here we use a very simple unbuffered fdStream for printing.
 866 // Only out.print_raw() and out.print_raw_cr() should be used, as other
 867 // printing methods need to allocate large buffer on stack. To format a
 868 // string, use jio_snprintf() with a static buffer or use staticBufferStream.
 869 fdStream VMError::out(defaultStream::output_fd());
 870 fdStream VMError::log; // error log used by VMError::report_and_die()
 871 
 872 /** Expand a pattern into a buffer starting at pos and open a file using constructed path */




 289     for(int i = 0; !sfs.is_done(); sfs.next(), i++) {
 290       sfs.current()->zero_print_on_error(i, st, buf, buflen);
 291       st->cr();
 292     }
 293 
 294     // Reset the frame anchor if necessary
 295     if (!has_last_Java_frame)
 296       jt->reset_last_Java_frame();
 297   }
 298 #else
 299   if (jt->has_last_Java_frame()) {
 300     st->print_cr("Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)");
 301     for(StackFrameStream sfs(jt); !sfs.is_done(); sfs.next()) {
 302       sfs.current()->print_on_error(st, buf, buflen, verbose);
 303       st->cr();
 304     }
 305   }
 306 #endif // ZERO
 307 }
 308 
 309 void VMError::print_oom_reasons(outputStream* st) {
 310   st->print_cr("# Possible reasons:");
 311   st->print_cr("#   The system is out of physical RAM or swap space");
 312   st->print_cr("#   In 32 bit mode, the process size limit was hit");
 313   st->print_cr("# Possible solutions:");
 314   st->print_cr("#   Reduce memory load on the system");
 315   st->print_cr("#   Increase physical memory or swap space");
 316   st->print_cr("#   Check if swap backing store is full");
 317   st->print_cr("#   Use 64 bit Java on a 64 bit OS");
 318   st->print_cr("#   Decrease Java heap size (-Xmx/-Xms)");
 319   st->print_cr("#   Decrease number of Java threads");
 320   st->print_cr("#   Decrease Java thread stack sizes (-Xss)");
 321   st->print_cr("#   Set larger code cache with -XX:ReservedCodeCacheSize=");
 322   st->print_cr("# This output file may be truncated or incomplete.");
 323 }
 324 
 325 const char* VMError::gc_mode() {
 326   if (UseG1GC)            return "g1 gc";
 327   if (UseParallelGC)      return "parallel gc";
 328   if (UseConcMarkSweepGC) return "concurrent mark sweep gc";
 329   if (UseSerialGC)        return "serial gc";
 330   return "ERROR in GC mode";
 331 }
 332 
 333 // This is the main function to report a fatal error. Only one thread can
 334 // call this function, so we don't need to worry about MT-safety. But it's
 335 // possible that the error handler itself may crash or die on an internal
 336 // error, for example, when the stack/heap is badly damaged. We must be
 337 // able to handle recursive errors that happen inside error handler.
 338 //
 339 // Error reporting is done in several steps. If a crash or internal error
 340 // occurred when reporting an error, the nested signal/exception handler
 341 // can skip steps that are already (or partially) done. Error reporting will
 342 // continue from the next step. This allows us to retrieve and print
 343 // information that may be unsafe to get after a fatal error. If it happens,
 344 // you may find nested report_and_die() frames when you look at the stack
 345 // in a debugger.
 346 //
 347 // In general, a hang in error handler is much worse than a crash or internal
 348 // error, as it's harder to recover from a hang. Deadlock can happen if we
 349 // try to grab a lock that is already owned by current thread, or if the
 350 // owner is blocked forever (e.g. in os::infinite_sleep()). If possible, the
 351 // error handler and all the functions it called should avoid grabbing any
 352 // lock. An important thing to notice is that memory allocation needs a lock.


 365   // don't allocate large buffer on stack
 366   static char buf[O_BUFLEN];
 367 
 368   BEGIN
 369 
 370   STEP(10, "(printing fatal error message)")
 371 
 372     st->print_cr("#");
 373     if (should_report_bug(_id)) {
 374       st->print_cr("# A fatal error has been detected by the Java Runtime Environment:");
 375     } else {
 376       st->print_cr("# There is insufficient memory for the Java "
 377                    "Runtime Environment to continue.");
 378     }
 379 
 380 #ifndef PRODUCT
 381   // Error handler self tests
 382 
 383   // test secondary error handling. Test it twice, to test that resetting
 384   // error handler after a secondary crash works.
 385   STEP(20, "(test secondary crash 1)")
 386     if (_verbose && TestCrashInErrorHandler != 0) {
 387       st->print_cr("Will crash now (TestCrashInErrorHandler=%d)...",
 388         TestCrashInErrorHandler);
 389       controlled_crash(TestCrashInErrorHandler);
 390     }
 391 
 392   STEP(30, "(test secondary crash 2)")
 393     if (_verbose && TestCrashInErrorHandler != 0) {
 394       st->print_cr("Will crash now (TestCrashInErrorHandler=%d)...",
 395         TestCrashInErrorHandler);
 396       controlled_crash(TestCrashInErrorHandler);
 397     }
 398 
 399   STEP(40, "(test safefetch in error handler)")
 400     // test whether it is safe to use SafeFetch32 in Crash Handler. Test twice
 401     // to test that resetting the signal handler works correctly.
 402     if (_verbose && TestSafeFetchInErrorHandler) {
 403       st->print_cr("Will test SafeFetch...");
 404       if (CanUseSafeFetch32()) {
 405         int* const invalid_pointer = (int*) get_segfault_address();
 406         const int x = 0x76543210;
 407         int i1 = SafeFetch32(invalid_pointer, x);
 408         int i2 = SafeFetch32(invalid_pointer, x);
 409         if (i1 == x && i2 == x) {
 410           st->print_cr("SafeFetch OK."); // Correctly deflected and returned default pattern
 411         } else {
 412           st->print_cr("??");
 413         }
 414       } else {
 415         st->print_cr("not possible; skipped.");
 416       }
 417     }
 418 #endif // PRODUCT
 419 
 420   STEP(50, "(printing type of error)")
 421 
 422      switch(_id) {
 423        case OOM_MALLOC_ERROR:
 424        case OOM_MMAP_ERROR:
 425          if (_size) {
 426            st->print("# Native memory allocation ");
 427            st->print((_id == (int)OOM_MALLOC_ERROR) ? "(malloc) failed to allocate " :
 428                                                  "(mmap) failed to map ");
 429            jio_snprintf(buf, sizeof(buf), SIZE_FORMAT, _size);
 430            st->print("%s", buf);
 431            st->print(" bytes");
 432            if (_message != NULL) {
 433              st->print(" for ");
 434              st->print("%s", _message);
 435            }
 436            st->cr();
 437          } else {
 438            if (_message != NULL) {
 439              st->print("# ");
 440              st->print_cr("%s", _message);
 441            }
 442          }
 443          // In error file give some solutions
 444          if (_verbose) {
 445            print_oom_reasons(st);












 446          } else {
 447            return;  // that's enough for the screen
 448          }
 449          break;
 450        case INTERNAL_ERROR:
 451        default:
 452          break;
 453      }
 454 
 455   STEP(60, "(printing exception/signal name)")
 456 
 457      st->print_cr("#");
 458      st->print("#  ");
 459      // Is it an OS exception/signal?
 460      if (os::exception_name(_id, buf, sizeof(buf))) {
 461        st->print("%s", buf);
 462        st->print(" (0x%x)", _id);                // signal number
 463        st->print(" at pc=" PTR_FORMAT, _pc);
 464      } else {
 465        if (should_report_bug(_id)) {
 466          st->print("Internal Error");
 467        } else {
 468          st->print("Out of Memory Error");
 469        }
 470        if (_filename != NULL && _lineno > 0) {
 471 #ifdef PRODUCT
 472          // In product mode chop off pathname?
 473          char separator = os::file_separator()[0];
 474          const char *p = strrchr(_filename, separator);
 475          const char *file = p ? p+1 : _filename;
 476 #else
 477          const char *file = _filename;
 478 #endif
 479          st->print(" (%s:%d)", file, _lineno);
 480        } else {
 481          st->print(" (0x%x)", _id);
 482        }
 483      }
 484 
 485   STEP(70, "(printing current thread and pid)")
 486 
 487      // process id, thread id
 488      st->print(", pid=%d", os::current_process_id());
 489      st->print(", tid=" INTPTR_FORMAT, os::current_thread_id());
 490      st->cr();
 491 
 492   STEP(80, "(printing error message)")
 493 
 494      if (should_report_bug(_id)) {  // already printed the message.
 495        // error message
 496        if (_detail_msg) {
 497          st->print_cr("#  %s: %s", _message ? _message : "Error", _detail_msg);
 498        } else if (_message) {
 499          st->print_cr("#  Error: %s", _message);
 500        }
 501     }
 502 
 503   STEP(90, "(printing Java version string)")
 504 
 505      // VM version
 506      st->print_cr("#");
 507      JDK_Version::current().to_string(buf, sizeof(buf));
 508      const char* runtime_name = JDK_Version::runtime_name() != NULL ?
 509                                   JDK_Version::runtime_name() : "";
 510      const char* runtime_version = JDK_Version::runtime_version() != NULL ?
 511                                   JDK_Version::runtime_version() : "";
 512      st->print_cr("# JRE version: %s (%s) (build %s)", runtime_name, buf, runtime_version);
 513      // This is the long version with some default settings added
 514      st->print_cr("# Java VM: %s (%s, %s%s%s, %s, %s)",
 515                    Abstract_VM_Version::vm_name(),
 516                    Abstract_VM_Version::vm_release(),
 517                    Abstract_VM_Version::vm_info_string(),
 518                    TieredCompilation ? ", tiered" : "",
 519                    UseCompressedOops ? ", compressed oops" : "",
 520                    gc_mode(),
 521                    Abstract_VM_Version::vm_platform_string()
 522                  );
 523 
 524   STEP(100, "(printing problematic frame)")
 525 
 526      // Print current frame if we have a context (i.e. it's a crash)
 527      if (_context) {
 528        st->print_cr("# Problematic frame:");
 529        st->print("# ");
 530        frame fr = os::fetch_frame_from_context(_context);
 531        fr.print_on_error(st, buf, sizeof(buf));
 532        st->cr();
 533        st->print_cr("#");
 534      }
 535 
 536   STEP(110, "(printing core file information)")
 537     st->print("# ");
 538     if (CreateCoredumpOnCrash) {
 539       if (coredump_status) {
 540         st->print("Core dump will be written. Default location: %s", coredump_message);
 541       } else {
 542         st->print("No core dump will be written. %s", coredump_message);
 543       }
 544     } else {
 545       st->print("CreateCoredumpOnCrash turned off, no core file dumped");
 546     }
 547     st->cr();
 548     st->print_cr("#");
 549 
 550   STEP(120, "(printing bug submit message)")
 551 
 552      if (should_report_bug(_id) && _verbose) {
 553        print_bug_submit_message(st, _thread);
 554      }
 555 
 556   STEP(130, "(printing summary)" )
 557 
 558      if (_verbose) {
 559        st->cr();
 560        st->print_cr("---------------  S U M M A R Y ------------");
 561        st->cr();
 562      }
 563 
 564   STEP(140, "(printing VM options)" )
 565 
 566      if (_verbose) {
 567        // VM options
 568        Arguments::print_summary_on(st);
 569        st->cr();
 570      }
 571 
 572   STEP(150, "(printing summary machine and OS info)")
 573 
 574      if (_verbose) {
 575        os::print_summary_info(st, buf, sizeof(buf));
 576      }
 577 
 578 
 579   STEP(160, "(printing date and time)" )
 580 
 581      if (_verbose) {
 582        os::print_date_and_time(st, buf, sizeof(buf));
 583      }
 584 
 585   STEP(170, "(printing thread)" )
 586 
 587      if (_verbose) {
 588        st->cr();
 589        st->print_cr("---------------  T H R E A D  ---------------");
 590        st->cr();
 591      }
 592 
 593   STEP(180, "(printing current thread)" )
 594 
 595      // current thread
 596      if (_verbose) {
 597        if (_thread) {
 598          st->print("Current thread (" PTR_FORMAT "):  ", _thread);
 599          _thread->print_on_error(st, buf, sizeof(buf));
 600          st->cr();
 601        } else {
 602          st->print_cr("Current thread is native thread");
 603        }
 604        st->cr();
 605      }
 606 
 607   STEP(190, "(printing current compile task)" )
 608 
 609      if (_verbose && _thread && _thread->is_Compiler_thread()) {
 610         CompilerThread* t = (CompilerThread*)_thread;
 611         if (t->task()) {
 612            st->cr();
 613            st->print_cr("Current CompileTask:");
 614            t->task()->print_line_on_error(st, buf, sizeof(buf));





 615            st->cr();
 616         }







 617      }
 618 
 619 
 620   STEP(200, "(printing stack bounds)" )
 621 
 622      if (_verbose) {
 623        st->print("Stack: ");
 624 
 625        address stack_top;
 626        size_t stack_size;
 627 
 628        if (_thread) {
 629           stack_top = _thread->stack_base();
 630           stack_size = _thread->stack_size();
 631        } else {
 632           stack_top = os::current_stack_base();
 633           stack_size = os::current_stack_size();
 634        }
 635 
 636        address stack_bottom = stack_top - stack_size;
 637        st->print("[" PTR_FORMAT "," PTR_FORMAT "]", stack_bottom, stack_top);
 638 
 639        frame fr = _context ? os::fetch_frame_from_context(_context)
 640                            : os::current_frame();
 641 
 642        if (fr.sp()) {
 643          st->print(",  sp=" PTR_FORMAT, fr.sp());
 644          size_t free_stack_size = pointer_delta(fr.sp(), stack_bottom, 1024);
 645          st->print(",  free space=" SIZE_FORMAT "k", free_stack_size);
 646        }
 647 
 648        st->cr();
 649      }
 650 
 651   STEP(210, "(printing native stack)" )
 652 
 653    if (_verbose) {
 654      if (os::platform_print_native_stack(st, _context, buf, sizeof(buf))) {
 655        // We have printed the native stack in platform-specific code
 656        // Windows/x64 needs special handling.
 657      } else {
 658        frame fr = _context ? os::fetch_frame_from_context(_context)
 659                            : os::current_frame();
 660 
 661        print_native_stack(st, fr, _thread, buf, sizeof(buf));
 662      }
 663    }
 664 
 665   STEP(220, "(printing Java stack)" )
 666 
 667      if (_verbose && _thread && _thread->is_Java_thread()) {
 668        print_stack_trace(st, (JavaThread*)_thread, buf, sizeof(buf));
 669      }
 670 
 671   STEP(230, "(printing target Java thread stack)" )
 672 
 673      // printing Java thread stack trace if it is involved in GC crash
 674      if (_verbose && _thread && (_thread->is_Named_thread())) {
 675        JavaThread*  jt = ((NamedThread *)_thread)->processed_thread();
 676        if (jt != NULL) {
 677          st->print_cr("JavaThread " PTR_FORMAT " (nid = " UINTX_FORMAT ") was being processed", jt, jt->osthread()->thread_id());
 678          print_stack_trace(st, jt, buf, sizeof(buf), true);
 679        }
 680      }
 681 
 682   STEP(240, "(printing siginfo)" )
 683 
 684      // signal no, signal code, address that caused the fault
 685      if (_verbose && _siginfo) {
 686        st->cr();
 687        os::print_siginfo(st, _siginfo);

 688        st->cr();
 689      }
 690 
 691   STEP(250, "(printing register info)")
 692 
 693      // decode register contents if possible
 694      if (_verbose && _context && Universe::is_fully_initialized()) {
 695        os::print_register_info(st, _context);
 696        st->cr();
 697      }
 698 
 699   STEP(260, "(printing registers, top of stack, instructions near pc)")
 700 
 701      // registers, top of stack, instructions near pc
 702      if (_verbose && _context) {
 703        os::print_context(st, _context);
 704        st->cr();
 705      }
 706 
 707   STEP(270, "(printing VM operation)" )
 708 
 709      if (_verbose && _thread && _thread->is_VM_thread()) {
 710         VMThread* t = (VMThread*)_thread;
 711         VM_Operation* op = t->vm_operation();
 712         if (op) {
 713           op->print_on_error(st);
 714           st->cr();


 715           st->cr();
 716         }
 717      }
 718 
 719   STEP(280, "(printing process)" )
 720 
 721      if (_verbose) {
 722        st->cr();
 723        st->print_cr("---------------  P R O C E S S  ---------------");
 724        st->cr();
 725      }
 726 
 727   STEP(290, "(printing all threads)" )
 728 
 729      // all threads
 730      if (_verbose && _thread) {
 731        Threads::print_on_error(st, _thread, buf, sizeof(buf));
 732        st->cr();
 733      }
 734 
 735   STEP(300, "(printing VM state)" )
 736 
 737      if (_verbose) {
 738        // Safepoint state
 739        st->print("VM state:");
 740 
 741        if (SafepointSynchronize::is_synchronizing()) st->print("synchronizing");
 742        else if (SafepointSynchronize::is_at_safepoint()) st->print("at safepoint");
 743        else st->print("not at safepoint");
 744 
 745        // Also see if error occurred during initialization or shutdown
 746        if (!Universe::is_fully_initialized()) {
 747          st->print(" (not fully initialized)");
 748        } else if (VM_Exit::vm_exited()) {
 749          st->print(" (shutting down)");
 750        } else {
 751          st->print(" (normal execution)");
 752        }
 753        st->cr();
 754        st->cr();
 755      }
 756 
 757   STEP(310, "(printing owned locks on error)" )
 758 
 759      // mutexes/monitors that currently have an owner
 760      if (_verbose) {
 761        print_owned_locks_on_error(st);
 762        st->cr();
 763      }
 764 
 765   STEP(320, "(printing number of OutOfMemoryError and StackOverflow exceptions)")
 766 
 767      if (_verbose && Exceptions::has_exception_counts()) {
 768        st->print_cr("OutOfMemory and StackOverflow Exception counts:");
 769        Exceptions::print_exception_counts_on_error(st);
 770        st->cr();
 771      }
 772 
 773   STEP(330, "(printing compressed oops mode")
 774 
 775      if (_verbose && UseCompressedOops) {
 776        Universe::print_compressed_oops_mode(st);
 777        if (UseCompressedClassPointers) {
 778          Metaspace::print_compressed_class_space(st);
 779        }
 780        st->cr();
 781      }
 782 
 783   STEP(340, "(printing heap information)" )
 784 
 785      if (_verbose && Universe::is_fully_initialized()) {
 786        Universe::heap()->print_on_error(st);
 787        st->cr();
 788 
 789        st->print_cr("Polling page: " INTPTR_FORMAT, os::get_polling_page());
 790        st->cr();
 791      }
 792 
 793   STEP(350, "(printing code cache information)" )
 794 
 795      if (_verbose && Universe::is_fully_initialized()) {
 796        // print code cache information before vm abort
 797        CodeCache::print_summary(st);
 798        st->cr();
 799      }
 800 
 801   STEP(360, "(printing ring buffers)" )
 802 
 803      if (_verbose) {
 804        Events::print_all(st);
 805        st->cr();
 806      }
 807 
 808   STEP(370, "(printing dynamic libraries)" )
 809 
 810      if (_verbose) {
 811        // dynamic libraries, or memory map
 812        os::print_dll_info(st);
 813        st->cr();
 814      }
 815 
 816   STEP(380, "(printing VM options)" )
 817 
 818      if (_verbose) {
 819        // VM options
 820        Arguments::print_on(st);
 821        st->cr();
 822      }
 823   
 824 
 825   STEP(390, "(printing warning if internal testing API used)" )
 826 
 827      if (WhiteBox::used()) {
 828        st->print_cr("Unsupported internal testing APIs have been used.");
 829        st->cr();
 830      }
 831 
 832   STEP(400, "(printing all environment variables)" )
 833 
 834      if (_verbose) {
 835        os::print_environment_variables(st, env_list);
 836        st->cr();
 837      }
 838 
 839   STEP(410, "(printing signal handlers)" )
 840 
 841      if (_verbose) {
 842        os::print_signal_handlers(st, buf, sizeof(buf));
 843        st->cr();
 844      }
 845 
 846   STEP(420, "(Native Memory Tracking)" )
 847      if (_verbose) {
 848        MemTracker::error_report(st);
 849      }
 850 
 851   STEP(430, "(printing system)" )
 852 
 853      if (_verbose) {
 854        st->cr();
 855        st->print_cr("---------------  S Y S T E M  ---------------");
 856        st->cr();
 857      }
 858 
 859   STEP(440, "(printing OS information)" )
 860 
 861      if (_verbose) {
 862        os::print_os_info(st);
 863        st->cr();
 864      }
 865 
 866   STEP(450, "(printing CPU info)" )
 867      if (_verbose) {
 868        os::print_cpu_info(st, buf, sizeof(buf));
 869        st->cr();
 870      }
 871 
 872   STEP(460, "(printing memory info)" )
 873 
 874      if (_verbose) {
 875        os::print_memory_info(st);
 876        st->cr();
 877      }
 878 
 879   STEP(470, "(printing internal vm info)" )
 880 
 881      if (_verbose) {
 882        st->print_cr("vm_info: %s", Abstract_VM_Version::internal_vm_info_string());
 883        st->cr();
 884      }
 885 








 886   // print a defined marker to show that error handling finished correctly.
 887   STEP(480, "(printing end marker)" )
 888 
 889      if (_verbose) {
 890        st->print_cr("END.");
 891      }

 892 
 893   END
 894 
 895 # undef BEGIN
 896 # undef STEP
 897 # undef END
 898 }
 899 
 900 VMError* volatile VMError::first_error = NULL;
 901 volatile jlong VMError::first_error_tid = -1;
 902 
 903 // An error could happen before tty is initialized or after it has been
 904 // destroyed. Here we use a very simple unbuffered fdStream for printing.
 905 // Only out.print_raw() and out.print_raw_cr() should be used, as other
 906 // printing methods need to allocate large buffer on stack. To format a
 907 // string, use jio_snprintf() with a static buffer or use staticBufferStream.
 908 fdStream VMError::out(defaultStream::output_fd());
 909 fdStream VMError::log; // error log used by VMError::report_and_die()
 910 
 911 /** Expand a pattern into a buffer starting at pos and open a file using constructed path */


src/share/vm/utilities/vmError.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File