当前位置:网站首页>What is oom, why it happens and some solutions
What is oom, why it happens and some solutions
2022-07-26 12:03:00 【pan_ junbiao】
1、 What is? OOM
OOM, Full name “Out Of Memory”, Translated into Chinese “ Out of memory ”, originate java.lang.OutOfMemoryError. Take a look at the official statement about : Thrown when the Java Virtual Machine cannot allocate an object because it is out of memory, and no more memory could be made available by the garbage collector. That is to say , When JVM Because there is not enough memory to allocate space for the object and the garbage collector has no space to recycle , You'll throw this out error( notes : Not exception, Because this problem is too serious to be applied ).
2、 why OOM
Why is there no memory ? There are two reasons :
(1) Less allocated : For example, the memory available to the virtual machine itself ( Usually through the start-up VM Parameter assignment ) too little .
(2) Too many apps , And not released after use , wasted . This will cause memory leakage or memory overflow .
Memory leak : The used memory has not been released , Cause the virtual machine can't use the memory again , At this point, the memory leaks , Because applicants don't have to , And can't be assigned to others by virtual machine .
out of memory : The requested memory exceeds JVM The memory size that can be provided , This is called overflow .
In the days when there was no automatic garbage collection , such as C Language and C++ Language , We must be personally responsible for the application and release of memory , If memory is requested , After use, I forgot to release , such as C++ Medium new Yes, but not delete, Then it may cause memory leakage . Occasional memory leaks may not cause problems , A large number of memory leaks may lead to memory overflow .
And in the Java In language , Due to the existence of automatic garbage collection mechanism , therefore , We generally don't have to actively release the memory occupied by unused objects , That is, in theory , It doesn't exist “ Memory leak ” Of . however , If it's not coded properly , such as , Put the reference of an object into the global Map in , Although the method is over , But because the garbage collector will recycle memory according to the reference of the object , As a result, the object cannot be recycled in time . If this happens more often , It will cause memory overflow , For example, the caching mechanism often used in the system .Java Memory leaks in , differ C++ I forgot delete, It is often a logical reason to leak .
3、OOM The type of
JVM Memory model :
according to JVM standard ,JAVA The virtual machine will manage the following memory areas when running :
- Program counter : The line number indicator of bytecode executed by the current thread , Thread private .
- JAVA Virtual machine stack :Java Memory model for method execution , Every Java The execution of the method corresponds to the operation of a stack frame into and out of the stack .
- Native Method Stack : similar “ JAVA Virtual machine stack ”, But for native Method provides a memory environment .
- JAVA Pile up : Where object memory is allocated , The main area of memory garbage collection , All threads share . It can be divided into Cenozoic , Old generation .
- Method area : Used for storage has been JVM Class information loaded 、 Constant 、 Static variables 、 Real time compiler compiled code and other data .Hotspot Medium “ Forever ”.
- Runtime constant pool : Part of the method area , Store constant information , Such as various literal quantities 、 Symbol references, etc .
- Direct memory : Not at all JVM Part of the runtime data area , Directly accessible memory , such as NIO I'll use this part .
- according to JVM standard , Except that the program counter will not throw OOM Outside , Each other memory area may throw OOM.
The most common OOM There are three situations :
- java.lang.OutOfMemoryError: Java heap space ------>java Heap memory overflow , This is the most common case , It is usually caused by memory leak or improper heap size setting . For memory leaks , Need to find the leak code in the program through the memory monitoring software , The heap size can be determined by virtual machine parameters -Xms,-Xmx And so on .
- java.lang.OutOfMemoryError: PermGen space ------>java Permanent generation overflow , The method area overflowed , It usually occurs in a large number of Class perhaps jsp page , Or use cglib And so on , Because there will be a lot of Class Information is stored in the method area . This can be solved by changing the size of the method area , Use similar -XX:PermSize=64m -XX:MaxPermSize=256m Form modification . in addition , Too many constants, especially strings, can also cause method area overflow .
- java.lang.StackOverflowError ------> I can't throw it OOM error, But it's also quite common Java out of memory .JAVA Virtual machine stack overflow , Generally, it is caused by the existence of dead loop or deep recursive call in the program , If the stack size is set too small, this overflow will occur . You can use virtual machine parameters -Xss To set the stack size .( Comments from netizens :SOF It doesn't count OOM.OOM yes JVM out of memory , and SOF Is only stack memory overflow , Create stack frame overflow through recursive infinite loop , The principle is different .)
4、OOM analysis –heapdump
want dump Memory image of heap , There are two ways to do this :
Set up JVM Parameters -XX:+HeapDumpOnOutOfMemoryError, Set when OOM Automatically dump Pile up information . However, this method needs to be improved JDK5 Above version .
Use JDK Self contained jmap command ."jmap -dump:format=b,file=heap.bin " among pid Can pass jps obtain .
dump After heap memory information , Need to be right dump Analysis of the documents , To find OOM Why . Common tools are :mat: eclipse memory analyzer, be based on eclipse RCP Memory analysis tools . For more information, see http://www.eclipse.org/mat/, Recommended .
jhat:JDK Self contained java heap analyze tool, You can change the objects in the heap to html In the form of , Including the number of objects , Size and so on , And support object query language OQL, After analyzing the related applications , Can pass http://localhost:7000 To access the analysis results . It is not recommended to use , Because in the actual investigation process , Generally speaking, it starts from the production environment dump File out , Then pull it to your own development machine for analysis , therefore , It's better to use advanced analysis tools, such as the previous one mat To be efficient .
This link :IBM Developer Provides a way to adopt mat Examples of analysis .
Be careful : because JVM The specification is not correct dump Define the format of the file , So different virtual machines produce dump The files are not the same . In the analysis , Different analysis tools need to be used for the output of different virtual machines ( Of course , Some tools can be compatible with the formats of multiple virtual machines ).IBM HeapAnalyzer It's also analysis heap A commonly used tool for .
Original author :Qi_Meng6
Original address :https://blog.csdn.net/qq_42447950/article/details/81435080
More detailed learning articles are recommended : What is? OOM, why OOM And some solutions _ Blog full of notes -CSDN Blog _oom The cause of the abnormality and the solution
边栏推荐
- Live broadcast preview at 19:30 on July 27: harmonyos3 and Huawei's full scene new product launch
- C language code quantity statistical tool
- Wulin headlines - station building expert competition
- 3.2 create menu and game pages (Part 2)
- 《多线程下ThreadLocal使用场景实例》
- 基于STM32的SIM900A发送中文和英文短信
- Flink 在 讯飞 AI 营销业务的实时数据分析实践
- On the construction and management of low code technology in logistics transportation platform
- SSJ-21B时间继电器
- Pytoch deep learning quick start tutorial -- mound tutorial notes (II)
猜你喜欢

Sword finger offer 25. merge two sorted linked lists

Pytoch deep learning quick start tutorial -- mound tutorial notes (II)

Audio and video+

Hou Peixin, chairman of the openharmony Working Committee of the open atom open source foundation, sent a message to the openatom openharmony sub forum
![[download attached] a powerful web automated vulnerability scanning tool - Xray](/img/5e/1db72ce9bf758b1e68e8d6d2026302.png)
[download attached] a powerful web automated vulnerability scanning tool - Xray

Introduction to FPGA (I) - the first FPGA project

Audio and video technology development weekly | 255

Marriage seeking story

CVPR 2022 单目深度估计新SOTA—NeW CRFs:Neural Window Fullyconnected CRFs

了解string类
随机推荐
按位与怎么写SQL
Question and answer No. 48: geek appointment - construction path of observable system
Pytorch深度学习快速入门教程 -- 土堆教程笔记(一)
DS-24C/DC220V时间继电器
Pytest interface automation test framework | use decorators to decorate the use cases that need to be run
Flink's real-time data analysis practice in iFLYTEK AI marketing business
V01 - XX,记录美好生活从日志开始
An online duplicate of a hidden bug
FPGA入门学习(一) - 第一个FPGA工程
Pytest interface automation test framework | pytest configuration file
pytest接口自动化测试框架 | 通过标记表达式执行用例
[communication principle] Chapter 2 -- deterministic signal
C language code quantity statistical tool
Pytest interface automation test framework | execute use cases through markup expressions
CVPR 2022 单目深度估计新SOTA—NeW CRFs:Neural Window Fullyconnected CRFs
Pytest interface automated testing framework | pytest obtains execution data, and pytest disables plug-ins
大佬们,请教一下,我按照文档配了cdc连接oracle,总是运行报错找不到类 ValidstionE
百问百答第48期:极客有约——可观测体系的建设路径
pytest接口自动化测试框架 | pytest的setup和teardown函数
一些实用、常用、效率越来越高的 Kubernetes 别名