Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/SuspendCount/suspendcnt001a.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.jdwp.ThreadReference.SuspendCount;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdwp.*;2829import java.io.*;3031/**32* This class represents debuggee part in the test.33*/34public class suspendcnt001a {3536// name for the tested thread37public static final String THREAD_NAME = "TestedThreadName";38public static final String FIELD_NAME = "thread";3940// notification object to notify debuggee that thread started41private static Object threadStarted = new Object();42// lock object to prevent thread from exit43private static Object threadLock = new Object();4445// scaffold objects46private static volatile ArgumentHandler argumentHandler = null;47private static volatile Log log = null;4849public static void main(String args[]) {50suspendcnt001a _suspendcnt001a = new suspendcnt001a();51System.exit(suspendcnt001.JCK_STATUS_BASE + _suspendcnt001a.runIt(args, System.err));52}5354public int runIt(String args[], PrintStream out) {55//make log for debugee messages56argumentHandler = new ArgumentHandler(args);57log = new Log(out, argumentHandler);5859// make communication pipe to debugger60log.display("Creating pipe");61IOPipe pipe = argumentHandler.createDebugeeIOPipe(log);6263// lock the object to prevent thread from exit64synchronized (threadLock) {6566// load tested class and create tested thread67log.display("Creating object of tested class");68TestedClass.thread = new TestedClass(THREAD_NAME);6970// start the thread and wait for notification from it71synchronized (threadStarted) {72TestedClass.thread.start();73try {74threadStarted.wait();75// send debugger signal READY76log.display("Sending signal to debugger: " + suspendcnt001.READY);77pipe.println(suspendcnt001.READY);78} catch (InterruptedException e) {79log.complain("Interruption while waiting for thread started: " + e);80pipe.println(suspendcnt001.ERROR);81}82}8384// wait for signal QUIT from debugeer85log.display("Waiting for signal from debugger: " + suspendcnt001.QUIT);86String signal = pipe.readln();87log.display("Received signal from debugger: " + signal);8889// check received signal90if (signal == null || !signal.equals(suspendcnt001.QUIT)) {91log.complain("Unexpected communication signal from debugee: " + signal92+ " (expected: " + suspendcnt001.QUIT + ")");93log.display("Debugee FAILED");94return suspendcnt001.FAILED;95}9697// allow started thread to exit98}99100// exit debugee101log.display("Debugee PASSED");102return suspendcnt001.PASSED;103}104105// tested thread class106public static class TestedClass extends Thread {107108// field with the tested Thread value109public static volatile TestedClass thread = null;110111TestedClass(String name) {112super(name);113}114115public void run() {116log.display("Tested thread started");117118// notify debuggee that thread really started119synchronized (threadStarted) {120threadStarted.notifyAll();121}122123// wait for lock object released124synchronized (threadLock) {125log.display("Tested thread finished");126}127}128}129130}131132133