Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/ClassPrepareEvent/thread/thread001a.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.ClassPrepareEvent.thread;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdi.*;2829import java.io.*;3031// This class is the debugged application in the test3233class thread001a {34public static Object threadExitLock = new Object();3536public static void main(String args[]) {37thread001a _thread001a = new thread001a();38System.exit(thread001.JCK_STATUS_BASE + _thread001a.runIt(args, System.err));39}4041int runIt(String args[], PrintStream out) {42ArgumentHandler argHandler = new ArgumentHandler(args);43IOPipe pipe = argHandler.createDebugeeIOPipe();44final Log log = new Log(out, argHandler);4546// final long threadStartTimeout = 10 * 100; // milliseconds4748// notify debugger that debugge started49pipe.println(thread001.COMMAND_READY);5051// wait for command RUN from debugger to create another thread52String command = pipe.readln();53if (!command.equals(thread001.COMMAND_RUN)) {54log.complain("TEST BUG: Debugee: unknown command: " + command);55return thread001.FAILED;56}5758class InnerThread extends Thread {59public volatile boolean started = false;60public volatile Object startedNotification = new Object();6162InnerThread (String name) {63super(name);64}6566public void run() {67ClassForInnerThread a = new ClassForInnerThread();6869// start outer thread from inner thread and wait tor it started70OuterThread outerThread = new OuterThread("outerThread");71synchronized (outerThread.startedNotification) {72outerThread.start();73try {74outerThread.startedNotification.wait();75} catch (InterruptedException e) {76log.complain("Unexpected InterruptedException while waiting for outer thread started: " + e);77return;78}79}8081// check if outer thread actually started82if (!outerThread.started) {83log.complain("Outer thread NOT started from inner thread in debuggee: "84+ outerThread.getName());85outerThread.interrupt();86return;87}8889// notify main thread that both threads started90synchronized (startedNotification) {91started = true;92startedNotification.notify();93}9495// wait for main thread releases mionitor to permint this thread to finish96synchronized (thread001a.threadExitLock) {97}9899}100}101102// prevent further started thread from exit103synchronized (threadExitLock) {104105// start an inner thread from main thread and wait for it started106InnerThread innerThread = new InnerThread("innerThread");107synchronized (innerThread.startedNotification) {108innerThread.start();109try {110innerThread.startedNotification.wait();111} catch (InterruptedException e) {112log.complain("Unexpected InterruptedException while waiting for inner thread started: " + e);113return thread001.FAILED;114}115}116117// check if threads really started and notify debugger118if (!innerThread.started) {119log.complain("Inner thread NOT started from main thread in debuggee: "120+ innerThread.getName());121innerThread.interrupt();122pipe.println(thread001.COMMAND_ERROR);123} else {124log.display("All threads started in debuggee");125pipe.println(thread001.COMMAND_DONE);126}127128// wait for command QUIT from debugger to release started threads and exit129command = pipe.readln();130if (!command.equals(thread001.COMMAND_QUIT)) {131log.complain("TEST BUG: Debugee: unknown command: " + command);132return thread001.FAILED;133}134135// release monitor to permit started threads to finish136}137138return thread001.PASSED;139}140}141142class OuterThread extends Thread {143public volatile boolean started = false;144public volatile Object startedNotification = new Object();145146OuterThread (String name) {147super(name);148}149150public void run() {151ClassForOuterThread a = new ClassForOuterThread();152153// notify main thread that this thread started154synchronized (startedNotification) {155started = true;156startedNotification.notify();157}158159// wait for main thread releases mionitor to permint this thread to finish160synchronized (thread001a.threadExitLock) {161}162}163}164165class ClassForInnerThread {}166167class ClassForOuterThread {}168169170