This is the mail archive of the
mauve-discuss@sources.redhat.com
mailing list for the Mauve project.
Re: Adding your java test to The Mauve Java test suite?
- From: Petter Reinholdtsen <pere at hungry dot com>
- To: Bill Pugh <pugh at cs dot umd dot edu>
- Cc: Jeremy Manson <jmanson at cs dot umd dot edu>, mauve-discuss at sources dot redhat dot com
- Date: 18 May 2002 15:47:46 +0200
- Subject: Re: Adding your java test to The Mauve Java test suite?
- References: <E177bzs-0005x5-00@saruman.uio.no><p05111701b906d038fb9a@[129.2.176.73]>
- Reply-by: Tue, 1 Jan 1801 04:37:40 +1000
[Bill Pugh]
> Actually, we have a set of three test cases for volatiles, all of
> which should be added to mauve. I'll ask Jeremy (a grad student
> working with me on the Java Memory Model) to get involved in helping
> you with this and preparing versions of all three that work in the
> mauve test harness.
Thanks. He should get active on the mauve mailinglist, and start
sending patches and new test-cases.
> All three are available at:
> http://www.cs.umd.edu/~pugh/java/memoryModel/Volatiles.tar
>
> It looks like the one below is a valid port of the AtomicLong test.
That is correct.
>> Is it OK
>> with you that I submit this patch for inclusion into Mauve, licensed
>> using the GPL?
>
> yes, of course, although we should do it right and get all three tests
> in mauve.
Just to make sure the Mauve developers are aware of this test, I copy
this message to the mailing list. (I hope they accept non-subscriber
postings. :-)
This is a test for the CVS version of Mauve. I stored it in
'gnu/testlet/java/lang/Long/AtomicLong.java' in my tree. Please
include it in the Mauve distribution.
//// Test if access to volatile long (64 bit) valuies is atomic.
//
// From an example in Dr. Dobb's Journal june 2002, page 93.
// Copyright (c) 2002 Peter Haggar and Petter Reinholdtsen
// Written by Peter Haggar, and addapted for mauve by Petter
// Reinholdtsen <pere@td.org.uit.no>
// This file is part of Mauve.
// Mauve is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.
// Mauve is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Mauve; see the file COPYING. If not, write to
// the Free Software Foundation, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
// Tags: JDK1.0
package gnu.testlet.java.lang.Long;
import gnu.testlet.Testlet;
import gnu.testlet.TestHarness;
public class AtomicLong implements Testlet
{
static volatile long val;
static int count = 10000000;
static volatile boolean failed = false;
class Runner extends Thread
{
long key;
TestHarness harness;
Runner(int k, TestHarness h)
{
harness = h;
long temp = k;
// key = 00000001 00000001 for thread 1
// key = 00000002 00000002 for thread 2
key = (temp << 32) | temp;
}
public void run()
{
for (int i = 0; !failed && i < count; i++)
{
// This 64 bit assignment is supposed to be atomic since
// val is declared atomic
long temp = val; // temp = 00000001 00000001
long temp1 = temp >>> 32; // temp1 = 00000000 00000001
long temp2 = temp << 32; // temp2 = 00000001 00000000
temp2 = temp2 >>> 32; // temp2 = 00000000 00000001
if (temp1 != temp2)
failed = true;
// This 64-bit assigment is supposed to be atomic
// since val is declared volatile. temp1 should
// always equal temp2.
val = key;// val should always = 00000001 00000001 for thread 1
}
}
}
public void test (TestHarness harness)
{
final int threadcount = 10;
try {
Thread[] threads = new Thread[threadcount];
for (int t = 0; t < threadcount; t++)
{
threads[t] = new Runner(t + 1, harness);
threads[t].start();
}
for (int t = 0; t < threadcount; t++)
{
try {
threads[t].join();
} catch (InterruptedException e) {
harness.fail("Error: Unexpected exception " + e);
}
}
harness.check(!failed, "Error: access to 'volatile long' is "+
"not atomic.");
} catch (Exception e) {
harness.fail("Error: Unexpected exception " + e);
}
}
}