views:

223

answers:

4

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?

A: 

What about the information provided by the -verbose:gc and -XX:+PrintGCDetails command line options? Isn't it helpful?

[Edit: Obviously not]

Itay
That doesn't print which garbage collector is being used.
Thirler
+5  A: 

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

JoseK
+1  A: 

As Joachim already pointed out, the article you refer to describes the VM strategies offered by Sun's VM. The VM specification itself does not mandate specific GC algorithms and hence it won't make sense to have e.g. enumerated values for these in the API.

You can however get some infos from the Management API:

List<GarbageCollectorMXBean> beans = 
    ManagementFactory.getGarbageCollectorMXBeans();

Iterating through these beans, you can get the name of the GC (although only as a string) and the names of the memory pools, which are managed by the different GCs.

jarnbjo
+1  A: 

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

antispam
This is precisely what I need, unfortunately it isn't available on Windows (no clue why though).
Thirler
Maybe you should add that information (Windows) to the question ;)
antispam