Java Notes


Enable hotspot Dtrace probes

$ jinfo -flag -XX:+DTraceAllocProbes <JVM PID> $ jinfo -flag -XX:+DTraceMethodProbes <JVM PID> $ jinfo -flag -XX:+DTraceMonitorProbes <JVM PID> $ jinfo -flag -XX:+ExtendedDTraceProbes <JVM PID>

Get garbage collection metrics

$ java -verbose:gc -XX:-PrintGCDetails and -XX:-PrintGCTimeStamps -Xloggc:/home/matty/gc.log

Start JVM with remote management capabilities

$ java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8180 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false

Get a heap dump and vew it in a browser

$ jmap -dump:file=heap.bin $ jhat -J-mx512m heap.bin $ curl http://localhost:7000

Set the minimum and mximum amount of heap space

$ java -server Xms1g -Xmx1g

Enable parallel garbage collection. This will use all CPUs to perform garbage collection, so short pauses may occur

$ java -server -XX:UseParallelGC -XX:UseParallelOldGC

Use the concurrent mark/sweep method to minimize pauses

$ java -server -XX:+UseConcMarkSweepGC

Set the thread stack size to 256k (default 1MB)

$ java -server -XX:ThreadStackSize=256k

Tell java to ignore calls to System.gc()

$ java -server -XX:+DisableExplicitGC

Set the new generation size for newly created objects

$ java -server -Xmn256m

Log when garbage colelctions events occur

$ java -server -verbose:gc

Enable the JMX management agents so jconsole works

$ java -server -Dcom.sun.management.jmxremote

Dump the heap if we run out of memory

$ java -XX:+HeapDumpOnOutOfMemoryError

Touch each memory page to avoid ZFODs

$ java XX:+AlwaysPreTouch ...

Set the old and new ratio to 2:1 (384mb -> 256mb old, 128mb new)

$ java -XX:NewRatio=2

Adjust the perm gen size

$ java -server -Xss512k -XX:PermSize=256 -XX:MaxPermSize=256m -Xms1024m \ -Xmx1024m -Xloggc:/var/llogs/gclog -verbose:gc

DTrace hotspot probes:

Probe arguments

References

*Garbage collection tuning:
http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html

THIS INFORMATION IS PROVIDED UNDER A GPLV2 LICENSE
THE GPLV2 LICENSE CAN BE VIEWED HERE