Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to tell which GC algorithm the JVM is currently using

I am using Java 5 and our custom server application needs GC tunning, as some times we are experiencing 15-20 seconds pause on peak hours. We are running Java 5 on a server class machine with JVM args like -server -d64

Is there a way to tell which GC algorithm the JVM is currently using?

http://docs.oracle.com/javase/1.5.0/docs/guide/vm/gc-ergonomics.html

On server-class machines running the server VM, the garbage collector (GC) has changed from the previous serial collector (-XX:+UseSerialGC) to a parallel collector (-XX:+UseParallelGC). You can override this default by using the -XX:+UseSerialGC command-line option to the java command.

1) I want to know is that really happening?

my next question is I have added the following at command line arguments

-verbose:gc -XX:+PrintGCTimeStamps -XX:+PrintGCDetails -XX:+PrintGCApplicationStoppedTime -XX:+PrintGCApplicationConcurrentTime -Xloggc:logs/gc.log

2) will they have any performance or behavioral effect on the running JVM except logging GC logs?

like image 504
Syed Saulat Hussain Rizvi Avatar asked Feb 15 '12 18:02

Syed Saulat Hussain Rizvi


4 Answers

you can use -XX:+PrintFlagsFinal to print out JVM parameters and their settings.

java -XX:+PrintFlagsFinal -server -version

like image 81
stones333 Avatar answered Oct 27 '22 00:10

stones333


You can use jmap -heap <jvm_pid> to print java heap summary. For example, Intellij's heap summary is like the following if I run the jmap -heap 2592:

Attaching to process ID 2592, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.101-b13

using parallel threads in the new generation.
using thread-local object allocation.
Concurrent Mark-Sweep GC
Truncated...

As you you can spot from the output, the JVM instance running with 2592 process id is using CMS GC algorithm.

Also, if the algorithm was determined by those -XX:+Use*GC flags, you can find that using the jcmd <pid> VM.flags. For example:

$ jcmd 2715 VM.flags 
2715:
-XX:CICompilerCount=4 -XX:InitialHeapSize=268435456
-XX:MaxHeapSize=734003200 -XX:MaxNewSize=244318208 
-XX:MinHeapDeltaBytes=524288 -XX:NewSize=89128960 -XX:OldSize=179306496 
-XX:+UseCompressedClassPointers -XX:+UseCompressedOops 
-XX:+UseFastUnorderedTimeStamps -XX:+UseParallelGC 

As you can see that VM is using the Parallel GC.

like image 34
Ali Dehghani Avatar answered Oct 27 '22 01:10

Ali Dehghani


You can get the current gc(s) in use using the GarbageCollectorMXBeans.

And pretty much all logging has a performance affect.

like image 43
jtahlborn Avatar answered Oct 27 '22 00:10

jtahlborn


Attach Visual VM to your process and inspect the mbeans. If you've never used it before (it's part of the Oracle JDK download), you will likely have to install the MBean plugin (which is easy)

http://docs.oracle.com/javase/6/docs/technotes/guides/visualvm/

http://visualvm.java.net/mbeans_tab.html

like image 39
wolfcastle Avatar answered Oct 27 '22 01:10

wolfcastle