Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/Event/request/request001a.java
41161 views
1
/*
2
* Copyright (c) 2001, 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.jdi.Event.request;
25
26
import nsk.share.*;
27
import nsk.share.jdi.*;
28
29
/**
30
* This class is used as debuggee application for the request001 JDI test.
31
*/
32
33
public class request001a {
34
35
//----------------------------------------------------- templete section
36
37
static final int PASSED = 0;
38
static final int FAILED = 2;
39
static final int PASS_BASE = 95;
40
41
static ArgumentHandler argHandler;
42
static Log log;
43
44
//-------------------------------------------------- log procedures
45
46
private static void log1(String message) {
47
log.display("**> debuggee: " + message);
48
}
49
50
private static void logErr(String message) {
51
log.complain("**> debuggee: " + message);
52
}
53
54
//====================================================== test program
55
56
static TestClass tcObject = new TestClass();
57
58
static String threadNames[] = {
59
"awThread", "mwThread", "bpThread", "excThread",
60
"menThread", "mexThread", "stThread"
61
};
62
63
static int threadsN = threadNames.length;
64
65
static Thread threads[] = new Thread[threadsN];
66
67
static Thread thread2 = null;
68
69
//------------------------------------------------------ common section
70
71
static int exitCode = PASSED;
72
73
static int instruction = 1;
74
static int end = 0;
75
76
static int maxInstr = 1; // 2;
77
78
static int lineForComm = 2;
79
80
private static void methodForCommunication() {
81
int i1 = instruction;
82
int i2 = i1;
83
int i3 = i2;
84
}
85
//---------------------------------------------------- main method
86
87
public static void main (String argv[]) {
88
89
argHandler = new ArgumentHandler(argv);
90
log = argHandler.createDebugeeLog();
91
92
log1("debuggee started!");
93
94
95
label0:
96
for (int i = 0; ; i++) {
97
98
if (instruction > maxInstr) {
99
logErr("ERROR: unexpected instruction: " + instruction);
100
exitCode = FAILED;
101
break ;
102
}
103
104
switch (i) {
105
106
//------------------------------------------------------ section tested
107
108
case 0:
109
thread2 = new Thread3request001a("thread2");
110
threadStart(thread2);
111
try {
112
// we should wait here for thread2 completion (see 6671428)
113
thread2.join();
114
} catch (InterruptedException e) {
115
logErr("ERROR: unexpected exception: " + e);
116
exitCode = FAILED;
117
break ;
118
}
119
120
for (int n1 = 0; n1 < threadsN; n1++) {
121
if (n1 < threadsN-1)
122
threads[n1] = new Thread1request001a(threadNames[n1]);
123
else
124
threads[n1] = new Thread2request001a(threadNames[n1]);
125
}
126
log1(" threads has been created");
127
128
synchronized (lockingObject2) {
129
log1(" loop: threadStart(threads[n2])");
130
for (int n2 = 0; n2 < threadsN; n2++)
131
if ( threadStart(threads[n2]) != PASSED )
132
break label0;
133
134
log1(" methodForCommunication();");
135
methodForCommunication();
136
}
137
138
for (int n2 = 0; n2 < threadsN; n2++) {
139
synchronized (locks[n2]) {
140
log1(" synchronized (locks[n2]) : n2 == " + n2);
141
}
142
}
143
144
methodForCommunication();
145
break ;
146
147
//------------------------------------------------- standard end section
148
149
default:
150
instruction = end;
151
methodForCommunication();
152
break label0;
153
}
154
}
155
156
System.exit(exitCode + PASS_BASE);
157
}
158
159
static Object waitnotifyObj = new Object();
160
static Object lockingObject = new Object();
161
162
static int threadStart(Thread t) {
163
synchronized (waitnotifyObj) {
164
t.start();
165
try {
166
waitnotifyObj.wait();
167
} catch ( Exception e) {
168
exitCode = FAILED;
169
logErr(" Exception : " + e );
170
return FAILED;
171
}
172
}
173
return PASSED;
174
}
175
176
177
public static void nullMethod() {
178
throw new NullPointerException("test");
179
}
180
181
static Object lockingObject2 = new Object();
182
static Object locks[] = new Object[threadsN];
183
184
static volatile int n = 0;
185
186
static class Thread1request001a extends Thread {
187
188
int threadIndex;
189
190
public Thread1request001a(String threadName) {
191
super(threadName);
192
threadIndex = n;
193
locks[threadIndex] = new Object();
194
n++;
195
}
196
197
public void run() {
198
log3(" 'run': enter :: threadIndex == " + threadIndex);
199
200
synchronized (locks[threadIndex]) {
201
log3("enter synchronized (locks[threadIndex]) :: threadIndex == " + threadIndex);
202
synchronized (waitnotifyObj) {
203
waitnotifyObj.notify();
204
}
205
log3(" 'run': exit synchronized (waitnotifyObj)");
206
207
synchronized (lockingObject2) {
208
TestClass.method();
209
}
210
log3("exit synchronized (locks[threadIndex]) :: threadIndex == " + threadIndex);
211
}
212
return;
213
}
214
215
}
216
217
static class Thread2request001a extends Thread {
218
219
int threadIndex;
220
221
public Thread2request001a(String threadName) {
222
super(threadName);
223
threadIndex = n;
224
locks[threadIndex] = new Object();
225
n++;
226
}
227
228
public void run() {
229
log3(" 'run': enter :: threadIndex == " + threadIndex);
230
231
synchronized (locks[threadIndex]) {
232
log3("enter synchronized (locks[threadIndex]) :: threadIndex == " + threadIndex);
233
synchronized (waitnotifyObj) {
234
waitnotifyObj.notify();
235
}
236
m1();
237
log3("exit synchronized (locks[threadIndex]) :: threadIndex == " + threadIndex);
238
}
239
return;
240
}
241
242
private void m1() {
243
synchronized (lockingObject2) {
244
log3(" 'm1': enter");
245
246
log3(" 'm1': exit");
247
}
248
}
249
250
}
251
252
static class Thread3request001a extends Thread {
253
254
String tName = null;
255
256
public Thread3request001a(String threadName) {
257
super(threadName);
258
tName = threadName;
259
}
260
261
public void run() {
262
log3(" 'run': enter :: threadName == " + tName);
263
synchronized (waitnotifyObj) {
264
waitnotifyObj.notify();
265
}
266
log3(" 'run': exit :: threadName == " + tName);
267
}
268
}
269
270
271
public static void log3(String str) {
272
log1(Thread.currentThread().getName() + " : " + str);
273
}
274
275
}
276
277
class TestClass {
278
279
static int breakpointLine = 3;
280
static String awFieldName = "var1";
281
static String mwFieldName = "var2";
282
283
static int var1 = 0;
284
static int var2 = 0;
285
static int var3 = 0;
286
287
static void method () {
288
var1 += 1;
289
var3 += 1;
290
var2 = var3;
291
try {
292
request001a.nullMethod();
293
} catch ( NullPointerException e ) {
294
request001a.log3(" NullPointerException : " + e);
295
}
296
}
297
}
298
299