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
* Brian Goetz presentation on concurrency http://developers.sun.com/events/techdays/presentations/2007/TD_BOS_Concurrency_Goetz.pdf
* Generational collection: http://www.javaworld.com/javaworld/jw-01-2002/jw-0111-hotspotgc.html
* IBM’s Java developer site: http://www.ibm.com/developerworks/java
* Using jconsole: http://java.sun.com/j2se/1.5.0/docs/guide/management/jconsole.html
* Troubleshooting: http://java.sun.com/j2se/1.5/pdf/jdk50_ts_guide.pdf
* Quick troubleshooting guide: http://java.sun.com/javase/6/webnotes/trouble/other/matrix6-Unix.html
* Garbage collection FAQ: http://java.sun.com/docs/hotspot/gc1.4.2/faq.html
* Java threads tutorial: http://scv.bu.edu/Doc/Java/tutorial/java/threads/
* JVM specification: http://java.sun.com/docs/books/jvms/second_edition/html/VMSpecTOC.doc.html
* Java DTrace probes: http://java.sun.com/javase/6/docs/technotes/guides/vm/dtrace.html
http://blogs.sun.com/kamg/entry/built_in_dtrace_probes_in
* Jstat utility:
http://java.sun.com/j2se/1.5.0/docs/tooldocs/share/jstat.html * Reference objects and garbage collection
http://java.sun.com/developer/technicalArticles/ALT/RefObj/ * JVM option list:
http://blogs.sun.com/watt/resource/jvm-options-list.html * Improving Java Application Performance and Scalability by Reducing Garbage Collection Times and Sizing Memory Using JDK 1.4.1:
http://developers.sun.com/mobility/midp/articles/garbagecollection2/ * Turbo-charging Java HotSpot Virtual Machine, v1.4.x to Improve the Performance and Scalability of Application Servers:
http://java.sun.com/developer/technicalArticles/Programming/turbo/ * Object query language:
http://blogs.sun.com/sundararajan/entry/what_s_in_my_java * JVM monitoring with SNMP:
http://gentoo-wiki.com/JVM_Monitoring_with_SNMP

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