|
1 /* |
|
2 * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
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 6224859 |
|
27 * @summary JDWP: Mixing application suspends and debugger suspends can cause hangs |
|
28 * @comment converted from test/jdk/com/sun/jdi/MixedSuspendTest.sh |
|
29 * |
|
30 * @library /test/lib |
|
31 * @run main/othervm MixedSuspendTest |
|
32 */ |
|
33 |
|
34 import lib.jdb.JdbCommand; |
|
35 import lib.jdb.JdbTest; |
|
36 |
|
37 class MixedSuspendTarg extends Thread { |
|
38 |
|
39 static volatile boolean started = true; |
|
40 static String lock = "startLock"; |
|
41 |
|
42 public static void main(String[] args){ |
|
43 System.out.println("Howdy from MixedSuspendTarg"); |
|
44 |
|
45 MixedSuspendTarg mytarg = new MixedSuspendTarg(); |
|
46 |
|
47 synchronized(lock) { |
|
48 mytarg.start(); |
|
49 try { |
|
50 lock.wait(); |
|
51 } catch(InterruptedException ee) { |
|
52 } |
|
53 } |
|
54 mytarg.suspend(); |
|
55 bkpt(); |
|
56 System.out.println("Debuggee: resuming thread"); |
|
57 |
|
58 // If the bug occurs, this resume hangs in the back-end |
|
59 mytarg.resume(); |
|
60 System.out.println("Debuggee: resumed thread"); |
|
61 synchronized(lock) { |
|
62 started = false; |
|
63 } |
|
64 System.out.println("Debuggee: exitting, started = " + started); |
|
65 } |
|
66 |
|
67 public void run() { |
|
68 synchronized(lock) { |
|
69 lock.notifyAll(); |
|
70 } |
|
71 while (true) { |
|
72 synchronized(lock) { |
|
73 if (!started) { |
|
74 break; |
|
75 } |
|
76 int i = 0; |
|
77 } |
|
78 } |
|
79 |
|
80 System.out.println("Debuggee: end of thread"); |
|
81 } |
|
82 |
|
83 static void bkpt() { |
|
84 //System.out.println("bkpt reached, thread = " + this.getName()); |
|
85 int i = 0; // @1 breakpoint |
|
86 } |
|
87 } |
|
88 |
|
89 public class MixedSuspendTest extends JdbTest { |
|
90 public static void main(String argv[]) { |
|
91 new MixedSuspendTest().run(); |
|
92 } |
|
93 |
|
94 private MixedSuspendTest() { |
|
95 super(DEBUGGEE_CLASS); |
|
96 } |
|
97 |
|
98 private static final String DEBUGGEE_CLASS = MixedSuspendTarg.class.getName(); |
|
99 |
|
100 @Override |
|
101 protected void runCases() { |
|
102 setBreakpointsFromTestSource("MixedSuspendTest.java", 1); |
|
103 jdb.command(JdbCommand.run()); |
|
104 jdb.command(JdbCommand.cont().allowExit()); |
|
105 |
|
106 // This test fails by timing out. |
|
107 } |
|
108 } |