Skip to main content

alphaWorks  >  Forums  >  Multi-Thread Run-time Analysis Tool for Java  >  developerWorks

hybrid vs pure happens-before    Point your RSS reader here for a feed of the latest messages in this thread


     

 
 

My developerWorks
 Welcome, Guest
Sign in or register
Permlink Replies: 12 - Pages: 1 - Last Post: Jul 2, 2009 8:26 PM Last Post By: ' P Threads: [ Previous | Next ]
kcc

Posts: 11
Registered: Jan 22, 2009 04:46:21 AM
hybrid vs pure happens-before
Posted: Jun 08, 2009 10:43:38 AM
Click to report abuse...   Click to reply to this thread Reply
Hello,
As I understand, MTRAT is a hybrid races detector.
Is there a flag which makes MTRAT act like a pure happens-before detector (i.e. treat Unlock()/Lock() as a happens-before arc)?
Thanks,
--kcc
daniel-laptop

Posts: 21
Registered: Nov 19, 2008 08:25:14 PM
Re: hybrid vs pure happens-before
Posted: Jun 08, 2009 11:29:52 PM   in response to: kcc in response to: kcc's post
Click to report abuse...   Click to reply to this thread Reply
Hi,

Currently MTRAT didn't provide related flag. As you may know, the happens-before used in our hybrid method is a subset of the pure happen-before approach for performance consideration, since pure happen-before introduces big performance overhead. So only enabling happen-before in MTRAT will not act like a pure one.
kcc

Posts: 11
Registered: Jan 22, 2009 04:46:21 AM
Re: hybrid vs pure happens-before
Posted: Jun 11, 2009 08:40:09 AM   in response to: daniel-laptop in response to: daniel-laptop's post
Click to report abuse...   Click to reply to this thread Reply
Are thread start/create and finish/join considered as h-b arcs? (looks like yes)
What about notify/wait? (looks like *NO*)
What are the other event pairs handled as h-b arcs?
daniel-laptop

Posts: 21
Registered: Nov 19, 2008 08:25:14 PM
Re: hybrid vs pure happens-before
Posted: Jun 11, 2009 09:28:52 AM   in response to: kcc in response to: kcc's post
Click to report abuse...   Click to reply to this thread Reply
Thread start/create, finish/join, notify/wait are all supported in MTRAT.
kcc

Posts: 11
Registered: Jan 22, 2009 04:46:21 AM
Re: hybrid vs pure happens-before
Posted: Jun 11, 2009 10:38:26 AM   in response to: daniel-laptop in response to: daniel-laptop's post
Click to report abuse...   Click to reply to this thread Reply
>> notify/wait are all supported
Hm. I can't see this support.
Did I do something wrong?

% cat -n NotifyWaitTest.java
1 public class NotifyWaitTest {
2 public static int var;
3 public static boolean done;
4 public static Object lock;
5
6 public static void main (String[] args) {
7 System.out.println("NotifyWaitTest:");
8 lock = new Object();
9 done = false;
10 var = 0;
11 Thread t1 = new Thread() {
12 public void run() {
13 var++;
14 // allow Thread2 to block on 'done'.
15 try { Thread.sleep(3000); } catch (Exception e) {}
16 synchronized (lock) {
17 done = true;
18 System.out.println("setting done to true");
19 lock.notify();
20 }
21 }
22 };
23
24 Thread t2 = new Thread() {
25 public void run() {
26 synchronized (lock) {
27 while (!done) {
28 System.out.println("blocking on done");
29 try { lock.wait(); } catch (Exception e) {}
30 }
31 System.out.println("unblocked");
32 }
33 var++;
34 }
35 };
36 t1.start();
37 t2.start();
38 try { t1.join(); t2.join(); } catch (Exception e) {}
39 System.out.println("var = " + var);
40 }
41 }
% javac NotifyWaitTest.java && ../mtrat/mtrat NotifyWaitTest
NotifyWaitTest:
blocking on done
setting done to true
unblocked
Data Race 1 : 55 : NotifyWaitTest : var
Thread "Thread-1" : Tid 11 : Rid 0 : WRITE
Lock Set : [ ]
Vector Clock : 2
NotifyWaitTest$1 : run : 13
Thread "Thread-2" : Tid 12 : Rid 0 : WRITE
Lock Set : [ ]
Vector Clock : 2
NotifyWaitTest$2 : run : 33

var = 2

daniel-laptop

Posts: 21
Registered: Nov 19, 2008 08:25:14 PM
Re: hybrid vs pure happens-before
Posted: Jun 14, 2009 11:08:09 AM   in response to: kcc in response to: kcc's post
Click to report abuse...   Click to reply to this thread Reply
Yes, you are right. I reproduced this problem in my linux box. I have found the root cause, but it's not related to our happen-before relationship building in our runtime analysis, it's because some information which is used to build hp relationship is cleared incautiously when a thread is terminated.

If modify the code as below, the hp will work in your case. Thanks for your test case, which help me to fix the problem, please feel free to let me know your further questions :)

try { Thread.sleep(3000); } catch (Exception e) {}
16 synchronized (lock) {
17 done = true;
18 System.out.println("setting done to true");
19 lock.notify();
try { Thread.sleep(2000); } catch (Exception e) {}
20 }
21 }
22 };
kcc

Posts: 11
Registered: Jan 22, 2009 04:46:21 AM
Re: hybrid vs pure happens-before
Posted: Jun 16, 2009 10:53:36 PM   in response to: daniel-laptop in response to: daniel-laptop's post
Click to report abuse...   Click to reply to this thread Reply
Ok. I expect this is not hard to fix.
Few more questions:

