Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What's the use of OOM?

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the use of OOM, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

I. the meaning of OOM:

OOM, the full name is "Out Of Memory", which means "out of memory". It comes from java.lang.OutOfMemoryError.

Second, why java.lang.OutOfMemoryError appears: that is, OOM:

Officially, when JVM does not have enough memory to allocate space for objects and the garbage collector has no space to reclaim, it will throw java.lang.OutOfMemoryError: (note: this is a serious problem because it is too serious to be processed by the application).

The specific reasons are roughly twofold:

1. Self-reasons: for example, the virtual machine itself has too little memory to use.

2. External reasons: if the application uses too much and does not release it, memory is wasted. This will cause a memory leak or a memory overflow.

Memory leak: the applied memory is not released, so that the virtual machine cannot use the memory again, and the memory is leaked because the applicant does not use it and cannot be allocated to someone else by the virtual machine.

Memory overflow: the requested memory exceeds the amount of memory that JVM can provide, which is called an overflow.

3. Error type of OOM

First, let's talk about the areas of memory that the JAVA virtual machine manages when it runs:

1. Program counter: line number indicator of bytecode executed by the current thread, thread private

2. JAVA virtual machine stack: the memory model executed by the Java method. The execution of each Java method corresponds to the operation of entering and leaving the stack frame.

3. Local method stack: similar to the "JAVA virtual machine stack", but provides an in-memory environment for native methods to run.

4. JAVA heap: the place where object memory is allocated, the main area of memory garbage collection, shared by all threads. Can be divided into the new generation, the old generation.

5. Method area: used to store class information, constants, static variables, code compiled by just-in-time compiler, etc., which have been loaded by JVM. The eternal generation in Hotspot.

6. Runtime constant pool: part of the method area that stores constant information, such as various literals, symbolic references, and so on.

7. Direct memory: memory that is not part of the JVM runtime data area and can be accessed directly, such as NIO.

So every other memory region may throw OOM except that the program counter will not throw OOM.

Common OOM situations:

1. Java.lang.OutOfMemoryError: Java heap space-> java heap memory overflow is the most common, which is usually caused by memory leakage or improper heap size setting. For memory leaks, you need to find the leaked code in the program through the memory monitoring software, and the heap size can be modified by the virtual machine parameter-Xms,-Xmx, etc.

2. Java.lang.OutOfMemoryError: PermGen space-> java permanent generation overflow, that is, method area overflow, which usually occurs in a large number of Class or jsp pages, or in the case of reflection mechanisms such as cglib, because a large amount of Class information is stored in the method area. When this happens, you can change the size of the method area and modify it in a form similar to-XX:PermSize=64m-XX:MaxPermSize=256m. Note that too many constants, especially strings, can also cause the method area to overflow.

3. Java.lang.StackOverflowError-> does not throw OOM error, but it is also a common Java memory overflow. JAVA virtual machine stack overflow is usually caused by endless loops or deep recursive calls in the program, which can also occur when the stack size setting is too small. The stack size can be set by the virtual machine parameter-Xss.

IV. OOM analysis

Heap Dump (heap dump file) it is a memory snapshot of a Java process at some point in time. There are many types of Heap Dump. In general, however, heap dump saves information about java objects and classes when it triggers a snapshot. The FullGC is usually triggered before writing the heap dump file, so the object information left after the FullGC is saved in the heap dump file.

You can get a HPROF binary Heap Dump file after OutOfMemoryError occurs by setting the following JVM parameter:

-XX:+HeapDumpOnOutOfMemoryError

The generated files are written directly to the working directory.

Note: this method requires a later version of JDK5.

After you dump the heap memory information, you need to analyze the file to find out the cause of OOM. You can use the following ways:

Mat: eclipse memory analyzer, a memory analysis tool based on eclipse RCP. Reference for specific use: http://www.eclipse.org/mat/, recommended.

Jhat:JDK comes with java heap analyze tool, which can display the objects in the heap in the form of html, including the number and size of objects, and supports object query language OQL. After analyzing related applications, you can access the analysis results through http://localhost:7000. It is not recommended.

Thank you for reading this article carefully. I hope the article "what's the use of OOM" shared by the editor will be helpful to everyone? at the same time, I also hope that you will support and pay attention to the industry information channel, and more related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report