Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventSet/resume/resume009a.java
41161 views
/*1* Copyright (c) 2001, 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.EventSet.resume;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdi.*;2829/**30* This class is used as debuggee application for the resume009 JDI test.31*/3233public class resume009a {3435//----------------------------------------------------- template section3637static final int PASSED = 0;38static final int FAILED = 2;39static final int PASS_BASE = 95;4041static ArgumentHandler argHandler;42static Log log;4344//-------------------------------------------------- log procedures4546private static void log1(String message) {47log.display("**> debuggee: " + message);48}4950private static void logErr(String message) {51log.complain("**> debuggee: " + message);52}5354//====================================================== test program5556static Threadresume009a thread0 = null;57static Threadresume009a thread1 = null;58static Threadresume009a thread2 = null;5960//------------------------------------------------------ common section6162static int exitCode = PASSED;6364static int testCase = -1;65static int instruction = 1;66static int end = 0;67// static int quit = 0;68// static int continue = 2;69static int maxInstr = 1; // 2;7071static int lineForComm = 2;7273private static void methodForCommunication() {74int i1 = instruction;75int i2 = i1;76int i3 = i2;77}78//---------------------------------------------------- main method7980public static void main (String argv[]) {8182argHandler = new ArgumentHandler(argv);83log = argHandler.createDebugeeLog();8485log1("debuggee started!");8687label0:88for (int i = 0; ; i++) {8990if (instruction > maxInstr) {91logErr("ERROR: unexpected instruction: " + instruction);92exitCode = FAILED;93break ;94}9596switch (i) {9798//------------------------------------------------------ section tested99100case 0:101thread0 = new Threadresume009a("thread0");102methodForCommunication();103104threadRun(thread0);105106thread1 = new Threadresume009a("thread1");107// Wait for debugger to complete the first test case108// before advancing to the first breakpoint109waitForTestCase(0);110methodForCommunication();111break;112113case 1:114threadRun(thread1);115116thread2 = new Threadresume009a("thread2");117methodForCommunication();118break;119120case 2:121threadRun(thread2);122123//------------------------------------------------- standard end section124125default:126instruction = end;127methodForCommunication();128break label0;129}130}131132log1("debuggee exits");133System.exit(exitCode + PASS_BASE);134}135136static Object waitnotifyObj = new Object();137138static int threadRun(Thread t) {139synchronized (waitnotifyObj) {140t.start();141try {142waitnotifyObj.wait();143} catch ( Exception e) {144exitCode = FAILED;145logErr("Exception in threadRun : " + e );146return FAILED;147}148}149try {150t.join();151} catch ( InterruptedException e ) {152exitCode = FAILED;153logErr("InterruptedException in threadRun : " + e );154return FAILED;155}156return PASSED;157}158// Synchronize with debugger progression.159static void waitForTestCase(int t) {160while (testCase < t) {161try {162Thread.sleep(100);163} catch (InterruptedException e) {164// ignored165}166}167}168169static class Threadresume009a extends Thread {170171String tName = null;172173public Threadresume009a(String threadName) {174super(threadName);175tName = threadName;176}177178public void run() {179log1(" 'run': enter :: threadName == " + tName);180synchronized (waitnotifyObj) {181waitnotifyObj.notify();182}183log1(" 'run': exit :: threadName == " + tName);184return;185}186}187188}189190191