Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I see which garbage collector java is using

The Java Virtual Machine supports several garbage collection strategies.

This article explains them.

Now I am wondering which (automatically selected) strategy my application is using, is there any way to let the JVM(version 1.6) print this information?

Edit: The JVM detects if it is in client or server mode. So the question really is how can I see which has been detected?

like image 923
Thirler Avatar asked Mar 23 '10 10:03

Thirler


People also ask

Which garbage collector is used in Java?

In Java, the programmers don't need to take care of destroying the objects that are out of use. The Garbage Collector takes care of it. Garbage Collector is a Daemon thread that keeps running in the background. Basically, it frees up the heap memory by destroying the unreachable objects.

Which garbage collector is used by default?

G1 Garbage Collector is the default garbage collection of Java 9. G1 collector replaced the CMS collector since it's more performance efficient. How G1 Garbage Collector works is different from other collectors. Unlike other collectors, the G1 collector partitions the heap space into multiple equal-sized regions.

What is the default garbage collector in Java 17?

normal/satb (product, default) This marking mode does the similar work as G1, the default garbage collector for OpenJDK 17.


2 Answers

jmap -heap

Prints a heap summary. GC algorithm used, heap configuration and generation wise heap usage are printed.

http://java.sun.com/javase/6/docs/technotes/tools/share/jmap.html

like image 129
fglez Avatar answered Oct 07 '22 20:10

fglez


http://java.sun.com/j2se/1.5.0/docs/guide/vm/gc-ergonomics.html which is applicable for J2SE 6 as well states that the default is the Parallel Collector.

We tested this once on a JVM 1.5 by setting only

-server -Xms3g -Xmx3g -XX:PermSize=128m -XX:LargePageSizeInBytes=4m -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps

and the output showed

41359.597: [GC [PSYoungGen: 90499K->32K(377344K)] 268466K->181862K(2474496K), 0.0183138 secs]
41359.615: [Full GC [PSYoungGen: 32K->0K(377344K)] [PSOldGen: 181830K->129760K(2097152K)] 181862K->129760K(2474496K) [PSPermGen: 115335K->115335K(131072K)], 4.4590942 secs]

where PS stands for Parallel Scavenging

like image 23
JoseK Avatar answered Oct 07 '22 19:10

JoseK