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());
|
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 if (h_exception->is_a(SystemDictionary::LinkageError_klass())) {
155 Atomic::inc(&Exceptions::_linkage_errors);
156 }
157
158 assert(h_exception->is_a(SystemDictionary::Throwable_klass()), "exception is not a subclass of java/lang/Throwable");
159
160 // set the pending exception
161 thread->set_pending_exception(h_exception(), file, line);
162
163 // vm log
164 if (LogEvents){
165 Events::log_exception(thread, "Exception <%s%s%s> (" INTPTR_FORMAT ") thrown at [%s, line %d]",
166 h_exception->print_value_string(), message ? ": " : "", message ? message : "",
167 p2i(h_exception()), file, line);
168 }
169 }
170
171
172 void Exceptions::_throw_msg(Thread* thread, const char* file, int line, Symbol* name, const char* message,
173 Handle h_loader, Handle h_protection_domain) {
174 // Check for special boot-strapping/vm-thread handling
175 if (special_exception(thread, file, line, name, message)) return;
176 // Create and throw exception
177 Handle h_cause(thread, NULL);
412 if (TraceMethodHandles) {
413 tty->print_cr("[constant/invoke]dynamic passes through an Error for " INTPTR_FORMAT, p2i((void *)exception));
414 exception->print();
415 }
416 return;
417 }
418
419 // Otherwise wrap the exception in a BootstrapMethodError
420 if (TraceMethodHandles) {
421 tty->print_cr("[constant/invoke]dynamic throws BSME for " INTPTR_FORMAT, p2i((void *)exception));
422 exception->print();
423 }
424 Handle nested_exception(THREAD, exception);
425 THREAD->clear_pending_exception();
426 THROW_CAUSE(vmSymbols::java_lang_BootstrapMethodError(), nested_exception)
427 }
428 }
429
430 // Exception counting for hs_err file
431 volatile int Exceptions::_stack_overflow_errors = 0;
432 volatile int Exceptions::_linkage_errors = 0;
433 volatile int Exceptions::_out_of_memory_error_java_heap_errors = 0;
434 volatile int Exceptions::_out_of_memory_error_metaspace_errors = 0;
435 volatile int Exceptions::_out_of_memory_error_class_metaspace_errors = 0;
436
437 void Exceptions::count_out_of_memory_exceptions(Handle exception) {
438 if (oopDesc::equals(exception(), Universe::out_of_memory_error_metaspace())) {
439 Atomic::inc(&_out_of_memory_error_metaspace_errors);
440 } else if (oopDesc::equals(exception(), Universe::out_of_memory_error_class_metaspace())) {
441 Atomic::inc(&_out_of_memory_error_class_metaspace_errors);
442 } else {
443 // everything else reported as java heap OOM
444 Atomic::inc(&_out_of_memory_error_java_heap_errors);
445 }
446 }
447
448 void print_oom_count(outputStream* st, const char *err, int count) {
449 if (count > 0) {
450 st->print_cr("OutOfMemoryError %s=%d", err, count);
451 }
452 }
453
454 bool Exceptions::has_exception_counts() {
455 return (_stack_overflow_errors + _out_of_memory_error_java_heap_errors +
456 _out_of_memory_error_metaspace_errors + _out_of_memory_error_class_metaspace_errors) > 0;
457 }
458
459 void Exceptions::print_exception_counts_on_error(outputStream* st) {
460 print_oom_count(st, "java_heap_errors", _out_of_memory_error_java_heap_errors);
461 print_oom_count(st, "metaspace_errors", _out_of_memory_error_metaspace_errors);
462 print_oom_count(st, "class_metaspace_errors", _out_of_memory_error_class_metaspace_errors);
463 if (_stack_overflow_errors > 0) {
464 st->print_cr("StackOverflowErrors=%d", _stack_overflow_errors);
465 }
466 if (_linkage_errors > 0) {
467 st->print_cr("LinkageErrors=%d", _linkage_errors);
468 }
469 }
470
471 // Implementation of ExceptionMark
472
473 ExceptionMark::ExceptionMark(Thread*& thread) {
474 thread = Thread::current();
475 _thread = thread;
476 if (_thread->has_pending_exception()) {
477 oop exception = _thread->pending_exception();
478 _thread->clear_pending_exception(); // Needed to avoid infinite recursion
479 exception->print();
480 fatal("ExceptionMark constructor expects no pending exceptions");
481 }
482 }
483
484
485 ExceptionMark::~ExceptionMark() {
486 if (_thread->has_pending_exception()) {
487 Handle exception(_thread, _thread->pending_exception());
|