Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/threadDeathRequests/thrdeathreq001.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.threadDeathRequests;
25
26
import com.sun.jdi.VirtualMachine;
27
import com.sun.jdi.VMDisconnectedException;
28
import com.sun.jdi.request.ThreadDeathRequest;
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.threadDeathRequests()</code>
42
* properly returns all ThreadDeathRequest objects when:
43
* <li>event requests are disabled
44
* <li>event requests are enabled.<br>
45
* ThreadDeathRequest 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 thrdeathreq001 {
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.threadDeathRequests.thrdeathreq001t";
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 thrdeathreq001().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
ThreadDeathRequest thrdeathRequest[] =
90
new ThreadDeathRequest[THR_NUM];
91
String cmd;
92
93
debuggee = binder.bindToDebugee(DEBUGGEE_CLASS);
94
pipe = debuggee.createIOPipe();
95
debuggee.redirectStderr(log, "thrdeathreq001t.err> ");
96
vm = debuggee.VM();
97
EventRequestManager erManager = vm.eventRequestManager();
98
debuggee.resume();
99
cmd = pipe.readln();
100
if (!cmd.equals(COMMAND_READY)) {
101
log.complain("TEST BUG: unknown debuggee's command: " + cmd);
102
tot_res = FAILED;
103
return quitDebuggee();
104
}
105
106
for (int i=0; i<THR_NUM; i++) {
107
log.display("Creating ThreadDeathRequest #" + i
108
+ " with the property ("
109
+ PROPS[i][0] + "," + PROPS[i][1] + ")...");
110
thrdeathRequest[i] = erManager.createThreadDeathRequest();
111
thrdeathRequest[i].putProperty(PROPS[i][0], PROPS[i][1]);
112
}
113
elThread = new EventListener();
114
elThread.start();
115
116
// Check ThreadDeath requests when event requests are disabled
117
log.display("\n1) Getting ThreadDeathRequest objects with disabled event requests...");
118
checkRequests(erManager, 1);
119
120
// Check ThreadDeath requests when event requests are enabled
121
for (int i=0; i<THR_NUM; i++) {
122
thrdeathRequest[i].enable();
123
}
124
log.display("\n2) Getting ThreadDeathRequest objects with enabled event requests...");
125
checkRequests(erManager, 2);
126
127
// Finish the test
128
for (int i=0; i<THR_NUM; i++) {
129
thrdeathRequest[i].disable();
130
}
131
return quitDebuggee();
132
}
133
134
private void checkRequests(EventRequestManager erManager, int t_case) {
135
List reqL = erManager.threadDeathRequests();
136
if (reqL.size() != THR_NUM) {
137
log.complain("TEST CASE #" + t_case + " FAILED: found " + reqL.size()
138
+ " ThreadDeathRequest objects\n\texpected: " + THR_NUM);
139
tot_res = FAILED;
140
return;
141
}
142
for (int i=0; i<THR_NUM; i++) {
143
ThreadDeathRequest thrdReq =
144
(ThreadDeathRequest) reqL.get(i);
145
boolean notFound = true;
146
for (int j=0; j<THR_NUM; j++) {
147
String propKey = (String) thrdReq.getProperty(PROPS[j][0]);
148
if (propKey != null) {
149
if (propKey.equals(PROPS[j][1])) {
150
log.display("Found expected ThreadDeathRequest object with the property: ("
151
+ PROPS[j][0] + "," + propKey + ")");
152
} else {
153
log.complain("TEST CASE #" + t_case
154
+ " FAILED: found ThreadDeathRequest object with the unexpected property: ("
155
+ PROPS[j][0] + "," + propKey + ")");
156
tot_res = FAILED;
157
}
158
notFound = false;
159
break;
160
}
161
}
162
if (notFound) {
163
log.complain("\nTEST CASE #" + t_case
164
+ " FAILED: found unexpected ThreadDeathRequest object");
165
tot_res = FAILED;
166
}
167
}
168
}
169
170
private int quitDebuggee() {
171
if (elThread != null) {
172
elThread.isConnected = false;
173
try {
174
if (elThread.isAlive())
175
elThread.join();
176
} catch (InterruptedException e) {
177
log.complain("TEST INCOMPLETE: caught InterruptedException "
178
+ e);
179
tot_res = FAILED;
180
}
181
}
182
183
pipe.println(COMMAND_QUIT);
184
debuggee.waitFor();
185
int debStat = debuggee.getStatus();
186
if (debStat != (JCK_STATUS_BASE + PASSED)) {
187
log.complain("TEST FAILED: debuggee's process finished with status: "
188
+ debStat);
189
tot_res = FAILED;
190
} else
191
log.display("Debuggee's process finished with status: "
192
+ debStat);
193
194
return tot_res;
195
}
196
197
class EventListener extends Thread {
198
public volatile boolean isConnected = true;
199
200
public void run() {
201
try {
202
do {
203
EventSet eventSet = vm.eventQueue().remove(1000);
204
if (eventSet != null) { // there is not a timeout
205
EventIterator it = eventSet.eventIterator();
206
while (it.hasNext()) {
207
Event event = it.nextEvent();
208
if (event instanceof VMDeathEvent) {
209
tot_res = FAILED;
210
isConnected = false;
211
log.complain("TEST FAILED: unexpected VMDeathEvent");
212
} else if (event instanceof VMDisconnectEvent) {
213
tot_res = FAILED;
214
isConnected = false;
215
log.complain("TEST FAILED: unexpected VMDisconnectEvent");
216
} else
217
log.display("EventListener: following JDI event occured: "
218
+ event.toString());
219
}
220
if (isConnected) {
221
eventSet.resume();
222
}
223
}
224
} while (isConnected);
225
} catch (InterruptedException e) {
226
tot_res = FAILED;
227
log.complain("FAILURE in EventListener: caught unexpected "
228
+ e);
229
} catch (VMDisconnectedException e) {
230
tot_res = FAILED;
231
log.complain("FAILURE in EventListener: caught unexpected "
232
+ e);
233
e.printStackTrace();
234
}
235
log.display("EventListener: exiting");
236
}
237
}
238
}
239
240