Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/resume/resume002/resume002a.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.resume.resume002;
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 resume002a {
34
public static void main(String args[]) {
35
resume002a _resume002a = new resume002a();
36
System.exit(resume002.JCK_STATUS_BASE + _resume002a.runIt(args, System.out));
37
}
38
39
static void lastBreak () {}
40
static int numThreads = 5; // number of threads
41
static Thread holder [] = new Thread[numThreads];
42
43
static Object waitnotify = new Object();
44
45
public int runIt(String args[], PrintStream out) {
46
JdbArgumentHandler argumentHandler = new JdbArgumentHandler(args);
47
Log log = new Log(out, argumentHandler);
48
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, "MyThread#" + i);
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(resume002.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 resume002.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
String name;
106
107
MyThread (Lock l, String name) {
108
this.lock = l;
109
this.name = name;
110
}
111
112
public void run() {
113
synchronized (resume002a.waitnotify) {
114
resume002a.waitnotify.notifyAll();
115
}
116
try {
117
lock.setLock();
118
} catch(Exception e) {
119
System.err.println("TEST ERROR: Caught unexpected Exception while waiting in MyThread: " +
120
e.getMessage());
121
System.exit(resume002.FAILED);
122
}
123
lock.releaseLock();
124
}
125
}
126
127