Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/createStepRequest/crstepreq004a.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 crstepreq004a {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;49private static IOPipe pipe;5051//------------------------------------------------------ mutable common fields5253//------------------------------------------------------ test specific fields5455static Object lockObj = new Object();56static Object lockObj1 = new Object();57private static volatile boolean isFirstThreadReady = false;58private static volatile boolean isSecondThreadReady = false;5960//------------------------------------------------------ mutable common method6162public static void main (String argv[]) {6364argHandler = new ArgumentHandler(argv);65log = new Log(System.out, argHandler);66pipe = argHandler.createDebugeeIOPipe(log);6768display("debuggee started!");6970label0:71for (int testCase = 0; instruction != quit; testCase++) {7273switch (testCase) {74case 0:75case 1:76case 2:77runTestCase(testCase);78break;79default:80instruction = quit;81break;82}8384if (instruction == quit)85break;86}8788display("debuggee exits");89System.exit(PASSED + PASS_BASE);90}9192//--------------------------------------------------------- test specific methodss9394private static void runTestCase(int testCaseId) {95isFirstThreadReady = false;96isSecondThreadReady = false;97Thread thread1 = new Thread1crstepreq004a("thread1");98Thread thread2 = new Thread2crstepreq004a("thread2");99synchronized (lockObj) {100thread1.start();101while (!isFirstThreadReady) {102shortSleep();103}104thread2.start();105while (!isSecondThreadReady) {106shortSleep();107}108109display("call methodForCommunication() #" + testCaseId);110methodForCommunication();111}112threadJoin(thread1, "1");113threadJoin(thread2, "2");114}115116static void threadJoin (Thread t, String number) {117try {118t.join();119} catch ( InterruptedException e ) {120exitCode = FAILED;121complain("Case #" + number + ": caught unexpected InterruptedException while waiting for thread finish" );122}123}124125//---------------------------------------------------------- immutable common methods126127static void shortSleep() {128try {129Thread.currentThread().sleep(10);130} catch (InterruptedException e) {131e.printStackTrace();132}133}134135static void display(String msg) {136log.display("debuggee > " + msg);137}138139static void complain(String msg) {140log.complain("debuggee FAILURE > " + msg);141}142143private static void methodForCommunication() {144int i = instruction;145int curInstruction = i; // crstepreq004.lineForBreakInThread146}147148static void lockAndNotify1() {149synchronized(lockObj1) {150isFirstThreadReady = true;151synchronized(lockObj) {152}153}154}155156static void lockAndNotify2() {157isSecondThreadReady = true;158synchronized(lockObj1) { // thread is waiting here the lock when step request is created.159int i = 1; // This is line of step event for STEP_INTO and STEP_OVER -- crstepreq004.checkedLines[0-1]160} // crstepreq004.checkedLinesAlt[0-1]161}162}163164//--------------------------------------------------------- test specific classes165166/**167* First thread which owns and locks the crstepreq004a.lockObj1 monitor .168*/169class Thread1crstepreq004a extends Thread {170public Thread1crstepreq004a (String name) {171super(name);172}173174public void run() {175crstepreq004a.display("enter thread " + getName());176crstepreq004a.lockAndNotify1();177crstepreq004a.display("exit thread " + getName());178}179}180181/**182* Second thread which who owns the crstepreq004a.lockObj1 monitor .183*/184class Thread2crstepreq004a extends Thread {185public Thread2crstepreq004a (String name) {186super(name);187}188189public void run() {190crstepreq004a.display("enter thread " + getName());191crstepreq004a.lockAndNotify2();192crstepreq004a.display("exit thread " + getName()); // This is line of step event for STEP_OUT -- crstepreq004.checkedLines[2] checkedLinesAlt[2].193}194}195196197