--- old/src/share/vm/utilities/exceptions.hpp 2015-06-05 16:15:25.637767707 -0400 +++ new/src/share/vm/utilities/exceptions.hpp 2015-06-05 16:15:25.123378571 -0400 @@ -102,6 +102,11 @@ class Exceptions { static bool special_exception(Thread *thread, const char* file, int line, Handle exception); static bool special_exception(Thread* thread, const char* file, int line, Symbol* name, const char* message); + + // Count out of memory errors that are interesting in error diagnosis + static volatile int _out_of_memory_error_java_heap_errors; + static volatile int _out_of_memory_error_metaspace_errors; + static volatile int _out_of_memory_error_class_metaspace_errors; public: // this enum is defined to indicate whether it is safe to // ignore the encoding scheme of the original message string. @@ -160,6 +165,14 @@ static void throw_stack_overflow_exception(Thread* thread, const char* file, int line, methodHandle method); + // Exception counting for error files of interesting exceptions that may have + // caused a problem for the jvm + static volatile int _stack_overflow_errors; + + static bool has_exception_counts(); + static void count_out_of_memory_exceptions(Handle exception); + static void print_exception_counts_on_error(outputStream* st); + // for AbortVMOnException flag NOT_PRODUCT(static void debug_check_abort(Handle exception, const char* message = NULL);) NOT_PRODUCT(static void debug_check_abort(const char *value_string, const char* message = NULL);) --- old/src/share/vm/runtime/os.cpp 2015-06-05 16:15:25.707627810 -0400 +++ new/src/share/vm/runtime/os.cpp 2015-06-05 16:15:25.067669002 -0400 @@ -843,7 +843,7 @@ pd_print_cpu_info(st); } -void os::print_date_and_time(outputStream *st) { +void os::print_date_and_time(outputStream *st, char* buf, size_t buflen) { const int secs_per_day = 86400; const int secs_per_hour = 3600; const int secs_per_min = 60; @@ -852,6 +852,10 @@ (void)time(&tloc); st->print("time: %s", ctime(&tloc)); // ctime adds newline. + struct tm* tz = localtime(&tloc); + ::strftime(buf, buflen, "%Z", tz); + st->print_cr("timezone: %s", buf); + double t = os::elapsedTime(); // NOTE: It tends to crash after a SEGV if we want to printf("%f",...) in // Linux. Must be a bug in glibc ? Workaround is to round "t" to int --- old/src/share/vm/runtime/sharedRuntime.cpp 2015-06-05 16:15:25.580929970 -0400 +++ new/src/share/vm/runtime/sharedRuntime.cpp 2015-06-05 16:15:24.894287934 -0400 @@ -732,6 +732,8 @@ if (StackTraceInThrowable) { java_lang_Throwable::fill_in_stack_trace(exception); } + // Increment counter for hs_err file reporting + Atomic::inc(&Exceptions::_stack_overflow_errors); throw_and_post_jvmti_exception(thread, exception); JRT_END --- old/src/share/vm/utilities/exceptions.cpp 2015-06-05 16:15:25.983374788 -0400 +++ new/src/share/vm/utilities/exceptions.cpp 2015-06-05 16:15:25.340791097 -0400 @@ -154,6 +154,10 @@ return; } + if (h_exception->is_a(SystemDictionary::OutOfMemoryError_klass())) { + count_out_of_memory_exceptions(h_exception); + } + assert(h_exception->is_a(SystemDictionary::Throwable_klass()), "exception is not a subclass of java/lang/Throwable"); // set the pending exception @@ -228,6 +232,8 @@ if (StackTraceInThrowable) { java_lang_Throwable::fill_in_stack_trace(exception, method()); } + // Increment counter for hs_err file reporting + Atomic::inc(&Exceptions::_stack_overflow_errors); } else { // if prior exception, throw that one instead exception = Handle(THREAD, THREAD->pending_exception()); @@ -404,6 +410,44 @@ h_prot, to_utf8_safe); } + +// Exception counting for hs_err file +volatile int Exceptions::_stack_overflow_errors = 0; +volatile int Exceptions::_out_of_memory_error_java_heap_errors = 0; +volatile int Exceptions::_out_of_memory_error_metaspace_errors = 0; +volatile int Exceptions::_out_of_memory_error_class_metaspace_errors = 0; + +void Exceptions::count_out_of_memory_exceptions(Handle exception) { + if (exception() == Universe::out_of_memory_error_metaspace()) { + Atomic::inc(&_out_of_memory_error_metaspace_errors); + } else if (exception() == Universe::out_of_memory_error_class_metaspace()) { + Atomic::inc(&_out_of_memory_error_class_metaspace_errors); + } else { + // everything else reported as java heap OOM + Atomic::inc(&_out_of_memory_error_java_heap_errors); + } +} + +void print_oom_count(outputStream* st, const char *err, int count) { + if (count > 0) { + st->print_cr("OutOfMemoryError %s=%d", err, count); + } +} + +bool Exceptions::has_exception_counts() { + return (_stack_overflow_errors + _out_of_memory_error_java_heap_errors + + _out_of_memory_error_metaspace_errors + _out_of_memory_error_class_metaspace_errors) > 0; +} + +void Exceptions::print_exception_counts_on_error(outputStream* st) { + print_oom_count(st, "java_heap_errors", _out_of_memory_error_java_heap_errors); + print_oom_count(st, "metaspace_errors", _out_of_memory_error_metaspace_errors); + print_oom_count(st, "class_metaspace_errors", _out_of_memory_error_class_metaspace_errors); + if (_stack_overflow_errors > 0) { + st->print_cr("StackOverflowErrors=%d", _stack_overflow_errors); + } +} + // Implementation of ExceptionMark ExceptionMark::ExceptionMark(Thread*& thread) { --- old/src/share/vm/utilities/vmError.cpp 2015-06-05 16:15:25.463168638 -0400 +++ new/src/share/vm/utilities/vmError.cpp 2015-06-05 16:15:24.957622262 -0400 @@ -714,6 +714,24 @@ st->cr(); } + STEP(182, "(printing number of OutOfMemoryError and StackOverflow exceptions)") + + if (_verbose && Exceptions::has_exception_counts()) { + st->print_cr("OutOfMemory and StackOverflow Exception counts:"); + Exceptions::print_exception_counts_on_error(st); + st->cr(); + } + + STEP(185, "(printing compressed oops mode") + + if (_verbose && UseCompressedOops) { + Universe::print_compressed_oops_mode(st); + if (UseCompressedClassPointers) { + Metaspace::print_compressed_class_space(st); + } + st->cr(); + } + STEP(190, "(printing heap information)" ) if (_verbose && Universe::is_fully_initialized()) { @@ -819,7 +837,7 @@ STEP(280, "(printing date and time)" ) if (_verbose) { - os::print_date_and_time(st); + os::print_date_and_time(st, buf, sizeof(buf)); st->cr(); } --- old/src/share/vm/memory/universe.hpp 2015-06-05 16:15:25.801947492 -0400 +++ new/src/share/vm/memory/universe.hpp 2015-06-05 16:15:24.761916286 -0400 @@ -398,7 +398,7 @@ static void set_narrow_ptrs_base(address a) { _narrow_ptrs_base = a; } static address narrow_ptrs_base() { return _narrow_ptrs_base; } - static void print_compressed_oops_mode(); + static void print_compressed_oops_mode(outputStream* st); // this is set in vm_version on sparc (and then reset in universe afaict) static void set_narrow_oop_shift(int shift) { --- old/src/share/vm/memory/universe.cpp 2015-06-05 16:15:25.767652863 -0400 +++ new/src/share/vm/memory/universe.cpp 2015-06-05 16:15:25.104782510 -0400 @@ -754,7 +754,7 @@ Universe::set_narrow_ptrs_base(Universe::narrow_oop_base()); if (PrintCompressedOopsMode || (PrintMiscellaneous && Verbose)) { - Universe::print_compressed_oops_mode(); + Universe::print_compressed_oops_mode(tty); } // Tell tests in which mode we run. @@ -781,27 +781,24 @@ return JNI_OK; } -void Universe::print_compressed_oops_mode() { - tty->cr(); - tty->print("heap address: " PTR_FORMAT ", size: " SIZE_FORMAT " MB", +void Universe::print_compressed_oops_mode(outputStream* st) { + st->print("heap address: " PTR_FORMAT ", size: " SIZE_FORMAT " MB", p2i(Universe::heap()->base()), Universe::heap()->reserved_region().byte_size()/M); - tty->print(", Compressed Oops mode: %s", narrow_oop_mode_to_string(narrow_oop_mode())); + st->print(", Compressed Oops mode: %s", narrow_oop_mode_to_string(narrow_oop_mode())); if (Universe::narrow_oop_base() != 0) { - tty->print(": " PTR_FORMAT, p2i(Universe::narrow_oop_base())); + st->print(": " PTR_FORMAT, p2i(Universe::narrow_oop_base())); } if (Universe::narrow_oop_shift() != 0) { - tty->print(", Oop shift amount: %d", Universe::narrow_oop_shift()); + st->print(", Oop shift amount: %d", Universe::narrow_oop_shift()); } if (!Universe::narrow_oop_use_implicit_null_checks()) { - tty->print(", no protected page in front of the heap"); + st->print(", no protected page in front of the heap"); } - - tty->cr(); - tty->cr(); + st->cr(); } ReservedSpace Universe::reserve_heap(size_t heap_size, size_t alignment) { --- old/src/share/vm/memory/metaspace.cpp 2015-06-05 16:15:25.958076762 -0400 +++ new/src/share/vm/memory/metaspace.cpp 2015-06-05 16:15:25.314418472 -0400 @@ -3132,10 +3132,21 @@ initialize_class_space(metaspace_rs); if (PrintCompressedOopsMode || (PrintMiscellaneous && Verbose)) { - gclog_or_tty->print_cr("Narrow klass base: " PTR_FORMAT ", Narrow klass shift: %d", - p2i(Universe::narrow_klass_base()), Universe::narrow_klass_shift()); - gclog_or_tty->print_cr("Compressed class space size: " SIZE_FORMAT " Address: " PTR_FORMAT " Req Addr: " PTR_FORMAT, - compressed_class_space_size(), p2i(metaspace_rs.base()), p2i(requested_addr)); + print_compressed_class_space(gclog_or_tty, requested_addr); + } +} + +void Metaspace::print_compressed_class_space(outputStream* st, const char* requested_addr) { + st->print_cr("Narrow klass base: " PTR_FORMAT ", Narrow klass shift: %d", + p2i(Universe::narrow_klass_base()), Universe::narrow_klass_shift()); + if (_class_space_list != NULL) { + address base = (address)_class_space_list->current_virtual_space()->bottom(); + st->print("Compressed class space size: " SIZE_FORMAT " Address: " PTR_FORMAT, + compressed_class_space_size(), p2i(base)); + if (requested_addr != 0) { + st->print(" Req Addr: " PTR_FORMAT, p2i(requested_addr)); + } + st->cr(); } } --- old/src/share/vm/memory/metaspace.hpp 2015-06-05 16:15:25.637613294 -0400 +++ new/src/share/vm/memory/metaspace.hpp 2015-06-05 16:15:24.894227208 -0400 @@ -254,6 +254,8 @@ // Debugging support void verify(); + static void print_compressed_class_space(outputStream* st, const char* requested_addr = 0); + class AllocRecordClosure : public StackObj { public: virtual void doit(address ptr, MetaspaceObj::Type type, int byte_size) = 0; --- old/src/share/vm/interpreter/interpreterRuntime.cpp 2015-06-05 16:15:25.801989758 -0400 +++ new/src/share/vm/interpreter/interpreterRuntime.cpp 2015-06-05 16:15:25.014512737 -0400 @@ -309,6 +309,8 @@ Handle exception = get_preinitialized_exception( SystemDictionary::StackOverflowError_klass(), CHECK); + // Increment counter for hs_err file reporting + Atomic::inc(&Exceptions::_stack_overflow_errors); THROW_HANDLE(exception); IRT_END --- old/src/share/vm/runtime/os.hpp 2015-06-05 16:15:26.027859658 -0400 +++ new/src/share/vm/runtime/os.hpp 2015-06-05 16:15:25.314139705 -0400 @@ -596,7 +596,7 @@ static void print_register_info(outputStream* st, void* context); static void print_siginfo(outputStream* st, void* siginfo); static void print_signal_handlers(outputStream* st, char* buf, size_t buflen); - static void print_date_and_time(outputStream* st); + static void print_date_and_time(outputStream* st, char* buf, size_t buflen); static void print_location(outputStream* st, intptr_t x, bool verbose = false); static size_t lasterror(char *buf, size_t len);