Monday, December 6, 2010

Freescale's Deadlock Preventer is now released!

To try it out:
  1. Be sure to have an Eclipse 3.6.1 SDK layout, and using JDK 1.6 as your default JRE (jdk 1.7 doesn't work yet)
  2. Install Git
  3. Set your user and email in Git
  4. Type in the shell (cygwin on windows):
git clone git@github.com:sbeauchamp/Deadlock-Preventer.git
This will create a directory on your file system containing all the deadlock preventer plugins.
If you simply want to run the deadlock preventer tool, get the 4 plugins under
./Deadlock-Preventer/build/eclipse/plugins/
And copy them in the eclipse/dropins of your eclipse directory:
You will see that a new view is available from "Other/Deadlock Preventer".

alt
The easiest way to try is out is to create a new java project, with the following sample code in Main.java:
public class Main {
public static void main(String[] args) {
new Main().test();
}
Object lock = new Object();
Object lock2 = new Object();
private void test() {
synchronized(lock) {
synchronized(lock2) {
code();
}
}
Thread thread = new Thread(new Runnable() {
public void run() {
synchronized(lock2) {
synchronized(lock) {
code();
}
}
}
});
thread.start();
try {
thread.join();
} catch (InterruptedException e1) {
}
}
private void code() {
System.out.println("test");
}
}
Then create a new launch configuration to run the program. The new configuration will automatically appear in the combo box under the tab "Eclipse JDT Debugging" of the "Deadlock Preventer" view.
Once you click "Debug" from that tab (using the "Run/Debug" menu does not have the same effect), the program runs with the deadlock preventer automatically instrumenting the byte code.
You will then see the following error being reported:

altAnd if double-clicked the full information is displayed:

alt
By setting a breakpoint on "RuntimeException"s and using the 'Interactive' or “throw exception" mode, you are able to break in the debugger at the exact point where the inconsistent locking order is detected.
This should be enough to get your started with using the deadlock preventer, and investigating potential deadlocks in your programs.
In a next post, I will post the different options and runtime settings of the deadlock preventer including those useful to integrate it in a release engineering process.
P.S. I submitted a talk to EclipseCon 2011 on the deadlock preventer and using it to prevent deadlocks in Eclipse plugins. Please drop a comment in the submission if you think it would be an interesting talk.

5 comments:

Anonymous said...

Just installed it. It detects some deadlocks that I suspected but never got to find exactly. I hope that I will solve them soon.
BTW, you provide easy access to product launch configuration but why don't you provide launch configuration of tests? Is there a technical reason?

Serge Beauchamp said...

Hi, I'm happy it can be of use for you :)

There's not really a technical reason why it wouldn't work for test launch configurations.

All the view needs to be able to support a new launch configuration type, is to know which launch configuration setting corresponds to the vm arguments.

You can see in "com.freescale.deadlockpreventer.agent.workbench.LaunchConfigurationConfigurator.java line 161, it hard-codes the LC types it supports (those having the "org.eclipse.jdt.launching.VM_ARGUMENTS" setting).

If there was an Eclipse debugger API to set such setting, it could support any LC type transparently, but I couldn't find one.

I'll look into supporting more types.

Serge Beauchamp said...

You can now download an updated version off github, which supports "JUnit" and "JUnit Plug-in Test" types of launch configurations.

Anonymous said...

Nice :)

I hope to find time to test it next week.

But going further... Is there an application to launch it in headless mode in order to integrate it in Continuous Integration?

Serge Beauchamp said...

Yup, there's a mode where it can be used programatically from the command line to report issues automatically from, say, nightly builds.

I'll write a post in a few days about it.