Java,  Mac OS X

Some Command Line java Debugging Options

There’s an excellent tool that can be used to grab a heap dump from a Java process. It’s called jmap. To do so, run the jmap command, followed by a format and a file path as the format and file operators. Also, provide the PID, as follows:

jmap -dump:format=b,file=~/memdump.hprof 80446

Once dumped, you can view the dump file in the Memory Analyzer Tool (MAP) and find objects that use use too much memory and/or have memory leaks, as part of your troubleshooting. You can also replace the pid with a name of an executable or a core. Run the map tool along with a -h option for a help summary.

A sister tool is jps, which can be used to just list running processes by pid and then path. To run, assuming the same pid as earlier:

jps 80446

You can also run a java debugger daemon using jsadebugd, which attaches a process as a debug server. Then stack, map and info can attach via RMI. Finally, not everyone has access to every path on a file system. So jinfo can be used to view a configuration for a Java process or core. To run, simply run jinfo followed by a pid, executable or core name, as follows (assuming 80446 is the pid for the java process in question:

jinfo 80446