Systemtap scripts using hotspot and hotspot_jni tapsets from IcedTea

Below are a few examples demonstrating possible uses for systemtap static probe tracing in IcedTea/OpenJDK.

To run these scripts, you'll need a fairly recent IcedTea6 build of OpenJDK, which has been configured with the "--enable-systemtap" option. This may already be included on your system. At this point I assume you have systemtap installed and are able to run a systemtap script in the general case; if not, see the SystemTap page.

JThreadStats, displays a summary of the method calls of each thread in a java program. The current and maximal method nesting depth, as well as a tally of the number of method calls, are displayed for each thread. Run as:
$ stap -c 'java -XX:+DTraceMethodProbes (main_class_name)'
If you are using an IcedTea which you built yourself, you may need to specify the path to the tapsets directory within your local build, such as:
-I (icedtea_dir)/openjdk/build/linux-amd64/j2sdk-image/tapset
This extra parameter applies equally to the examples below. Note that you will need to adjust the path above to the actual (icedtea_dir) on your system, or also for example if you are on an i686 system rather than amd64.

JObjectStats, displays a summary of each thread's object allocations (number and total size in bytes of objects). Also displayed is a tally of garbage collection executions. Run as:
$ stap jobjectstats.stp -c 'java -XX:+DTraceAllocProbes (main_class_name)'

JObjectStats2, based on above. Displays, for each thread showing activity in an interval, the top 5 class types allocated. Intervals terminate once a single class has been allocated 8192 times in a single thread, or every 3 seconds. Cumulative data is stored for a final summary once process ends. Run as:
$ stap jobjectstats2.stp -c 'java -XX:+DTraceAllocProbes (main_class_name)'

JContendStats, displays a summary of each thread's contention status. Threads that have not shown contention activity are omitted. Also displayed is a tally of wait events per thread, as well as total waiting time. Run as:
$ stap jcontendstats.stp -c 'java -XX:+DTraceMonitorProbes (main_class_name)'

You can also run a java app directly (rather than calling the java executable), provided the app has a way to pass the appropriate -XX parameter to the jvm. There is a -XX:+ExtendedDtraceProbes which implies all three off the -XX parameters used above; these enable optional dtrace probes, as documented here. Having the probes enabled adds significant overhead, so only the necessary group(s) of probes should be enabled when attempting to trace java programs using systemtap.
It *may* be possible to attach systemtap to an already running java program and use these scripts, but in some cases you will notice anomalous output.