src/share/vm/utilities/exceptions.cpp

changeset 9301
d47844b56aaf
parent 7089
6e0cb14ce59b
child 9448
73d689add964
child 9478
f3108e56b502
     1.1 --- a/src/share/vm/utilities/exceptions.cpp	Wed Feb 21 11:11:07 2018 +0530
     1.2 +++ b/src/share/vm/utilities/exceptions.cpp	Wed Mar 14 03:19:46 2018 -0700
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -154,6 +154,10 @@
    1.11      return;
    1.12    }
    1.13  
    1.14 +  if (h_exception->is_a(SystemDictionary::OutOfMemoryError_klass())) {
    1.15 +    count_out_of_memory_exceptions(h_exception);
    1.16 +  }
    1.17 +
    1.18    assert(h_exception->is_a(SystemDictionary::Throwable_klass()), "exception is not a subclass of java/lang/Throwable");
    1.19  
    1.20    // set the pending exception
    1.21 @@ -228,6 +232,8 @@
    1.22      if (StackTraceInThrowable) {
    1.23        java_lang_Throwable::fill_in_stack_trace(exception, method());
    1.24      }
    1.25 +    // Increment counter for hs_err file reporting
    1.26 +    Atomic::inc(&Exceptions::_stack_overflow_errors);
    1.27    } else {
    1.28      // if prior exception, throw that one instead
    1.29      exception = Handle(THREAD, THREAD->pending_exception());
    1.30 @@ -404,6 +410,44 @@
    1.31                                     h_prot, to_utf8_safe);
    1.32  }
    1.33  
    1.34 +
    1.35 +// Exception counting for hs_err file
    1.36 +volatile int Exceptions::_stack_overflow_errors = 0;
    1.37 +volatile int Exceptions::_out_of_memory_error_java_heap_errors = 0;
    1.38 +volatile int Exceptions::_out_of_memory_error_metaspace_errors = 0;
    1.39 +volatile int Exceptions::_out_of_memory_error_class_metaspace_errors = 0;
    1.40 +
    1.41 +void Exceptions::count_out_of_memory_exceptions(Handle exception) {
    1.42 +  if (exception() == Universe::out_of_memory_error_metaspace()) {
    1.43 +     Atomic::inc(&_out_of_memory_error_metaspace_errors);
    1.44 +  } else if (exception() == Universe::out_of_memory_error_class_metaspace()) {
    1.45 +     Atomic::inc(&_out_of_memory_error_class_metaspace_errors);
    1.46 +  } else {
    1.47 +     // everything else reported as java heap OOM
    1.48 +     Atomic::inc(&_out_of_memory_error_java_heap_errors);
    1.49 +  }
    1.50 +}
    1.51 +
    1.52 +void print_oom_count(outputStream* st, const char *err, int count) {
    1.53 +  if (count > 0) {
    1.54 +    st->print_cr("OutOfMemoryError %s=%d", err, count);
    1.55 +  }
    1.56 +}
    1.57 +
    1.58 +bool Exceptions::has_exception_counts() {
    1.59 +  return (_stack_overflow_errors + _out_of_memory_error_java_heap_errors +
    1.60 +         _out_of_memory_error_metaspace_errors + _out_of_memory_error_class_metaspace_errors) > 0;
    1.61 +}
    1.62 +
    1.63 +void Exceptions::print_exception_counts_on_error(outputStream* st) {
    1.64 +  print_oom_count(st, "java_heap_errors", _out_of_memory_error_java_heap_errors);
    1.65 +  print_oom_count(st, "metaspace_errors", _out_of_memory_error_metaspace_errors);
    1.66 +  print_oom_count(st, "class_metaspace_errors", _out_of_memory_error_class_metaspace_errors);
    1.67 +  if (_stack_overflow_errors > 0) {
    1.68 +    st->print_cr("StackOverflowErrors=%d", _stack_overflow_errors);
    1.69 +  }
    1.70 +}
    1.71 +
    1.72  // Implementation of ExceptionMark
    1.73  
    1.74  ExceptionMark::ExceptionMark(Thread*& thread) {

mercurial