[英]GC (Allocation Failure) VS OutOfMemoryError Exception
'OutOfMemoryError': Usually, this error is thrown when there is insufficient space to allocate an object in the Java heap. 'OutOfMemoryError':通常,当 Java 堆中没有足够的空间分配对象时会抛出此错误。
GC (Allocation Failure): Allocation Failure” means that there is an allocation request that is bigger than the available space in young generation. GC(Allocation Failure):Allocation Failure”表示有一个大于年轻代可用空间的分配请求。
Does this mean Allocation Failure will be thrown when Young generation memory is full (Minor GC) and "OutOfMemoryError" is thrown in full GC?这是否意味着当年轻代内存已满(Minor GC)并且在full GC中抛出“OutOfMemoryError”时会抛出Allocation Failure?
These could become related as far as I can tell;据我所知,这些可能会变得相关; but they are entirely different things.但它们是完全不同的东西。
OutOfMemory
is an error you can not recover from - the JVM will die at this point. OutOfMemory
是一个您无法从中恢复的错误 - JVM 将在此时死亡。
GC (Allocation Failure): Allocation Failure
is the reason why GC will kick in (and do a minor collection). GC (Allocation Failure): Allocation Failure
是 GC 将启动(并进行次要收集)的原因。 At this point some things might happen, like: enough space is freed for the new allocation to fit into young generation
.此时可能会发生一些事情,例如:为新分配释放足够的空间以适应young generation
。 Or that did not happen and some objects will be promoted to the old generation
.或者那没有发生并且一些对象将被提升到old generation
。 If they can't be promoted
, a full GC
might be triggered - and if that does not free enough space an OutOfMemory
might be thrown.如果它们can't be promoted
,可能会触发一个full GC
- 如果这不能释放足够的空间,则可能会抛出OutOfMemory
。
In general, an OutOfMemoryError
occurs when you have exceeded the maximum memory you have already allocated to the JVM.通常,当您超过已分配给 JVM 的最大内存时,会发生OutOfMemoryError
。 This amount can be changed when starting java using jvm parameters.使用 jvm 参数启动 java 时可以更改此数量。 eg -Xmx2G
.例如-Xmx2G
。 Note that this amount isn't used immediately.请注意,此金额不会立即使用。 See below.见下文。
GC (Allocation Failure) is similar, except it occurs when the garbage collector runs out of memory on the heap, and it attempts to allocate more. GC(分配失败)与此类似,不同之处在于它发生在垃圾收集器耗尽堆上的内存并尝试分配更多内存时。 If your allocated memory is higher than your available system memory, this will fail.如果您分配的内存高于可用的系统内存,这将失败。 Essentially, the JVM tries to allocate memory which isn't there.本质上,JVM 会尝试分配不存在的内存。
Allocation (Evacuation) Failure 分配(疏散)失败
As with CMS, the G1 collector runs parts of its collection while the application continues to run and there is a risk that the application will allocate objects faster than the garbage collector can recover free space. 与CMS一样,G1收集器在应用程序继续运行时运行其集合的一部分,并且存在应用程序分配对象的速度快于垃圾收集器可以恢复可用空间的风险。 See the section Concurrent Mode Failure in Concurrent Mark Sweep (CMS) Collector for the analogous CMS behavior. 有关类似的CMS行为,请参阅并发标记扫描(CMS)收集器中的并发模式失败部分。 In G1, the failure (exhaustion of the Java heap) occurs while G1 is copying live data out of one region (evacuating) into another region. 在G1中,G1正在将实时数据从一个区域(撤离)复制到另一个区域时发生故障(Java堆的耗尽)。 The copying is done to compact the live data. 进行复制以压缩实时数据。 If a free (empty) region cannot be found during the evacuation of a region being garbage collected, then an allocation failure occurs (because there is no space to allocate the live objects from the region being evacuated) and a stop-the-world (STW) full collection is done. 如果在撤离被垃圾收集的区域期间无法找到空闲(空)区域,则会发生分配失败(因为没有空间来分配来自撤离区域的活动对象)和停止世界( STW)完整收藏完成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.