Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/createStepRequest/crstepreq008a.java
41161 views
/*1* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package nsk.jdi.EventRequestManager.createStepRequest;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdi.*;2829// THIS TEST IS LINE NUMBER SENSITIVE3031/**32* The debugged application of the test.33*/34public class crstepreq008a {3536//----------------------------------------------------- immutable common fields3738static final int PASSED = 0;39static final int FAILED = 2;40static final int PASS_BASE = 95;41static final int quit = -1;4243static int instruction = 1;44static int lineForComm = 2;45static int exitCode = PASSED;4647private static ArgumentHandler argHandler;48private static Log log;4950//---------------------------------------------------------- immutable common methods5152static void display(String msg) {53log.display("debuggee > " + msg);54}5556static void complain(String msg) {57log.complain("debuggee FAILURE > " + msg);58}5960static void methodForCommunication() {61int i = instruction; // crstepreq008.lineForBreak62int curInstruction = i;63}6465//------------------------------------------------------ mutable common fields6667//------------------------------------------------------ test specific fields6869static final int maxCase = 4;70static Object waitnotifyObj = new Object();71static Thread thread1;7273//------------------------------------------------------ mutable common method7475public static void main (String argv[]) {7677argHandler = new ArgumentHandler(argv);78log = argHandler.createDebugeeLog();7980display("debuggee started!");8182label0:83for (int testCase = 0; testCase < maxCase && instruction != quit; testCase++) {8485thread1 = new Thread0crstepreq008a(testCase);86threadStart(thread1);87threadJoin (thread1, testCase);8889}9091display("debuggee exits");92System.exit(PASSED + PASS_BASE);93}9495//--------------------------------------------------------- test specific methodss9697static void threadJoin (Thread t, int number) {98try {99t.join();100} catch ( InterruptedException e ) {101exitCode = FAILED;102complain("Case #" + number + ": caught unexpected InterruptedException while waiting for thread finish" );103}104}105106static int threadStart (Thread t) {107synchronized (waitnotifyObj) {108t.start();109try {110waitnotifyObj.wait();111} catch (InterruptedException e) {112exitCode = FAILED;113complain("Caught unexpected InterruptedException while waiting for thread start" );114return FAILED;115}116}117return PASSED;118}119120}121122//--------------------------------------------------------- test specific classes123124/**125* This thread will be suspended on breakpoint. No locks are used.126*/127class Thread0crstepreq008a extends Thread {128int testCase;129130public Thread0crstepreq008a (int testCase) {131super("thread" + testCase);132this.testCase = testCase;133}134135public void run() {136crstepreq008a.display("enter thread " + getName());137synchronized(crstepreq008a.waitnotifyObj) {138crstepreq008a.waitnotifyObj.notifyAll();139}140141crstepreq008a.methodForCommunication();142caseRun();143crstepreq008a.display("exit thread " + getName());144}145146void caseRun() {147int i;148try {149switch (testCase) {150case 0:151i = m00(1); // crstepreq008.checkedLines[0][0-2]152i = m00(2); i = m00(3);153break;154155case 1:156i = m01(1); i = m01(2);157break;158159case 2:160i = m02(-1);161break;162163case 3:164i = m03(-1);165break;166}167} catch (DummyException e) {168crstepreq008a.display("DummyException was caught for testCase # " + testCase);169}170}171172int m00 (int arg) {173return arg++; // crstepreq008.checkedLines[1][0-2]174}175176int m01 (int arg) {177return m00(arg);178}179180int m02 (int arg) throws DummyException {181if (arg < 0) { // crstepreq008.checkedLines[2][0-1]182throw new DummyException(); // crstepreq008.checkedLines[2][2]// crstepreq008.checkedLines[3][0-2]183}184return arg++;185}186187int m03 (int arg) throws DummyException {188return m02(arg);189}190191class DummyException extends Exception {}192}193194195