< prev index next >

src/hotspot/share/utilities/exceptions.cpp

Print this page
rev 50234 : 8204477: Count linkage errors and print in Exceptions::print_exception_counts_on_error


  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/systemDictionary.hpp"
  27 #include "classfile/vmSymbols.hpp"
  28 #include "compiler/compileBroker.hpp"
  29 #include "logging/log.hpp"
  30 #include "logging/logStream.hpp"
  31 #include "memory/resourceArea.hpp"
  32 #include "oops/oop.inline.hpp"
  33 #include "runtime/handles.inline.hpp"
  34 #include "runtime/init.hpp"
  35 #include "runtime/java.hpp"
  36 #include "runtime/javaCalls.hpp"
  37 #include "runtime/os.hpp"
  38 #include "runtime/thread.inline.hpp"
  39 #include "runtime/threadCritical.hpp"

  40 #include "utilities/events.hpp"
  41 #include "utilities/exceptions.hpp"
  42 
  43 // Implementation of ThreadShadow
  44 void check_ThreadShadow() {
  45   const ByteSize offset1 = byte_offset_of(ThreadShadow, _pending_exception);
  46   const ByteSize offset2 = Thread::pending_exception_offset();
  47   if (offset1 != offset2) fatal("ThreadShadow::_pending_exception is not positioned correctly");
  48 }
  49 
  50 
  51 void ThreadShadow::set_pending_exception(oop exception, const char* file, int line) {
  52   assert(exception != NULL && oopDesc::is_oop(exception), "invalid exception oop");
  53   _pending_exception = exception;
  54   _exception_file    = file;
  55   _exception_line    = line;
  56 }
  57 
  58 void ThreadShadow::clear_pending_exception() {
  59   LogTarget(Debug, exceptions) lt;


 134   assert(h_exception() != NULL, "exception should not be NULL");
 135 
 136   // tracing (do this up front - so it works during boot strapping)
 137   log_info(exceptions)("Exception <%s%s%s> (" INTPTR_FORMAT ") \n"
 138                        "thrown [%s, line %d]\nfor thread " INTPTR_FORMAT,
 139                        h_exception->print_value_string(),
 140                        message ? ": " : "", message ? message : "",
 141                        p2i(h_exception()), file, line, p2i(thread));
 142   // for AbortVMOnException flag
 143   Exceptions::debug_check_abort(h_exception, message);
 144 
 145   // Check for special boot-strapping/vm-thread handling
 146   if (special_exception(thread, file, line, h_exception)) {
 147     return;
 148   }
 149 
 150   if (h_exception->is_a(SystemDictionary::OutOfMemoryError_klass())) {
 151     count_out_of_memory_exceptions(h_exception);
 152   }
 153 




 154   assert(h_exception->is_a(SystemDictionary::Throwable_klass()), "exception is not a subclass of java/lang/Throwable");
 155 
 156   // set the pending exception
 157   thread->set_pending_exception(h_exception(), file, line);
 158 
 159   // vm log
 160   if (LogEvents){
 161     Events::log_exception(thread, "Exception <%s%s%s> (" INTPTR_FORMAT ") thrown at [%s, line %d]",
 162                           h_exception->print_value_string(), message ? ": " : "", message ? message : "",
 163                           p2i(h_exception()), file, line);
 164   }
 165 }
 166 
 167 
 168 void Exceptions::_throw_msg(Thread* thread, const char* file, int line, Symbol* name, const char* message,
 169                             Handle h_loader, Handle h_protection_domain) {
 170   // Check for special boot-strapping/vm-thread handling
 171   if (special_exception(thread, file, line, name, message)) return;
 172   // Create and throw exception
 173   Handle h_cause(thread, NULL);


 408       if (TraceMethodHandles) {
 409         tty->print_cr("[constant/invoke]dynamic passes through an Error for " INTPTR_FORMAT, p2i((void *)exception));
 410         exception->print();
 411       }
 412       return;
 413     }
 414 
 415     // Otherwise wrap the exception in a BootstrapMethodError
 416     if (TraceMethodHandles) {
 417       tty->print_cr("[constant/invoke]dynamic throws BSME for " INTPTR_FORMAT, p2i((void *)exception));
 418       exception->print();
 419     }
 420     Handle nested_exception(THREAD, exception);
 421     THREAD->clear_pending_exception();
 422     THROW_CAUSE(vmSymbols::java_lang_BootstrapMethodError(), nested_exception)
 423   }
 424 }
 425 
 426 // Exception counting for hs_err file
 427 volatile int Exceptions::_stack_overflow_errors = 0;

 428 volatile int Exceptions::_out_of_memory_error_java_heap_errors = 0;
 429 volatile int Exceptions::_out_of_memory_error_metaspace_errors = 0;
 430 volatile int Exceptions::_out_of_memory_error_class_metaspace_errors = 0;
 431 
 432 void Exceptions::count_out_of_memory_exceptions(Handle exception) {
 433   if (oopDesc::equals(exception(), Universe::out_of_memory_error_metaspace())) {
 434      Atomic::inc(&_out_of_memory_error_metaspace_errors);
 435   } else if (oopDesc::equals(exception(), Universe::out_of_memory_error_class_metaspace())) {
 436      Atomic::inc(&_out_of_memory_error_class_metaspace_errors);
 437   } else {
 438      // everything else reported as java heap OOM
 439      Atomic::inc(&_out_of_memory_error_java_heap_errors);
 440   }
 441 }
 442 
 443 void print_oom_count(outputStream* st, const char *err, int count) {
 444   if (count > 0) {
 445     st->print_cr("OutOfMemoryError %s=%d", err, count);
 446   }
 447 }
 448 
 449 bool Exceptions::has_exception_counts() {
 450   return (_stack_overflow_errors + _out_of_memory_error_java_heap_errors +
 451          _out_of_memory_error_metaspace_errors + _out_of_memory_error_class_metaspace_errors) > 0;
 452 }
 453 
 454 void Exceptions::print_exception_counts_on_error(outputStream* st) {
 455   print_oom_count(st, "java_heap_errors", _out_of_memory_error_java_heap_errors);
 456   print_oom_count(st, "metaspace_errors", _out_of_memory_error_metaspace_errors);
 457   print_oom_count(st, "class_metaspace_errors", _out_of_memory_error_class_metaspace_errors);
 458   if (_stack_overflow_errors > 0) {
 459     st->print_cr("StackOverflowErrors=%d", _stack_overflow_errors);



 460   }
 461 }
 462 
 463 // Implementation of ExceptionMark
 464 
 465 ExceptionMark::ExceptionMark(Thread*& thread) {
 466   thread     = Thread::current();
 467   _thread    = thread;
 468   if (_thread->has_pending_exception()) {
 469     oop exception = _thread->pending_exception();
 470     _thread->clear_pending_exception(); // Needed to avoid infinite recursion
 471     exception->print();
 472     fatal("ExceptionMark constructor expects no pending exceptions");
 473   }
 474 }
 475 
 476 
 477 ExceptionMark::~ExceptionMark() {
 478   if (_thread->has_pending_exception()) {
 479     Handle exception(_thread, _thread->pending_exception());




  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/systemDictionary.hpp"
  27 #include "classfile/vmSymbols.hpp"
  28 #include "compiler/compileBroker.hpp"
  29 #include "logging/log.hpp"
  30 #include "logging/logStream.hpp"
  31 #include "memory/resourceArea.hpp"
  32 #include "oops/oop.inline.hpp"
  33 #include "runtime/handles.inline.hpp"
  34 #include "runtime/init.hpp"
  35 #include "runtime/java.hpp"
  36 #include "runtime/javaCalls.hpp"
  37 #include "runtime/os.hpp"
  38 #include "runtime/thread.inline.hpp"
  39 #include "runtime/threadCritical.hpp"
  40 #include "runtime/atomic.hpp"
  41 #include "utilities/events.hpp"
  42 #include "utilities/exceptions.hpp"
  43 
  44 // Implementation of ThreadShadow
  45 void check_ThreadShadow() {
  46   const ByteSize offset1 = byte_offset_of(ThreadShadow, _pending_exception);
  47   const ByteSize offset2 = Thread::pending_exception_offset();
  48   if (offset1 != offset2) fatal("ThreadShadow::_pending_exception is not positioned correctly");
  49 }
  50 
  51 
  52 void ThreadShadow::set_pending_exception(oop exception, const char* file, int line) {
  53   assert(exception != NULL && oopDesc::is_oop(exception), "invalid exception oop");
  54   _pending_exception = exception;
  55   _exception_file    = file;
  56   _exception_line    = line;
  57 }
  58 
  59 void ThreadShadow::clear_pending_exception() {
  60   LogTarget(Debug, exceptions) lt;


 135   assert(h_exception() != NULL, "exception should not be NULL");
 136 
 137   // tracing (do this up front - so it works during boot strapping)
 138   log_info(exceptions)("Exception <%s%s%s> (" INTPTR_FORMAT ") \n"
 139                        "thrown [%s, line %d]\nfor thread " INTPTR_FORMAT,
 140                        h_exception->print_value_string(),
 141                        message ? ": " : "", message ? message : "",
 142                        p2i(h_exception()), file, line, p2i(thread));
 143   // for AbortVMOnException flag
 144   Exceptions::debug_check_abort(h_exception, message);
 145 
 146   // Check for special boot-strapping/vm-thread handling
 147   if (special_exception(thread, file, line, h_exception)) {
 148     return;
 149   }
 150 
 151   if (h_exception->is_a(SystemDictionary::OutOfMemoryError_klass())) {
 152     count_out_of_memory_exceptions(h_exception);
 153   }
 154 
 155   if (h_exception->is_a(SystemDictionary::LinkageError_klass())) {
 156     Atomic::inc(&_linkage_errors);
 157   }
 158 
 159   assert(h_exception->is_a(SystemDictionary::Throwable_klass()), "exception is not a subclass of java/lang/Throwable");
 160 
 161   // set the pending exception
 162   thread->set_pending_exception(h_exception(), file, line);
 163 
 164   // vm log
 165   if (LogEvents){
 166     Events::log_exception(thread, "Exception <%s%s%s> (" INTPTR_FORMAT ") thrown at [%s, line %d]",
 167                           h_exception->print_value_string(), message ? ": " : "", message ? message : "",
 168                           p2i(h_exception()), file, line);
 169   }
 170 }
 171 
 172 
 173 void Exceptions::_throw_msg(Thread* thread, const char* file, int line, Symbol* name, const char* message,
 174                             Handle h_loader, Handle h_protection_domain) {
 175   // Check for special boot-strapping/vm-thread handling
 176   if (special_exception(thread, file, line, name, message)) return;
 177   // Create and throw exception
 178   Handle h_cause(thread, NULL);


 413       if (TraceMethodHandles) {
 414         tty->print_cr("[constant/invoke]dynamic passes through an Error for " INTPTR_FORMAT, p2i((void *)exception));
 415         exception->print();
 416       }
 417       return;
 418     }
 419 
 420     // Otherwise wrap the exception in a BootstrapMethodError
 421     if (TraceMethodHandles) {
 422       tty->print_cr("[constant/invoke]dynamic throws BSME for " INTPTR_FORMAT, p2i((void *)exception));
 423       exception->print();
 424     }
 425     Handle nested_exception(THREAD, exception);
 426     THREAD->clear_pending_exception();
 427     THROW_CAUSE(vmSymbols::java_lang_BootstrapMethodError(), nested_exception)
 428   }
 429 }
 430 
 431 // Exception counting for hs_err file
 432 volatile int Exceptions::_stack_overflow_errors = 0;
 433 volatile int Exceptions::_linkage_errors = 0;
 434 volatile int Exceptions::_out_of_memory_error_java_heap_errors = 0;
 435 volatile int Exceptions::_out_of_memory_error_metaspace_errors = 0;
 436 volatile int Exceptions::_out_of_memory_error_class_metaspace_errors = 0;
 437 
 438 void Exceptions::count_out_of_memory_exceptions(Handle exception) {
 439   if (oopDesc::equals(exception(), Universe::out_of_memory_error_metaspace())) {
 440      Atomic::inc(&_out_of_memory_error_metaspace_errors);
 441   } else if (oopDesc::equals(exception(), Universe::out_of_memory_error_class_metaspace())) {
 442      Atomic::inc(&_out_of_memory_error_class_metaspace_errors);
 443   } else {
 444      // everything else reported as java heap OOM
 445      Atomic::inc(&_out_of_memory_error_java_heap_errors);
 446   }
 447 }
 448 
 449 void print_oom_count(outputStream* st, const char *err, int count) {
 450   if (count > 0) {
 451     st->print_cr("OutOfMemoryError %s=%d", err, count);
 452   }
 453 }
 454 
 455 bool Exceptions::has_exception_counts() {
 456   return (_stack_overflow_errors + _out_of_memory_error_java_heap_errors +
 457          _out_of_memory_error_metaspace_errors + _out_of_memory_error_class_metaspace_errors) > 0;
 458 }
 459 
 460 void Exceptions::print_exception_counts_on_error(outputStream* st) {
 461   print_oom_count(st, "java_heap_errors", _out_of_memory_error_java_heap_errors);
 462   print_oom_count(st, "metaspace_errors", _out_of_memory_error_metaspace_errors);
 463   print_oom_count(st, "class_metaspace_errors", _out_of_memory_error_class_metaspace_errors);
 464   if (_stack_overflow_errors > 0) {
 465     st->print_cr("StackOverflowErrors=%d", _stack_overflow_errors);
 466   }
 467   if (_linkage_errors > 0) {
 468     st->print_cr("LinkageErrors=%d", _linkage_errors);
 469   }
 470 }
 471 
 472 // Implementation of ExceptionMark
 473 
 474 ExceptionMark::ExceptionMark(Thread*& thread) {
 475   thread     = Thread::current();
 476   _thread    = thread;
 477   if (_thread->has_pending_exception()) {
 478     oop exception = _thread->pending_exception();
 479     _thread->clear_pending_exception(); // Needed to avoid infinite recursion
 480     exception->print();
 481     fatal("ExceptionMark constructor expects no pending exceptions");
 482   }
 483 }
 484 
 485 
 486 ExceptionMark::~ExceptionMark() {
 487   if (_thread->has_pending_exception()) {
 488     Handle exception(_thread, _thread->pending_exception());


< prev index next >