8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 6207928 6328220 6378321 6625723
27 * @summary Recursive lock invariant sanity checks
28 * @library /lib/testlibrary/
29 * @author Martin Buchholz
30 */
31
32 import static java.util.concurrent.TimeUnit.MILLISECONDS;
33
34 import java.io.ByteArrayInputStream;
35 import java.io.ByteArrayOutputStream;
36 import java.io.IOException;
37 import java.io.InputStream;
38 import java.io.ObjectInputStream;
39 import java.io.ObjectOutputStream;
40 import java.util.Random;
41 import java.util.concurrent.CyclicBarrier;
42 import java.util.concurrent.ExecutorService;
43 import java.util.concurrent.Executors;
44 import java.util.concurrent.TimeUnit;
45 import java.util.concurrent.locks.Lock;
46 import java.util.concurrent.locks.ReentrantLock;
47 import java.util.concurrent.locks.ReentrantReadWriteLock;
48 import jdk.testlibrary.Utils;
49
50 // I am the Cownt, and I lahve to cownt.
51 public class Count {
52 static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
53 final Random rnd = new Random();
54
55 void lock(Lock lock) {
56 try {
57 switch (rnd.nextInt(4)) {
58 case 0: lock.lock(); break;
59 case 1: lock.lockInterruptibly(); break;
60 case 2: check(lock.tryLock()); break;
61 case 3: check(lock.tryLock(45, TimeUnit.MINUTES)); break;
62 }
63 } catch (Throwable t) { unexpected(t); }
64 }
65
66 void test(String[] args) throws Throwable {
67 for (boolean fair : new boolean[] { true, false })
68 for (boolean serialClone : new boolean[] { true, false }) {
|
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 6207928 6328220 6378321 6625723
27 * @summary Recursive lock invariant sanity checks
28 * @library /test/lib
29 * @author Martin Buchholz
30 */
31
32 import static java.util.concurrent.TimeUnit.MILLISECONDS;
33
34 import java.io.ByteArrayInputStream;
35 import java.io.ByteArrayOutputStream;
36 import java.io.IOException;
37 import java.io.InputStream;
38 import java.io.ObjectInputStream;
39 import java.io.ObjectOutputStream;
40 import java.util.Random;
41 import java.util.concurrent.CyclicBarrier;
42 import java.util.concurrent.ExecutorService;
43 import java.util.concurrent.Executors;
44 import java.util.concurrent.TimeUnit;
45 import java.util.concurrent.locks.Lock;
46 import java.util.concurrent.locks.ReentrantLock;
47 import java.util.concurrent.locks.ReentrantReadWriteLock;
48 import jdk.test.lib.Utils;
49
50 // I am the Cownt, and I lahve to cownt.
51 public class Count {
52 static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
53 final Random rnd = new Random();
54
55 void lock(Lock lock) {
56 try {
57 switch (rnd.nextInt(4)) {
58 case 0: lock.lock(); break;
59 case 1: lock.lockInterruptibly(); break;
60 case 2: check(lock.tryLock()); break;
61 case 3: check(lock.tryLock(45, TimeUnit.MINUTES)); break;
62 }
63 } catch (Throwable t) { unexpected(t); }
64 }
65
66 void test(String[] args) throws Throwable {
67 for (boolean fair : new boolean[] { true, false })
68 for (boolean serialClone : new boolean[] { true, false }) {
|