TLtest.java: Reduce sleep time.

2004-07-27  Bryce McKinlay  <mckinlay@redhat.com>

	* testsuite/libjava.lang/TLtest.java: Reduce sleep time.
	* testsuite/libjava.lang/Thread_Alive.java: Remove old email address.
	Reduce sleep time.
	* testsuite/libjava.lang/Thread_HoldsLock.java: Modify to work around
	compiler bug.
	* testsuite/libjava.lang/Thread_Interrupt.java: Remove old email
	address. Reduce sleep times. Synchronize with target threads before
	attempting to interrupt them. Don't try to calibrate yeild count,
	instead, always loop for a fixed time.
	* testsuite/libjava.lang/Thread_Join.java: Remove old email address.
	* testsuite/libjava.lang/Thread_Monitor.java: Likewise.
	* testsuite/libjava.lang/Thread_Wait.java: Likewise.
	* testsuite/libjava.lang/Thread_Wait_2.java: Likewise.
	* testsuite/libjava.lang/Thread_Wait_Interrupt.java: Likewise.
	* testsuite/libjava.lang/pr179.java: Likewise.
	* testsuite/libjava.lang/Thread_Sleep.java: Likewise. Reduce sleep
	time. Remove upper bounds check on sleep time.

From-SVN: r85248
This commit is contained in:
Bryce McKinlay 2004-07-28 02:44:06 +00:00 committed by Bryce McKinlay
parent 1a837f7746
commit ce961468b7
12 changed files with 58 additions and 46 deletions

View File

@ -1,3 +1,23 @@
2004-07-27 Bryce McKinlay <mckinlay@redhat.com>
* testsuite/libjava.lang/TLtest.java: Reduce sleep time.
* testsuite/libjava.lang/Thread_Alive.java: Remove old email address.
Reduce sleep time.
* testsuite/libjava.lang/Thread_HoldsLock.java: Modify to work around
compiler bug.
* testsuite/libjava.lang/Thread_Interrupt.java: Remove old email
address. Reduce sleep times. Synchronize with target threads before
attempting to interrupt them. Don't try to calibrate yeild count,
instead, always loop for a fixed time.
* testsuite/libjava.lang/Thread_Join.java: Remove old email address.
* testsuite/libjava.lang/Thread_Monitor.java: Likewise.
* testsuite/libjava.lang/Thread_Wait.java: Likewise.
* testsuite/libjava.lang/Thread_Wait_2.java: Likewise.
* testsuite/libjava.lang/Thread_Wait_Interrupt.java: Likewise.
* testsuite/libjava.lang/pr179.java: Likewise.
* testsuite/libjava.lang/Thread_Sleep.java: Likewise. Reduce sleep
time. Remove upper bounds check on sleep time.
2004-07-27 Bryce McKinlay <mckinlay@redhat.com> 2004-07-27 Bryce McKinlay <mckinlay@redhat.com>
* testsuite/libjava.lang/Thread_HoldsLock.java: New test case. * testsuite/libjava.lang/Thread_HoldsLock.java: New test case.

View File

@ -46,7 +46,7 @@ class ThreadTest extends Thread {
d.set (Integer.toString (value)); d.set (Integer.toString (value));
try { try {
sleep((int)(Math.random() * 500)); sleep((int)((Math.random() * 20)));
} catch (InterruptedException e) {} } catch (InterruptedException e) {}
} }

View File

