Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/threadStartRequests/thrstartreq001.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.EventRequestManager.threadStartRequests;
25
26
import com.sun.jdi.VirtualMachine;
27
import com.sun.jdi.VMDisconnectedException;
28
import com.sun.jdi.request.ThreadStartRequest;
29
import com.sun.jdi.request.EventRequestManager;
30
import com.sun.jdi.event.*;
31
32
import java.util.List;
33
import java.io.*;
34
35
import nsk.share.*;
36
import nsk.share.jpda.*;
37
import nsk.share.jdi.*;
38
39
/**
40
* The test checks that the JDI method
41
* <code>com.sun.jdi.request.EventRequestManager.threadStartRequests()</code>
42
* properly returns all ThreadStartRequest objects when:
43
* <li>event requests are disabled
44
* <li>event requests are enabled.<br>
45
* ThreadStartRequest objects are distinguished by the different
46
* <code>EventRequest</code>'s properties.<br>
47
* JDI EventHandler was added as workaround for the bug 4430096.
48
* This prevents the target VM from potential hangup.
49
*/
50
public class thrstartreq001 {
51
public static final int PASSED = 0;
52
public static final int FAILED = 2;
53
public static final int JCK_STATUS_BASE = 95;
54
static final String DEBUGGEE_CLASS =
55
"nsk.jdi.EventRequestManager.threadStartRequests.thrstartreq001t";
56
static final String COMMAND_READY = "ready";
57
static final String COMMAND_QUIT = "quit";
58
59
static final int THR_NUM = 7;
60
static final String PROPS[][] = {
61
{"first", "a quick"},
62
{"second", "brown"},
63
{"third", "fox"},
64
{"fourth", "jumps"},
65
{"fifth", "over"},
66
{"sixth", "the lazy"},
67
{"seventh", "dog"}
68
};
69
70
private Log log;
71
private IOPipe pipe;
72
private Debugee debuggee;
73
private VirtualMachine vm;
74
private EventListener elThread;
75
private volatile int tot_res = PASSED;
76
77
public static void main (String argv[]) {
78
System.exit(run(argv,System.out) + JCK_STATUS_BASE);
79
}
80
81
public static int run(String argv[], PrintStream out) {
82
return new thrstartreq001().runIt(argv, out);
83
}
84
85
private int runIt(String args[], PrintStream out) {
86
ArgumentHandler argHandler = new ArgumentHandler(args);
87
log = new Log(out, argHandler);
88
Binder binder = new Binder(argHandler, log);
89
ThreadStartRequest thrstartRequest[] = new ThreadStartRequest[THR_NUM];
90
String cmd;
91
92
debuggee = binder.bindToDebugee(DEBUGGEE_CLASS);
93
pipe = debuggee.createIOPipe();
94
debuggee.redirectStderr(log, "thrstartreq001t.err> ");
95
vm = debuggee.VM();
96
EventRequestManager erManager = vm.eventRequestManager();
97
debuggee.resume();
98
cmd = pipe.readln();
99
if (!cmd.equals(COMMAND_READY)) {
100
log.complain("TEST BUG: unknown debuggee's command: " + cmd);
101
tot_res = FAILED;
102
return quitDebuggee();
103
}
104
105
for (int i=0; i<THR_NUM; i++) {
106
log.display("Creating ThreadStartRequest #" + i
107
+ " with the property ("
108
+ PROPS[i][0] + "," + PROPS[i][1] + ")...");
109
thrstartRequest[i] = erManager.createThreadStartRequest();
110
thrstartRequest[i].putProperty(PROPS[i][0], PROPS[i][1]);
111
}
112
elThread = new EventListener();
113
elThread.start();
114
115
// Check ThreadStart requests when event requests are disabled
116
log.display("\n1) Getting ThreadStartRequest objects with disabled event requests...");
117
checkRequests(erManager, 1);
118
119
// Check ThreadStart requests when event requests are enabled
120
for (int i=0; i<THR_NUM; i++) {
121
thrstartRequest[i].enable();
122
}
123
log.display("\n2) Getting ThreadStartRequest objects with enabled event requests...");
124
checkRequests(erManager, 2);
125
126
// Finish the test
127
for (int i=0; i<THR_NUM; i++) {
128
thrstartRequest[i].disable();
129
}
130
return quitDebuggee();
131
}
132
133
private void checkRequests(EventRequestManager erManager, int t_case) {
134
List reqL = erManager.threadStartRequests();
135
if (reqL.size() != THR_NUM) {
136
log.complain("TEST CASE #" + t_case + " FAILED: found " + reqL.size()
137
+ " ThreadStartRequest objects\n\texpected: " + THR_NUM);
138
tot_res = FAILED;
139
return;
140
}
141
for (int i=0; i<THR_NUM; i++) {
142
ThreadStartRequest thrsReq =
143
(ThreadStartRequest) reqL.get(i);
144
boolean notFound = true;
145
for (int j=0; j<THR_NUM; j++) {
146
String propKey = (String) thrsReq.getProperty(PROPS[j][0]);
147
if (propKey != null) {
148
if (propKey.equals(PROPS[j][1])) {
149
log.display("Found expected ThreadStartRequest object with the property: ("
150
+ PROPS[j][0] + "," + propKey + ")");
151
} else {
152
log.complain("TEST CASE #" + t_case
153
+ " FAILED: found ThreadStartRequest object with the unexpected property: ("
154
+ PROPS[j][0] + "," + propKey + ")");
155
tot_res = FAILED;
156
}
157
notFound = false;
158
break;
159
}
160
}
161
if (notFound) {
162
log.complain("\nTEST CASE #" + t_case
163
+ " FAILED: found unexpected ThreadStartRequest object");
164
tot_res = FAILED;
165
}
166
}
167
}
168
169
private int quitDebuggee() {
170
if (elThread != null) {
171
elThread.isConnected = false;
172
try {
173
if (elThread.isAlive())
174
elThread.join();
175
} catch (InterruptedException e) {
176
log.complain("TEST INCOMPLETE: caught InterruptedException "
177
+ e);
178
tot_res = FAILED;
179
}
180
}
181
182
pipe.println(COMMAND_QUIT);
183
debuggee.waitFor();
184
int debStat = debuggee.getStatus();
185
if (debStat != (JCK_STATUS_BASE + PASSED)) {
186
log.complain("TEST FAILED: debuggee's process finished with status: "
187
+ debStat);
188
tot_res = FAILED;
189
} else
190
log.display("Debuggee's process finished with status: "
191
+ debStat);
192
193
return tot_res;
194
}
195
196
class EventListener extends Thread {
197
public volatile boolean isConnected = true;
198
199
public void run() {
200
try {
201
do {
202
EventSet eventSet = vm.eventQueue().remove(1000);
203
if (eventSet != null) { // there is not a timeout
204
EventIterator it = eventSet.eventIterator();
205
while (it.hasNext()) {
206
Event event = it.nextEvent();
207
if (event instanceof VMDeathEvent) {
208
tot_res = FAILED;
209
isConnected = false;
210
log.complain("TEST FAILED: unexpected VMDeathEvent");
211
} else if (event instanceof VMDisconnectEvent) {
212
tot_res = FAILED;
213
isConnected = false;
214
log.complain("TEST FAILED: unexpected VMDisconnectEvent");
215
} else
216
log.display("EventListener: following JDI event occured: "
217
+ event.toString());
218
}
219
if (isConnected) {
220
eventSet.resume();
221
}
222
}
223
} while (isConnected);
224
} catch (InterruptedException e) {
225
tot_res = FAILED;
226
log.complain("FAILURE in EventListener: caught unexpected "
227
+ e);
228
} catch (VMDisconnectedException e) {
229
tot_res = FAILED;
230
log.complain("FAILURE in EventListener: caught unexpected "
231
+ e);
232
e.printStackTrace();
233
}
234
log.display("EventListener: exiting");
235
}
236
}
237
}
238
239