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

5

8

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?

Errantry answered 15/2, 2012 at 18:22 Comment(0)
W
7

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

java -XX:+PrintFlagsFinal -server -version

Wittenburg answered 15/10, 2012 at 23:29 Comment(0)
S
3

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.

Sleigh answered 10/1, 2017 at 10:54 Comment(0)
B
1

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

And pretty much all logging has a performance affect.

Bellbottoms answered 15/2, 2012 at 18:31 Comment(0)
G
1

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

Grath answered 15/2, 2012 at 18:38 Comment(0)
A
0

If the GC is becoming an issue I would recommend you take a look into Java RTS (real-time system).

Java RTS allows you to gain precise control on when the GC works. Meaning that you have utter control of the worst-case-scenario and, therefore, can simulate how your system will perform under the stressfull condition possible.

Angola answered 15/2, 2012 at 18:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.