1 /* 2 * Copyright (c) 2001, 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 package nsk.jdi.ThreadReference.isSuspended; 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 * ThreadReference. <BR> 40 * <BR> 41 * The test checks up that results of the method <BR> 42 * <code>com.sun.jdi.ThreadReference.isSuspended()</code> <BR> 43 * complies with its spec. <BR> 44 * <BR> 45 * After being started up, <BR> 46 * a debuggee creates a 'lockingObject' for synchronizing threads, <BR> 47 * enters a synchronized block in which it creates new thread, thread2, <BR> 48 * informs a debugger of the thread creation, and is waiting for reply. <BR> 49 * Since the thread2 uses the same locking object as main one <BR> 50 * it is locked up until the main thread leaves the synchronized block. <BR> 51 * Upon the receiption a message from the debuggee, the debugger <BR> 52 * performs the following. <BR> 53 * (1) Using the method ThreadReference.isSuspended() to get thread2's <BR> 54 * state in the following three pairs of suspend-resume methods: <BR> 55 * ThreadReference.suspend() - ThreadReference.resume() <BR> 56 * ThreadReference.suspend() - VirtualMachine.resume() <BR> 57 * VirtualMachine.suspend() - VirtualMachine.resume() <BR> 58 * (2) sets up three breakpoints for the thread2 at which it <BR> 59 * checks up thread2's state in the following pairs: <BR> 60 * suspended_at_breakpoint - EventSet.resume() <BR> 61 * suspended_at_breakpoint - ThreadReference.resume() <BR> 62 * suspended_at_breakpoint - VirtualMachine.resume() <BR> 63 * <BR> 64 */ 65 66 public class issuspended001 { 67 68 //----------------------------------------------------- templete section 69 static final int PASSED = 0; 70 static final int FAILED = 2; 71 static final int PASS_BASE = 95; 72 73 //----------------------------------------------------- templete parameters 74 static final String 75 sHeader1 = "\n==> nsk/jdi/ThreadReference/isSuspended/issuspended001 ", 76 sHeader2 = "--> debugger: ", 77 sHeader3 = "##> debugger: "; 78 79 // sHeader2 = "--> issuspended003: ", 80 // sHeader3 = "##> issuspended003: "; 81 82 //----------------------------------------------------- main method 83 main(String argv[])84 public static void main (String argv[]) { 85 int result = run(argv, System.out); 86 System.exit(result + PASS_BASE); 87 } 88 run(String argv[], PrintStream out)89 public static int run (String argv[], PrintStream out) { 90 return new issuspended001().runThis(argv, out); 91 } 92 93 //-------------------------------------------------- log procedures 94 95 private static Log logHandler; 96 log1(String message)97 private static void log1(String message) { 98 logHandler.display(sHeader1 + message); 99 } log2(String message)100 private static void log2(String message) { 101 logHandler.display(sHeader2 + message); 102 } log3(String message)103 private static void log3(String message) { 104 logHandler.complain(sHeader3 + message); 105 } 106 107 // ************************************************ test parameters 108 109 private String debuggeeName = 110 "nsk.jdi.ThreadReference.isSuspended.issuspended001a"; 111 112 private String testedClassName = 113 "nsk.jdi.ThreadReference.isSuspended.Threadissuspended001a"; 114 115 //String mName = "nsk.jdi.ThreadReference.isSuspended"; 116 117 //====================================================== test program 118 //------------------------------------------------------ common section 119 static ArgumentHandler argsHandler; 120 121 static int waitTime; 122 123 static VirtualMachine vm = null; 124 static EventRequestManager eventRManager = null; 125 static EventQueue eventQueue = null; 126 static EventSet eventSet = null; 127 128 ReferenceType testedclass = null; 129 ThreadReference thread2 = null; 130 ThreadReference mainThread = null; 131 132 static int testExitCode = PASSED; 133 134 static final int returnCode0 = 0; 135 static final int returnCode1 = 1; 136 static final int returnCode2 = 2; 137 static final int returnCode3 = 3; 138 static final int returnCode4 = 4; 139 140 //------------------------------------------------------ methods 141 runThis(String argv[], PrintStream out)142 private int runThis (String argv[], PrintStream out) { 143 144 Debugee debuggee; 145 146 argsHandler = new ArgumentHandler(argv); 147 logHandler = new Log(out, argsHandler); 148 Binder binder = new Binder(argsHandler, logHandler); 149 150 if (argsHandler.verbose()) { 151 debuggee = binder.bindToDebugee(debuggeeName + " -vbs"); 152 } else { 153 debuggee = binder.bindToDebugee(debuggeeName); 154 } 155 156 waitTime = argsHandler.getWaitTime(); 157 158 159 IOPipe pipe = new IOPipe(debuggee); 160 161 debuggee.redirectStderr(out); 162 log2("issuspended001a debuggee launched"); 163 debuggee.resume(); 164 165 String line = pipe.readln(); 166 if ((line == null) || !line.equals("ready")) { 167 log3("signal received is not 'ready' but: " + line); 168 return FAILED; 169 } else { 170 log2("'ready' recieved"); 171 } 172 173 vm = debuggee.VM(); 174 175 //------------------------------------------------------ testing section 176 log1(" TESTING BEGINS"); 177 178 for (int i = 0; ; i++) { 179 pipe.println("newcheck"); 180 line = pipe.readln(); 181 182 if (line.equals("checkend")) { 183 log2(" : returned string is 'checkend'"); 184 break ; 185 } else if (line.equals("waitnotifyerr")) { 186 log2(" : returned string is 'waitnotifyerr'"); 187 break ; 188 } else if (!line.equals("checkready")) { 189 log3("ERROR: returned string is not 'checkready'"); 190 testExitCode = FAILED; 191 break ; 192 } 193 194 log1("new checkready: #" + i); 195 196 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part 197 198 int expresult = returnCode0; 199 200 201 eventRManager = vm.eventRequestManager(); 202 eventQueue = vm.eventQueue(); 203 204 String threadName = "testedThread"; 205 206 String breakpointMethod1 = "runt1"; 207 String breakpointMethod2 = "runt2"; 208 209 String bpLine1 = "breakpointLineNumber1"; 210 String bpLine2 = "breakpointLineNumber2"; 211 String bpLine3 = "breakpointLineNumber3"; 212 213 214 List allThreads = null; 215 ListIterator listIterator = null; 216 List classes = null; 217 218 BreakpointRequest breakpRequest1 = null; 219 BreakpointRequest breakpRequest2 = null; 220 BreakpointRequest breakpRequest3 = null; 221 222 int suspCount = 0; 223 int frameCount; 224 225 226 label0: { 227 228 log2("getting ThreadReference objects and setting up breakponts"); 229 try { 230 allThreads = vm.allThreads(); 231 classes = vm.classesByName(testedClassName); 232 testedclass = (ReferenceType) classes.get(0); 233 } catch ( Exception e) { 234 log3("ERROR: Exception at very beginning !? : " + e); 235 expresult = returnCode1; 236 break label0; 237 } 238 239 listIterator = allThreads.listIterator(); 240 for (;;) { 241 try { 242 thread2 = (ThreadReference) listIterator.next(); 243 if (thread2.name().equals(threadName)) 244 break ; 245 } catch ( NoSuchElementException e ) { 246 log3("ERROR: NoSuchElementException for listIterator.next()"); 247 log3("ERROR: NO THREAD2 ?????????!!!!!!!"); 248 expresult = returnCode1; 249 break label0; 250 } 251 } 252 253 log2("getting ThreadReference objects for main thread"); 254 listIterator = allThreads.listIterator(); 255 for (;;) { 256 try { 257 mainThread = (ThreadReference) listIterator.next(); 258 if (mainThread.name().equals("main")) 259 break ; 260 } catch ( NoSuchElementException e ) { 261 log3("ERROR: NoSuchElementException for listIterator.next() for 'mainThread'"); 262 log3("ERROR: NO MAIN THREAD ?????????!!!!!!!"); 263 expresult = returnCode1; 264 break label0; 265 } 266 } 267 268 log2("setting up breakpoints"); 269 270 breakpRequest1 = settingBreakpoint(breakpointMethod1, bpLine1, "one"); 271 if (breakpRequest1 == null) { 272 expresult = returnCode1; 273 break label0; 274 } 275 breakpRequest3 = settingBreakpoint(breakpointMethod1, bpLine3, "three"); 276 if (breakpRequest3 == null) { 277 expresult = returnCode1; 278 break label0; 279 } 280 breakpRequest2 = settingBreakpoint(breakpointMethod2, bpLine2, "two"); 281 if (breakpRequest2 == null) { 282 expresult = returnCode1; 283 break label0; 284 } 285 } 286 287 label1: { 288 289 if (expresult != returnCode0) 290 break label1; 291 292 log2(" checking up the thread2 before to begin testing it"); 293 294 suspCount = thread2.suspendCount(); 295 log2(" suspendCount == " + suspCount); 296 if (!thread2.isSuspended()) { 297 log2(" : !thread2.isSuspended()"); 298 } else { 299 log3("ERROR: thread2.isSuspended()"); 300 expresult = returnCode1; 301 } 302 303 if (expresult != returnCode0) 304 break label1; 305 306 log2(".....testing case 1:"); 307 log2(".....the thread2 is suspended with thread2.suspend();"); 308 log2(".....and resumed with thread2.resume();"); 309 310 thread2.suspend(); 311 312 suspCount = thread2.suspendCount(); 313 log2(" checking up the thread2 after suspending it"); 314 if (thread2.isSuspended()) { 315 log2(" : thread2.isSuspended()"); 316 } else { 317 log3("ERROR: !thread2.isSuspended()"); 318 expresult = returnCode1; 319 } 320 log2(" suspendCount == " + suspCount); 321 322 thread2.resume(); 323 324 suspCount = thread2.suspendCount(); 325 log2(" checking up the thread2 after resuming it"); 326 if (!thread2.isSuspended()) { 327 log2(" : !thread2.isSuspended()"); 328 } else { 329 log3("ERROR: thread2.isSuspended()"); 330 expresult = returnCode1; 331 } 332 log2(" suspendCount == " + suspCount); 333 334 335 log2(".....testing case 2:"); 336 log2(".....the thread2 is suspended with thread2.suspend();"); 337 log2(".....and resumed with vm.resume();"); 338 339 thread2.suspend(); 340 341 suspCount = thread2.suspendCount(); 342 log2(" checking up the thread2 after suspending it"); 343 if (thread2.isSuspended()) { 344 log2(" : thread2.isSuspended()"); 345 } else { 346 log3("ERROR: !thread2.isSuspended()"); 347 expresult = returnCode1; 348 } 349 log2(" suspendCount == " + suspCount); 350 351 vm.resume(); 352 353 suspCount = thread2.suspendCount(); 354 log2(" checking up the thread2 after resuming the application in VM"); 355 if (!thread2.isSuspended()) { 356 log2(" : !thread2.isSuspended()"); 357 } else { 358 log3("ERROR: thread2.isSuspended()"); 359 expresult = returnCode1; 360 } 361 log2(" suspendCount == " + suspCount); 362 363 364 log2(".....testing case 3:"); 365 log2(".....the thread2 is suspended with vm.suspend();"); 366 log2(".....and resumed with vm.resume();"); 367 368 vm.suspend(); 369 370 suspCount = thread2.suspendCount(); 371 log2(" checking up the thread2 after suspending the application in VM"); 372 if (thread2.isSuspended()) { 373 log2(" : thread2.isSuspended()"); 374 } else { 375 log3("ERROR: !thread2.isSuspended()"); 376 expresult = returnCode1; 377 } 378 log2(" suspendCount == " + suspCount); 379 380 vm.resume(); 381 382 suspCount = thread2.suspendCount(); 383 log2(" checking up the thread2 after resuming the application in VM"); 384 if (!thread2.isSuspended()) { 385 log2(" : !thread2.isSuspended()"); 386 } else { 387 log3("ERROR: thread2.isSuspended()"); 388 expresult = returnCode1; 389 } 390 log2(" suspendCount == " + suspCount); 391 } 392 393 if (expresult == returnCode0) { 394 log2(" enabling breakpRequest1"); 395 breakpRequest1.enable(); 396 } 397 398 log2(" instructing main thread to leave the synchronized block"); 399 pipe.println("continue"); 400 line = pipe.readln(); 401 if (!line.equals("out_of_synchronized")) { 402 log3("ERROR: returned string is not 'out_of_synchronized'"); 403 expresult = returnCode2; 404 } 405 406 label2: { 407 408 if (expresult == returnCode0) 409 expresult = breakpoint(); 410 if (expresult != returnCode0) 411 break label2; 412 413 log2(" the thread2 is at first breakpoint"); 414 try { 415 frameCount = thread2.frameCount(); 416 log2(" frameCount == " + frameCount); 417 } catch ( Exception e ) { 418 log3("ERROR: Exception for : frameCount = thread2.frameCount(); : " + e); 419 expresult = returnCode1; 420 } 421 422 log2(" checking up that thread2 is suspended at first breakpoint"); 423 log2(" suspendCount == " + thread2.suspendCount()); 424 if ( thread2.isAtBreakpoint() ) { 425 log2(" : thread2.isAtBreakpoint()"); 426 } else { 427 log3("ERROR: !thread2.isAtBreakpoint()"); 428 expresult = returnCode1; 429 } 430 if ( thread2.isSuspended() ) { 431 log2(" : thread2.isSuspended()"); 432 } else { 433 log3("ERROR: !thread2.isSuspended()"); 434 expresult = returnCode1; 435 } 436 } 437 438 label3: { 439 440 if (expresult != returnCode0) 441 break label3; 442 443 log2(" instructing main thread to enter the synchronized block"); 444 pipe.println("enter_synchronized"); 445 line = pipe.readln(); 446 if (!line.equals("in_synchronized")) { 447 log3("ERROR: returned string is not 'in_synchronized'"); 448 expresult = returnCode4; 449 break label3; 450 } 451 452 eventSet.resume(); 453 454 log2(" the thread2 has left the breakpoint"); 455 456 log2(".....testing case 4: suspended_at_breakpoint - eventSet.resume();"); 457 log2(".....checking up that the thread2 is not at first breakpoint"); 458 if ( !thread2.isAtBreakpoint() ) { 459 log2(" : !thread2.isAtBreakpoint()"); 460 } else { 461 log3("ERROR: thread2.isAtBreakpoint()"); 462 expresult = returnCode1; 463 } 464 log2(" checking up that the thread2 is not suspended"); 465 log2(" suspendCount == " + thread2.suspendCount()); 466 if ( !thread2.isSuspended() ) { 467 log2(" : !thread2.isSuspended() "); 468 } else { 469 log3("ERROR: thread2.isSuspended()"); 470 expresult = returnCode1; 471 } 472 473 if (expresult == returnCode0) { 474 log2(" enabling breakpRequest2"); 475 breakpRequest2.enable(); 476 } 477 478 log2(" instructing main thread to leave the synchronized block"); 479 480 pipe.println("leave_synchronized"); 481 line = pipe.readln(); 482 if (!line.equals("out_of_synchronized")) { 483 log3("ERROR: returned string is not 'out_of_synchronized'"); 484 expresult = returnCode4; 485 } 486 } 487 488 label4: { 489 490 if (expresult == returnCode0) 491 expresult = breakpoint(); 492 if (expresult != returnCode0) 493 break label4; 494 495 log2(" the thread2 is at second breakpoint"); 496 try { 497 frameCount = thread2.frameCount(); 498 log2(" frameCount == " + frameCount); 499 } catch ( Exception e ) { 500 log3("ERROR: Exception for : frameCount = thread2.frameCount(); : " + e); 501 expresult = returnCode1; 502 } 503 504 log2(" checking up that the thread2 is suspended at second breakpoint"); 505 log2(" suspendCount == " + thread2.suspendCount()); 506 if ( thread2.isAtBreakpoint() ) { 507 log2(" : thread2.isAtBreakpoint()"); 508 } else { 509 log3("ERROR: !thread2.isAtBreakpoint()"); 510 expresult = returnCode1; 511 } 512 if ( thread2.isSuspended() ) { 513 log2(" : thread2.isSuspended()"); 514 } else { 515 log3("ERROR: !thread2.isSuspended()"); 516 expresult = returnCode1; 517 } 518 } 519 520 label5: { 521 522 if (expresult != returnCode0) 523 break label5; 524 525 log2(" instructing main thread to enter the synchronized block"); 526 pipe.println("enter_synchronized"); 527 line = pipe.readln(); 528 if (!line.equals("in_synchronized")) { 529 log3("ERROR: returned string is not 'in_synchronized'"); 530 expresult = returnCode4; 531 break label5; 532 } 533 534 thread2.resume(); 535 536 log2(" the thread2 has left the breakpoint"); 537 538 log2(".....testing case 5: suspended_at_breakpoint - thread2.resume();"); 539 log2(".....checking up that the thread is not at a breakpoint"); 540 if ( !thread2.isAtBreakpoint() ) { 541 log2(" : !thread2.isAtBreakpoint() "); 542 } else { 543 log3("ERROR: thread2.isAtBreakpoint()"); 544 expresult = returnCode1; 545 } 546 log2(" checking up that the thread is not suspended"); 547 log2(" suspendCount == " + thread2.suspendCount()); 548 if ( !thread2.isSuspended() ) { 549 log2(" : !thread2.isSuspended() "); 550 } else { 551 log3("ERROR: thread2.isSuspended()"); 552 expresult = returnCode1; 553 } 554 555 if (expresult == returnCode0) { 556 log2(" enabling breakpRequest3"); 557 breakpRequest3.enable(); 558 } 559 560 log2(" instructing main thread to leave the synchronized block"); 561 pipe.println("leave_synchronized"); 562 line = pipe.readln(); 563 if (!line.equals("out_of_synchronized")) { 564 log3("ERROR: returned string is not 'out_of_synchronized'"); 565 expresult = returnCode4; 566 } 567 } 568 569 label6: { 570 571 if (expresult == returnCode0) 572 expresult = breakpoint(); 573 if (expresult != returnCode0) 574 break label6; 575 576 log2(" the thread2 is at third breakpoint"); 577 try { 578 frameCount = thread2.frameCount(); 579 log2(" frameCount == " + frameCount); 580 } catch ( Exception e ) { 581 log3("ERROR: Exception for : frameCount = thread2.frameCount(); : " + e); 582 expresult = returnCode1; 583 } 584 585 log2(" checking up that the thread2 is suspended at third breakpoint"); 586 log2(" suspendCount == " + thread2.suspendCount()); 587 if ( thread2.isAtBreakpoint() ) { 588 log2(" : thread2.isAtBreakpoint()"); 589 } else { 590 log3("ERROR: !thread2.isAtBreakpoint()"); 591 expresult = returnCode1; 592 } 593 if ( thread2.isSuspended() ) { 594 log2(" : thread2.isSuspended()"); 595 } else { 596 log3("ERROR: !thread2.isSuspended()"); 597 expresult = returnCode1; 598 } 599 600 vm.resume(); 601 602 log2(" the thread has left the breakpoint"); 603 604 log2(".....testing case 6: suspended_at_breakpoint - vm.resume();"); 605 log2(".....checking up that the thread is not at a breakpoint"); 606 if ( !thread2.isAtBreakpoint() ) { 607 log2(" : !thread2.isAtBreakpoint() "); 608 } else { 609 log3("ERROR: thread2.isAtBreakpoint()"); 610 expresult = returnCode1; 611 } 612 log2(" checking that the thread is not suspended"); 613 log2(" suspendCount == " + thread2.suspendCount()); 614 if ( !thread2.isSuspended() ) { 615 log2(" : !thread2.isSuspended() "); 616 } else { 617 log3("ERROR: thread2.isSuspended()"); 618 expresult = returnCode1; 619 } 620 } 621 622 if (expresult != returnCode4) { 623 if (line.equals("in_synchronized")) { 624 log2("instrucring the main thread to leave synchronized block"); 625 pipe.println("leave_synchronized"); 626 line = pipe.readln(); 627 } 628 pipe.println("continue"); 629 line = pipe.readln(); 630 if (!line.equals("docontinue")) { 631 log3("ERROR: returned string is not 'docontinue'"); 632 expresult = returnCode2; 633 } 634 } 635 636 log2("resuming vm; for case :"); 637 log2("the thread2 had been suspended at a breakpoint when the test has been aborted"); 638 vm.resume(); 639 640 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 641 log2(" the end of testing"); 642 if (expresult != returnCode0) 643 testExitCode = FAILED; 644 } 645 log1(" TESTING ENDS"); 646 647 //-------------------------------------------------- test summary section 648 //------------------------------------------------- standard end section 649 650 pipe.println("quit"); 651 log2("waiting for the debuggee to finish ..."); 652 debuggee.waitFor(); 653 654 int status = debuggee.getStatus(); 655 if (status != PASSED + PASS_BASE) { 656 log3("debuggee returned UNEXPECTED exit status: " + 657 status + " != PASS_BASE"); 658 testExitCode = FAILED; 659 } else { 660 log2("debuggee returned expected exit status: " + 661 status + " == PASS_BASE"); 662 } 663 664 if (testExitCode != PASSED) { 665 logHandler.complain("TEST FAILED"); 666 } 667 return testExitCode; 668 } 669 670 671 /* 672 * private BreakpointRequest settingBreakpoint(String, String, String) 673 * 674 * It sets up a breakpoint within a given method at given line number 675 * for the thread2 only. 676 * Third parameter is required for any case in future debugging, as if. 677 * 678 * Return codes: 679 * = BreakpointRequest object in case of success 680 * = null in case of an Exception thrown within the method 681 */ 682 settingBreakpoint( String methodName, String bpLine, String property)683 private BreakpointRequest settingBreakpoint ( String methodName, 684 String bpLine, 685 String property) { 686 687 log2("setting up a breakpoint: method: '" + methodName + "' line: " + bpLine ); 688 689 List alllineLocations = null; 690 Location lineLocation = null; 691 BreakpointRequest breakpRequest = null; 692 693 try { 694 Method method = (Method) testedclass.methodsByName(methodName).get(0); 695 696 alllineLocations = method.allLineLocations(); 697 698 int n = 699 ( (IntegerValue) testedclass.getValue(testedclass.fieldByName(bpLine) ) ).value(); 700 if (n > alllineLocations.size()) { 701 log3("ERROR: TEST_ERROR_IN_settingBreakpoint(): number is out of bound of method's lines"); 702 } else { 703 lineLocation = (Location) alllineLocations.get(n); 704 try { 705 breakpRequest = eventRManager.createBreakpointRequest(lineLocation); 706 breakpRequest.putProperty("number", property); 707 breakpRequest.addThreadFilter(thread2); 708 breakpRequest.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD); 709 } catch ( Exception e1 ) { 710 log3("ERROR: inner Exception within settingBreakpoint() : " + e1); 711 breakpRequest = null; 712 } 713 } 714 } catch ( Exception e2 ) { 715 log3("ERROR: ATTENTION: outer Exception within settingBreakpoint() : " + e2); 716 breakpRequest = null; 717 } 718 719 if (breakpRequest == null) 720 log2(" A BREAKPOINT HAS NOT BEEN SET UP"); 721 else 722 log2(" a breakpoint has been set up"); 723 724 return breakpRequest; 725 } 726 727 728 /* 729 * private int breakpoint () 730 * 731 * It removes events from EventQueue until gets first BreakpointEvent. 732 * To get next EventSet value, it uses the method 733 * EventQueue.remove(int timeout) 734 * The timeout argument passed to the method, is "waitTime*60000". 735 * Note: the value of waitTime is set up with 736 * the method ArgumentHandler.getWaitTime() at the beginning of the test. 737 * 738 * Return codes: 739 * = returnCode0 - success; 740 * = returnCode2 - Exception when "eventSet = eventQueue.remove()" is executed 741 * = returnCode3 - default case when loop of processing an event, that is, 742 * an unspecified event was taken from the EventQueue 743 */ 744 breakpoint()745 private int breakpoint () { 746 747 int returnCode = returnCode0; 748 749 log2(" waiting for BreakpointEvent"); 750 751 labelBP: 752 for (;;) { 753 754 log2(" new: eventSet = eventQueue.remove();"); 755 try { 756 eventSet = eventQueue.remove(waitTime*60000); 757 if (eventSet == null) { 758 log3("ERROR: timeout for waiting for a BreakpintEvent"); 759 returnCode = returnCode2; 760 break labelBP; 761 } 762 } catch ( Exception e ) { 763 log3("ERROR: Exception for eventSet = eventQueue.remove(); : " + e); 764 returnCode = 1; 765 break labelBP; 766 } 767 768 if (eventSet != null) { 769 770 log2(" : eventSet != null; size == " + eventSet.size()); 771 772 EventIterator eIter = eventSet.eventIterator(); 773 Event ev = null; 774 775 for (; eIter.hasNext(); ) { 776 777 if (returnCode != returnCode0) 778 break; 779 780 ev = eIter.nextEvent(); 781 782 ll: for (int ifor =0; ; ifor++) { 783 784 try { 785 switch (ifor) { 786 787 case 0: AccessWatchpointEvent awe = (AccessWatchpointEvent) ev; 788 log2(" AccessWatchpointEvent removed"); 789 break ll; 790 case 1: BreakpointEvent be = (BreakpointEvent) ev; 791 log2(" BreakpointEvent removed"); 792 break labelBP; 793 case 2: ClassPrepareEvent cpe = (ClassPrepareEvent) ev; 794 log2(" ClassPreparEvent removed"); 795 break ll; 796 case 3: ClassUnloadEvent cue = (ClassUnloadEvent) ev; 797 log2(" ClassUnloadEvent removed"); 798 break ll; 799 case 4: ExceptionEvent ee = (ExceptionEvent) ev; 800 log2(" ExceptionEvent removed"); 801 break ll; 802 case 5: MethodEntryEvent mene = (MethodEntryEvent) ev; 803 log2(" MethodEntryEvent removed"); 804 break ll; 805 case 6: MethodExitEvent mexe = (MethodExitEvent) ev; 806 log2(" MethodExiEvent removed"); 807 break ll; 808 case 7: ModificationWatchpointEvent mwe = (ModificationWatchpointEvent) ev; 809 log2(" ModificationWatchpointEvent removed"); 810 break ll; 811 case 8: StepEvent se = (StepEvent) ev; 812 log2(" StepEvent removed"); 813 break ll; 814 case 9: ThreadDeathEvent tde = (ThreadDeathEvent) ev; 815 log2(" ThreadDeathEvent removed"); 816 break ll; 817 case 10: ThreadStartEvent tse = (ThreadStartEvent) ev; 818 log2(" ThreadStartEvent removed"); 819 break ll; 820 case 11: VMDeathEvent vmde = (VMDeathEvent) ev; 821 log2(" VMDeathEvent removed"); 822 break ll; 823 case 12: VMStartEvent vmse = (VMStartEvent) ev; 824 log2(" VMStartEvent removed"); 825 break ll; 826 case 13: WatchpointEvent we = (WatchpointEvent) ev; 827 log2(" WatchpointEvent removed"); 828 break ll; 829 830 default: log3("ERROR: default case for casting event"); 831 returnCode = returnCode3; 832 break ll; 833 } // switch 834 } catch ( ClassCastException e ) { 835 } // try 836 } // ll: for (int ifor =0; ; ifor++) 837 } // for (; ev.hasNext(); ) 838 } 839 } 840 if (returnCode == returnCode0) 841 log2(" : eventSet == null: EventQueue is empty"); 842 843 return returnCode; 844 } 845 846 847 } 848