JVM ClassUnloadingWithConcurrentMark flag

1.6k views Asked by At

I have a question about ClassUnloadingWithConcurrentMark flag since I didn't find any useful help anywhere. If we use G1GC is set to true by default (-XX:+ClassUnloadingWithConcurrentMark). If I use -XX:-ClassUnloadingWithConcurrentMark flag to turn off class unloading after G1 concurrent mark where is class unloading executed then (which phase)? I read somewhere that it happens when full GC is activated by what if full GC is never triggered? I have problems with long remark phases - unloading in below example took more than 3 seconds:

2015-06-08T08:09:16.318+0200: 572818.729: [GC remark 572818.729: [Finalize Marking, 0.0002590 secs] 572818.729: [GC ref-proc, 0.4479462 secs] 572819.177: [Unloading, 3.2004912 secs], 3.6499382 secs]
 [Times: user=0.20 sys=0.08, real=3.64 secs] 

Would using -XX:-ClassUnloadingWithConcurrentMark be useful to me to reduce class unloading times? I'm afraid that If I'll use this option I'll have even more problems (for example outofmemory exceptions,...) if class unloading will never happen.

EDIT: if we are using -XX:+ClassUnloadingWithConcurrentMark (default option) is class unloading triggered every time GC remark phase occurs? In logs I have some GC with GC cause: Metadata GC Threshold, but others don't have this cause but Unloading still happens in remark phase. Why is that so?

2

There are 2 answers

8
the8472 On BEST ANSWER

I'm afraid that If I'll use this option I'll have even more problems

Why don't you just setup a test environment for these kinds of things and test it yourself?

Anyway, as already answered over here, the VM will perform some last-ditch heroics (1-2 full GCs, complete soft reference clearing) to ensure that the situation is not recoverable before throwing an OOM.

Would using -XX:-ClassUnloadingWithConcurrentMark be useful to me to reduce class unloading times?

Whether it will reduce them, I don't know, probably not. That's what you will have to try yourself. But it may delay the inevitable for a long time.

if we are using -XX:+ClassUnloadingWithConcurrentMark (default option) is class unloading triggered every time GC remark phase occurs?

yes, this was added with JDK-8049421 and the flag to turn it off again with JDK-8051607.

All you have to do is to search for "class unloading" on the openjdk bugtracker and/or the hotspot-gc-dev mailing lists. This is all public information.


Another thing you could try instead is setting -XX:MinMetaspaceFreeRatio=20 -XX:MaxMetaspaceFreeRatio=30. This would trigger class unloading sooner and hopefully cause a shorter cycle.

0
Ayoross On

G1 does class unloading during the STW Remark phase, this is the default behavior. You cannot prevent class unloading, because doing so would eventually cause "Out of Memory" errors.

The only way to mitigate this issue is to modify your code to stop using dynamic classes generation.