@ -1,6 +1,5 @@
// Test the status of the isAlive() flag before, during, and after thread // Test the status of the isAlive() flag before, during, and after thread
// execution. Check that thread's threadgroup is null after thread exits. // execution. Check that thread's threadgroup is null after thread exits.
// Origin: Bryce McKinlay <bryce@albatross.co.nz>
public class Thread_Alive implements Runnable public class Thread_Alive implements Runnable
{ {
@ -12,7 +11,7 @@ public class Thread_Alive implements Runnable
t.start(); t.start();
System.out.println(t.isAlive()); System.out.println(t.isAlive());
Thread.sleep(100); Thread.sleep(50);
synchronized (ta) synchronized (ta)
{ {

View File

@ -20,8 +20,8 @@ public class Thread_HoldsLock
public void check() public void check()
{ {
boolean held = Thread.currentThread().holdsLock(lock); Thread this_thread = Thread.currentThread();
System.out.println(held); System.out.println(this_thread.holdsLock(lock));
} }
} }

View File

@ -1,11 +1,21 @@
// Test interrupt() behaviour on a thread in wait(), sleep(), and spinning // Test interrupt() behaviour on a thread in wait(), sleep(), and spinning
// in a loop. // in a loop.
// Origin: Bryce McKinlay <bryce@albatross.co.nz>
class Waiter extends Thread class ThreadBase extends Thread
{
boolean ready = false;
synchronized void ready()
{
ready = true;
}
}
class Waiter extends ThreadBase
{ {
public synchronized void run() public synchronized void run()
{ {
super.ready();
System.out.println ("wait()"); System.out.println ("wait()");
try try
{ {
@ -22,14 +32,15 @@ class Waiter extends Thread
} }
} }
class Sleeper extends Thread class Sleeper extends ThreadBase
{ {
public void run() public void run()
{ {
super.ready();
System.out.println ("sleep()"); System.out.println ("sleep()");
try try
{ {
sleep(2000); sleep(5000);
System.out.println("Error: sleep() completed normally."); System.out.println("Error: sleep() completed normally.");
} }
catch (InterruptedException x) catch (InterruptedException x)
@ -42,40 +53,23 @@ class Sleeper extends Thread
} }
} }
class Looper extends Thread class Looper extends ThreadBase
{ {
// Return the number of Thread.yield()s we can do in 500ms.
static long calibrate ()
{
long i = 1;
for (int tries = 0; tries < 40; tries++)
{
long t = System.currentTimeMillis();
for (long n = 0; n < i; n++)
Thread.yield();
long t_prime = System.currentTimeMillis();
if (t_prime - t > 500)
return i;
i *= 2;
}
// We have no system clock. Give up.
throw new RuntimeException ("We have no system clock.");
}
static long yields = calibrate ();
public void run() public void run()
{ {
super.ready();
System.out.println ("Busy waiting"); System.out.println ("Busy waiting");
int count = 0; int count = 0;
for (long i=0; i < yields; i++) long start = System.currentTimeMillis();
while (true)
{ {
Thread.yield(); Thread.yield();
count += 5;
if (isInterrupted ()) if (isInterrupted ())
break; break;
long now = System.currentTimeMillis();
if ((now - start) > 5000)
break;
} }
synchronized (this) synchronized (this)
{ {
@ -91,10 +85,11 @@ class Looper extends Thread
} }
} }
class Joiner extends Thread class Joiner extends ThreadBase
{ {
public void run() public void run()
{ {
super.ready();
System.out.println("join()"); System.out.println("join()");
try try
{ {
@ -133,11 +128,17 @@ public class Thread_Interrupt
sleep_and_interrupt (j); sleep_and_interrupt (j);
} }
public static void sleep_and_interrupt(Thread t) public static void sleep_and_interrupt(ThreadBase t)
{ {
try try
{ {
Thread.sleep (250); synchronized (t)
{
while (!t.ready)
t.wait(10);
}
Thread.sleep (50);
t.interrupt (); t.interrupt ();
long t1 = System.currentTimeMillis(); long t1 = System.currentTimeMillis();
t.join (5000); t.join (5000);

View File

@ -1,5 +1,4 @@
// Many threads join a single thread. // Many threads join a single thread.
// Origin: Bryce McKinlay <bryce@albatross.co.nz>
class Sleeper implements Runnable class Sleeper implements Runnable
{ {

View File

@ -1,5 +1,4 @@
// Test that monitor locks work and are recursive. // Test that monitor locks work and are recursive.
// Origin: Bryce McKinlay <bryce@albatross.co.nz>
class T implements Runnable class T implements Runnable
{ {

View File

@ -1,5 +1,4 @@
// Test that Thread.sleep() works. // Test that Thread.sleep() works.
// Origin: Bryce McKinlay <bryce@albatross.co.nz>
public class Thread_Sleep public class Thread_Sleep
{ {
@ -9,9 +8,9 @@ public class Thread_Sleep
{ {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
System.out.println("sleeping"); System.out.println("sleeping");
Thread.sleep(1000); Thread.sleep(50);
long end = System.currentTimeMillis(); long end = System.currentTimeMillis();
if ((end - start) > 1100 || (end - start) < 990) if ((end - start) < 50)
System.out.println ("failed"); System.out.println ("failed");
else else
System.out.println("ok"); System.out.println("ok");

View File

@ -1,5 +1,4 @@
// Test basic thread creation and wait/notify functionality. // Test basic thread creation and wait/notify functionality.
// Origin: Bryce McKinlay <bryce@albatross.co.nz>
public class Thread_Wait implements Runnable public class Thread_Wait implements Runnable
{ {

View File

@ -1,6 +1,5 @@
// Create many threads waiting on a monitor. Interrupt some of them. Do the // Create many threads waiting on a monitor. Interrupt some of them. Do the
// others wake up correctly with notify() and/or notifyAll()? // others wake up correctly with notify() and/or notifyAll()?
// Origin: Bryce McKinlay <bryce@albatross.co.nz>
import java.util.Vector; import java.util.Vector;

View File

@ -1,6 +1,5 @@
// Create two threads waiting on a monitor. Interrupt one of them. Does the // Create two threads waiting on a monitor. Interrupt one of them. Does the
// other wake up correctly? // other wake up correctly?
// Origin: Bryce McKinlay <bryce@albatross.co.nz>
class Waiter extends Thread class Waiter extends Thread
{ {

View File

@ -4,8 +4,6 @@
// Class.isInstance() and Class.isAssignableFrom(), and isAssignableFrom() // Class.isInstance() and Class.isAssignableFrom(), and isAssignableFrom()
// functionality in the event that an interface argument that is not // functionality in the event that an interface argument that is not
// implemented by any loaded class is given. // implemented by any loaded class is given.
//
// Bryce McKinlay <bryce@albatross.co.nz>
class A class A
{ {