Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/threads/threads002/threads002a.java
40951 views
1
/*
2
* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
package nsk.jdb.threads.threads002;
25
26
import nsk.share.*;
27
import nsk.share.jpda.*;
28
import nsk.share.jdb.*;
29
30
import java.io.*;
31
32
/* This is debuggee aplication */
33
public class threads002a {
34
public static void main(String args[]) {
35
threads002a _threads002a = new threads002a();
36
System.exit(threads002.JCK_STATUS_BASE + _threads002a.runIt(args, System.out));
37
}
38
39
static void lastBreak () {}
40
41
static int numThreads = 5; // number of threads
42
static Object waitnotify = new Object();
43
44
public int runIt(String args[], PrintStream out) {
45
JdbArgumentHandler argumentHandler = new JdbArgumentHandler(args);
46
Log log = new Log(out, argumentHandler);
47
48
Thread holder [] = new Thread[numThreads];
49
Lock lock = new Lock();
50
51
try {
52
lock.setLock();
53
for (int i = 0; i < numThreads ; i++) {
54
holder[i] = new MyThread(lock);
55
synchronized (waitnotify) {
56
holder[i].start();
57
waitnotify.wait();
58
}
59
}
60
} catch (Exception e) {
61
System.err.println("TEST ERROR: Caught unexpected Exception while waiting in main thread: " +
62
e.getMessage());
63
System.exit(threads002.FAILED);
64
}
65
66
lastBreak(); // When jdb stops here, there should be 5 running MyThreads.
67
lock.releaseLock();
68
69
for (int i = 0; i < numThreads ; i++) {
70
if (holder[i].isAlive()) {
71
try {
72
holder[i].join(argumentHandler.getWaitTime() * 60000);
73
} catch (InterruptedException e) {
74
throw new Failure("Unexpected InterruptedException catched while waiting for join of: " + holder[i]);
75
}
76
}
77
}
78
79
log.display("Debuggee PASSED");
80
return threads002.PASSED;
81
}
82
83
}
84
85
class Lock {
86
boolean lockSet;
87
88
synchronized void setLock() throws InterruptedException {
89
while (lockSet == true)
90
wait();
91
lockSet = true;
92
}
93
94
synchronized void releaseLock() {
95
if (lockSet == true) {
96
lockSet = false;
97
notify();
98
}
99
}
100
}
101
102
class MyThread extends Thread {
103
104
Lock lock;
105
MyThread (Lock l) {
106
this.lock = l;
107
}
108
109
public void run() {
110
synchronized (threads002a.waitnotify) {
111
threads002a.waitnotify.notifyAll();
112
}
113
try {
114
lock.setLock();
115
} catch(Exception e) {
116
System.err.println("TEST ERROR: Caught unexpected Exception while waiting in MyThread: " +
117
e.getMessage());
118
System.exit(threads002.FAILED);
119
}
120
lock.releaseLock();
121
}
122
}
123
124