Some adventures in road and trail running.
For Running stuff click here. For Eclipse stuff click here.

Monday, October 15, 2007

Deadlock Detection with Eclipse

Recently I was working away developing and repeatedly kept having Eclipse lock up on me via a deadlock. Annoying!

Since I have the privilege of working both on and in Eclipse I had the tools at hand to diagnose the problem. Since your CPU is not doing any work whilst sitting in a deadlock you may as well invoke the debugger and log the bug to save yourself and others future pain.

Of course I knew the problem was not in my code :-)
But I had no idea where the bug might be hiding.
So I launched a debug session of the Eclipse application and performed the steps I knew would lead to the deadlock.

Once in the deadlock I went to the debug view, and set it to show monitor information via the view menu.
I selected the debug process and clicked "pause".
This will pause the JVM and suspend execution of all threads (not like they were doing anything anyway!).

The Eclipse debug framework will make it easy for your to diagnose and report the problem.
Within the view, the threads that are in contention will be indicated in red. The monitor(s) that a thread is waiting for and/or owns are indicated.

In the simple example shown below we have two threads that are deadlocked
Even better when you log the bug report you can provide stack traces pointing right to the problem.
Happy debugging.


Chris Aniszczyk (zx) said...

you learn something new everyday :D

Jacek Pospychala said...

it's excellent. But you were running Eclipse in Eclipse, right?

What I really miss, is that often Eclipse works really good for me, but when it hangs I's always after I launched it just for few seconds and left for hours. Maybe adding some params to my eclipse.ini would help.

Darin Swanson said...

You are correct Jacek.

Your problem could be:
- eclipse is being swapped back into active memory?
- there is a leak and Eclipse has run out of memory after being left open for a long time...which would be a bug.

You can also use the default VM dump etc to report the problem. Details found at:

Anonymous said...

I could apply this to something I was working on today. Thanks for posting it :-).

Darin Swanson said...

Thanks Elias. I look forward to meeting you at the Eclipse demo camp.