Skip to content, Skip to search

Changes

Debugging

1,054 bytes added, 08:37, 26 September 2014
Expand command line debugging section. Add jstack use. Explain how to use the stack trace.
= Debugging JVM hangs =
When the Java VM hangs, the reason might be a dead-lock. You can often find out what is happening by reading the thread dump which you can get via {{key|Ctrl}}+{{key|\}} (aka "stack trace" - a snapshot of what is being executed in the console where you started FijiJVM). On Linux and MacOSX, you You can also send the signal ''3'' via acquire a thread dump in either of the ''kill'' command. On Windows, you may need to press {{key|Ctrl}}+{{key|Pause}} (i.e., {{key|Break}}) instead of {{key|Ctrl}}+{{key|\}}.following ways:
* If you [[#Command line debugging|launch Fiji from the console]], you can press {{key|Ctrl}}+{{key|\}} in the same console to print the stack trace. On Windows, you may need to press {{key|Ctrl}}+{{key|Pause}} (i.e., {{key|Break}}) instead of {{key|Ctrl}}+{{key|\}}.* Alternately, you can use the ''jstack'' command (you don't need to run Fiji from the command line in this case). This requires that you first find the PID (process ID) of Fiji. You can do so by running:<source lang="bash">jps</source>::from the command line to print a list of running Java processes. If you're not sure which PID is Fiji's, you can close Fiji, run ''jps'', open Fiji and run ''jps'' again. Whichever PID is present in the second run but not the first is Fiji's. Then, to acquire a stack trace, just run:<source lang="bash">jstack <Fiji's PID></source> For GUI-based debugging, can also attach to the JVM Fiji PID using the ''jvisualvm'' program that you can find in ''java/<platform>/<jdk>/bin/''. Here you can simply press a big ''Thread Dump'' button to view the stack trace. MacOSX users, please note that Apple decided that the VisualVM tool should no longer be shipped with the Java Development Kit; you will have to download it [http://visualvm.java.net/download.html from here]. Regardless of which method you use to acquire the stack trace, to debug you will want to acquire multiple stack traces over time and compare. If all the stack traces are in the same method execution, then that's the source of the deadlock (or slowdown).
= Debugging memory leaks =
One way to find out what is happening is to use ''jvisualvm'' (see [[#Debugging JVM hangs]]) to connect to the Fiji process, click on ''Heap Dump'' in the ''Monitor'' tab, in said tab select the sub-tab ''Classes'' and sort by size. Double-clicking on the top user should get you to a detailed list of ''Instances'' where you can expand the tree of references to find out what is holding a reference still.
 
MacOSX users, please note that Apple decided that the VisualVM tool should no longer be shipped with the Java Development Kit; you will have to download it [http://visualvm.java.net/download.html from here].
= Debugging hard JVM crashes =
Bureaucrat, emailconfirmed, incoming, administrator, uploaders
735
edits