什么时候发生内存不足? [英] When does out of memory happen?

查看:75
本文介绍了什么时候发生内存不足?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,在运行我们的应用程序时,我们遇到了内存不足的异常.

Recently, when running our application, we met an out of memory exception.

这是异常发生之前的堆转储

This is the heap dump right before the exception happened

Heap
 def new generation   total 1572864K, used 366283K [0x00000006b0000000, 0x000000071aaa0000, 0x000000071aaa0000)
  eden space 1398144K, 13% used [0x00000006b0000000, 0x00000006bbb12d40, 0x0000000705560000)
  from space 174720K, 100% used [0x0000000710000000, 0x000000071aaa0000, 0x000000071aaa0000)
  to   space 174720K,   0% used [0x0000000705560000, 0x0000000705560000, 0x0000000710000000)

 tenured generation   total 3495296K, used 2658714K [0x000000071aaa0000, 0x00000007f0000000, 0x00000007f0000000)
  the space 3495296K,  76% used [0x000000071aaa0000, 0x00000007bcf06ba8, 0x00000007bcf06c00, 0x00000007f0000000)

 compacting perm gen  total 42048K, used 41778K [0x00000007f0000000, 0x00000007f2910000, 0x0000000800000000)
  the space 42048K,    99% used [0x00000007f0000000, 0x00000007f28ccb80, 0x00000007f28ccc00, 0x00000007f2910000)

No shared spaces configured.

看来老一代几乎快吃饱了(76%).我认为最终达到100%OOM时会发生.但是,看起来伊甸园只有13%.

It looks like old gen was almost full (76%). I assume when it finally reaches 100% OOM happens. However, it looks like eden is only at 13%.

有人可以解释为什么即使年轻一代中仍然有一些空间,OOM仍会发生吗?

Can someone explain why OOM happens even if there is still some space in young gen?

推荐答案

JVM可能抛出OutOfMemoryError的原因有很多,其中包括

There is a dozen of different reasons why JVM may throw OutOfMemoryError, including

  • Java堆空间:在尝试分配大于两个堆生成中的最大连续可用块的对象或数组时;
  • 超出了GC开销限制:当JVM花在垃圾收集上的时间比例太高时(请参阅GCTimeLimitGCHeapFreeLimit);
  • PermGen空间(在Java 8之前)或元空间(从Java 8开始):当类元数据的数量超过MaxPermSizeMaxMetaspaceSize时;
  • 请求的数组大小超出VM限制:在尝试分配长度大于Integer.MAX_VALUE - 2的数组时;
  • 无法创建新的本机线程:在达到用户进程的操作系统限制(请参见ulimit -u)或没有足够的虚拟内存来为线程堆栈保留空间时;
  • 直接缓冲区内存:当所有直接ByteBuffer的大小超过MaxDirectMemorySize或没有可用的虚拟内存来满足直接缓冲区分配时;
  • 当JVM无法为其内部结构分配内存时,要么是由于可用虚拟内存已用完,要么是因为达到了特定的操作系统限制(例如,内存映射区域的最大数量);
  • 当JNI代码未能分配某些本机资源时;
  • 等等更不用说应用程序可以随时因为开发人员的决定而抛出OutOfMemoryError本身.
  • Java heap space: when trying to allocate an object or an array larger than maximum continuous free block in either of heap generations;
  • GC overhead limit exceeded: when the proportion of time JVM spends doing garbage collection becomes too high (see GCTimeLimit, GCHeapFreeLimit);
  • PermGen space (before Java 8) or Metaspace (since Java 8): when the amount of class metadata exceeds MaxPermSize or MaxMetaspaceSize;
  • Requested array size exceeds VM limit: when trying to allocate an array with length larger than Integer.MAX_VALUE - 2;
  • Unable to create new native thread: when reaching the OS limit of user processes (see ulimit -u) or when there is not enough virtual memory to reserve space for thread stack;
  • Direct buffer memory: when the size of all direct ByteBuffers exceeds MaxDirectMemorySize or when there is no virtual memory available to satisfy direct buffer allocation;
  • When JVM cannot allocate memory for its internal structures, either because run out of available virtual memory or because certain OS limit reached (e.g. maximum number of memory map areas);
  • When JNI code failed to allocate some native resource;
  • Etc. Not to mention that an application can throw OutOfMemoryError itself at any time just because a developer decides so.

要找出导致特定错误的原因,至少应查看错误消息,stacktrace和GC日志.

To find out what is the reason of your particular error, you should at least look at the error message, the stacktrace and GC logs.

这篇关于什么时候发生内存不足?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