Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Concurrent Mark Sweep (CMS) a stop the world event?

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.

I wish to know the following

IS Concurrent Mark Sweep collection a stop the world event?

Does it happen even when the perm space is not full?

like image 859
user4127 Avatar asked Jan 20 '14 09:01

user4127


Video Answer


2 Answers

CMS is a type of GC and is divided into phases

enter image description here

As you can see two phases - Initial mark and Remark are stop the world events.

Source : Under Reviewing Generational GC and CMS section.

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.

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.

like image 155
Aniket Thakur Avatar answered Sep 21 '22 08:09

Aniket Thakur


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 is stop the world.

Depending on your JVM, it may be that the permgen only gets collected when a full GC occurs, and that classes are only collected / unloaded when the permgen is GC'ed.

But you can't infer that the class unloading causes the long pauses. In fact, it is more likely the other way around if your GC stats say that the permgen is not filling up.

It is also possible that your logging of class unloading is causing the "stop the world" problem: see 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 may ease your problems.

like image 33
Stephen C Avatar answered Sep 18 '22 08:09

Stephen C