This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes Static deadlock analysis Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Static deadlock analysis" Watch "Static deadlock analysis" New topic
Author

Static deadlock analysis

Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24081
    
  15

Deadlocks are always, at the base of it, caused by different threads locking sets of objects in different orders. Is anyone aware of any tool which can do a sort of "static deadlock analysis" of a library? By this, I mean examine trajectories though possible call stacks, and find cases where locks are acquired in varying orders. You can simply run an application and watch to see if it deadlocks; but a library represents many possible applications, and whereas some of those may be fine, others may deadlock because of errors in the library.

Of course, one way to deal with this would be to design things properly from the start; this doesn't help if the codebase already exists. And another approach would be an extensive, and expensive, code review, but there is no guarantee that would find all the issues.

Anyway, has anyone ever heard of a tool that does anything like this automatically?


[Jess in Action][AskingGoodQuestions]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
That would be interesting ... it would take an unusual understanding of possible sequential passes through code. Too hard for me anyhow.

Some thread package - Doug Lea? - has a method that takes an array of things you'd like to synchronize on. It sorts the array in "natural" order and locks objects in that order. So a bunch of different clients could ask for diffrent overlapping combinations of objects and always get them in the proper order. I thought that was pretty clever, probably need to go look up how it works.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Yaroslav Chinskiy
Ranch Hand

Joined: Jan 09, 2001
Posts: 147
Hi,

I used to use JProbe to profile and test apps. JProbe used to give wornings indicating possible deadlocks.


Same features are probably in OptimizeIt and JProfiler.

The biggest problem with deadlock is its only apperent at runtime and may depend on the ThreadScheduler. So you may find a tool that will analize the code and indicate that its style may lead to deadlock.

Let us know if you find anything usefull.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24081
    
  15

Thanks Yaroslav -- you're right, JProbe has a kind of lock-order analysis as a component of their Threadalyzer tool:


Lock Order Analyzer
The Lock Order analyzer predicts possible deadlocks by tracking the order in which locks are acquired, and reporting cases where concurrent threads need to hold the same lock and the same time.


But I'm concerned about the word "tracking" which implies to me that it watches a running app, as opposed to doing static analysis. It's really easy to find deadlocks in a real app, in my experience: you just run the sections you're testing in a loop on a multiprocessor machine, and your deadlock will turn up soon enough. I'm more interested in testing possible applications that don't yet exist, but which use a library which includes possibly faulty synchronization primitives.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Static deadlock analysis
 
Similar Threads
tips to improve the performance of my application
preemptive scheduler
Model Driven Language with event processing accent
A lot of deadlocks using JDBC
ecperf problems