ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/LockSupportTest.java
(Generate patch)

Comparing jsr166/src/test/tck/LockSupportTest.java (file contents):
Revision 1.25 by jsr166, Sat Apr 25 04:55:31 2015 UTC vs.
Revision 1.30 by jsr166, Fri May 12 18:57:11 2017 UTC

# Line 25 | Line 25 | public class LockSupportTest extends JSR
25          return new TestSuite(LockSupportTest.class);
26      }
27  
28 +    static {
29 +        // Reduce the risk of rare disastrous classloading in first call to
30 +        // LockSupport.park: https://bugs.openjdk.java.net/browse/JDK-8074773
31 +        Class<?> ensureLoaded = LockSupport.class;
32 +    }
33 +
34      /**
35       * Returns the blocker object used by tests in this file.
36       * Any old object will do; we'll return a convenient one.
# Line 180 | Line 186 | public class LockSupportTest extends JSR
186          Thread t = newStartedThread(new CheckedRunnable() {
187              public void realRun() {
188                  pleaseInterrupt.countDown();
189 <                do {
189 >                for (int tries = MAX_SPURIOUS_WAKEUPS; tries-->0; ) {
190                      parkMethod.park();
191 <                    // park may return spuriously
192 <                } while (! Thread.currentThread().isInterrupted());
191 >                    if (Thread.interrupted())
192 >                        return;
193 >                }
194 >                fail("too many consecutive spurious wakeups?");
195              }});
196  
197          await(pleaseInterrupt);
# Line 215 | Line 223 | public class LockSupportTest extends JSR
223      }
224      public void testParkAfterInterrupt(final ParkMethod parkMethod) {
225          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
218        final AtomicBoolean pleasePark = new AtomicBoolean(false);
226          Thread t = newStartedThread(new CheckedRunnable() {
227              public void realRun() throws Exception {
228                  pleaseInterrupt.countDown();
229 <                while (!pleasePark.get())
229 >                while (!Thread.currentThread().isInterrupted())
230                      Thread.yield();
224                assertTrue(Thread.currentThread().isInterrupted());
231                  parkMethod.park();
232 <                assertTrue(Thread.currentThread().isInterrupted());
232 >                assertTrue(Thread.interrupted());
233              }});
234  
235          await(pleaseInterrupt);
236          t.interrupt();
231        pleasePark.set(true);
237          awaitTermination(t);
238      }
239  
# Line 250 | Line 255 | public class LockSupportTest extends JSR
255      public void testParkTimesOut(final ParkMethod parkMethod) {
256          Thread t = newStartedThread(new CheckedRunnable() {
257              public void realRun() {
258 <                for (;;) {
258 >                for (int tries = MAX_SPURIOUS_WAKEUPS; tries-->0; ) {
259                      long startTime = System.nanoTime();
260                      parkMethod.park(timeoutMillis());
256                    // park may return spuriously
261                      if (millisElapsedSince(startTime) >= timeoutMillis())
262                          return;
263                  }
264 +                fail("too many consecutive spurious wakeups?");
265              }});
266  
267          awaitTermination(t);
# Line 290 | Line 295 | public class LockSupportTest extends JSR
295              public void realRun() {
296                  Thread t = Thread.currentThread();
297                  started.countDown();
298 <                do {
298 >                for (int tries = MAX_SPURIOUS_WAKEUPS; tries-->0; ) {
299                      assertNull(LockSupport.getBlocker(t));
300                      parkMethod.park();
301                      assertNull(LockSupport.getBlocker(t));
302 <                    // park may return spuriously
303 <                } while (! Thread.currentThread().isInterrupted());
302 >                    if (Thread.interrupted())
303 >                        return;
304 >                }
305 >                fail("too many consecutive spurious wakeups?");
306              }});
307  
308          long startTime = System.nanoTime();
# Line 311 | Line 318 | public class LockSupportTest extends JSR
318                  assertNull(x);  // ok
319                  if (millisElapsedSince(startTime) > LONG_DELAY_MS)
320                      fail("timed out");
321 +                if (t.getState() == Thread.State.TERMINATED)
322 +                    break;
323                  Thread.yield();
324              }
325          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines