author | gadams |
Thu, 13 Sep 2018 07:54:38 -0400 | |
changeset 51732 | dc68380e6497 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
51732
dc68380e6497
8210252: com/sun/jdi/DebuggerThreadTest.java fails with NPE
gadams
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/** |
|
44423 | 25 |
* @test |
26 |
* @bug 4513488 |
|
27 |
* @summary Test for JDI: Internal JDI helper threads should setDaemon(true) |
|
28 |
* @author Tim Bell |
|
2 | 29 |
* |
44423 | 30 |
* @run build TestScaffold VMConnection TargetListener TargetAdapter |
31 |
* @run compile -g DebuggerThreadTest.java |
|
32 |
* @run driver DebuggerThreadTest |
|
2 | 33 |
*/ |
34 |
import com.sun.jdi.*; |
|
35 |
import com.sun.jdi.event.*; |
|
36 |
import com.sun.jdi.request.*; |
|
37 |
||
38 |
import java.util.*; |
|
39 |
||
40 |
/********** target program **********/ |
|
41 |
||
42 |
class DebuggerThreadTarg { |
|
43 |
public void ready() { |
|
44 |
} |
|
45 |
public static void main(String[] args){ |
|
46 |
System.out.println("Howdy!"); |
|
47 |
DebuggerThreadTarg targ = new DebuggerThreadTarg(); |
|
48 |
targ.ready(); |
|
49 |
System.out.println("Goodbye from DebuggerThreadTarg!"); |
|
50 |
} |
|
51 |
} |
|
52 |
||
53 |
/********** test program **********/ |
|
54 |
||
55 |
public class DebuggerThreadTest extends TestScaffold { |
|
56 |
||
57 |
DebuggerThreadTest (String args[]) { |
|
58 |
super(args); |
|
59 |
} |
|
60 |
||
61 |
public static void main(String[] args) throws Exception { |
|
62 |
new DebuggerThreadTest(args).startTests(); |
|
63 |
} |
|
64 |
||
65 |
/* |
|
66 |
* Move to top ThreadGroup and dump all threads. |
|
67 |
*/ |
|
68 |
public void dumpThreads() { |
|
51732
dc68380e6497
8210252: com/sun/jdi/DebuggerThreadTest.java fails with NPE
gadams
parents:
47216
diff
changeset
|
69 |
int finishedThreads = 0; |
2 | 70 |
ThreadGroup tg = Thread.currentThread().getThreadGroup(); |
71 |
ThreadGroup parent = tg.getParent(); |
|
72 |
while (parent != null) { |
|
73 |
tg = parent; |
|
74 |
parent = tg.getParent(); |
|
75 |
} |
|
76 |
int listThreads = tg.activeCount(); |
|
77 |
Thread list[] = new Thread[listThreads * 2]; |
|
78 |
int gotThreads = tg.enumerate(list, true); |
|
79 |
for (int i = 0; i < Math.min(gotThreads, list.length); i++){ |
|
80 |
Thread t = list[i]; |
|
51732
dc68380e6497
8210252: com/sun/jdi/DebuggerThreadTest.java fails with NPE
gadams
parents:
47216
diff
changeset
|
81 |
ThreadGroup tga = t.getThreadGroup(); |
dc68380e6497
8210252: com/sun/jdi/DebuggerThreadTest.java fails with NPE
gadams
parents:
47216
diff
changeset
|
82 |
String groupName; |
dc68380e6497
8210252: com/sun/jdi/DebuggerThreadTest.java fails with NPE
gadams
parents:
47216
diff
changeset
|
83 |
if (tga == null) { |
dc68380e6497
8210252: com/sun/jdi/DebuggerThreadTest.java fails with NPE
gadams
parents:
47216
diff
changeset
|
84 |
groupName = "<completed>"; |
dc68380e6497
8210252: com/sun/jdi/DebuggerThreadTest.java fails with NPE
gadams
parents:
47216
diff
changeset
|
85 |
finishedThreads++ ; |
dc68380e6497
8210252: com/sun/jdi/DebuggerThreadTest.java fails with NPE
gadams
parents:
47216
diff
changeset
|
86 |
} else { |
dc68380e6497
8210252: com/sun/jdi/DebuggerThreadTest.java fails with NPE
gadams
parents:
47216
diff
changeset
|
87 |
groupName = tga.getName(); |
dc68380e6497
8210252: com/sun/jdi/DebuggerThreadTest.java fails with NPE
gadams
parents:
47216
diff
changeset
|
88 |
} |
2 | 89 |
|
90 |
System.out.println("Thread [" + i + "] group = '" + |
|
91 |
groupName + |
|
92 |
"' name = '" + t.getName() + |
|
93 |
"' daemon = " + t.isDaemon()); |
|
94 |
||
95 |
if (groupName.startsWith("JDI ") && |
|
96 |
(! t.isDaemon())) { |
|
97 |
failure("FAIL: non-daemon thread '" + t.getName() + |
|
98 |
"' found in ThreadGroup '" + groupName + "'"); |
|
99 |
} |
|
51732
dc68380e6497
8210252: com/sun/jdi/DebuggerThreadTest.java fails with NPE
gadams
parents:
47216
diff
changeset
|
100 |
} |
dc68380e6497
8210252: com/sun/jdi/DebuggerThreadTest.java fails with NPE
gadams
parents:
47216
diff
changeset
|
101 |
if (finishedThreads > 0 ) { |
dc68380e6497
8210252: com/sun/jdi/DebuggerThreadTest.java fails with NPE
gadams
parents:
47216
diff
changeset
|
102 |
failure("FAIL: " + finishedThreads + |
dc68380e6497
8210252: com/sun/jdi/DebuggerThreadTest.java fails with NPE
gadams
parents:
47216
diff
changeset
|
103 |
" threads completed while VM suspended."); |
2 | 104 |
} |
105 |
} |
|
106 |
||
107 |
protected void runTests() throws Exception { |
|
108 |
try { |
|
109 |
/* |
|
110 |
* Get to the top of ready() |
|
111 |
*/ |
|
112 |
startTo("DebuggerThreadTarg", "ready", "()V"); |
|
113 |
||
114 |
dumpThreads(); |
|
115 |
||
116 |
listenUntilVMDisconnect(); |
|
117 |
||
118 |
} finally { |
|
119 |
/* |
|
120 |
* deal with results of test |
|
121 |
* if anything has called failure("foo") testFailed will be true |
|
122 |
*/ |
|
123 |
if (!testFailed) { |
|
124 |
println("DebuggerThreadTest: passed"); |
|
125 |
} else { |
|
126 |
throw new Exception("DebuggerThreadTest: failed"); |
|
127 |
} |
|
128 |
} |
|
129 |
return; |
|
130 |
} |
|
131 |
} |