Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/untrace/untrace001/untrace001a.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.untrace.untrace001;
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 untrace001a {
34
35
public static void main(String args[]) {
36
untrace001a _untrace001a = new untrace001a();
37
System.exit(untrace001.JCK_STATUS_BASE + _untrace001a.runIt(args, System.out));
38
}
39
40
static void breakHere() {}
41
42
static final String MYTHREAD = "MyThread";
43
static final int numThreads = 1; // number of threads.
44
45
static JdbArgumentHandler argumentHandler;
46
static Log log;
47
48
static Object mainThreadLock0 = new Object();
49
static Object mainThreadLock1 = new Object();
50
static volatile boolean mainThreadRunning;
51
static volatile boolean[] flags = new boolean[numThreads];
52
53
public int runIt(String args[], PrintStream out) {
54
55
argumentHandler = new JdbArgumentHandler(args);
56
log = new Log(out, argumentHandler);
57
58
int i;
59
Thread holder [] = new Thread[numThreads];
60
Object[] locks = new Object[numThreads];
61
62
for (i = 0; i < numThreads ; i++) {
63
locks[i] = new Object();
64
holder[i] = new MyThread(locks[i], i, MYTHREAD + "-" + i);
65
}
66
67
synchronized (mainThreadLock0) {
68
synchronized (mainThreadLock1) {
69
for (i = 0; i < numThreads ; i++) {
70
holder[i].start();
71
try {
72
mainThreadRunning = false;
73
while (!mainThreadRunning) {
74
mainThreadLock1.wait();
75
}
76
} catch (InterruptedException e) {
77
log.complain("Main thread was interrupted while waiting for start of " + MYTHREAD + "-" + i);
78
return untrace001.FAILED;
79
}
80
81
synchronized (locks[i]) { // holder[i] must wait on its lock[i] at this moment.
82
log.display("Thread " + MYTHREAD + "-" + i + " is waiting");
83
}
84
}
85
}
86
breakHere(); // a break to get thread ids and then to turn on tracing.
87
88
// waits on all MyThreads completion
89
for (i = 0; i < numThreads ; i++) {
90
synchronized (locks[i]) {
91
flags[i] = true;
92
locks[i].notifyAll();
93
}
94
95
try {
96
mainThreadRunning = false;
97
while (!mainThreadRunning) {
98
mainThreadLock0.wait();
99
}
100
} catch (InterruptedException e) {
101
log.complain("Main thread was interrupted while waiting for " + MYTHREAD + "-" + i);
102
return untrace001.FAILED;
103
}
104
105
breakHere(); // a break to turn off tracing.
106
107
synchronized (locks[i]) {
108
flags[i] = true;
109
locks[i].notifyAll();
110
}
111
112
if (holder[i].isAlive() && !holder[i].interrupted()) {
113
try {
114
holder[i].join();
115
} catch (InterruptedException e) {
116
log.complain("Main thread was interrupted while waiting for finish of " + MYTHREAD + "-" + i);
117
return untrace001.FAILED;
118
}
119
}
120
}
121
}
122
123
log.display("Debuggee PASSED");
124
return untrace001.PASSED;
125
}
126
}
127
128
129
class MyThread extends Thread {
130
Object lock;
131
int ind;
132
String name;
133
134
public MyThread (Object l, int i, String n) {
135
lock = l;
136
ind = i;
137
name = n;
138
}
139
140
public void run() {
141
// Concatenate strings in advance to avoid lambda calculations later
142
final String ThreadFinished = "Thread finished: " + this.name;
143
final String ThreadInterrupted = "Thread was interrupted: " + this.name;
144
untrace001a.log.display("Thread started: " + this.name);
145
146
synchronized (lock) {
147
synchronized (untrace001a.mainThreadLock1) {
148
untrace001a.mainThreadRunning = true;
149
untrace001a.mainThreadLock1.notify();
150
}
151
152
try {
153
untrace001a.flags[ind] = false;
154
while (!untrace001a.flags[ind]) {
155
lock.wait();
156
}
157
int square = func1(2);
158
159
synchronized (untrace001a.mainThreadLock0) {
160
untrace001a.mainThreadRunning = true;
161
untrace001a.mainThreadLock0.notify();
162
}
163
164
untrace001a.flags[ind] = false;
165
while (!untrace001a.flags[ind]) {
166
lock.wait();
167
}
168
square = func1(3);
169
170
untrace001a.log.display(ThreadFinished);
171
} catch (InterruptedException e) {
172
untrace001a.log.display(ThreadInterrupted);
173
}
174
}
175
176
untrace001a.log.display(ThreadFinished);
177
}
178
179
public int func1(int i) {
180
return func2(i);
181
}
182
183
public int func2(int i) {
184
return func3(i);
185
}
186
187
public int func3(int i) {
188
return i*i;
189
}
190
}
191
192