From ce961468b70fa2bcbb593b6b1a3345250f24e0aa Mon Sep 17 00:00:00 2001 From: Bryce McKinlay Date: Wed, 28 Jul 2004 02:44:06 +0000 Subject: [PATCH] TLtest.java: Reduce sleep time. 2004-07-27 Bryce McKinlay * 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 --- libjava/ChangeLog | 20 ++++++ libjava/testsuite/libjava.lang/TLtest.java | 2 +- .../testsuite/libjava.lang/Thread_Alive.java | 3 +- .../libjava.lang/Thread_HoldsLock.java | 4 +- .../libjava.lang/Thread_Interrupt.java | 63 ++++++++++--------- .../testsuite/libjava.lang/Thread_Join.java | 1 - .../libjava.lang/Thread_Monitor.java | 1 - .../testsuite/libjava.lang/Thread_Sleep.java | 5 +- .../testsuite/libjava.lang/Thread_Wait.java | 1 - .../testsuite/libjava.lang/Thread_Wait_2.java | 1 - .../libjava.lang/Thread_Wait_Interrupt.java | 1 - libjava/testsuite/libjava.lang/pr179.java | 2 - 12 files changed, 58 insertions(+), 46 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 2ad34fae6e4..09ef4626600 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,23 @@ +2004-07-27 Bryce McKinlay + + * 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 * testsuite/libjava.lang/Thread_HoldsLock.java: New test case. diff --git a/libjava/testsuite/libjava.lang/TLtest.java b/libjava/testsuite/libjava.lang/TLtest.java index b7f4115b23f..6ddd0cbcd89 100644 --- a/libjava/testsuite/libjava.lang/TLtest.java +++ b/libjava/testsuite/libjava.lang/TLtest.java @@ -46,7 +46,7 @@ class ThreadTest extends Thread { d.set (Integer.toString (value)); try { - sleep((int)(Math.random() * 500)); + sleep((int)((Math.random() * 20))); } catch (InterruptedException e) {} } diff --git a/libjava/testsuite/libjava.lang/Thread_Alive.java b/libjava/testsuite/libjava.lang/Thread_Alive.java index d97ea25c5d3..e885e1624cd 100644 --- a/libjava/testsuite/libjava.lang/Thread_Alive.java +++ b/libjava/testsuite/libjava.lang/Thread_Alive.java @@ -1,6 +1,5 @@ // Test the status of the isAlive() flag before, during, and after thread // execution. Check that thread's threadgroup is null after thread exits. -// Origin: Bryce McKinlay public class Thread_Alive implements Runnable { @@ -12,7 +11,7 @@ public class Thread_Alive implements Runnable t.start(); System.out.println(t.isAlive()); - Thread.sleep(100); + Thread.sleep(50); synchronized (ta) { diff --git a/libjava/testsuite/libjava.lang/Thread_HoldsLock.java b/libjava/testsuite/libjava.lang/Thread_HoldsLock.java index 3a46466cb13..62119a16083 100644 --- a/libjava/testsuite/libjava.lang/Thread_HoldsLock.java +++ b/libjava/testsuite/libjava.lang/Thread_HoldsLock.java @@ -20,8 +20,8 @@ public class Thread_HoldsLock public void check() { - boolean held = Thread.currentThread().holdsLock(lock); - System.out.println(held); + Thread this_thread = Thread.currentThread(); + System.out.println(this_thread.holdsLock(lock)); } } diff --git a/libjava/testsuite/libjava.lang/Thread_Interrupt.java b/libjava/testsuite/libjava.lang/Thread_Interrupt.java index cb569c827c4..a69247422fe 100644 --- a/libjava/testsuite/libjava.lang/Thread_Interrupt.java +++ b/libjava/testsuite/libjava.lang/Thread_Interrupt.java @@ -1,11 +1,21 @@ // Test interrupt() behaviour on a thread in wait(), sleep(), and spinning // in a loop. -// Origin: Bryce McKinlay -class Waiter extends Thread +class ThreadBase extends Thread +{ + boolean ready = false; + + synchronized void ready() + { + ready = true; + } +} + +class Waiter extends ThreadBase { public synchronized void run() { + super.ready(); System.out.println ("wait()"); try { @@ -22,14 +32,15 @@ class Waiter extends Thread } } -class Sleeper extends Thread +class Sleeper extends ThreadBase { public void run() { + super.ready(); System.out.println ("sleep()"); try { - sleep(2000); + sleep(5000); System.out.println("Error: sleep() completed normally."); } 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() { + super.ready(); System.out.println ("Busy waiting"); int count = 0; - for (long i=0; i < yields; i++) + long start = System.currentTimeMillis(); + while (true) { Thread.yield(); - count += 5; if (isInterrupted ()) break; + long now = System.currentTimeMillis(); + if ((now - start) > 5000) + break; } synchronized (this) { @@ -91,10 +85,11 @@ class Looper extends Thread } } -class Joiner extends Thread +class Joiner extends ThreadBase { public void run() { + super.ready(); System.out.println("join()"); try { @@ -133,11 +128,17 @@ public class Thread_Interrupt sleep_and_interrupt (j); } - public static void sleep_and_interrupt(Thread t) + public static void sleep_and_interrupt(ThreadBase t) { try { - Thread.sleep (250); + synchronized (t) + { + while (!t.ready) + t.wait(10); + } + + Thread.sleep (50); t.interrupt (); long t1 = System.currentTimeMillis(); t.join (5000); diff --git a/libjava/testsuite/libjava.lang/Thread_Join.java b/libjava/testsuite/libjava.lang/Thread_Join.java index 711b05cf0f8..9f7f2fb1590 100644 --- a/libjava/testsuite/libjava.lang/Thread_Join.java +++ b/libjava/testsuite/libjava.lang/Thread_Join.java @@ -1,5 +1,4 @@ // Many threads join a single thread. -// Origin: Bryce McKinlay class Sleeper implements Runnable { diff --git a/libjava/testsuite/libjava.lang/Thread_Monitor.java b/libjava/testsuite/libjava.lang/Thread_Monitor.java index f1ffa674c37..649a75c762c 100644 --- a/libjava/testsuite/libjava.lang/Thread_Monitor.java +++ b/libjava/testsuite/libjava.lang/Thread_Monitor.java @@ -1,5 +1,4 @@ // Test that monitor locks work and are recursive. -// Origin: Bryce McKinlay class T implements Runnable { diff --git a/libjava/testsuite/libjava.lang/Thread_Sleep.java b/libjava/testsuite/libjava.lang/Thread_Sleep.java index e7f4a81532c..7220a6a3a6a 100644 --- a/libjava/testsuite/libjava.lang/Thread_Sleep.java +++ b/libjava/testsuite/libjava.lang/Thread_Sleep.java @@ -1,5 +1,4 @@ // Test that Thread.sleep() works. -// Origin: Bryce McKinlay public class Thread_Sleep { @@ -9,9 +8,9 @@ public class Thread_Sleep { long start = System.currentTimeMillis(); System.out.println("sleeping"); - Thread.sleep(1000); + Thread.sleep(50); long end = System.currentTimeMillis(); - if ((end - start) > 1100 || (end - start) < 990) + if ((end - start) < 50) System.out.println ("failed"); else System.out.println("ok"); diff --git a/libjava/testsuite/libjava.lang/Thread_Wait.java b/libjava/testsuite/libjava.lang/Thread_Wait.java index a6492821b4b..88508243a0a 100644 --- a/libjava/testsuite/libjava.lang/Thread_Wait.java +++ b/libjava/testsuite/libjava.lang/Thread_Wait.java @@ -1,5 +1,4 @@ // Test basic thread creation and wait/notify functionality. -// Origin: Bryce McKinlay public class Thread_Wait implements Runnable { diff --git a/libjava/testsuite/libjava.lang/Thread_Wait_2.java b/libjava/testsuite/libjava.lang/Thread_Wait_2.java index a03cb943812..7ee51726c29 100644 --- a/libjava/testsuite/libjava.lang/Thread_Wait_2.java +++ b/libjava/testsuite/libjava.lang/Thread_Wait_2.java @@ -1,6 +1,5 @@ // Create many threads waiting on a monitor. Interrupt some of them. Do the // others wake up correctly with notify() and/or notifyAll()? -// Origin: Bryce McKinlay import java.util.Vector; diff --git a/libjava/testsuite/libjava.lang/Thread_Wait_Interrupt.java b/libjava/testsuite/libjava.lang/Thread_Wait_Interrupt.java index be7b5551614..609527cda99 100644 --- a/libjava/testsuite/libjava.lang/Thread_Wait_Interrupt.java +++ b/libjava/testsuite/libjava.lang/Thread_Wait_Interrupt.java @@ -1,6 +1,5 @@ // Create two threads waiting on a monitor. Interrupt one of them. Does the // other wake up correctly? -// Origin: Bryce McKinlay class Waiter extends Thread { diff --git a/libjava/testsuite/libjava.lang/pr179.java b/libjava/testsuite/libjava.lang/pr179.java index ec99efc1a79..7124dedeef1 100644 --- a/libjava/testsuite/libjava.lang/pr179.java +++ b/libjava/testsuite/libjava.lang/pr179.java @@ -4,8 +4,6 @@ // Class.isInstance() and Class.isAssignableFrom(), and isAssignableFrom() // functionality in the event that an interface argument that is not // implemented by any loaded class is given. -// -// Bryce McKinlay class A { -- 2.30.2