Skip to main content

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

MTRAT and volatile    Point your RSS reader here for a feed of the latest messages in this thread


     

 
 

My developerWorks
 Welcome, Guest
Sign in or register
This question is answered.

Permlink Replies: 2 - Pages: 1 - Last Post: Jul 2, 2009 7:20 AM Last Post By: kcc Threads: [ Previous | Next ]
kcc

Posts: 11
Registered: Jan 22, 2009 04:46:21 AM
MTRAT and volatile
Posted: Jun 22, 2009 11:45:58 AM
 
Click to report abuse...   Click to reply to this thread Reply
Hi,
Does MTRAT support volatile as correct way of synchronization?

It looks like it does not:

% cat VolatileTest.java
public class VolatileTest {
public static volatile boolean volatile_var;
public static void main (String[] args) {
volatile_var = false;
(new Thread() { public void run() { volatile_var = true; }; }).start();
(new Thread() { public void run() { while (!volatile_var); }; }).start();
}
}
% javac VolatileTest.java && java VolatileTest && mtrat VolatileTest
Data Race 1 : 49 : VolatileTest : volatile_var
Thread "Thread-1" : Tid 11 : Rid 0 : WRITE
Lock Set : [ ]
Vector Clock : 2
VolatileTest$1 : run : 5
Thread "Thread-2" : Tid 12 : Rid 0 : READ
Lock Set : [ ]
Vector Clock : 2
VolatileTest$2 : run : 6

Thanks!

' P

Posts: 18
Registered: Mar 11, 2008 09:35:44 PM
Re: MTRAT and volatile
Posted: Jul 02, 2009 07:14:03 AM   in response to: kcc in response to: kcc's post
 
Click to report abuse...   Click to reply to this thread Reply
In our current implementation, all the volatile fields access are regarded as race-free, according to java memory model. In mtrat, there is an option, -Dcom.ibm.mtrat.novolatile=true, tell instrumentation engine to skip all the instrumentation to volatile fields accesses. However, we think there are some points to improve,
1. volatile long should not be race-free, so volatile long access should be not discarded.
2. -Dcom.ibm.mtrat.novolatile=true only enable discard volatile fields access in its owner class. For example, if volatile field VF is declared in class Foo, only VF accesses in class Foo is discarded. There should be some room to improve.

As your case shown, MTRAT can't know field volatile_var is a volatile or not by inspecting visitField instruction. We will fix this problem soon.
kcc

Posts: 11
Registered: Jan 22, 2009 04:46:21 AM
Re: MTRAT and volatile
Posted: Jul 02, 2009 07:20:45 AM   in response to: kcc in response to: kcc's post
 
Click to report abuse...   Click to reply to this thread Reply
thanks!

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