Java Concurrent Mark Sweep (CMS) 是世界大事吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21230165/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is Concurrent Mark Sweep (CMS) a stop the world event?
提问by user4127
I see many unloading of classes and my entire system will hang during that period of time..
我看到许多类卸载,我的整个系统将在这段时间内挂起。
[Unloading class sun.reflect.GeneratedMethodAccessor117]
[Unloading class sun.reflect.GeneratedConstructorAccessor1896]
[Unloading class sun.reflect.GeneratedSerializationConstructorAccessor485]
[Unloading class sun.reflect.GeneratedSerializationConstructorAccessor579]
.... // about 1700 of them
at the same time I do not see a spike in perm space, so it doesn't seems to be a GC event.
同时我没有看到烫发空间的峰值,所以它似乎不是一个 GC 事件。
I wish to know the following
我想知道以下内容
IS Concurrent Mark Sweep collection a stop the world event?
Concurrent Mark Sweep 系列是世界大事的终结者吗?
Does it happen even when the perm space is not full?
即使烫发空间未满也会发生吗?
回答by Aniket Thakur
CMS is a type of GC and is divided into phases
CMS 是 GC 的一种,分为几个阶段
As you can see two phases - Initial mark and Remark are stop the world events.
如您所见,两个阶段 - 初始标记和备注是停止世界事件。
Source: Under Reviewing Generational GC and CMS
section.
来源:下Reviewing Generational GC and CMS
节。
Does it happen even when the perm space is not full?
AFAIK for this you should have CMSClassUnloadingEnabled
with UseConcMarkSweepGC
. And FGC will be triggered when permgen area reaches it's threshold.
AFAIK 为此,您应该CMSClassUnloadingEnabled
使用UseConcMarkSweepGC
. 当 permgen 区域达到其阈值时,将触发 FGC。
Also though Concurrent Sweep(phrase (4)) is not STW event if permgen area get filled up(and GC is still processing permgen area) it may led to stopping all process threads and only GC thread running till all required memory is reclaimed.
此外,虽然并发扫描(短语(4))不是 STW 事件,如果永久区域被填满(并且 GC 仍在处理永久区域),它可能会导致停止所有进程线程并且只有 GC 线程运行,直到所有需要的内存被回收。
回答by Stephen C
CMS is not an "event". It is a garbage collector. CMS does have a couple of phases where everything is stopped, but under normal circumstances these are very short (a few milliseconds). In general, if you get a long pause it means that the CMS is not able to keep up with the rate of garbage generation (within the constraints that have been set), and that the JVM has had to perform a full GC using the "mark-sweep" collector ... which isstop the world.
CMS 不是“事件”。它是一个垃圾收集器。CMS 确实有几个阶段,一切都停止了,但在正常情况下,这些阶段非常短(几毫秒)。通常,如果您遇到长时间的暂停,则意味着 CMS 无法跟上垃圾生成的速度(在已设置的约束范围内),并且 JVM 必须使用“ mark-sweep”收集器......这是停止世界。
Depending on your JVM, it may bethat the permgen only gets collected when a full GC occurs, and that classes are only collected / unloaded when the permgen is GC'ed.
根据您的 JVM,可能只有在发生完整 GC 时才会收集 permgen,并且只有在 permgen 被 GC 时才会收集/卸载类。
But you can't infer that the class unloading causesthe long pauses. In fact, it is more likely the other way around if your GC stats say that the permgen is not filling up.
但是你不能推断出类卸载导致了长时间的停顿。事实上,如果您的 GC 统计数据表明 permgen 没有填满,则更有可能相反。
It is also possible that your loggingof class unloading is causingthe "stop the world" problem: see http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6637203
您的类卸载日志也可能导致“停止世界”问题:请参阅http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6637203
Observations:
观察:
If you have thousands of messages about unloading dynamically created classes, then I would take a look at the architecture of your system. Are you over-using proxy classes?
With Java 8, permgen goes away and is replaced with metaspace. Upgrading mayease your problems.
如果你有成千上万条关于卸载动态创建的类的消息,那么我会看看你的系统的架构。您是否过度使用代理类?
在 Java 8 中,permgen 消失了,取而代之的是元空间。升级可能会缓解您的问题。
回答by Terry Cho
Usually perm gc doesn't make hang up issue.
通常 perm gc 不会造成挂断问题。
The reason is, Perm is usually stabilized after all classes in application has been loaded. it can be a result of hang up. It means, if JVM doesn't have enough memory. It tries to Full-GC. As a part of the full gc, Perm will be GCed.
原因是,Perm 通常在应用程序中的所有类都加载后稳定。这可能是挂断的结果。这意味着,如果 JVM 没有足够的内存。它尝试 Full-GC。作为完整 gc 的一部分,Perm 将被 GC。
About the question u asked CMS also makes Full GC. It just reduce # of Full GC. During Minor GC, it also collect Old memory area.
关于你问的问题 CMS 也使 Full GC。它只是减少了 Full GC 的数量。在 Minor GC 期间,它还收集旧内存区域。
In my opinion, you may have a problem in Heap memory and it makes a # of Full GC and make a hang issue. So u need to check memory usage by using Visual JVM tools or some kinds of GC log analysis. You may find that the Old memory area are full and JVM tried to GC it. but sufficient memory is not freed and it retry gc . and retry retry..etc.
在我看来,您可能在堆内存中遇到了问题,这会导致 # of Full GC 并导致挂起问题。所以你需要使用 Visual JVM 工具或某些 GC 日志分析来检查内存使用情况。您可能会发现 Old 内存区域已满,JVM 尝试对其进行 GC。但没有释放足够的内存,它重试 gc 。并重试重试..等。
I think you may have a memory leak. issue. So it is better to GC log analysis and if it is memory leak issue, u need to have heap dump and analysis it.
我想你可能有内存泄漏。问题。因此最好进行GC日志分析,如果是内存泄漏问题,则需要进行堆转储并进行分析。