Mercurial > hg > truffle
annotate test/serviceability/threads/TestFalseDeadLock.java @ 15547:cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
author | Tom Rodriguez <tom.rodriguez@oracle.com> |
---|---|
date | Wed, 07 May 2014 10:58:26 -0700 |
parents | ef748153ee8f |
children |
rev | line source |
---|---|
10985
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
1 /* |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
4 * |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
8 * |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
13 * accompanied this code). |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
14 * |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
18 * |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
21 * questions. |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
22 */ |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
23 |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
24 import java.lang.management.ManagementFactory; |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
25 import java.lang.management.ThreadMXBean; |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
26 import java.util.Random; |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
27 |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
28 /* |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
29 * @test |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
30 * @bug 8016304 |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
31 * @summary Make sure no deadlock is reported for this program which has no deadlocks. |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
32 * @run main/othervm TestFalseDeadLock |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
33 */ |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
34 |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
35 /* |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
36 * This test will not provoke the bug every time it is run since the bug is intermittent. |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
37 * The test has a fixed running time of 5 seconds. |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
38 */ |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
39 |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
40 public class TestFalseDeadLock { |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
41 private static ThreadMXBean bean; |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
42 private static volatile boolean running = true; |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
43 private static volatile boolean found = false; |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
44 |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
45 public static void main(String[] args) throws Exception { |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
46 bean = ManagementFactory.getThreadMXBean(); |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
47 Thread[] threads = new Thread[500]; |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
48 for (int i = 0; i < threads.length; i++) { |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
49 Test t = new Test(); |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
50 threads[i] = new Thread(t); |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
51 threads[i].start(); |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
52 } |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
53 try { |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
54 Thread.sleep(5000); |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
55 } catch (InterruptedException ex) { |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
56 } |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
57 running = false; |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
58 for (Thread t : threads) { |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
59 t.join(); |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
60 } |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
61 if (found) { |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
62 throw new Exception("Deadlock reported, but there is no deadlock."); |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
63 } |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
64 } |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
65 |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
66 public static class Test implements Runnable { |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
67 public void run() { |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
68 Random r = new Random(); |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
69 while (running) { |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
70 try { |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
71 synchronized (this) { |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
72 wait(r.nextInt(1000) + 1); |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
73 } |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
74 } catch (InterruptedException ex) { |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
75 } |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
76 recurse(2000); |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
77 } |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
78 if (bean.findDeadlockedThreads() != null) { |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
79 System.out.println("FOUND!"); |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
80 found = true; |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
81 } |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
82 } |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
83 |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
84 private void recurse(int i) { |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
85 if (!running) { |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
86 // It is important for the test to call println here |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
87 // since there are locks inside that path. |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
88 System.out.println("Hullo"); |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
89 } |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
90 else if (i > 0) { |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
91 recurse(i - 1); |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
92 } |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
93 } |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
94 } |
ef748153ee8f
8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8
sla
parents:
diff
changeset
|
95 } |