Friday, January 23, 2015

Most Useful JVM arguments



  
Most of us know these commands or arguments. Still wanted to collect and have it in Single place.

Check a java process status
ps –ef | grep java or
jps
Check java application status by specifying application status
jps –lv | grep <app name>
Example jps –lv | grep managed
To know about java process information including arguments
jinfo <PID> <-d64>
-d64 is required when java process is running on 64 platform
To get stack trace or thread dumps
jstack < PID >
It can be redirected to an output file
To get heap dump for memory issue analysis
jmap -dump:live,format=b,file=heap.bin <pid>
Generating a heap in production environment is not recommended. So can capture only historical data using,
jmap -histo:live  <pid> >> filename.txt
To understand what each thread is doing at the time of a crash
Jdb
ptree – to known the process tree- can view parent processes

Useful Java parameters
Some options may vary per architecture/OS/JVM version. Boolean options are turned on with -XX:+<option> and turned off with -XX:-<option>. Numeric options are set with -XX:<option>=<number>. Numbers can include 'm' or 'M' for megabytes, 'k' or 'K' for kilobytes, and 'g' or 'G' for gigabytes (for example, 32k is the same as 32768). String options are set with -XX:<option>=<string>, are usually used to specify a file, a path, or a list of commands
Set Heap Size
 Xms<size>, Xmx<size>,
Sizing Young Generation
Xmn<size>
XX:MaxNewSize=size
PermSpace sizing
-XX:MaxPermSize=64m
Size Thread Stack size
-XX:ThreadStackSize=512
Print GC details
-Xloggc:<filename>            Log GC verbose output to specified file. The verbose output is controlled by the normal verbose GC flags.
-XX:-UseGCLogFileRotation             Enabled GC log rotation, requires -Xloggc.
-XX:NumberOfGClogFiles=1
-XX:GCLogFileSize=8K
-XX:-PrintGC      Print messages at garbage collection. Manageable.
-XX:-PrintGCDetails         Print more details at garbage collection. Manageable. (Introduced in 1.4.0.)
-XX:-PrintGCTimeStamps             Print timestamps
GC algorithm
Parallel GC- New and old generation
XX:+UseParallelGC,X:+UseParallelOldGC,XX:ParallelGCThreads=24
G1 GC
-XX:+UseG1GC -XX:G1ReservePercent=n -XX:G1HeapRegionSize=n
Concurrent GC –Old Generation
-XX:-UseConcMarkSweepGC -XX:ConcGCThreads=n
Disable Explicit Garbage collection
-XX:-DisableExplicitGC