OOM counters

Baesken, Matthias matthias.baesken at sap.com
Wed Sep 19 09:12:42 UTC 2018

Hello,  Currently we have already counters in the Hotspot codebase counting Java heap,
Metaspace and class metaspace related OOMs.

See declarations:


107  // Count out of memory errors that are interesting in error diagnosis
108  static volatile int _out_of_memory_error_java_heap_errors;
109  static volatile int _out_of_memory_error_metaspace_errors;
110  static volatile int _out_of_memory_error_class_metaspace_errors;

output :


460void 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  }

But currently  the output is  only done from vmError.cpp , in case of
a)  error reporting
b)  jcmd  vm.info  (in case exceptions happened, otherwise the section is not printed)

(see void VMError::print_vm_info(outputStream* st) { ... } )

It would be interesting for us to get the values of the existing counters via JDK coding.
In our proprietary JVM we had a similar mechanism.

Is there anything planned for this (or even already something present) ?

There exists already a class java/lang/management/MemoryMXBean.java  with a  management interface for the memory system of
the Java virtual machine.  It contains some "getter" - methods like

    public int getObjectPendingFinalizationCount();
    public MemoryUsage getHeapMemoryUsage();

Do you think we could add a method (or methods) for accessing the existing OOM counters
( for example,  public OomCounters getOutOfMemoryCounters();  ) ?

Best regards, Matthias

More information about the hotspot-dev mailing list