Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/interrupt/interrupt001/interrupt001a.java
40955 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.interrupt.interrupt001;
25
26
import nsk.share.*;
27
import nsk.share.jdb.*;
28
29
import java.io.*;
30
import java.util.concurrent.Semaphore;
31
import java.util.concurrent.atomic.AtomicInteger;
32
33
/* This is debuggee aplication */
34
public class interrupt001a {
35
private class MyThread extends Thread {
36
final Object lock;
37
int ind;
38
String name;
39
40
public MyThread (Object l, int i, String n) {
41
lock = l;
42
ind = i;
43
name = n;
44
}
45
46
public void run() {
47
synchronized (lock) {
48
synchronized (waitnotify) {
49
threadRunning = true;
50
waitnotify.notify();
51
}
52
53
try {
54
flags[ind] = false;
55
while (!flags[ind]) {
56
lock.wait();
57
}
58
} catch (InterruptedException e) {
59
notInterrupted.decrementAndGet();
60
synchronized (waitnotify) {
61
waitnotify.notify();
62
}
63
}
64
}
65
}
66
}
67
68
public static void main(String args[]) {
69
interrupt001a _interrupt001a = new interrupt001a();
70
System.exit(interrupt001.JCK_STATUS_BASE + _interrupt001a.runIt(args, System.out));
71
}
72
73
static void breakHere () {}
74
75
static final String MYTHREAD = "MyThread";
76
static final int numThreads = 5; // number of threads
77
static volatile boolean allWorkersAreWaiting = false;
78
79
private final Object waitnotify = new Object();
80
private volatile boolean threadRunning;
81
private volatile boolean[] flags = new boolean[numThreads];
82
83
private JdbArgumentHandler argumentHandler;
84
private Log log;
85
86
public static final AtomicInteger notInterrupted = new AtomicInteger(numThreads);
87
88
public int runIt(String args[], PrintStream out) {
89
90
argumentHandler = new JdbArgumentHandler(args);
91
log = new Log(out, argumentHandler);
92
93
int i;
94
Thread[] holder = new Thread[numThreads];
95
Object[] locks = new Object[numThreads];
96
97
for (i = 0; i < numThreads ; i++) {
98
locks[i] = new Object();
99
holder[i] = new MyThread(locks[i], i, MYTHREAD + "-" + i);
100
}
101
102
synchronized (waitnotify) {
103
for (i = 0; i < numThreads ; i++) {
104
holder[i].start();
105
try {
106
threadRunning = false;
107
while (!threadRunning) {
108
waitnotify.wait();
109
}
110
} catch (InterruptedException e) {
111
log.complain("Main thread was interrupted while waiting for start of " + MYTHREAD + "-" + i);
112
return interrupt001.FAILED;
113
}
114
}
115
}
116
117
// allWorkersAreWaiting will be set to true by the debugger thread
118
// when it sees all of the worker treads are waiting.
119
do {
120
breakHere(); // a break to get thread ids and then to interrupt MyThreads.
121
} while (!allWorkersAreWaiting);
122
123
long waitTime = argumentHandler.getWaitTime() * 60 * 1000;
124
long startTime = System.currentTimeMillis();
125
while (notInterrupted.get() > 0 && System.currentTimeMillis() - startTime <= waitTime) {
126
synchronized (waitnotify) {
127
try {
128
waitnotify.wait(waitTime);
129
} catch (InterruptedException e) {
130
log.display("Main thread was interrupted while waiting");
131
}
132
}
133
}
134
for (i = 0; i < numThreads ; i++) {
135
if (holder[i].isAlive()) {
136
synchronized (locks[i]) {
137
flags[i] = true;
138
locks[i].notifyAll();
139
}
140
}
141
}
142
breakHere(); // a break to check if MyThreads were interrupted
143
144
log.display("Debuggee PASSED");
145
return interrupt001.PASSED;
146
}
147
}
148
149