src/share/vm/utilities/exceptions.cpp

changeset 9301
d47844b56aaf
parent 7089
6e0cb14ce59b
child 9448
73d689add964
child 9478
f3108e56b502
equal deleted inserted replaced
9300:b3dd617b29cf 9301:d47844b56aaf
1 /* 1 /*
2 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
152 // Check for special boot-strapping/vm-thread handling 152 // Check for special boot-strapping/vm-thread handling
153 if (special_exception(thread, file, line, h_exception)) { 153 if (special_exception(thread, file, line, h_exception)) {
154 return; 154 return;
155 } 155 }
156 156
157 if (h_exception->is_a(SystemDictionary::OutOfMemoryError_klass())) {
158 count_out_of_memory_exceptions(h_exception);
159 }
160
157 assert(h_exception->is_a(SystemDictionary::Throwable_klass()), "exception is not a subclass of java/lang/Throwable"); 161 assert(h_exception->is_a(SystemDictionary::Throwable_klass()), "exception is not a subclass of java/lang/Throwable");
158 162
159 // set the pending exception 163 // set the pending exception
160 thread->set_pending_exception(h_exception(), file, line); 164 thread->set_pending_exception(h_exception(), file, line);
161 165
226 exception = Handle(THREAD, e); // fill_in_stack trace does gc 230 exception = Handle(THREAD, e); // fill_in_stack trace does gc
227 assert(InstanceKlass::cast(k)->is_initialized(), "need to increase min_stack_allowed calculation"); 231 assert(InstanceKlass::cast(k)->is_initialized(), "need to increase min_stack_allowed calculation");
228 if (StackTraceInThrowable) { 232 if (StackTraceInThrowable) {
229 java_lang_Throwable::fill_in_stack_trace(exception, method()); 233 java_lang_Throwable::fill_in_stack_trace(exception, method());
230 } 234 }
235 // Increment counter for hs_err file reporting
236 Atomic::inc(&Exceptions::_stack_overflow_errors);
231 } else { 237 } else {
232 // if prior exception, throw that one instead 238 // if prior exception, throw that one instead
233 exception = Handle(THREAD, THREAD->pending_exception()); 239 exception = Handle(THREAD, THREAD->pending_exception());
234 } 240 }
235 _throw(THREAD, file, line, exception); 241 _throw(THREAD, file, line, exception);
402 Handle h_cause(thread, NULL); 408 Handle h_cause(thread, NULL);
403 return Exceptions::new_exception(thread, name, message, h_cause, h_loader, 409 return Exceptions::new_exception(thread, name, message, h_cause, h_loader,
404 h_prot, to_utf8_safe); 410 h_prot, to_utf8_safe);
405 } 411 }
406 412
413
414 // Exception counting for hs_err file
415 volatile int Exceptions::_stack_overflow_errors = 0;
416 volatile int Exceptions::_out_of_memory_error_java_heap_errors = 0;
417 volatile int Exceptions::_out_of_memory_error_metaspace_errors = 0;
418 volatile int Exceptions::_out_of_memory_error_class_metaspace_errors = 0;
419
420 void Exceptions::count_out_of_memory_exceptions(Handle exception) {
421 if (exception() == Universe::out_of_memory_error_metaspace()) {
422 Atomic::inc(&_out_of_memory_error_metaspace_errors);
423 } else if (exception() == Universe::out_of_memory_error_class_metaspace()) {
424 Atomic::inc(&_out_of_memory_error_class_metaspace_errors);
425 } else {
426 // everything else reported as java heap OOM
427 Atomic::inc(&_out_of_memory_error_java_heap_errors);
428 }
429 }
430
431 void print_oom_count(outputStream* st, const char *err, int count) {
432 if (count > 0) {
433 st->print_cr("OutOfMemoryError %s=%d", err, count);
434 }
435 }
436
437 bool Exceptions::has_exception_counts() {
438 return (_stack_overflow_errors + _out_of_memory_error_java_heap_errors +
439 _out_of_memory_error_metaspace_errors + _out_of_memory_error_class_metaspace_errors) > 0;
440 }
441
442 void Exceptions::print_exception_counts_on_error(outputStream* st) {
443 print_oom_count(st, "java_heap_errors", _out_of_memory_error_java_heap_errors);
444 print_oom_count(st, "metaspace_errors", _out_of_memory_error_metaspace_errors);
445 print_oom_count(st, "class_metaspace_errors", _out_of_memory_error_class_metaspace_errors);
446 if (_stack_overflow_errors > 0) {
447 st->print_cr("StackOverflowErrors=%d", _stack_overflow_errors);
448 }
449 }
450
407 // Implementation of ExceptionMark 451 // Implementation of ExceptionMark
408 452
409 ExceptionMark::ExceptionMark(Thread*& thread) { 453 ExceptionMark::ExceptionMark(Thread*& thread) {
410 thread = Thread::current(); 454 thread = Thread::current();
411 _thread = thread; 455 _thread = thread;

mercurial