Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/createStepRequest/crstepreq009a.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 crstepreq009a {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; // crstepreq009.lineForBreak62int curInstruction = i;63}6465//------------------------------------------------------ mutable common fields6667//------------------------------------------------------ test specific fields6869static final int maxCase = 3;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 Thread0crstepreq009a(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 Thread0crstepreq009a extends Thread {128int testCase;129130public Thread0crstepreq009a (int testCase) {131super("thread" + testCase);132this.testCase = testCase;133}134135public void run() {136crstepreq009a.display("enter thread " + getName());137synchronized(crstepreq009a.waitnotifyObj) {138crstepreq009a.waitnotifyObj.notifyAll();139}140141crstepreq009a.methodForCommunication();142caseRun();143crstepreq009a.display("exit thread " + getName());144}145146void caseRun() {147int i;148switch (testCase) {149case 0:150i = m01(1); // crstepreq009.checkedLines[0][2]151i = m01(2);152break;153154case 1:155i = m02(1);156break;157158case 2:159i = m04(-2);160break;161162}163}164165int m00 (int arg) {166return arg++; // crstepreq009.checkedLines[0-2][0]167}168169int m01 (int arg) {170return m00(arg); // crstepreq009.checkedLines[0][1]171}172173int m02 (int arg) {174int j = m00(arg); return m00(arg); } // crstepreq009.checkedLines[1][1-2]175176int m03 (int arg) throws DummyException {177arg = m00(arg); if (arg < 0) { throw new DummyException(); }; // crstepreq009.checkedLines[2][1-2]178return arg++;179}180181int m04 (int arg) {182int j = 0;183try {184j = m03(arg) + 1;185} catch (DummyException e) {186crstepreq009a.display("DummyException was caught for testCase # " + testCase);187}188return j;189}190191class DummyException extends Exception {}192}193194195