hotspot/src/share/vm/utilities/vmError.cpp

Print this page




 195     if (_filename != NULL && _lineno > 0) {
 196       // skip directory names
 197       char separator = os::file_separator()[0];
 198       const char *p = strrchr(_filename, separator);
 199 
 200       jio_snprintf(buf, buflen,
 201         "Internal Error at %s:%d, pid=%d, tid=" UINTX_FORMAT " \nError: %s",
 202         p ? p + 1 : _filename, _lineno,
 203         os::current_process_id(), os::current_thread_id(),
 204         _message ? _message : "");
 205     } else {
 206       jio_snprintf(buf, buflen,
 207         "Internal Error (0x%x), pid=%d, tid=" UINTX_FORMAT,
 208         _id, os::current_process_id(), os::current_thread_id());
 209     }
 210   }
 211 
 212   return buf;
 213 }
 214 













































 215 
 216 // This is the main function to report a fatal error. Only one thread can
 217 // call this function, so we don't need to worry about MT-safety. But it's
 218 // possible that the error handler itself may crash or die on an internal
 219 // error, for example, when the stack/heap is badly damaged. We must be
 220 // able to handle recursive errors that happen inside error handler.
 221 //
 222 // Error reporting is done in several steps. If a crash or internal error
 223 // occurred when reporting an error, the nested signal/exception handler
 224 // can skip steps that are already (or partially) done. Error reporting will
 225 // continue from the next step. This allows us to retrieve and print
 226 // information that may be unsafe to get after a fatal error. If it happens,
 227 // you may find nested report_and_die() frames when you look at the stack
 228 // in a debugger.
 229 //
 230 // In general, a hang in error handler is much worse than a crash or internal
 231 // error, as it's harder to recover from a hang. Deadlock can happen if we
 232 // try to grab a lock that is already owned by current thread, or if the
 233 // owner is blocked forever (e.g. in os::infinite_sleep()). If possible, the
 234 // error handler and all the functions it called should avoid grabbing any


 440           int count = 0;
 441 
 442           while (count++ < StackPrintLimit) {
 443              fr.print_on_error(st, buf, sizeof(buf));
 444              st->cr();
 445              if (os::is_first_C_frame(&fr)) break;
 446              fr = os::get_sender_for_C_frame(&fr);
 447           }
 448 
 449           if (count > StackPrintLimit) {
 450              st->print_cr("...<more frames>...");
 451           }
 452 
 453           st->cr();
 454        }
 455      }
 456 
 457   STEP(130, "(printing Java stack)" )
 458 
 459      if (_verbose && _thread && _thread->is_Java_thread()) {
 460        JavaThread* jt = (JavaThread*)_thread;
 461 #ifdef ZERO
 462        if (jt->zero_stack()->sp() && jt->top_zero_frame()) {
 463          // StackFrameStream uses the frame anchor, which may not have
 464          // been set up.  This can be done at any time in Zero, however,
 465          // so if it hasn't been set up then we just set it up now and
 466          // clear it again when we're done.
 467          bool has_last_Java_frame = jt->has_last_Java_frame();
 468          if (!has_last_Java_frame)
 469            jt->set_last_Java_frame();
 470          st->print("Java frames:");
 471 
 472          // If the top frame is a Shark frame and the frame anchor isn't
 473          // set up then it's possible that the information in the frame
 474          // is garbage: it could be from a previous decache, or it could
 475          // simply have never been written.  So we print a warning...
 476          StackFrameStream sfs(jt);
 477          if (!has_last_Java_frame && !sfs.is_done()) {
 478            if (sfs.current()->zeroframe()->is_shark_frame()) {
 479              st->print(" (TOP FRAME MAY BE JUNK)");
 480            }
 481          }
 482          st->cr();
 483 
 484          // Print the frames
 485          for(int i = 0; !sfs.is_done(); sfs.next(), i++) {
 486            sfs.current()->zero_print_on_error(i, st, buf, sizeof(buf));
 487            st->cr();
 488          }
 489 
 490          // Reset the frame anchor if necessary
 491          if (!has_last_Java_frame)
 492            jt->reset_last_Java_frame();
 493        }
 494 #else
 495        if (jt->has_last_Java_frame()) {
 496          st->print_cr("Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)");
 497          for(StackFrameStream sfs(jt); !sfs.is_done(); sfs.next()) {
 498            sfs.current()->print_on_error(st, buf, sizeof(buf));
 499            st->cr();
 500          }
 501        }
 502 #endif // ZERO
 503      }
 504 
 505   STEP(135, "(printing target Java thread stack)" )
 506 
 507      // printing Java thread stack trace if it is involved in GC crash
 508      if (_verbose && (_thread->is_Named_thread())) {
 509        JavaThread*  jt = ((NamedThread *)_thread)->processed_thread();
 510        if (jt != NULL) {
 511          st->print_cr("JavaThread " PTR_FORMAT " (nid = " UINTX_FORMAT ") was being processed", jt, jt->osthread()->thread_id());
 512          if (jt->has_last_Java_frame()) {
 513            st->print_cr("Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)");
 514            for(StackFrameStream sfs(jt); !sfs.is_done(); sfs.next()) {
 515              sfs.current()->print_on_error(st, buf, sizeof(buf), true);
 516              st->cr();
 517            }
 518          }
 519        }
 520      }
 521 
 522   STEP(140, "(printing VM operation)" )
 523 
 524      if (_verbose && _thread && _thread->is_VM_thread()) {
 525         VMThread* t = (VMThread*)_thread;
 526         VM_Operation* op = t->vm_operation();
 527         if (op) {
 528           op->print_on_error(st);
 529           st->cr();
 530           st->cr();
 531         }
 532      }
 533 
 534   STEP(150, "(printing current compile task)" )
 535 
 536      if (_verbose && _thread && _thread->is_Compiler_thread()) {
 537         CompilerThread* t = (CompilerThread*)_thread;
 538         if (t->task()) {




 195     if (_filename != NULL && _lineno > 0) {
 196       // skip directory names
 197       char separator = os::file_separator()[0];
 198       const char *p = strrchr(_filename, separator);
 199 
 200       jio_snprintf(buf, buflen,
 201         "Internal Error at %s:%d, pid=%d, tid=" UINTX_FORMAT " \nError: %s",
 202         p ? p + 1 : _filename, _lineno,
 203         os::current_process_id(), os::current_thread_id(),
 204         _message ? _message : "");
 205     } else {
 206       jio_snprintf(buf, buflen,
 207         "Internal Error (0x%x), pid=%d, tid=" UINTX_FORMAT,
 208         _id, os::current_process_id(), os::current_thread_id());
 209     }
 210   }
 211 
 212   return buf;
 213 }
 214 
 215 void VMError::print_stack_trace(outputStream* st, JavaThread* jt,
 216                                 char* buf, int buflen, bool verbose) {
 217 #ifdef ZERO
 218   if (jt->zero_stack()->sp() && jt->top_zero_frame()) {
 219     // StackFrameStream uses the frame anchor, which may not have
 220     // been set up.  This can be done at any time in Zero, however,
 221     // so if it hasn't been set up then we just set it up now and
 222     // clear it again when we're done.
 223     bool has_last_Java_frame = jt->has_last_Java_frame();
 224     if (!has_last_Java_frame)
 225       jt->set_last_Java_frame();
 226     st->print("Java frames:");
 227 
 228     // If the top frame is a Shark frame and the frame anchor isn't
 229     // set up then it's possible that the information in the frame
 230     // is garbage: it could be from a previous decache, or it could
 231     // simply have never been written.  So we print a warning...
 232     StackFrameStream sfs(jt);
 233     if (!has_last_Java_frame && !sfs.is_done()) {
 234       if (sfs.current()->zeroframe()->is_shark_frame()) {
 235         st->print(" (TOP FRAME MAY BE JUNK)");
 236       }
 237     }
 238     st->cr();
 239 
 240     // Print the frames
 241     for(int i = 0; !sfs.is_done(); sfs.next(), i++) {
 242       sfs.current()->zero_print_on_error(i, st, buf, buflen);
 243       st->cr();
 244     }
 245 
 246     // Reset the frame anchor if necessary
 247     if (!has_last_Java_frame)
 248       jt->reset_last_Java_frame();
 249   }
 250 #else
 251   if (jt->has_last_Java_frame()) {
 252     st->print_cr("Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)");
 253     for(StackFrameStream sfs(jt); !sfs.is_done(); sfs.next()) {
 254       sfs.current()->print_on_error(st, buf, buflen, verbose);
 255       st->cr();
 256     }
 257   }
 258 #endif // ZERO
 259 }
 260 
 261 // This is the main function to report a fatal error. Only one thread can
 262 // call this function, so we don't need to worry about MT-safety. But it's
 263 // possible that the error handler itself may crash or die on an internal
 264 // error, for example, when the stack/heap is badly damaged. We must be
 265 // able to handle recursive errors that happen inside error handler.
 266 //
 267 // Error reporting is done in several steps. If a crash or internal error
 268 // occurred when reporting an error, the nested signal/exception handler
 269 // can skip steps that are already (or partially) done. Error reporting will
 270 // continue from the next step. This allows us to retrieve and print
 271 // information that may be unsafe to get after a fatal error. If it happens,
 272 // you may find nested report_and_die() frames when you look at the stack
 273 // in a debugger.
 274 //
 275 // In general, a hang in error handler is much worse than a crash or internal
 276 // error, as it's harder to recover from a hang. Deadlock can happen if we
 277 // try to grab a lock that is already owned by current thread, or if the
 278 // owner is blocked forever (e.g. in os::infinite_sleep()). If possible, the
 279 // error handler and all the functions it called should avoid grabbing any


 485           int count = 0;
 486 
 487           while (count++ < StackPrintLimit) {
 488              fr.print_on_error(st, buf, sizeof(buf));
 489              st->cr();
 490              if (os::is_first_C_frame(&fr)) break;
 491              fr = os::get_sender_for_C_frame(&fr);
 492           }
 493 
 494           if (count > StackPrintLimit) {
 495              st->print_cr("...<more frames>...");
 496           }
 497 
 498           st->cr();
 499        }
 500      }
 501 
 502   STEP(130, "(printing Java stack)" )
 503 
 504      if (_verbose && _thread && _thread->is_Java_thread()) {
 505        print_stack_trace(st, (JavaThread*)_thread, buf, sizeof(buf));










































 506      }
 507 
 508   STEP(135, "(printing target Java thread stack)" )
 509 
 510      // printing Java thread stack trace if it is involved in GC crash
 511      if (_verbose && (_thread->is_Named_thread())) {
 512        JavaThread*  jt = ((NamedThread *)_thread)->processed_thread();
 513        if (jt != NULL) {
 514          st->print_cr("JavaThread " PTR_FORMAT " (nid = " UINTX_FORMAT ") was being processed", jt, jt->osthread()->thread_id());
 515          print_stack_trace(st, jt, buf, sizeof(buf), true);






 516        }
 517      }
 518 
 519   STEP(140, "(printing VM operation)" )
 520 
 521      if (_verbose && _thread && _thread->is_VM_thread()) {
 522         VMThread* t = (VMThread*)_thread;
 523         VM_Operation* op = t->vm_operation();
 524         if (op) {
 525           op->print_on_error(st);
 526           st->cr();
 527           st->cr();
 528         }
 529      }
 530 
 531   STEP(150, "(printing current compile task)" )
 532 
 533      if (_verbose && _thread && _thread->is_Compiler_thread()) {
 534         CompilerThread* t = (CompilerThread*)_thread;
 535         if (t->task()) {