Class Unloading in Java's G1 Garbage Collector (G1GC)
Asked Answered
O

2

7

In Java 6 we used to use the following GC configuration to prevent Perm Gen OutOfMemoryException after several redeployments of our app:

-XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled

We're moving to Java 7 and want to use the new G1 GC, which from what I've read, moves the classes from the PermGen in Java memory to native memory.

Is there some flag to enable unloading unused classes?

Ouzo answered 23/9, 2013 at 13:27 Comment(0)
B
10

The G1 performs the class unloading during a Full GC, so you do not need to specify any parameters to enable this.

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

Also, check out this email thread from the HotSpot GC mailing list: Bug in G1GC it performs Full GC when code cache is full resulting in overkill. They discuss class unloading in G1 quite extensively. In summary, you can use -noclassgc if you are seeing issues with class unloading but usually there are no problems with class unloading in G1.

Birdhouse answered 23/9, 2013 at 18:46 Comment(0)
A
1

G1 performs class unloading during the Remark phase, which is stop-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]

Note that it is Java 8 that replaces Permgen with Metaspace, and that CMS does class unloading too (with the switch CMSClassUnloadingEnabled), so if you still have Out of Memory errors, it won't help.

Aurignacian answered 25/4, 2019 at 14:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.