Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/wherei/wherei001/wherei001a.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.wherei.wherei001;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdb.*;2829import java.io.*;3031/* This is debuggee aplication */32public class wherei001a {33public static void main(String args[]) {34wherei001a _wherei001a = new wherei001a();35System.exit(wherei001.JCK_STATUS_BASE + _wherei001a.runIt(args, System.out));36}3738static void lastBreak () {}3940static int numThreads = 5; // number of threads. one lock per thread.41static Object lock = new Object();42static Object waitnotify = new Object();4344static JdbArgumentHandler argumentHandler;45static Log log;4647public int runIt(String args[], PrintStream out) {4849argumentHandler = new JdbArgumentHandler(args);50log = new Log(out, argumentHandler);5152int i;53Thread holder [] = new Thread[numThreads];54Lock locks[] = new Lock[numThreads];5556for (i = 0; i < numThreads ; i++) {57locks[i] = new Lock();58holder[i] = new MyThread(locks[i],"MyThread-" + i);59}6061// lock monitor to prevent threads from finishing after they started62synchronized (lock) {63synchronized (waitnotify) {64for (i = 0; i < numThreads ; i++) {65holder[i].start();66try {67waitnotify.wait();68} catch ( Exception e ) {69log.complain("TEST ERROR: caught Exception while waiting: " + e);70e.printStackTrace();71}72}73}74lastBreak();75}7677log.display("Debuggee PASSED");78return wherei001.PASSED;79}80}818283class MyThread extends Thread {84Lock lock;85String name;86// Concatenate strings in advance to avoid lambda calculations later87final String ThreadFinished = "Thread finished: " + this.name;8889public MyThread (Lock l, String n) {90this.lock = l;91name = n;92}9394public void run() {95int square = func1(100);96wherei001a.log.display(name + " returns " + square);97lock.releaseLock();98}99100public int func1(int i) {101char x1 = 'x';102String s1 = "hello world";103return func2(i);104}105106public int func2(int i) {107char x2 = 'x';108String s2 = "hello world";109return func3(i);110}111112public int func3(int i) {113char x3 = 'x';114String s3 = "hello world";115return func4(i);116}117118public int func4(int i) {119char x4 = 'x';120String s4 = "hello world";121return func5(i);122}123124public int func5(int i) {125char x5 = 'x';126String s5 = "hello world";127synchronized (wherei001a.waitnotify) {128wherei001a.waitnotify.notify();129}130// prevent thread for early finish131synchronized (wherei001a.lock) {132wherei001a.log.display(ThreadFinished);133}134return i*i;135}136}137138class Lock {139boolean lockSet;140141synchronized void setLock() throws InterruptedException {142while (lockSet == true ) {143wait();144}145lockSet = true;146}147148synchronized void releaseLock() {149if (lockSet == true) {150lockSet = false;151notify();152}153}154}155156157