Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetAllThreads/allthr001.java
40948 views
/*1* Copyright (c) 2003, 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.jvmti.GetAllThreads;2425import java.io.PrintStream;2627public class allthr001 {2829static {30try {31System.loadLibrary("allthr001");32} catch (UnsatisfiedLinkError ule) {33System.err.println("Could not load allthr001 library");34System.err.println("java.library.path:"35+ System.getProperty("java.library.path"));36throw ule;37}38}3940native static void setSysCnt();41native static void checkInfo(int thr_ind);42native static int getRes();4344public static Object lock1 = new Object();45public static Object lock2 = new Object();46public static int waitTime = 2;4748public static void main(String[] args) {49args = nsk.share.jvmti.JVMTITest.commonInit(args);5051System.exit(run(args, System.out) + 95/*STATUS_TEMP*/);52}5354public static int run(String args[], PrintStream out) {55if (args.length > 0) {56try {57int i = Integer.parseInt(args[0]);58waitTime = i;59} catch (NumberFormatException ex) {60out.println("# Wrong argument \"" + args[0]61+ "\", the default value is used");62}63}64out.println("# Waiting time = " + waitTime + " mins");6566setSysCnt();67checkInfo(0);6869ThreadGroup tg = new ThreadGroup("tg1");70allthr001a t_a = new allthr001a(tg, "thread1");71t_a.setDaemon(true);72checkInfo(1);7374synchronized (lock1) {75try {76t_a.start();77lock1.wait();78} catch (InterruptedException e) {79throw new Error("Unexpected " + e);80}81}82checkInfo(2);8384synchronized (lock2) {85lock2.notify();86}8788try {89t_a.join(waitTime * 60000);90} catch (InterruptedException e) {91throw new Error("Unexpected " + e);92}93checkInfo(3);9495checkInfo(4);96return getRes();97}98}99100class allthr001a extends Thread {101allthr001a(ThreadGroup tg, String name) {102super(tg, name);103}104105public void run() {106synchronized (allthr001.lock2) {107synchronized (allthr001.lock1) {108allthr001.lock1.notify();109}110try {111allthr001.lock2.wait();112} catch (InterruptedException e) {113throw new Error("Unexpected " + e);114}115}116}117}118119120