Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/where/where006/where006a.java
40951 views
/*1* Copyright (c) 2002, 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.jdb.where.where006;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdb.*;2829import java.io.*;3031/* This is debuggee aplication */32public class where006a {33public static void main(String args[]) {34where006a _where006a = new where006a();35System.exit(where006.JCK_STATUS_BASE + _where006a.runIt(args, System.out));36}3738static void lastBreak () {}3940static int numThreads = 5; // number of threads. one lock per thread.4142static Object lock = new Object();43static Object waitnotify = new Object();4445public int runIt(String args[], PrintStream out) {46JdbArgumentHandler argumentHandler = new JdbArgumentHandler(args);47Log log = new Log(out, argumentHandler);4849Thread holder [] = new Thread[numThreads];50Lock locks[] = new Lock[numThreads];5152for (int i = 0; i < numThreads ; i++) {53locks[i] = new Lock();54holder[i] = new MyThread(locks[i],"MyThread-" + i);55}5657// lock monitor to prevent threads from finishing after they started58synchronized (lock) {59synchronized (waitnotify) {60for (int i = 0; i < numThreads ; i++) {61holder[i].start();62try {63waitnotify.wait();64} catch ( Exception e ) {65System.err.println("TEST ERROR: caught Exception while waiting: " + e);66e.printStackTrace();67}68}69}70lastBreak(); // dummy breakpoint71}7273for (int i = 0; i < numThreads ; i++) {74if (holder[i].isAlive()) {75try {76holder[i].join(argumentHandler.getWaitTime() * 60000);77} catch (InterruptedException e) {78throw new Failure("Unexpected InterruptedException catched while waiting for join of: " + holder[i]);79}80}81}8283log.display("Debuggee PASSED");84return where006.PASSED;85}8687}8889class Lock {90boolean lockSet;9192synchronized void setLock() throws InterruptedException {93while (lockSet == true )94wait();95lockSet = true;96}9798synchronized void releaseLock() {99if (lockSet == true) {100lockSet = false;101notify();102}103}104}105106class MyThread extends Thread {107Lock lock;108String name;109MyThread(Lock l, String n) {this.lock = l; name = n;}110111public void run() {112// Concatenate strings in advance to avoid lambda calculations later113final String ThreadFinished = "Thread finished: " + this.name;114int square = func1(10);115lock.releaseLock();116System.out.println(ThreadFinished);117}118119public int func1(int i) {120return func2(i);121}122123public int func2(int i) {124return func3(i);125}126127public int func3(int i) {128return func4(i);129}130131public int func4(int i) {132return func5(i);133}134135public int func5(int i) {136synchronized (where006a.waitnotify) {137where006a.waitnotify.notify();138}139// prevent thread for early finish140synchronized (where006a.lock) {}141return i*i;142}143}144145146