1. What are the other events that are handled as h-b?
2. Can you add a flag that will treat Unlock=>Lock as h-b arc (even if this will make the tool terribly slow)?
3. Can you add a pair of annotations that create a custom h-b arc? Something like we have for C++: http://code.google.com/p/data-race-test/wiki/DynamicAnnotations#Message_queue
daniel-laptop

Posts: 21
Registered: Nov 19, 2008 08:25:14 PM
Re: hybrid vs pure happens-before
Posted: Jun 23, 2009 12:48:21 AM   in response to: kcc in response to: kcc's post
Click to report abuse...   Click to reply to this thread Reply
1. Thread start/create, finish/join, notify/wait are all supported in MTRAT.
2. I am sorry I don't quite understand your requirement. What do you really want?
3. That's interesting. We will discuss it to see if we have extra effort to do it.
kcc

Posts: 11
Registered: Jan 22, 2009 04:46:21 AM
Re: hybrid vs pure happens-before
Posted: Jun 23, 2009 01:14:43 AM   in response to: daniel-laptop in response to: daniel-laptop's post
Click to report abuse...   Click to reply to this thread Reply
>> 2. I am sorry I don't quite understand your requirement. What do you really want?

In Threadsanitizer (http://code.google.com/p/data-race-test/wiki/ThreadSanitizer) we have two basic modes:
a) hybrid mode (similar to what MTRAT does) and
b) pure happens-before mode: has much fewer false reports (of course, it is slower, less predictable, and misses some real races)

The difference in the implementation is in two lines:
http://code.google.com/p/data-race-test/source/browse/trunk/tsan/thread_sanitizer.cc?spec=svn1037&r=996#3536
http://code.google.com/p/data-race-test/source/browse/trunk/tsan/thread_sanitizer.cc?spec=svn1037&r=996#3560

This shouldn't be too hard to implement: just handle Unlock as Notify and Lock as Wait (under a special command line flag)
daniel-laptop

Posts: 21
Registered: Nov 19, 2008 08:25:14 PM
Re: hybrid vs pure happens-before
Posted: Jul 01, 2009 12:46:11 AM   in response to: kcc in response to: kcc's post
Click to report abuse...   Click to reply to this thread Reply
Yes, it should be easy to implement. Could you please tell me how you will use MTRAT after that? Why do you want this flag in MTRAT?
kcc

Posts: 11
Registered: Jan 22, 2009 04:46:21 AM
Re: hybrid vs pure happens-before
Posted: Jul 01, 2009 01:00:53 AM   in response to: daniel-laptop in response to: daniel-laptop's post
Click to report abuse...   Click to reply to this thread Reply
> {quote:title=daniel-laptop wrote:}{quote}
> Could you please tell me how you will use MTRAT after that? Why do you want this flag in MTRAT?

We are using ThreadSanitizer to find races in our C++ code.
It has too basic modes:
1. Conservative (pure-happens-before) which could be used by novice users because it gives very few false positives.
2. Aggressive (hybrid) which is used by the folks who can spend more time de-racing their code.
The hybrid mode has more false positives, but with dynamic annotations they can be defeated.

Ideally, we need a similar thing for Java.
Currently, MTRAT seems unusable because it has too many false reports and no way to suppress them.
These are the things we would need:
a. pure happens-before mode
b. annotations for the hybrid mode
c. support for volatile
d. support for java.util.concurrent (e.g., as I can see, CountDownLatch is not supported)
e. some way to suppress warnings that are not fixable by annotations (e.g. third_party code). Something like valgrind suppressions.

We've assembled few unittests for a Java race detector at http://code.google.com/p/data-race-test/source/browse/#svn/trunk/jtsan
MTRAT has a number of false reports there.

BTW, I am a bit puzzled by the license. It says "You are not authorized to use the Program for productive purposes".
So, I'll probably not be able to use it for testing real software...
??

' P

Posts: 18
Registered: Mar 11, 2008 09:35:44 PM
Re: hybrid vs pure happens-before
Posted: Jul 02, 2009 07:34:02 AM   in response to: kcc in response to: kcc's post
Click to report abuse...   Click to reply to this thread Reply
When we start MTRAT work, our target is very large program, such as Websphere middlewares, so we should make MTRAT as efficient as possible. That is the major reason that we choose hybrid approach. I agree with you that we may use pure happens-before mode to improve MTRAT's accuracy.

MTRAT supports for volatile, but not fully. I replied you in another thread on this problem.

MTRAT supports java.util.concurrent partially. We support ReentrantLock, Read/Writer Lock. CountDownLatch is not supported yet.

For license, I will talk with someone, and answer your question soon. Stay tune...
' P

Posts: 18
Registered: Mar 11, 2008 09:35:44 PM
Re: hybrid vs pure happens-before
Posted: Jul 02, 2009 08:26:39 PM   in response to: kcc in response to: kcc's post
Click to report abuse...   Click to reply to this thread Reply
In the section "1 License", you can say some words, shown below. "internal testing" should be fine.


IBM grants You a limited, nonexclusive, nontransferable
license to download, install, and use the Program during the
evaluation period solely for internal testing and evaluation purposes
and to provide feedback to IBM.

You may make a backup copy of the Program to support such
use. You are not authorized to use the Program for productive
purposes or to distribute the Program or any of its parts. You may
not modify or create derivative works of the Program. The
terms of this license apply to each copy that You make. You must
reproduce all copyright notices and all other legends of ownership on
each copy, or partial copy, of the Program.


Point your RSS reader here for a feed of the latest messages in all forums