Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Stop/stop001a.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.Stop;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 stop001a {3536// name for the tested thread37public static final String THREAD_NAME = "TestedThreadName";38public static final String THREAD_FIELD_NAME = "thread";39public static final String THROWABLE_FIELD_NAME = "throwable";4041// frames count for tested thread in recursive method invokation42public static final int FRAMES_COUNT = 10;4344// notification object to notify debuggee that thread is started45private static Object threadStarting = new Object();46// object which thread will wait for before being interruted47private static Object threadWaiting = new Object();4849// scaffold objects50private static volatile ArgumentHandler argumentHandler = null;51private static volatile Log log = null;5253public static void main(String args[]) {54stop001a _stop001a = new stop001a();55System.exit(stop001.JCK_STATUS_BASE + _stop001a.runIt(args, System.err));56}5758public int runIt(String args[], PrintStream out) {59//make log for debugee messages60argumentHandler = new ArgumentHandler(args);61log = new Log(out, argumentHandler);62long timeout = argumentHandler.getWaitTime() * 60 * 1000; // milliseconds6364// make communication pipe to debugger65log.display("Creating pipe");66IOPipe pipe = argumentHandler.createDebugeeIOPipe(log);6768// load tested class and create tested thread69log.display("Creating object of tested class");70TestedClass.thread = new TestedClass(THREAD_NAME);7172// start the thread and wait for notification from it73synchronized (threadStarting) {74TestedClass.thread.start();75try {76threadStarting.wait();77} catch (InterruptedException e) {78log.complain("Interruption while waiting for thread started:\n\t" + e);79pipe.println(stop001.ERROR);80log.display("Debugee FAILED");81return stop001.FAILED;82}8384// ensure that tested thread is waiting for object85synchronized (threadWaiting) {86// send debugger signal READY87log.display("Sending signal to debugger: " + stop001.READY);88pipe.println(stop001.READY);89}90}9192// wait for signal QUIT from debugeer93log.display("Waiting for signal from debugger: " + stop001.RUN);94String signal = pipe.readln();95log.display("Received signal from debugger: " + signal);9697// check received signal98if (signal == null || !signal.equals(stop001.RUN)) {99log.complain("Unexpected communication signal from debugee: " + signal100+ " (expected: " + stop001.RUN + ")");101log.display("Debugee FAILED");102return stop001.FAILED;103}104105// wait for thread finished in a waittime interval106log.display("Waiting for tested thread finished for timeout: " + timeout);107try {108TestedClass.thread.join(timeout);109} catch (InterruptedException e) {110log.complain("Interruption while waiting for tested thread finished:\n\t" + e);111pipe.println(stop001.ERROR);112log.display("Debugee FAILED");113return stop001.FAILED;114}115116// test if thread was interrupted by debugger117if (TestedClass.thread.isAlive()) {118log.display("Sending signal to debugger: " + stop001.NOT_STOPPED);119pipe.println(stop001.NOT_STOPPED);120// interrupt thread to allow it to finish121TestedClass.thread.interrupt();122} else {123log.display("Sending signal to debugger: " + stop001.STOPPED);124pipe.println(stop001.STOPPED);125}126127// wait for signal QUIT from debugeer128log.display("Waiting for signal from debugger: " + stop001.QUIT);129signal = pipe.readln();130log.display("Received signal from debugger: " + signal);131132// check received signal133if (signal == null || !signal.equals(stop001.QUIT)) {134log.complain("Unexpected communication signal from debugee: " + signal135+ " (expected: " + stop001.QUIT + ")");136log.display("Debugee FAILED");137return stop001.FAILED;138}139140// exit debugee141log.display("Debugee PASSED");142return stop001.PASSED;143}144145// tested thread class146public static class TestedClass extends Thread {147148// field with the tested Thread value149public static volatile TestedClass thread = null;150151// field with the tested Throwable value152public static volatile Throwable throwable = new Throwable("Tested throwable");153154TestedClass(String name) {155super(name);156}157158// start the thread and recursive invoke makeFrames()159public void run() {160log.display("Tested thread started");161162synchronized (threadWaiting) {163164// notify debuggee that thread started165synchronized (threadStarting) {166threadStarting.notifyAll();167}168169// wait infinitely for notification object170try {171threadWaiting.wait();172log.complain("Tested thread NOT interrupted");173} catch (InterruptedException e) {174log.display("Tested thread interrupted");175}176}177178log.display("Tested thread finished");179}180181}182183}184185186