In Sun Solaris there is an incredibly useful command for tracking down low level issues, the command is called truss. truss allows you to trace system calls and signals, this means you can watch a compiled program including the Java JVM while it makes system calls.

For example while trouble shooting a JReports reporting issue, all I had to go on was this exception message.

JReports connection error

I can tell based on the stack trace that it was trying to make a socket connection that failed, but unfortunately that is not a lot to go on. So I used the truss command with the following options, -t tells it which system calls to follow (I was only interested in connect since that is whats failing), the -v and -x allows me to see all the arguments getting passed to these system calls. The -p tell it which pid to watch and 4079 happened to be the pid of the Glassfish instance running JReports

#truss -t connect -v connect -x connect -fp 4079
4079/85485:     connect(367, 0xA977CDC8, 16, SOV_DEFAULT)       Err#146 ECONNREFUSED
4079/85485:             AF_INET  name = 127.0.0.1  port = 80

This tells me that JReports was trying to connect to localhost(127.0.0.1) on port 80, which is a problem since I have the reports server bound to a specific interface not all interfaces. Now I at least know the problem and can work on a solution thanks to truss.

If you are using Linux then check out strace.