Class Unloading in the Java G1 Garbage Collector (G1GC)

In Java 6, we used the following GC configuration to prevent a Perm Gen OutOfMemoryException after several OutOfMemoryException our application:

-XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled

We are switching to Java 7 and want to use the new G1 GC, which from the read has moved the classes from PermGen to Java memory in native memory.

Is there any flag that allows unloading unused classes?

+6
source share
2 answers

G1 does class unloading during a full GC, so you don't need to specify any parameters to enable this.

You can see for yourself by using the -XX:+TraceClassUnloading .

Also check this email flow from the HotSpot GC mailing list: Error in G1GC, it executes full GC when the cache code is full, which leads to overflow . They discuss class unloading in G1 in some detail. That way you can use -noclassgc if you see problems with class unloading, but usually there are no problems with class unloading in G1.

+8
source

G1 performs class unloading during the Remark phase, which is the stop of the world:

 [GC remark 2019-03-26T14:27:52.926+0000: 18.798: [Finalize Marking, 0.0004509 secs] 2019-03-26T14:27:52.926+0000: 18.799: [GC ref-proc, 0.0002791 secs] 2019-03-26T14:27:52.926+0000: 18.799: [Unloading, 0.0058844 secs], 0.0073053 secs] 

Please note that it is Java 8 that replaces Permgen with Metaspace, and the CMS also performs class unloading (with the CMSClassUnloadingEnabled switch), so if you still have Out of Memory errors, this will not help.

0
source

Source: https://habr.com/ru/post/954421/


All Articles