author | mikejwre |
Thu, 25 Mar 2010 15:05:15 -0700 | |
changeset 5074 | 9c9bfe8f3a47 |
parent 4335 | 365eb4449319 |
child 5506 | 202f599c92aa |
permissions | -rw-r--r-- |
1326 | 1 |
/* |
2 |
* Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 |
* have any questions. |
|
22 |
*/ |
|
23 |
||
24 |
/** |
|
25 |
* @test |
|
26 |
* @bug 6751643 |
|
27 |
* @summary ThreadReference.ownedMonitors() can return null |
|
28 |
* |
|
29 |
* @author jjh |
|
30 |
* |
|
31 |
* @run build TestScaffold VMConnection TargetListener TargetAdapter |
|
32 |
* @run compile -g SimulResumerTest.java |
|
4335
365eb4449319
6904183: Fix jdk/test/com/sun/jdi tests to run with -samevm
ohair
parents:
1326
diff
changeset
|
33 |
* @run main/othervm SimulResumerTest |
1326 | 34 |
*/ |
35 |
import com.sun.jdi.*; |
|
36 |
import com.sun.jdi.event.*; |
|
37 |
import com.sun.jdi.request.*; |
|
38 |
||
39 |
import java.util.*; |
|
40 |
||
41 |
/* |
|
42 |
* This debuggee basically runs two threads each of |
|
43 |
* which loop, hitting a bkpt in each iteration. |
|
44 |
* |
|
45 |
*/ |
|
46 |
class SimulResumerTarg extends Thread { |
|
47 |
static boolean one = false; |
|
48 |
static String name1 = "Thread 1"; |
|
49 |
static String name2 = "Thread 2"; |
|
50 |
static int count = 10000; |
|
51 |
public static void main(String[] args) { |
|
52 |
System.out.println("Howdy!"); |
|
53 |
SimulResumerTarg t1 = new SimulResumerTarg(name1); |
|
54 |
SimulResumerTarg t2 = new SimulResumerTarg(name2); |
|
55 |
||
56 |
t1.start(); |
|
57 |
t2.start(); |
|
58 |
} |
|
59 |
||
60 |
public SimulResumerTarg(String name) { |
|
61 |
super(name); |
|
62 |
} |
|
63 |
||
64 |
public void run() { |
|
65 |
if (getName().equals(name1)) { |
|
66 |
run1(); |
|
67 |
} else { |
|
68 |
run2(); |
|
69 |
} |
|
70 |
} |
|
71 |
||
72 |
public void bkpt1(int i) { |
|
73 |
synchronized(name1) { |
|
74 |
yield(); |
|
75 |
} |
|
76 |
} |
|
77 |
||
78 |
public void run1() { |
|
79 |
int i = 0; |
|
80 |
while (i < count) { |
|
81 |
i++; |
|
82 |
bkpt1(i); |
|
83 |
} |
|
84 |
} |
|
85 |
||
86 |
public void bkpt2(int i) { |
|
87 |
synchronized(name2) { |
|
88 |
yield(); |
|
89 |
} |
|
90 |
} |
|
91 |
||
92 |
public void run2() { |
|
93 |
int i = 0; |
|
94 |
while (i < count) { |
|
95 |
i++; |
|
96 |
bkpt2(i); |
|
97 |
} |
|
98 |
} |
|
99 |
} |
|
100 |
||
101 |
/********** test program **********/ |
|
102 |
||
103 |
public class SimulResumerTest extends TestScaffold { |
|
104 |
ReferenceType targetClass; |
|
105 |
ThreadReference mainThread; |
|
106 |
BreakpointRequest request1; |
|
107 |
BreakpointRequest request2; |
|
108 |
static volatile int bkpts = 0; |
|
109 |
static int iters = 0; |
|
110 |
Thread resumerThread; |
|
111 |
static int waitTime = 100; |
|
112 |
ThreadReference debuggeeThread1 = null; |
|
113 |
ThreadReference debuggeeThread2 = null; |
|
114 |
||
115 |
SimulResumerTest (String args[]) { |
|
116 |
super(args); |
|
117 |
} |
|
118 |
||
119 |
public static void main(String[] args) throws Exception { |
|
120 |
new SimulResumerTest(args).startTests(); |
|
121 |
} |
|
122 |
||
123 |
/* BreakpointEvent handler */ |
|
124 |
||
125 |
public void breakpointReached(BreakpointEvent event) { |
|
126 |
// save ThreadRefs for the two debuggee threads |
|
127 |
ThreadReference thr = event.thread(); |
|
128 |
if (bkpts == 0) { |
|
129 |
resumerThread.start(); |
|
130 |
debuggeeThread1 = thr; |
|
131 |
System.out.println("thr1 = " + debuggeeThread1); |
|
132 |
} |
|
133 |
||
134 |
if (debuggeeThread2 == null && thr != debuggeeThread1) { |
|
135 |
debuggeeThread2 = thr; |
|
136 |
System.out.println("thr2 = " + debuggeeThread2); |
|
137 |
} |
|
138 |
||
139 |
synchronized("abc") { |
|
140 |
bkpts++; |
|
141 |
} |
|
142 |
/** |
|
143 |
if (bkpts >= SimulResumerTarg.count * 2) { |
|
144 |
resumerThread.interrupt(); |
|
145 |
} |
|
146 |
*****/ |
|
147 |
||
148 |
} |
|
149 |
||
150 |
/********** test core **********/ |
|
151 |
||
152 |
void check(ThreadReference thr) { |
|
153 |
// This calls each ThreadReference method that could fail due to the bug |
|
154 |
// that occurs if a resume is done while a call to the method is in process. |
|
155 |
String kind = ""; |
|
156 |
if (thr != null) { |
|
157 |
try { |
|
158 |
kind = "ownedMonitors()"; |
|
159 |
System.out.println("kind = " + kind); |
|
160 |
if (thr.ownedMonitors() == null) { |
|
161 |
failure("failure: ownedMonitors = null"); |
|
162 |
} |
|
163 |
||
164 |
kind = "ownedMonitorsAndFrames()"; |
|
165 |
System.out.println("kind = " + kind); |
|
166 |
if (thr.ownedMonitorsAndFrames() == null) { |
|
167 |
failure("failure: ownedMonitorsAndFrames = null"); |
|
168 |
} |
|
169 |
||
170 |
kind = "currentContendedMonitor()"; |
|
171 |
System.out.println("kind = " + kind); |
|
172 |
thr.currentContendedMonitor(); |
|
173 |
// no failure return value here; could cause an NPE |
|
174 |
||
175 |
kind = "frames()"; |
|
176 |
System.out.println("kind = " + kind); |
|
177 |
List<StackFrame> frames = thr.frames(); |
|
178 |
// no failure return value here; could cause an NPE |
|
179 |
||
180 |
int nframes = frames.size(); |
|
181 |
if (nframes > 0) { |
|
182 |
// hmm, how could it ever be 0? |
|
183 |
kind = "frames(0, size - 1)"; |
|
184 |
System.out.println("kind = " + kind); |
|
185 |
thr.frames(0, frames.size() - 1); |
|
186 |
} |
|
187 |
||
188 |
kind = "frameCount()"; |
|
189 |
System.out.println("kind = " + kind); |
|
190 |
if (thr.frameCount() == -1) { |
|
191 |
failure("failure: frameCount = -1"); |
|
192 |
} |
|
193 |
||
194 |
kind = "name()"; |
|
195 |
System.out.println("kind = " + kind); |
|
196 |
if (thr.name() == null) { |
|
197 |
failure("failure: name = null"); |
|
198 |
} |
|
199 |
||
200 |
kind = "status()"; |
|
201 |
System.out.println("kind = " + kind); |
|
202 |
if (thr.status() < 0) { |
|
203 |
failure("failure: status < 0"); |
|
204 |
} |
|
205 |
||
206 |
} catch (IncompatibleThreadStateException ee) { |
|
207 |
// ignore |
|
208 |
} catch (VMDisconnectedException ee) { |
|
209 |
// This is how we stop. The debuggee runs to completion |
|
210 |
// and we get this exception. |
|
211 |
throw ee; |
|
212 |
} catch (Exception ee) { |
|
213 |
failure("failure: Got exception from " + kind + ": " + ee ); |
|
214 |
} |
|
215 |
} |
|
216 |
} |
|
217 |
||
218 |
protected void runTests() throws Exception { |
|
219 |
/* |
|
220 |
* Get to the top of main() |
|
221 |
* to determine targetClass and mainThread |
|
222 |
*/ |
|
223 |
BreakpointEvent bpe = startToMain("SimulResumerTarg"); |
|
224 |
targetClass = bpe.location().declaringType(); |
|
225 |
mainThread = bpe.thread(); |
|
226 |
EventRequestManager erm = vm().eventRequestManager(); |
|
227 |
final Thread mainThread = Thread.currentThread(); |
|
228 |
||
229 |
/* |
|
230 |
* Set event requests |
|
231 |
*/ |
|
232 |
Location loc1 = findMethod(targetClass, "bkpt1", "(I)V").location(); |
|
233 |
Location loc2 = findMethod(targetClass, "bkpt2", "(I)V").location(); |
|
234 |
request1 = erm.createBreakpointRequest(loc1); |
|
235 |
request2 = erm.createBreakpointRequest(loc2); |
|
236 |
request1.enable(); |
|
237 |
request2.enable(); |
|
238 |
||
239 |
/* |
|
240 |
* This thread will be started when we get the first bkpt. |
|
241 |
*/ |
|
242 |
resumerThread = new Thread("test resumer") { |
|
243 |
public void run() { |
|
244 |
while (true) { |
|
245 |
iters++; |
|
246 |
System.out.println("bkpts = " + bkpts + ", iters = " + iters); |
|
247 |
try { |
|
248 |
Thread.sleep(waitTime); |
|
249 |
check(debuggeeThread1); |
|
250 |
check(debuggeeThread2); |
|
251 |
} catch (InterruptedException ee) { |
|
252 |
// If the test completes, this occurs. |
|
253 |
println("resumer Interrupted"); |
|
254 |
break; |
|
255 |
} catch (VMDisconnectedException ee) { |
|
256 |
println("VMDisconnectedException"); |
|
257 |
break; |
|
258 |
} |
|
259 |
} |
|
260 |
} |
|
261 |
}; |
|
262 |
||
263 |
/* |
|
264 |
* resume the target, listening for events |
|
265 |
*/ |
|
266 |
listenUntilVMDisconnect(); |
|
267 |
resumerThread.interrupt(); |
|
268 |
/* |
|
269 |
* deal with results of test |
|
270 |
* if anything has called failure("foo") testFailed will be true |
|
271 |
*/ |
|
272 |
if (!testFailed) { |
|
273 |
println("SimulResumerTest: passed; bkpts = " + bkpts + ", iters = " + iters); |
|
274 |
} else { |
|
275 |
throw new Exception("SimulResumerTest: failed; bkpts = " + bkpts + ", iters = " + iters); |
|
276 |
} |
|
277 |
} |
|
278 |
} |