author | dtitov |
Wed, 06 Mar 2019 09:30:05 -0800 | |
changeset 54012 | 6684c75ab531 |
parent 53869 | 34906de6c017 |
permissions | -rw-r--r-- |
50018 | 1 |
/* |
53869
34906de6c017
8219388: Misleading log message "issuspended002a debuggee launched"
gadams
parents:
50018
diff
changeset
|
2 |
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved. |
50018 | 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 |
package nsk.jdi.VirtualMachine.allThreads; |
|
25 |
||
26 |
import nsk.share.*; |
|
27 |
import nsk.share.jpda.*; |
|
28 |
import nsk.share.jdi.*; |
|
29 |
||
30 |
import com.sun.jdi.*; |
|
31 |
import java.util.*; |
|
32 |
import java.io.*; |
|
33 |
||
34 |
import com.sun.jdi.event.*; |
|
35 |
import com.sun.jdi.request.*; |
|
36 |
||
37 |
/** |
|
38 |
* The test for the implementation of an object of the type <BR> |
|
39 |
* VirtualMachine. <BR> |
|
40 |
* <BR> |
|
41 |
* The test checks up that results of the method <BR> |
|
42 |
* <code>com.sun.jdi.VirtualMachine.allThreads()</code> <BR> |
|
43 |
* complies with the its spec. <BR> |
|
44 |
* <BR> |
|
54012
6684c75ab531
8218464: vmTestbase/nsk/jdi/VirtualMachine/allThreads/allthreads001/TestDescription.java failed
dtitov
parents:
53869
diff
changeset
|
45 |
* The test checks up the results of the method when <BR> |
50018 | 46 |
* it is invoked two times in raw immediately after <BR> |
47 |
* new thread has been started in the debuggee VM. <BR> |
|
48 |
* <BR> |
|
49 |
* After being started up, <BR> |
|
50 |
* a debuggee creates a 'lockingObject' for synchronizing threads, <BR> |
|
51 |
* enters a synchronized block in which it creates new thread, thread2, <BR> |
|
52 |
* informs a debugger of the thread2 creation, and is waiting for reply.<BR> |
|
53 |
* Since the thread2 uses the same locking object as main one <BR> |
|
54 |
* it is locked up until the main thread leaves the synchronized block. <BR> |
|
55 |
* Upon the receiption a message from the debuggee, the debugger <BR> |
|
56 |
* performs the following. <BR> |
|
57 |
* - Upon the receiption of the message "checkready", <BR> |
|
58 |
* the debugger invokes the method VirtualMachine.allThreads() <BR> |
|
59 |
* two times in raw, compares two List objects returned, <BR> |
|
60 |
* and prints out log containing numbers and names of threads <BR> |
|
61 |
* in first returned list. <BR> |
|
62 |
* <BR> |
|
63 |
*/ |
|
64 |
||
65 |
public class allthreads001 { |
|
66 |
||
67 |
//----------------------------------------------------- templete section |
|
68 |
static final int PASSED = 0; |
|
69 |
static final int FAILED = 2; |
|
70 |
static final int PASS_BASE = 95; |
|
71 |
||
72 |
//----------------------------------------------------- templete parameters |
|
73 |
static final String |
|
74 |
sHeader1 = "\n==> nsk/jdi/VirtualMachine/allThreads/allthreads001 ", |
|
75 |
sHeader2 = "--> debugger: ", |
|
76 |
sHeader3 = "##> debugger: "; |
|
77 |
||
78 |
//----------------------------------------------------- main method |
|
79 |
||
80 |
public static void main (String argv[]) { |
|
81 |
int result = run(argv, System.out); |
|
82 |
System.exit(result + PASS_BASE); |
|
83 |
} |
|
84 |
||
85 |
public static int run (String argv[], PrintStream out) { |
|
86 |
return new allthreads001().runThis(argv, out); |
|
87 |
} |
|
88 |
||
89 |
//-------------------------------------------------- log procedures |
|
90 |
||
91 |
private static Log logHandler; |
|
92 |
||
93 |
private static void log1(String message) { |
|
94 |
logHandler.display(sHeader1 + message); |
|
95 |
} |
|
96 |
private static void log2(String message) { |
|
97 |
logHandler.display(sHeader2 + message); |
|
98 |
} |
|
99 |
private static void log3(String message) { |
|
100 |
logHandler.complain(sHeader3 + message); |
|
101 |
} |
|
102 |
||
103 |
// ************************************************ test parameters |
|
104 |
||
105 |
private String debuggeeName = |
|
106 |
"nsk.jdi.VirtualMachine.allThreads.allthreads001a"; |
|
107 |
||
108 |
private String testedClassName = |
|
109 |
"nsk.jdi.StackFrame.setValue.Threadallthreads001a"; |
|
110 |
||
111 |
//String mName = "nsk.jdi.VirtualMachine.allThreads"; |
|
112 |
||
113 |
//====================================================== test program |
|
114 |
//------------------------------------------------------ common section |
|
115 |
static ArgumentHandler argsHandler; |
|
116 |
||
117 |
static int waitTime; |
|
118 |
||
119 |
static VirtualMachine vm = null; |
|
120 |
static EventRequestManager eventRManager = null; |
|
121 |
static EventQueue eventQueue = null; |
|
122 |
static EventSet eventSet = null; |
|
123 |
||
124 |
ReferenceType testedclass = null; |
|
125 |
ThreadReference thread2 = null; |
|
126 |
||
127 |
static int testExitCode = PASSED; |
|
128 |
||
129 |
static final int returnCode0 = 0; |
|
130 |
static final int returnCode1 = 1; |
|
131 |
static final int returnCode2 = 2; |
|
132 |
static final int returnCode3 = 3; |
|
133 |
static final int returnCode4 = 4; |
|
134 |
||
135 |
//------------------------------------------------------ methods |
|
136 |
||
137 |
private int runThis (String argv[], PrintStream out) { |
|
138 |
||
139 |
Debugee debuggee; |
|
140 |
||
141 |
argsHandler = new ArgumentHandler(argv); |
|
142 |
logHandler = new Log(out, argsHandler); |
|
143 |
Binder binder = new Binder(argsHandler, logHandler); |
|
144 |
||
145 |
||
146 |
if (argsHandler.verbose()) { |
|
147 |
debuggee = binder.bindToDebugee(debuggeeName + " -vbs"); // *** tp |
|
148 |
} else { |
|
149 |
debuggee = binder.bindToDebugee(debuggeeName); // *** tp |
|
150 |
} |
|
151 |
||
152 |
waitTime = argsHandler.getWaitTime(); |
|
153 |
||
154 |
||
155 |
IOPipe pipe = new IOPipe(debuggee); |
|
156 |
||
157 |
debuggee.redirectStderr(out); |
|
53869
34906de6c017
8219388: Misleading log message "issuspended002a debuggee launched"
gadams
parents:
50018
diff
changeset
|
158 |
log2(debuggeeName + " debuggee launched"); |
50018 | 159 |
debuggee.resume(); |
160 |
||
161 |
String line = pipe.readln(); |
|
162 |
if ((line == null) || !line.equals("ready")) { |
|
163 |
log3("signal received is not 'ready' but: " + line); |
|
164 |
return FAILED; |
|
165 |
} else { |
|
166 |
log2("'ready' recieved"); |
|
167 |
} |
|
168 |
||
169 |
VirtualMachine vm = debuggee.VM(); |
|
170 |
||
171 |
//------------------------------------------------------ testing section |
|
172 |
log1(" TESTING BEGINS"); |
|
173 |
||
174 |
for (int i = 0; ; i++) { |
|
175 |
pipe.println("newcheck"); |
|
176 |
line = pipe.readln(); |
|
177 |
||
178 |
if (line.equals("checkend")) { |
|
179 |
log2(" : returned string is 'checkend'"); |
|
180 |
break ; |
|
181 |
} else if (!line.equals("checkready")) { |
|
182 |
log3("ERROR: returned string is not 'checkready'"); |
|
183 |
testExitCode = FAILED; |
|
184 |
break ; |
|
185 |
} |
|
186 |
||
187 |
log1("new check: #" + i); |
|
188 |
||
189 |
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part |
|
190 |
||
191 |
int expresult = returnCode0; |
|
192 |
||
193 |
String threadName = "testedThread"; |
|
194 |
||
54012
6684c75ab531
8218464: vmTestbase/nsk/jdi/VirtualMachine/allThreads/allthreads001/TestDescription.java failed
dtitov
parents:
53869
diff
changeset
|
195 |
// Suspend VM to ensure no new background thread (e.g. JVMCI |
6684c75ab531
8218464: vmTestbase/nsk/jdi/VirtualMachine/allThreads/allthreads001/TestDescription.java failed
dtitov
parents:
53869
diff
changeset
|
196 |
// compiler thread) is started between two allThreads() calls. |
6684c75ab531
8218464: vmTestbase/nsk/jdi/VirtualMachine/allThreads/allthreads001/TestDescription.java failed
dtitov
parents:
53869
diff
changeset
|
197 |
vm.suspend(); |
50018 | 198 |
List allThreads1 = vm.allThreads(); |
199 |
log2("allThreads1.size() = " + allThreads1.size()); |
|
200 |
||
201 |
List allThreads2 = vm.allThreads(); |
|
202 |
log2("allThreads2.size() = " + allThreads2.size()); |
|
54012
6684c75ab531
8218464: vmTestbase/nsk/jdi/VirtualMachine/allThreads/allthreads001/TestDescription.java failed
dtitov
parents:
53869
diff
changeset
|
203 |
vm.resume(); |
50018 | 204 |
|
205 |
if ( allThreads1.size() != allThreads2.size() ) { |
|
206 |
log3("ERROR: allThreads1.size() != allThreads2.size()"); |
|
207 |
expresult = returnCode1; |
|
208 |
} |
|
209 |
// Verify that the target thread is running: |
|
210 |
boolean foundThread = false; |
|
211 |
for (int ii = 0; ii < allThreads1.size(); ii++) { |
|
212 |
if ((((ThreadReference) allThreads1.get(ii)).name().equals(threadName))) { |
|
213 |
foundThread = true; |
|
214 |
break; |
|
215 |
} |
|
216 |
} |
|
217 |
if (!foundThread) { |
|
218 |
log3("ERROR: did not find '" + threadName + "' on allThreads1 list."); |
|
219 |
expresult = returnCode1; |
|
220 |
} |
|
221 |
||
222 |
ThreadReference thread = null; |
|
223 |
Object[] arrayT = allThreads1.toArray(); |
|
224 |
||
225 |
for (int iii=0; iii < allThreads1.size(); iii++) { |
|
226 |
thread = (ThreadReference) arrayT[iii]; |
|
227 |
log2("thread.name(" + iii + ") = " + thread.name()); |
|
228 |
} |
|
229 |
||
230 |
log2(" forcing main thread to leave synchronized block"); |
|
231 |
pipe.println("continue"); |
|
232 |
line = pipe.readln(); |
|
233 |
if (!line.equals("docontinue")) { |
|
234 |
log3("ERROR: returned string is not 'docontinue'"); |
|
235 |
expresult = returnCode4; |
|
236 |
} |
|
237 |
||
238 |
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
239 |
log2(" the end of testing"); |
|
240 |
if (expresult != returnCode0) |
|
241 |
testExitCode = FAILED; |
|
242 |
} |
|
243 |
log1(" TESTING ENDS"); |
|
244 |
||
245 |
//-------------------------------------------------- test summary section |
|
246 |
//------------------------------------------------- standard end section |
|
247 |
||
248 |
pipe.println("quit"); |
|
249 |
log2("waiting for the debuggee to finish ..."); |
|
250 |
debuggee.waitFor(); |
|
251 |
||
252 |
int status = debuggee.getStatus(); |
|
253 |
if (status != PASSED + PASS_BASE) { |
|
254 |
log3("debuggee returned UNEXPECTED exit status: " + |
|
255 |
status + " != PASS_BASE"); |
|
256 |
testExitCode = FAILED; |
|
257 |
} else { |
|
258 |
log2("debuggee returned expected exit status: " + |
|
259 |
status + " == PASS_BASE"); |
|
260 |
} |
|
261 |
||
262 |
if (testExitCode != PASSED) { |
|
263 |
logHandler.complain("TEST FAILED"); |
|
264 |
} |
|
265 |
return testExitCode; |
|
266 |
} |
|
267 |
||
268 |
||
269 |
/* |
|
270 |
* private BreakpointRequest settingBreakpoint(String, String, String) |
|
271 |
* |
|
272 |
* It sets up a breakpoint within a given method at given line number |
|
273 |
* for the thread2 only. |
|
274 |
* Third parameter is required for any case in future debugging, as if. |
|
275 |
* |
|
276 |
* Return codes: |
|
277 |
* = BreakpointRequest object in case of success |
|
278 |
* = null in case of an Exception thrown within the method |
|
279 |
*/ |
|
280 |
/* |
|
281 |
private BreakpointRequest settingBreakpoint ( String methodName, |
|
282 |
String bpLine, |
|
283 |
String property) { |
|
284 |
||
285 |
log2("setting up a breakpoint: method: '" + methodName + "' line: " + bpLine ); |
|
286 |
||
287 |
List alllineLocations = null; |
|
288 |
Location lineLocation = null; |
|
289 |
BreakpointRequest breakpRequest = null; |
|
290 |
||
291 |
try { |
|
292 |
Method method = (Method) testedclass.methodsByName(methodName).get(0); |
|
293 |
||
294 |
alllineLocations = method.allLineLocations(); |
|
295 |
||
296 |
int n = |
|
297 |
( (IntegerValue) testedclass.getValue(testedclass.fieldByName(bpLine) ) ).value(); |
|
298 |
if (n > alllineLocations.size()) { |
|
299 |
log3("ERROR: TEST_ERROR_IN_settingBreakpoint(): number is out of bound of method's lines"); |
|
300 |
} else { |
|
301 |
lineLocation = (Location) alllineLocations.get(n); |
|
302 |
try { |
|
303 |
breakpRequest = eventRManager.createBreakpointRequest(lineLocation); |
|
304 |
breakpRequest.putProperty("number", property); |
|
305 |
breakpRequest.addThreadFilter(thread2); |
|
306 |
breakpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD); |
|
307 |
} catch ( Exception e1 ) { |
|
308 |
log3("ERROR: inner Exception within settingBreakpoint() : " + e1); |
|
309 |
breakpRequest = null; |
|
310 |
} |
|
311 |
} |
|
312 |
} catch ( Exception e2 ) { |
|
313 |
log3("ERROR: ATTENTION: outer Exception within settingBreakpoint() : " + e2); |
|
314 |
breakpRequest = null; |
|
315 |
} |
|
316 |
||
317 |
if (breakpRequest == null) |
|
318 |
log2(" A BREAKPOINT HAS NOT BEEN SET UP"); |
|
319 |
else |
|
320 |
log2(" a breakpoint has been set up"); |
|
321 |
||
322 |
return breakpRequest; |
|
323 |
} |
|
324 |
*/ |
|
325 |
||
326 |
/* |
|
327 |
* private int breakpoint () |
|
328 |
* |
|
329 |
* It removes events from EventQueue until gets first BreakpointEvent. |
|
330 |
* To get next EventSet value, it uses the method |
|
331 |
* EventQueue.remove(int timeout) |
|
332 |
* The timeout argument passed to the method, is "waitTime*60000". |
|
333 |
* Note: the value of waitTime is set up with |
|
334 |
* the method ArgumentHandler.getWaitTime() at the beginning of the test. |
|
335 |
* |
|
336 |
* Return codes: |
|
337 |
* = returnCode0 - success; |
|
338 |
* = returnCode2 - Exception when "eventSet = eventQueue.remove()" is executed |
|
339 |
* = returnCode3 - default case when loop of processing an event, that is, |
|
340 |
* an unspecified event was taken from the EventQueue |
|
341 |
*/ |
|
342 |
/* |
|
343 |
private int breakpoint () { |
|
344 |
||
345 |
int returnCode = returnCode0; |
|
346 |
||
347 |
log2(" waiting for BreakpointEvent"); |
|
348 |
||
349 |
labelBP: |
|
350 |
for (;;) { |
|
351 |
||
352 |
log2(" new: eventSet = eventQueue.remove();"); |
|
353 |
try { |
|
354 |
eventSet = eventQueue.remove(waitTime*60000); |
|
355 |
if (eventSet == null) { |
|
356 |
log3("ERROR: timeout for waiting for a BreakpintEvent"); |
|
357 |
returnCode = returnCode3; |
|
358 |
break labelBP; |
|
359 |
} |
|
360 |
} catch ( Exception e ) { |
|
361 |
log3("ERROR: Exception for eventSet = eventQueue.remove(); : " + e); |
|
362 |
returnCode = 1; |
|
363 |
break labelBP; |
|
364 |
} |
|
365 |
||
366 |
if (eventSet != null) { |
|
367 |
||
368 |
log2(" : eventSet != null; size == " + eventSet.size()); |
|
369 |
||
370 |
EventIterator eIter = eventSet.eventIterator(); |
|
371 |
Event ev = null; |
|
372 |
||
373 |
for (; eIter.hasNext(); ) { |
|
374 |
||
375 |
if (returnCode != returnCode0) |
|
376 |
break; |
|
377 |
||
378 |
ev = eIter.nextEvent(); |
|
379 |
||
380 |
ll: for (int ifor =0; ; ifor++) { |
|
381 |
||
382 |
try { |
|
383 |
switch (ifor) { |
|
384 |
||
385 |
case 0: AccessWatchpointEvent awe = (AccessWatchpointEvent) ev; |
|
386 |
log2(" AccessWatchpointEvent removed"); |
|
387 |
break ll; |
|
388 |
case 1: BreakpointEvent be = (BreakpointEvent) ev; |
|
389 |
log2(" BreakpointEvent removed"); |
|
390 |
break labelBP; |
|
391 |
case 2: ClassPrepareEvent cpe = (ClassPrepareEvent) ev; |
|
392 |
log2(" ClassPreparEvent removed"); |
|
393 |
break ll; |
|
394 |
case 3: ClassUnloadEvent cue = (ClassUnloadEvent) ev; |
|
395 |
log2(" ClassUnloadEvent removed"); |
|
396 |
break ll; |
|
397 |
case 4: ExceptionEvent ee = (ExceptionEvent) ev; |
|
398 |
log2(" ExceptionEvent removed"); |
|
399 |
break ll; |
|
400 |
case 5: MethodEntryEvent mene = (MethodEntryEvent) ev; |
|
401 |
log2(" MethodEntryEvent removed"); |
|
402 |
break ll; |
|
403 |
case 6: MethodExitEvent mexe = (MethodExitEvent) ev; |
|
404 |
log2(" MethodExiEvent removed"); |
|
405 |
break ll; |
|
406 |
case 7: ModificationWatchpointEvent mwe = (ModificationWatchpointEvent) ev; |
|
407 |
log2(" ModificationWatchpointEvent removed"); |
|
408 |
break ll; |
|
409 |
case 8: StepEvent se = (StepEvent) ev; |
|
410 |
log2(" StepEvent removed"); |
|
411 |
break ll; |
|
412 |
case 9: ThreadDeathEvent tde = (ThreadDeathEvent) ev; |
|
413 |
log2(" ThreadDeathEvent removed"); |
|
414 |
break ll; |
|
415 |
case 10: ThreadStartEvent tse = (ThreadStartEvent) ev; |
|
416 |
log2(" ThreadStartEvent removed"); |
|
417 |
break ll; |
|
418 |
case 11: VMDeathEvent vmde = (VMDeathEvent) ev; |
|
419 |
log2(" VMDeathEvent removed"); |
|
420 |
break ll; |
|
421 |
case 12: VMStartEvent vmse = (VMStartEvent) ev; |
|
422 |
log2(" VMStartEvent removed"); |
|
423 |
break ll; |
|
424 |
case 13: WatchpointEvent we = (WatchpointEvent) ev; |
|
425 |
log2(" WatchpointEvent removed"); |
|
426 |
break ll; |
|
427 |
||
428 |
default: log3("ERROR: default case for casting event"); |
|
429 |
returnCode = returnCode3; |
|
430 |
break ll; |
|
431 |
} // switch |
|
432 |
} catch ( ClassCastException e ) { |
|
433 |
} // try |
|
434 |
} // ll: for (int ifor =0; ; ifor++) |
|
435 |
} // for (; ev.hasNext(); ) |
|
436 |
} |
|
437 |
} |
|
438 |
if (returnCode == returnCode0) |
|
439 |
log2(" : eventSet == null: EventQueue is empty"); |
|
440 |
||
441 |
return returnCode; |
|
442 |
} |
|
443 |
*/ |
|
444 |
} |