• 1. Java heap space

  • 2. GC overhead exceeds the limit

  • 3. The requested array size exceeds the vm limit

  • 4. Perm Gen space

  • 5. Metaspace

  • 6. The local thread cannot be created

  • 7. Kill processes or child processes

  • 8. Stack_trace_with_native_method


1. Java heap space

Frequency: 5 stars

Cause the reason

  • Unable to allocate objects in the Java heap

  • Throughput increase

  • The application inadvertently saved an object reference and the object cannot be reclaimed by GC

  • Applications overuse Finalizer. Finalizer objects cannot be reclaimed immediately by the GC. Finalizer is called by the daemon thread of the end queue service. Sometimes the finalizer thread cannot keep up with the growth of the end queue

The solution

  • Increase the heap size with -xmx

  • Fix memory leaks in your application

2. GC overhead exceeds the limit

Frequency: 5 stars

Cause the reason

  • Java processes spent 98% of their time garbage collecting, recovered less than 2% of the heap space, and did so for the last five consecutive (compile-time constant) garbage collections.

The solution

  • Increase the heap size with -xmx

  • Remove the GC overhead limit with -xx: -usegCoverheadLimit

  • Fix memory leaks in your application

3. The requested array size exceeds the vm limit

Frequency: 2 stars

Cause the reason

  • The application attempted to allocate an array larger than the heap size

The solution

  • Increase the heap size with -xmx

  • Fixed a bug in the application where large arrays were allocated

4. Perm Gen space

Frequency: 3 stars

Cause the reason

The Perm Gen space contains:

  • Class name, field, method

  • An array of objects and types associated with a class

  • JIT compiler optimization

When Perm Gen runs out of space, an exception is thrown.

The solution

  • Use -xx: MaxPermSize to increase the Permgen size

  • Deploying an application without restarting the application can cause this problem. Restart the JVM

5. Metaspace

Frequency: 3 stars

Cause the reason

  • Starting with Java 8, Perm Gen was changed to Metaspace, which allocates class metadata in native memory (called Metaspace). If metaspace is exhausted, an exception is thrown

The solution

  • Increase the metaspace size by setting -xx: MaxMetaSpaceSize on the command line

  • Cancel – XX: maxmetsspacedize

  • Reduce the Java heap size to provide more free space for MetaSpace

  • Allocate more memory for the server

  • It may be an application bug. Fix the bug

6. The local thread cannot be created

Frequency: 5 stars

Cause the reason

  • Not enough memory to create a new thread. Since the thread was created in native memory, reporting this error indicates that there is insufficient native memory space

The solution

  • Allocate more memory to the machine

  • Reduce the Java heap space

  • Fix thread leaks in your application.

  • Add operating system level restrictions

  1. – ulimit -a

  • The number of user processes increases (-u) 1800

  • Reduce the thread stack size with -xss

7. Kill processes or child processes

Frequency: 1 star

Cause the reason

  • Kernel task: Out-of-memory finalizer, which kills processes if the available memory is extremely low

The solution

  • Migrate the process to a different machine

  • Add more memory to the machine

Unlike other OOM errors, this is triggered by the operating system, not the JVM.

8. Stack_trace_with_native_method

Frequency: 1 star

Cause the reason

  • Native method allocation failed

  • Print stack trace information, the top frame is native method

The solution

  • Use local tools of the operating system to diagnose faults



Follow wechat official account [Programmer’s Dream, focusing on Java, SpringBoot, SpringCloud, microservices, Docker, and full-stack technologies such as backend separation.