Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventSet/resume/resume008a.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 resume008 JDI test.31*/3233public class resume008a {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 Threadresume008a thread0 = null;57static Threadresume008a thread1 = null;58static Threadresume008a 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;7273// Debugger sets a breakpoint here to track debuggee74private static void methodForCommunication() {75int i1 = instruction;76int i2 = i1;77int i3 = i2;78}79//---------------------------------------------------- main method8081public static void main (String argv[]) {8283argHandler = new ArgumentHandler(argv);84log = argHandler.createDebugeeLog();8586log1("debuggee started!");8788label0:89for (int i = 0; ; i++) {90if (instruction > maxInstr) {91logErr("ERROR: unexpected instruction: " + instruction);92exitCode = FAILED;93break ;94}95switch (i) {96//------------------------------------------------------ section tested97case 0:98thread0 = new Threadresume008a("thread0");99methodForCommunication();100threadStart(thread0);101thread1 = new Threadresume008a("thread1");102// Wait for debugger to complete the first test case103// before advancing to the first breakpoint104waitForTestCase(0);105methodForCommunication();106break;107case 1:108threadStart(thread1);109thread2 = new Threadresume008a("thread2");110methodForCommunication();111break;112case 2:113threadStart(thread2);114//------------------------------------------------- standard end section115default:116instruction = end;117methodForCommunication();118break label0;119}120}121log1("debuggee exits");122System.exit(exitCode + PASS_BASE);123}124125static Object waitnotifyObj = new Object();126127static int threadStart(Thread t) {128synchronized (waitnotifyObj) {129t.start();130try {131waitnotifyObj.wait();132} catch ( Exception e) {133exitCode = FAILED;134logErr(" Exception : " + e );135return FAILED;136}137}138return PASSED;139}140// Synchronize with debugger progression.141static void waitForTestCase(int t) {142while (testCase < t) {143try {144Thread.sleep(100);145} catch (InterruptedException e) {146// ignored147}148}149}150static class Threadresume008a extends Thread {151String tName = null;152public Threadresume008a(String threadName) {153super(threadName);154tName = threadName;155}156public void run() {157log1(" 'run': enter :: threadName == " + tName);158synchronized (waitnotifyObj) {159waitnotifyObj.notify();160}161log1(" 'run': exit :: threadName == " + tName);162return;163}164}165}166167168