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.15 by jsr166, Mon Oct 4 20:15:16 2010 UTC vs.
Revision 1.31 by jsr166, Sat May 13 23:50:00 2017 UTC

# Line 2 | Line 2
2   * Written by Doug Lea and Martin Buchholz with assistance from
3   * members of JCP JSR-166 Expert Group and released to the public
4   * domain, as explained at
5 < * http://creativecommons.org/licenses/publicdomain
5 > * http://creativecommons.org/publicdomain/zero/1.0/
6   * Other contributors include Andrew Wright, Jeffrey Hayes,
7   * Pat Fisher, Mike Judd.
8   */
9  
10 < import junit.framework.*;
11 < import java.util.*;
12 < import java.util.concurrent.*;
10 > import static java.util.concurrent.TimeUnit.MILLISECONDS;
11 >
12 > import java.util.concurrent.CountDownLatch;
13   import java.util.concurrent.atomic.AtomicBoolean;
14 < import java.util.concurrent.locks.*;
14 > import java.util.concurrent.locks.LockSupport;
15 >
16 > import junit.framework.Test;
17 > import junit.framework.TestSuite;
18  
19   public class LockSupportTest extends JSR166TestCase {
20      public static void main(String[] args) {
21 <        junit.textui.TestRunner.run(suite());
21 >        main(suite(), args);
22      }
23  
24      public static Test suite() {
25          return new TestSuite(LockSupportTest.class);
26      }
27  
28 <    /**
29 <     * park is released by subsequent unpark
30 <     */
31 <    public void testParkBeforeUnpark() throws InterruptedException {
29 <        final CountDownLatch threadStarted = new CountDownLatch(1);
30 <        Thread t = new Thread(new CheckedRunnable() {
31 <            public void realRun() {
32 <                threadStarted.countDown();
33 <                LockSupport.park();
34 <            }});
35 <
36 <        t.start();
37 <        threadStarted.await();
38 <        Thread.sleep(SHORT_DELAY_MS);
39 <        LockSupport.unpark(t);
40 <        joinWith(t);
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 <     * parkUntil is released by subsequent unpark
35 >     * Returns the blocker object used by tests in this file.
36 >     * Any old object will do; we'll return a convenient one.
37       */
38 <    public void testParkUntilBeforeUnpark() throws InterruptedException {
39 <        final CountDownLatch threadStarted = new CountDownLatch(1);
40 <        Thread t = new Thread(new CheckedRunnable() {
49 <            public void realRun() {
50 <                long d = new Date().getTime() + LONG_DELAY_MS;
51 <                long nanos = LONG_DELAY_MS * 1000L * 1000L;
52 <                long t0 = System.nanoTime();
53 <                threadStarted.countDown();
54 <                LockSupport.parkUntil(d);
55 <                assertTrue(System.nanoTime() - t0 < nanos);
56 <            }});
38 >    static Object theBlocker() {
39 >        return LockSupportTest.class;
40 >    }
41  
42 <        t.start();
43 <        threadStarted.await();
44 <        Thread.sleep(SHORT_DELAY_MS);
45 <        LockSupport.unpark(t);
46 <        joinWith(t);
42 >    enum ParkMethod {
43 >        park() {
44 >            void park() {
45 >                LockSupport.park();
46 >            }
47 >            Thread.State parkedState() { return Thread.State.WAITING; }
48 >        },
49 >        parkUntil() {
50 >            void park(long millis) {
51 >                LockSupport.parkUntil(deadline(millis));
52 >            }
53 >        },
54 >        parkNanos() {
55 >            void park(long millis) {
56 >                LockSupport.parkNanos(MILLISECONDS.toNanos(millis));
57 >            }
58 >        },
59 >        parkBlocker() {
60 >            void park() {
61 >                LockSupport.park(theBlocker());
62 >            }
63 >            Thread.State parkedState() { return Thread.State.WAITING; }
64 >        },
65 >        parkUntilBlocker() {
66 >            void park(long millis) {
67 >                LockSupport.parkUntil(theBlocker(), deadline(millis));
68 >            }
69 >        },
70 >        parkNanosBlocker() {
71 >            void park(long millis) {
72 >                LockSupport.parkNanos(theBlocker(),
73 >                                      MILLISECONDS.toNanos(millis));
74 >            }
75 >        };
76 >
77 >        void park() { park(2 * LONG_DELAY_MS); }
78 >        void park(long millis) {
79 >            throw new UnsupportedOperationException();
80 >        }
81 >        Thread.State parkedState() { return Thread.State.TIMED_WAITING; }
82 >
83 >        /** Returns a deadline to use with parkUntil. */
84 >        long deadline(long millis) {
85 >            // beware of rounding
86 >            return System.currentTimeMillis() + millis + 1;
87 >        }
88      }
89  
90      /**
91 <     * parkNanos is released by subsequent unpark
91 >     * park is released by subsequent unpark
92       */
93 <    public void testParkNanosBeforeUnpark() throws InterruptedException {
94 <        final CountDownLatch threadStarted = new CountDownLatch(1);
95 <        Thread t = new Thread(new CheckedRunnable() {
93 >    public void testParkBeforeUnpark_park() {
94 >        testParkBeforeUnpark(ParkMethod.park);
95 >    }
96 >    public void testParkBeforeUnpark_parkNanos() {
97 >        testParkBeforeUnpark(ParkMethod.parkNanos);
98 >    }
99 >    public void testParkBeforeUnpark_parkUntil() {
100 >        testParkBeforeUnpark(ParkMethod.parkUntil);
101 >    }
102 >    public void testParkBeforeUnpark_parkBlocker() {
103 >        testParkBeforeUnpark(ParkMethod.parkBlocker);
104 >    }
105 >    public void testParkBeforeUnpark_parkNanosBlocker() {
106 >        testParkBeforeUnpark(ParkMethod.parkNanosBlocker);
107 >    }
108 >    public void testParkBeforeUnpark_parkUntilBlocker() {
109 >        testParkBeforeUnpark(ParkMethod.parkUntilBlocker);
110 >    }
111 >    public void testParkBeforeUnpark(final ParkMethod parkMethod) {
112 >        final CountDownLatch pleaseUnpark = new CountDownLatch(1);
113 >        Thread t = newStartedThread(new CheckedRunnable() {
114              public void realRun() {
115 <                long nanos = LONG_DELAY_MS * 1000L * 1000L;
116 <                long t0 = System.nanoTime();
74 <                threadStarted.countDown();
75 <                LockSupport.parkNanos(nanos);
76 <                assertTrue(System.nanoTime() - t0 < nanos);
115 >                pleaseUnpark.countDown();
116 >                parkMethod.park();
117              }});
118  
119 <        t.start();
80 <        threadStarted.await();
81 <        Thread.sleep(SHORT_DELAY_MS);
119 >        await(pleaseUnpark);
120          LockSupport.unpark(t);
121 <        joinWith(t);
121 >        awaitTermination(t);
122      }
123  
124      /**
125       * park is released by preceding unpark
126       */
127 <    public void testParkAfterUnpark() throws Exception {
128 <        final CountDownLatch threadStarted = new CountDownLatch(1);
91 <        final AtomicBoolean unparked = new AtomicBoolean(false);
92 <        Thread t = new Thread(new CheckedRunnable() {
93 <            public void realRun() throws Exception {
94 <                threadStarted.countDown();
95 <                while (!unparked.get())
96 <                    Thread.yield();
97 <                LockSupport.park();
98 <            }});
99 <
100 <        t.start();
101 <        threadStarted.await();
102 <        LockSupport.unpark(t);
103 <        unparked.set(true);
104 <        joinWith(t);
127 >    public void testParkAfterUnpark_park() {
128 >        testParkAfterUnpark(ParkMethod.park);
129      }
130 <
131 <    /**
108 <     * parkUntil is released by preceding unpark
109 <     */
110 <    public void testParkUntilAfterUnpark() throws Exception {
111 <        final CountDownLatch threadStarted = new CountDownLatch(1);
112 <        final AtomicBoolean unparked = new AtomicBoolean(false);
113 <        Thread t = new Thread(new CheckedRunnable() {
114 <            public void realRun() throws Exception {
115 <                threadStarted.countDown();
116 <                while (!unparked.get())
117 <                    Thread.yield();
118 <                long d = new Date().getTime() + LONG_DELAY_MS;
119 <                long nanos = LONG_DELAY_MS * 1000L * 1000L;
120 <                long t0 = System.nanoTime();
121 <                LockSupport.parkUntil(d);
122 <                assertTrue(System.nanoTime() - t0 < nanos);
123 <            }});
124 <
125 <        t.start();
126 <        threadStarted.await();
127 <        LockSupport.unpark(t);
128 <        unparked.set(true);
129 <        joinWith(t);
130 >    public void testParkAfterUnpark_parkNanos() {
131 >        testParkAfterUnpark(ParkMethod.parkNanos);
132      }
133 <
134 <    /**
135 <     * parkNanos is released by preceding unpark
136 <     */
137 <    public void testParkNanosAfterUnpark() throws Exception {
138 <        final CountDownLatch threadStarted = new CountDownLatch(1);
139 <        final AtomicBoolean unparked = new AtomicBoolean(false);
140 <        Thread t = new Thread(new CheckedRunnable() {
141 <            public void realRun() throws Exception {
142 <                threadStarted.countDown();
143 <                while (!unparked.get())
133 >    public void testParkAfterUnpark_parkUntil() {
134 >        testParkAfterUnpark(ParkMethod.parkUntil);
135 >    }
136 >    public void testParkAfterUnpark_parkBlocker() {
137 >        testParkAfterUnpark(ParkMethod.parkBlocker);
138 >    }
139 >    public void testParkAfterUnpark_parkNanosBlocker() {
140 >        testParkAfterUnpark(ParkMethod.parkNanosBlocker);
141 >    }
142 >    public void testParkAfterUnpark_parkUntilBlocker() {
143 >        testParkAfterUnpark(ParkMethod.parkUntilBlocker);
144 >    }
145 >    public void testParkAfterUnpark(final ParkMethod parkMethod) {
146 >        final CountDownLatch pleaseUnpark = new CountDownLatch(1);
147 >        final AtomicBoolean pleasePark = new AtomicBoolean(false);
148 >        Thread t = newStartedThread(new CheckedRunnable() {
149 >            public void realRun() {
150 >                pleaseUnpark.countDown();
151 >                while (!pleasePark.get())
152                      Thread.yield();
153 <                long nanos = LONG_DELAY_MS * 1000L * 1000L;
144 <                long t0 = System.nanoTime();
145 <                LockSupport.parkNanos(nanos);
146 <                assertTrue(System.nanoTime() - t0 < nanos);
153 >                parkMethod.park();
154              }});
155  
156 <        t.start();
150 <        threadStarted.await();
156 >        await(pleaseUnpark);
157          LockSupport.unpark(t);
158 <        unparked.set(true);
159 <        joinWith(t);
158 >        pleasePark.set(true);
159 >        awaitTermination(t);
160      }
161  
162      /**
163       * park is released by subsequent interrupt
164       */
165 <    public void testParkBeforeInterrupt() throws InterruptedException {
166 <        final CountDownLatch threadStarted = new CountDownLatch(1);
161 <        Thread t = new Thread(new CheckedRunnable() {
162 <            public void realRun() {
163 <                assertFalse(Thread.currentThread().isInterrupted());
164 <                threadStarted.countDown();
165 <                LockSupport.park();
166 <                assertTrue(Thread.currentThread().isInterrupted());
167 <            }});
168 <
169 <        t.start();
170 <        threadStarted.await();
171 <        Thread.sleep(SHORT_DELAY_MS);
172 <        t.interrupt();
173 <        joinWith(t);
165 >    public void testParkBeforeInterrupt_park() {
166 >        testParkBeforeInterrupt(ParkMethod.park);
167      }
168 <
169 <    /**
177 <     * parkUntil is released by subsequent interrupt
178 <     */
179 <    public void testParkUntilBeforeInterrupt() throws InterruptedException {
180 <        final CountDownLatch threadStarted = new CountDownLatch(1);
181 <        Thread t = new Thread(new CheckedRunnable() {
182 <            public void realRun() {
183 <                long d = new Date().getTime() + LONG_DELAY_MS;
184 <                long nanos = LONG_DELAY_MS * 1000L * 1000L;
185 <                long t0 = System.nanoTime();
186 <                threadStarted.countDown();
187 <                LockSupport.parkUntil(d);
188 <                assertTrue(System.nanoTime() - t0 < nanos);
189 <            }});
190 <
191 <        t.start();
192 <        threadStarted.await();
193 <        Thread.sleep(SHORT_DELAY_MS);
194 <        t.interrupt();
195 <        joinWith(t);
168 >    public void testParkBeforeInterrupt_parkNanos() {
169 >        testParkBeforeInterrupt(ParkMethod.parkNanos);
170      }
171 <
172 <    /**
173 <     * parkNanos is released by subsequent interrupt
174 <     */
175 <    public void testParkNanosBeforeInterrupt() throws InterruptedException {
176 <        final CountDownLatch threadStarted = new CountDownLatch(1);
177 <        Thread t = new Thread(new CheckedRunnable() {
171 >    public void testParkBeforeInterrupt_parkUntil() {
172 >        testParkBeforeInterrupt(ParkMethod.parkUntil);
173 >    }
174 >    public void testParkBeforeInterrupt_parkBlocker() {
175 >        testParkBeforeInterrupt(ParkMethod.parkBlocker);
176 >    }
177 >    public void testParkBeforeInterrupt_parkNanosBlocker() {
178 >        testParkBeforeInterrupt(ParkMethod.parkNanosBlocker);
179 >    }
180 >    public void testParkBeforeInterrupt_parkUntilBlocker() {
181 >        testParkBeforeInterrupt(ParkMethod.parkUntilBlocker);
182 >    }
183 >    public void testParkBeforeInterrupt(final ParkMethod parkMethod) {
184 >        final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
185 >        Thread t = newStartedThread(new CheckedRunnable() {
186              public void realRun() {
187 <                long nanos = LONG_DELAY_MS * 1000L * 1000L;
188 <                long t0 = System.nanoTime();
189 <                threadStarted.countDown();
190 <                LockSupport.parkNanos(nanos);
191 <                assertTrue(System.nanoTime() - t0 < nanos);
187 >                pleaseInterrupt.countDown();
188 >                for (int tries = MAX_SPURIOUS_WAKEUPS; tries-->0; ) {
189 >                    parkMethod.park();
190 >                    if (Thread.interrupted())
191 >                        return;
192 >                }
193 >                fail("too many consecutive spurious wakeups?");
194              }});
195  
196 <        t.start();
197 <        threadStarted.await();
214 <        Thread.sleep(SHORT_DELAY_MS);
196 >        await(pleaseInterrupt);
197 >        assertThreadBlocks(t, parkMethod.parkedState());
198          t.interrupt();
199 <        joinWith(t);
199 >        awaitTermination(t);
200      }
201  
202      /**
203       * park is released by preceding interrupt
204       */
205 <    public void testParkAfterInterrupt() throws Exception {
206 <        final CountDownLatch threadStarted = new CountDownLatch(1);
207 <        final AtomicBoolean unparked = new AtomicBoolean(false);
208 <        Thread t = new Thread(new CheckedRunnable() {
205 >    public void testParkAfterInterrupt_park() {
206 >        testParkAfterInterrupt(ParkMethod.park);
207 >    }
208 >    public void testParkAfterInterrupt_parkNanos() {
209 >        testParkAfterInterrupt(ParkMethod.parkNanos);
210 >    }
211 >    public void testParkAfterInterrupt_parkUntil() {
212 >        testParkAfterInterrupt(ParkMethod.parkUntil);
213 >    }
214 >    public void testParkAfterInterrupt_parkBlocker() {
215 >        testParkAfterInterrupt(ParkMethod.parkBlocker);
216 >    }
217 >    public void testParkAfterInterrupt_parkNanosBlocker() {
218 >        testParkAfterInterrupt(ParkMethod.parkNanosBlocker);
219 >    }
220 >    public void testParkAfterInterrupt_parkUntilBlocker() {
221 >        testParkAfterInterrupt(ParkMethod.parkUntilBlocker);
222 >    }
223 >    public void testParkAfterInterrupt(final ParkMethod parkMethod) {
224 >        final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
225 >        Thread t = newStartedThread(new CheckedRunnable() {
226              public void realRun() throws Exception {
227 <                threadStarted.countDown();
228 <                while (!unparked.get())
227 >                pleaseInterrupt.countDown();
228 >                while (!Thread.currentThread().isInterrupted())
229                      Thread.yield();
230 <                assertTrue(Thread.currentThread().isInterrupted());
231 <                LockSupport.park();
232 <                assertTrue(Thread.currentThread().isInterrupted());
230 >                parkMethod.park();
231 >                assertTrue(Thread.interrupted());
232              }});
233  
234 <        t.start();
236 <        threadStarted.await();
234 >        await(pleaseInterrupt);
235          t.interrupt();
236 <        unparked.set(true);
239 <        joinWith(t);
236 >        awaitTermination(t);
237      }
238  
239      /**
240 <     * parkUntil is released by preceding interrupt
240 >     * timed park times out if not unparked
241       */
242 <    public void testParkUntilAfterInterrupt() throws Exception {
243 <        final CountDownLatch threadStarted = new CountDownLatch(1);
244 <        final AtomicBoolean unparked = new AtomicBoolean(false);
245 <        Thread t = new Thread(new CheckedRunnable() {
246 <            public void realRun() throws Exception {
247 <                threadStarted.countDown();
248 <                while (!unparked.get())
249 <                    Thread.yield();
250 <                long d = new Date().getTime() + LONG_DELAY_MS;
251 <                long nanos = LONG_DELAY_MS * 1000L * 1000L;
252 <                long t0 = System.nanoTime();
253 <                LockSupport.parkUntil(d);
254 <                assertTrue(System.nanoTime() - t0 < nanos);
242 >    public void testParkTimesOut_parkNanos() {
243 >        testParkTimesOut(ParkMethod.parkNanos);
244 >    }
245 >    public void testParkTimesOut_parkUntil() {
246 >        testParkTimesOut(ParkMethod.parkUntil);
247 >    }
248 >    public void testParkTimesOut_parkNanosBlocker() {
249 >        testParkTimesOut(ParkMethod.parkNanosBlocker);
250 >    }
251 >    public void testParkTimesOut_parkUntilBlocker() {
252 >        testParkTimesOut(ParkMethod.parkUntilBlocker);
253 >    }
254 >    public void testParkTimesOut(final ParkMethod parkMethod) {
255 >        Thread t = newStartedThread(new CheckedRunnable() {
256 >            public void realRun() {
257 >                for (int tries = MAX_SPURIOUS_WAKEUPS; tries-->0; ) {
258 >                    long startTime = System.nanoTime();
259 >                    parkMethod.park(timeoutMillis());
260 >                    if (millisElapsedSince(startTime) >= timeoutMillis())
261 >                        return;
262 >                }
263 >                fail("too many consecutive spurious wakeups?");
264              }});
265  
266 <        t.start();
261 <        threadStarted.await();
262 <        t.interrupt();
263 <        unparked.set(true);
264 <        joinWith(t);
266 >        awaitTermination(t);
267      }
268  
269      /**
270 <     * parkNanos is released by preceding interrupt
270 >     * getBlocker(null) throws NullPointerException
271       */
272 <    public void testParkNanosAfterInterrupt() throws Exception {
273 <        final CountDownLatch threadStarted = new CountDownLatch(1);
274 <        final AtomicBoolean unparked = new AtomicBoolean(false);
275 <        Thread t = new Thread(new CheckedRunnable() {
276 <            public void realRun() throws Exception {
275 <                threadStarted.countDown();
276 <                while (!unparked.get())
277 <                    Thread.yield();
278 <                long nanos = LONG_DELAY_MS * 1000L * 1000L;
279 <                long t0 = System.nanoTime();
280 <                LockSupport.parkNanos(nanos);
281 <                assertTrue(System.nanoTime() - t0 < nanos);
282 <            }});
283 <
284 <        t.start();
285 <        threadStarted.await();
286 <        t.interrupt();
287 <        unparked.set(true);
288 <        joinWith(t);
272 >    public void testGetBlockerNull() {
273 >        try {
274 >            LockSupport.getBlocker(null);
275 >            shouldThrow();
276 >        } catch (NullPointerException success) {}
277      }
278  
279      /**
280 <     * parkNanos times out if not unparked
280 >     * getBlocker returns the blocker object passed to park
281       */
282 <    public void testParkNanosTimesOut() throws InterruptedException {
283 <        Thread t = new Thread(new CheckedRunnable() {
282 >    public void testGetBlocker_parkBlocker() {
283 >        testGetBlocker(ParkMethod.parkBlocker);
284 >    }
285 >    public void testGetBlocker_parkNanosBlocker() {
286 >        testGetBlocker(ParkMethod.parkNanosBlocker);
287 >    }
288 >    public void testGetBlocker_parkUntilBlocker() {
289 >        testGetBlocker(ParkMethod.parkUntilBlocker);
290 >    }
291 >    public void testGetBlocker(final ParkMethod parkMethod) {
292 >        final CountDownLatch started = new CountDownLatch(1);
293 >        Thread t = newStartedThread(new CheckedRunnable() {
294              public void realRun() {
295 <                final long timeoutNanos = SHORT_DELAY_MS * 1000L * 1000L;
296 <                long t0 = System.nanoTime();
297 <                LockSupport.parkNanos(timeoutNanos);
298 <                assertTrue(System.nanoTime() - t0 >= timeoutNanos);
299 <            }});
300 <
301 <        t.start();
302 <        joinWith(t);
295 >                Thread t = Thread.currentThread();
296 >                started.countDown();
297 >                for (int tries = MAX_SPURIOUS_WAKEUPS; tries-->0; ) {
298 >                    assertNull(LockSupport.getBlocker(t));
299 >                    parkMethod.park();
300 >                    assertNull(LockSupport.getBlocker(t));
301 >                    if (Thread.interrupted())
302 >                        return;
303 >                }
304 >                fail("too many consecutive spurious wakeups?");
305 >            }});
306 >
307 >        long startTime = System.nanoTime();
308 >        await(started);
309 >        for (;;) {
310 >            Object x = LockSupport.getBlocker(t);
311 >            if (x == theBlocker()) { // success
312 >                t.interrupt();
313 >                awaitTermination(t);
314 >                assertNull(LockSupport.getBlocker(t));
315 >                return;
316 >            } else {
317 >                assertNull(x);  // ok
318 >                if (millisElapsedSince(startTime) > LONG_DELAY_MS)
319 >                    fail("timed out");
320 >                if (t.getState() == Thread.State.TERMINATED)
321 >                    break;
322 >                Thread.yield();
323 >            }
324 >        }
325      }
326  
307
327      /**
328 <     * parkUntil times out if not unparked
328 >     * timed park(0) returns immediately.
329 >     *
330 >     * Requires hotspot fix for:
331 >     * 6763959 java.util.concurrent.locks.LockSupport.parkUntil(0) blocks forever
332 >     * which is in jdk7-b118 and 6u25.
333       */
334 <    public void testParkUntilTimesOut() throws InterruptedException {
335 <        Thread t = new Thread(new CheckedRunnable() {
334 >    public void testPark0_parkNanos() {
335 >        testPark0(ParkMethod.parkNanos);
336 >    }
337 >    public void testPark0_parkUntil() {
338 >        testPark0(ParkMethod.parkUntil);
339 >    }
340 >    public void testPark0_parkNanosBlocker() {
341 >        testPark0(ParkMethod.parkNanosBlocker);
342 >    }
343 >    public void testPark0_parkUntilBlocker() {
344 >        testPark0(ParkMethod.parkUntilBlocker);
345 >    }
346 >    public void testPark0(final ParkMethod parkMethod) {
347 >        Thread t = newStartedThread(new CheckedRunnable() {
348              public void realRun() {
349 <                long d = new Date().getTime() + SHORT_DELAY_MS;
315 <                // beware of rounding
316 <                long timeoutNanos = (SHORT_DELAY_MS - 1) * 1000L * 1000L;
317 <                long t0 = System.nanoTime();
318 <                LockSupport.parkUntil(d);
319 <                assertTrue(System.nanoTime() - t0 >= timeoutNanos);
349 >                parkMethod.park(0L);
350              }});
351  
352 <        t.start();
323 <        joinWith(t);
352 >        awaitTermination(t);
353      }
354  
355      /**
356 <     * parkUntil(0) returns immediately
328 <     * Requires hotspot fix for:
329 <     * 6763959 java.util.concurrent.locks.LockSupport.parkUntil(0) blocks forever
356 >     * timed park(Long.MIN_VALUE) returns immediately.
357       */
358 <    public void XXXtestParkUntil0Returns() throws InterruptedException {
359 <        Thread t = new Thread(new CheckedRunnable() {
358 >    public void testParkNeg_parkNanos() {
359 >        testParkNeg(ParkMethod.parkNanos);
360 >    }
361 >    public void testParkNeg_parkUntil() {
362 >        testParkNeg(ParkMethod.parkUntil);
363 >    }
364 >    public void testParkNeg_parkNanosBlocker() {
365 >        testParkNeg(ParkMethod.parkNanosBlocker);
366 >    }
367 >    public void testParkNeg_parkUntilBlocker() {
368 >        testParkNeg(ParkMethod.parkUntilBlocker);
369 >    }
370 >    public void testParkNeg(final ParkMethod parkMethod) {
371 >        Thread t = newStartedThread(new CheckedRunnable() {
372              public void realRun() {
373 <                LockSupport.parkUntil(0L);
373 >                parkMethod.park(Long.MIN_VALUE);
374              }});
375  
376 <        t.start();
338 <        joinWith(t);
339 <    }
340 <
341 <    private void joinWith(Thread t) throws InterruptedException {
342 <        t.join(MEDIUM_DELAY_MS);
343 <        if (t.isAlive()) {
344 <            fail("Test timed out");
345 <            t.interrupt();
346 <        }
376 >        awaitTermination(t);
377      }
378   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines