Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/stepRequests/stepreq001t.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.EventRequestManager.stepRequests;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdi.*;282930/**31* This is a debuggee class creating several dummy user and32* daemon threads with own names.33*/34public class stepreq001t {35private static ArgumentHandler argHandler;3637public static void main(String args[]) {38System.exit(new stepreq001t().runThis(args));39}4041private int runThis(String args[]) {42argHandler = new ArgumentHandler(args);43IOPipe pipe = argHandler.createDebugeeIOPipe();44Thread thrs[] = new Thread[stepreq001.THRDS_NUM];45Object lockObj = new Object();46Object readyObj = new Object();47String cmd;4849// Create several dummy threads and give them new names50thrs[0] = Thread.currentThread();51try {52thrs[0].setName(stepreq001.DEBUGGEE_THRDS[0]);53} catch (SecurityException e) {54System.err.println("TEST FAILURE: setName: caught in debuggee "55+ e);56pipe.println("failed");57return stepreq001.JCK_STATUS_BASE +58stepreq001.FAILED;59}60// Get a monitor in order to prevent the threads from exiting61synchronized(lockObj) {62for (int i=1; i<stepreq001.THRDS_NUM; i++) {63thrs[i] = new stepreq001a(readyObj, lockObj,64stepreq001.DEBUGGEE_THRDS[i]);65thrs[i].setDaemon(stepreq001.DAEMON_THRDS[i]);66if (argHandler.verbose())67System.out.println("Debuggee: starting thread #"68+ i + " \"" + thrs[i].getName() + "\"");69synchronized(readyObj) {70thrs[i].start();71try {72readyObj.wait(); // wait for the thread's readiness73} catch (InterruptedException e) {74System.out.println("TEST FAILURE: Debuggee: waiting for the thread "75+ thrs[i].toString() + ": caught " + e);76pipe.println("failed");77return stepreq001.JCK_STATUS_BASE +78stepreq001.FAILED;79}80}81if (argHandler.verbose())82System.out.println("Debuggee: the thread #"83+ i + " \"" + thrs[i].getName() + "\" started");84}85// Now the debuggee is ready for testing86pipe.println(stepreq001.COMMAND_READY);87cmd = pipe.readln();88}8990// The debuggee exits91for (int i=1; i<stepreq001.THRDS_NUM ; i++) {92try {93thrs[i].join(argHandler.getWaitTime()*60000);94if (argHandler.verbose())95System.out.println("Debuggee: thread #"96+ i + " \"" + thrs[i].getName() + "\" done");97} catch (InterruptedException e) {98System.err.println("Debuggee: joining the thread #"99+ i + " \"" + thrs[i].getName() + "\": " + e);100}101}102if (!cmd.equals(stepreq001.COMMAND_QUIT)) {103System.err.println("TEST BUG: unknown debugger command: "104+ cmd);105return stepreq001.JCK_STATUS_BASE +106stepreq001.FAILED;107}108return stepreq001.JCK_STATUS_BASE +109stepreq001.PASSED;110}111112class stepreq001a extends Thread {113private Object readyObj;114private Object lockObj;115116stepreq001a(Object readyObj, Object obj,117String name) {118super(name);119this.readyObj = readyObj;120lockObj = obj;121}122123public void run() {124Thread thr = Thread.currentThread();125126synchronized(readyObj) {127readyObj.notify(); // notify the main thread128}129if (argHandler.verbose())130System.out.println("Debuggee's thread \""131+ thr.getName() + "\": going to be blocked");132synchronized(lockObj) {133if (argHandler.verbose()) {134Thread.currentThread();135System.out.println("Debuggee's thread \""136+ thr.getName() + "\": unblocked, exiting...");137}138return;139}140}141}142}143144145